Class: BookingSync::Engine::APIClient

Inherits:
API::Client
  • Object
show all
Defined in:
lib/bookingsync/engine/api_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(token, options = {}) ⇒ APIClient

Returns a new instance of APIClient.



2
3
4
5
# File 'lib/bookingsync/engine/api_client.rb', line 2

def initialize(token, options = {})
  super
  @account = options[:account]
end

Instance Method Details

#call(method, path, data = nil, options = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/bookingsync/engine/api_client.rb', line 7

def call(method, path, data = nil, options = nil)
  tries ||= 1
  super
rescue BookingSync::API::Unauthorized => e
  token_expired = e.headers["www-authenticate"].include?("The access token expired")
  if token_expired && (tries -= 1) >= 0
    @token = @account.refresh_token!.token
    retry
  else
    raise
  end
end