Class: Retsly::Client
- Inherits:
-
Object
- Object
- Retsly::Client
- Defined in:
- lib/retsly/client.rb
Overview
rubocop:disable Style/MethodName
Constant Summary collapse
- BASE_URI =
'https://rets.io/api/v1/'.freeze
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#vendor ⇒ Object
Returns the value of attribute vendor.
Instance Method Summary collapse
- #api_failure(response) ⇒ Object
- #get(page, query_params = nil) ⇒ Object
-
#initialize(access_token:, vendor: nil) ⇒ Client
constructor
A new instance of Client.
- #Listing ⇒ Object
- #raw(page, query_params = nil) ⇒ Object
- #Vendor ⇒ Object
Constructor Details
#initialize(access_token:, vendor: nil) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 |
# File 'lib/retsly/client.rb', line 9 def initialize(access_token:, vendor: nil) @access_token = access_token @vendor = vendor raise 'Acces Token required' unless @access_token end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
6 7 8 |
# File 'lib/retsly/client.rb', line 6 def access_token @access_token end |
#vendor ⇒ Object
Returns the value of attribute vendor.
7 8 9 |
# File 'lib/retsly/client.rb', line 7 def vendor @vendor end |
Instance Method Details
#api_failure(response) ⇒ Object
35 36 37 |
# File 'lib/retsly/client.rb', line 35 def api_failure(response) raise "API Error: #{response.status} :: #{[response.bundle.name, response.bundle.message].join('-')}" end |
#get(page, query_params = nil) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/retsly/client.rb', line 15 def get(page, query_params = nil) raise 'A Page is required' unless page json = ::JSON.parse(raw(page, query_params)) response = ::Hashie::Rash.new(json) api_failure(response) unless response.success == true response.bundle end |
#Listing ⇒ Object
31 32 33 |
# File 'lib/retsly/client.rb', line 31 def Listing Retsly::Listing.new(client: self) end |
#raw(page, query_params = nil) ⇒ Object
23 24 25 |
# File 'lib/retsly/client.rb', line 23 def raw(page, query_params = nil) Net::HTTP.get(URI.parse("#{BASE_URI}#{page}?access_token=#{@access_token}#{query_params}")) end |
#Vendor ⇒ Object
27 28 29 |
# File 'lib/retsly/client.rb', line 27 def Vendor Retsly::Vendor.new(client: self) end |