Class: ReviewsCatcher::BaseService
- Inherits:
-
Object
- Object
- ReviewsCatcher::BaseService
- Defined in:
- lib/reviews_catcher/base_service.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #auth ⇒ Object
- #get(action) ⇒ Object
- #get_api_rating ⇒ Object
- #get_api_reviews ⇒ Object
-
#initialize(client) ⇒ BaseService
constructor
A new instance of BaseService.
- #url(action) ⇒ Object
Constructor Details
#initialize(client) ⇒ BaseService
Returns a new instance of BaseService.
9 10 11 |
# File 'lib/reviews_catcher/base_service.rb', line 9 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
7 8 9 |
# File 'lib/reviews_catcher/base_service.rb', line 7 def client @client end |
Instance Method Details
#auth ⇒ Object
13 14 15 |
# File 'lib/reviews_catcher/base_service.rb', line 13 def auth 'api_key=' + @client.api_key end |
#get(action) ⇒ Object
21 22 23 |
# File 'lib/reviews_catcher/base_service.rb', line 21 def get(action) HTTP.auth(auth).get(url(action)) end |
#get_api_rating ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/reviews_catcher/base_service.rb', line 25 def response = get('/api/v1/rating') if response.code == 200 response else fail InvalidApiRequestError.new("invalid response from API (CODE: #{response.code})") end end |
#get_api_reviews ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/reviews_catcher/base_service.rb', line 35 def get_api_reviews response = get('/api/v1/reviews') if response.code == 200 response else fail InvalidApiRequestError.new("invalid response from API (CODE: #{response.code})") end end |
#url(action) ⇒ Object
17 18 19 |
# File 'lib/reviews_catcher/base_service.rb', line 17 def url(action) @client.base_url + action end |