diff --git a/CHANGELOG.md b/CHANGELOG.md index 34f4f427..191b00c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ # master +## 0.1.11.1 - 2019-11-20 +- Added faraday_options to client. Can be used to modify faraday connection. + ## 0.1.11 - 2018-05-18 - Added `add_attachment_to_message`. diff --git a/README.md b/README.md index 6f7af984..d7f609c7 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,23 @@ rentals = api.rentals # => [BookingSync::API::Resource, BookingSync::API::Resour rentals.first.name # => "Small apartment" ``` +## Options + +### Faraday options + +can be used to add any options supported by a faraday request https://www.rubydoc.info/gems/faraday/Faraday/Request + +for example +```ruby +options = { + faraday_options: { + request: { timeout: 5 } + } +} + +api = BookingSync::API.new("OAUTH_TOKEN", options) +``` + ### Pagination All endpoints returning a collection of resources can be paginated. There are three ways to do it. diff --git a/lib/bookingsync/api/client.rb b/lib/bookingsync/api/client.rb index 2eb2ad18..078e7b36 100644 --- a/lib/bookingsync/api/client.rb +++ b/lib/bookingsync/api/client.rb @@ -122,7 +122,7 @@ def initialize(token, options = {}) @instrumenter = options[:instrumenter] || NoopInstrumenter @base_url = options[:base_url] @serializer = Serializer.new - @conn = Faraday.new(faraday_options) + @conn = Faraday.new(faraday_options(options)) @conn.headers[:accept] = MEDIA_TYPE @conn.headers[:content_type] = MEDIA_TYPE @conn.headers[:user_agent] = user_agent @@ -307,8 +307,11 @@ def middleware end end - def faraday_options - { builder: middleware, ssl: { verify: verify_ssl? } } + def faraday_options(options) + { + builder: middleware, + ssl: { verify: verify_ssl? } + }.merge(options.fetch(:faraday_options, {})) end # Return BookingSync base URL. Default is https://www.bookingsync.com diff --git a/lib/bookingsync/api/version.rb b/lib/bookingsync/api/version.rb index f8a83b35..8a22c562 100644 --- a/lib/bookingsync/api/version.rb +++ b/lib/bookingsync/api/version.rb @@ -1,5 +1,5 @@ module BookingSync module API - VERSION = "0.1.11" + VERSION = "0.1.11.1" end end diff --git a/spec/bookingsync/api/client_spec.rb b/spec/bookingsync/api/client_spec.rb index 3bc386b1..c4a07431 100644 --- a/spec/bookingsync/api/client_spec.rb +++ b/spec/bookingsync/api/client_spec.rb @@ -3,6 +3,25 @@ describe BookingSync::API::Client do let(:client) { BookingSync::API::Client.new(test_access_token) } + describe "options" do + let(:client) { BookingSync::API::Client.new(test_access_token, options) } + + context "faraday_options" do + let(:options) do + { + faraday_options: + { + request: { timeout: 1 } + } + } + end + + it "sets timeout" do + expect(client.instance_variable_get("@conn").options[:timeout]).to eq 1 + end + end + end + describe "#new" do it "initializes client object with given token" do client = BookingSync::API::Client.new("xyz")