Class: ApartmentRatings::Client

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

Instance Method Summary collapse

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(options = {})
  path = options.fetch(:api_base_path)
  params = {
    username: options.fetch(:username),
    password: options.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

#complexesObject



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