Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions google-apis-core/OVERVIEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ should pin `google-apis-core` to a 0.x version in your Gemfile. For example:

gem "google-apis-core", "~> 0.18"

The `faraday` integration ships with, and only tests against the default adapter, which wraps [net-http](https://github.com/ruby/net-http). You can change the adapter by setting the `:adapter` client option:

```ruby
Google::Apis::ClientOptions.default.adapter = :net_http_persistent # or :httpx, or...
```

There a **caveat** though: downloading media requires a `faraday` adapter which [implements the `on_data` streaming API](https://lostisland.github.io/faraday/#/advanced/streaming-responses?id=streaming-responses).

## Documentation

More detailed descriptions of the Google legacy REST clients are available in two documents.
Expand Down
1 change: 1 addition & 0 deletions google-apis-core/lib/google/apis/core/base_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ def new_client
Faraday.new options do |faraday|
faraday.response :logger, Google::Apis.logger if client_options.log_http_requests
faraday.response :follow_redirects_google_apis_core, limit: 5
faraday.adapter client_options.adapter if client_options.adapter
end
end

Expand Down
7 changes: 5 additions & 2 deletions google-apis-core/lib/google/apis/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ module Apis
:read_timeout_sec,
:send_timeout_sec,
:log_http_requests,
:transparent_gzip_decompression)
:transparent_gzip_decompression,
:adapter)

RequestOptions = Struct.new(
:authorization,
Expand All @@ -50,6 +51,8 @@ class ClientOptions
# @return [String] Name of the application, for identification in the User-Agent header
# @!attribute [rw] application_version
# @return [String] Version of the application, for identification in the User-Agent header
# @!attribute [rw] adapter
# @return [Symbol, Class] Faraday adapter to use (https://lostisland.github.io/faraday/#/adapters/index?id=adapters)
# @!attribute [rw] proxy_url
# @return [String] URL of a proxy server
# @!attribute [rw] log_http_requests
Expand Down Expand Up @@ -82,7 +85,7 @@ class RequestOptions
# @!attribute [rw] max_interval
# @return [Integer] The maximum interval in seconds that any individual retry can reach.
# @!attribute [rw] multiplier
# @return [Numeric] Each successive interval grows by this factor. A multipler of 1.5 means the next interval
# @return [Numeric] Each successive interval grows by this factor. A multipler of 1.5 means the next interval
# will be 1.5x the current interval.
# @!attribute [rw] header
# @return [Hash<String,String>] Additional HTTP headers to include in requests.
Expand Down
12 changes: 12 additions & 0 deletions google-apis-core/spec/google/apis/core/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@
end
end

context 'with adapter' do
after(:example) do
Google::Apis::ClientOptions.default.adapter = nil
end

it 'should allow switching the adapter' do
Google::Apis::ClientOptions.default.adapter = Faraday::Adapter::Test
expect(service.client).to be_a(Faraday::Connection)
expect(service.client.builder.adapter).to eq(Faraday::Adapter::Test)
end
end

context 'when making simple commands' do
let(:command) { service.send(:make_simple_command, :get, 'zoo/animals', authorization: 'foo') }

Expand Down
Loading