Class: ApartmentRatings::Client
- Inherits:
-
Object
- Object
- ApartmentRatings::Client
- Defined in:
- lib/apartment_ratings/client.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #refresh_token ⇒ Object
- #token ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/apartment_ratings/client.rb', line 8 def initialize( = {}) path = .fetch(:api_base_path) @connection = Faraday.new(path) do |faraday| faraday.request :url_encoded # Unfortunately, we need to encode post and put params faraday.request :json # NOTE: Unfortunately, the response content type is not json... But we know it is. faraday.response :json, content_type: /\Atext\/html;charset=ISO-8859-1\z/ faraday.response :logger if ApartmentRatings.config.debug faraday.adapter ApartmentRatings.config.faraday_adapter || Faraday.default_adapter end end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
6 7 8 |
# File 'lib/apartment_ratings/client.rb', line 6 def connection @connection end |
Instance Method Details
#refresh_token ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/apartment_ratings/client.rb', line 27 def refresh_token @token = nil result = JSON.parse @connection.post('login', ApartmentRatings.credentials.merge(format: 'json')).body if result['success'] @token = result['response'] else fail ApartmentRatings::Errors::InvalidToken end end |
#token ⇒ Object
23 24 25 |
# File 'lib/apartment_ratings/client.rb', line 23 def token @token ||= refresh_token end |