class AirbnbApi::Client

Attributes

id[R]
oauth_token[R]
secret[R]

Public Class Methods

new(id:, secret: nil, oauth_token: nil) click to toggle source
# File lib/airbnb_api/client.rb, line 6
def initialize(id:, secret: nil, oauth_token: nil)
  @id = id
  @secret = secret
  @oauth_token = oauth_token
end

Public Instance Methods

adapter() click to toggle source
# File lib/airbnb_api/client.rb, line 20
def adapter
  @adapter ||= Faraday.default_adapter
end
base_url() click to toggle source
# File lib/airbnb_api/client.rb, line 16
def base_url
  'https://api.airbnb.com'
end
http() click to toggle source
# File lib/airbnb_api/client.rb, line 24
def http
  @http ||= Faraday.new(url: base_url) do |faraday|
    faraday.headers = headers
    faraday.request :url_encoded
    faraday.response :json

    faraday.use AirbnbApi::Util::ErrorHandling

    faraday.adapter adapter
  end
end
listings() click to toggle source
# File lib/airbnb_api/client.rb, line 50
def listings
  AirbnbApi::Service::Listing.new(self)
end
oauth_token?() click to toggle source
# File lib/airbnb_api/client.rb, line 46
def oauth_token?
  @oauth_token != nil
end
tokens() click to toggle source
# File lib/airbnb_api/client.rb, line 54
def tokens
  return AirbnbApi::Service::Token.new(self) if AirbnbApi::Service::Token.can_use_client?(self)
  raise AirbnbApi::Errors::InvalidClient
end
version() click to toggle source
# File lib/airbnb_api/client.rb, line 12
def version
  @version ||= 'v2'
end

Private Instance Methods

basic_auth_header() click to toggle source
# File lib/airbnb_api/client.rb, line 76
def basic_auth_header
  @basic_auth_header ||= Base64.strict_encode64("#{id}:#{secret}")
end
headers() click to toggle source
# File lib/airbnb_api/client.rb, line 61
def headers
  default = {
    'Accept' => 'application/json',
    'Content-Type' => 'application/json'
  }

  if oauth_token
    default['X-Airbnb-Oauth-Token'] = oauth_token
    default['X-Airbnb-API-Key'] = id
  else
    default['Authorization'] = "Basic #{basic_auth_header}"
  end
  default
end