Skip to content
Open
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 6 additions & 3 deletions lib/bookingsync/api/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/bookingsync/api/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module BookingSync
module API
VERSION = "0.1.11"
VERSION = "0.1.11.1"
end
end
19 changes: 19 additions & 0 deletions spec/bookingsync/api/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down