Module: ApartmentRatings
- Defined in:
- lib/apartment_ratings.rb,
lib/apartment_ratings/client.rb,
lib/apartment_ratings/errors.rb,
lib/apartment_ratings/review.rb,
lib/apartment_ratings/address.rb,
lib/apartment_ratings/complex.rb,
lib/apartment_ratings/configuration.rb,
lib/apartment_ratings/reviews/rating.rb,
lib/apartment_ratings/reviews/response.rb
Defined Under Namespace
Modules: Errors, Reviews
Classes: Address, Client, Complex, Configuration, Review
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.config ⇒ Object
Returns the value of attribute config.
20
21
22
|
# File 'lib/apartment_ratings.rb', line 20
def config
@config
end
|
Class Method Details
23
24
25
|
# File 'lib/apartment_ratings.rb', line 23
def self.configure
@config = ApartmentRatings::Configuration.new.tap { |configuration| yield(configuration) }
end
|
.credentials ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/apartment_ratings.rb', line 27
def self.credentials
if config.nil?
fail ApartmentRatings::Errors::InvalidConfig
else
config.select { |key, _| [:username, :password].include?(key) }
end
end
|
.default_params ⇒ Object
61
62
63
64
65
66
|
# File 'lib/apartment_ratings.rb', line 61
def self.default_params
{
serviceToken: client.token,
username: credentials[:username]
}
end
|
.post(url = nil, params = {}, headers = nil, errors_opts = { token: 0 }, &block) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/apartment_ratings.rb', line 45
def self.post(url = nil, params = {}, = nil, errors_opts = { token: 0 }, &block)
payload = default_params.merge(params)
json_result = client.connection.post(url, payload, ).body
result = JSON.parse json_result
if !result['errors'].nil? && !result['errors']['serviceToken'].nil?
fail ApartmentRatings::Errors::InvalidToken unless errors_opts[:token] < ApartmentRatings.config.max_token_retry
client.refresh_token
return post(url, params, , { token: (errors_opts[:token] + 1) }, &block)
else
block.call(result)
end
end
|