Class: ApartmentRatings::Client
- Inherits:
-
Object
- Object
- ApartmentRatings::Client
- Defined in:
- lib/apartment_ratings/client.rb
Instance Method Summary collapse
- #complex(id) ⇒ Object
- #complexes ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/apartment_ratings/client.rb', line 5 def initialize( = {}) path = .fetch(:api_base_path) params = { username: .fetch(:username), password: .fetch(:password) } @client = Faraday.new(path, params) do |faraday| faraday.response :json, content_type: /\bjson\z/ faraday.response :logger if ApartmentRatings.config.debug faraday.adapter ApartmentRatings.config.faraday_adapter || Faraday.default_adapter end end |
Instance Method Details
#complex(id) ⇒ Object
26 27 28 29 |
# File 'lib/apartment_ratings/client.rb', line 26 def complex(id) result = @client.get('complex', complexId: id) Complex.new result end |
#complexes ⇒ Object
20 21 22 23 24 |
# File 'lib/apartment_ratings/client.rb', line 20 def complexes result = @client.get('index') # TODO: store the result and hangle unsuccessful response result['complexes'].map { |complex_json| Complex.new complex_json } end |