Class: GiantBombApi::Client
- Inherits:
-
Object
- Object
- GiantBombApi::Client
- Defined in:
- lib/giant_bomb_api/client.rb
Constant Summary collapse
- API_URL =
'https://www.giantbomb.com/api/'.freeze
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
Instance Method Summary collapse
-
#initialize(api_key: nil, options: {}) ⇒ Client
constructor
A new instance of Client.
- #send_request(giant_bomb_api_request) ⇒ Object
Constructor Details
#initialize(api_key: nil, options: {}) ⇒ Client
Returns a new instance of Client.
13 14 15 16 |
# File 'lib/giant_bomb_api/client.rb', line 13 def initialize(api_key: nil, options: {}) @api_key = api_key @options = end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
9 10 11 |
# File 'lib/giant_bomb_api/client.rb', line 9 def api_key @api_key end |
Instance Method Details
#send_request(giant_bomb_api_request) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/giant_bomb_api/client.rb', line 18 def send_request(giant_bomb_api_request) connection = Faraday.new(url: API_URL) do |faraday| faraday.request :url_encoded faraday.use FaradayMiddleware::FollowRedirects faraday.adapter Faraday.default_adapter end response = connection.get do |req| req.url giant_bomb_api_request.end_point req.[:timeout] = 5 req.[:open_timeout] = 2 req.params = giant_bomb_api_request.params.merge(format: 'json', api_key: api_key) end response_json = JSON.parse(response.body) if(response_json["status_code"] == 1) response = handle_success_response(response_json) response.request = giant_bomb_api_request response else handle_error_response(response_json) end end |