Class: AirbnbApi::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/airbnb_api/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, secret: nil, oauth_token: nil) ⇒ Client

Returns a new instance of Client.



6
7
8
9
10
# 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

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/airbnb_api/client.rb', line 5

def id
  @id
end

#oauth_tokenObject (readonly)

Returns the value of attribute oauth_token.



5
6
7
# File 'lib/airbnb_api/client.rb', line 5

def oauth_token
  @oauth_token
end

#secretObject (readonly)

Returns the value of attribute secret.



5
6
7
# File 'lib/airbnb_api/client.rb', line 5

def secret
  @secret
end

Instance Method Details

#adapterObject



20
21
22
# File 'lib/airbnb_api/client.rb', line 20

def adapter
  @adapter ||= Faraday.default_adapter
end

#base_urlObject



16
17
18
# File 'lib/airbnb_api/client.rb', line 16

def base_url
  'https://api.airbnb.com'
end

#httpObject



24
25
26
27
28
29
30
31
32
33
34
# 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

#listingsObject



50
51
52
# File 'lib/airbnb_api/client.rb', line 50

def listings
  AirbnbApi::Service::Listing.new(self)
end

#oauth_token?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/airbnb_api/client.rb', line 46

def oauth_token?
  @oauth_token != nil
end

#tokensObject



54
55
56
57
# 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

#versionObject



12
13
14
# File 'lib/airbnb_api/client.rb', line 12

def version
  @version ||= 'v2'
end