Class: FootStats::Request
- Inherits:
-
Object
- Object
- FootStats::Request
- Defined in:
- lib/foot_stats/request.rb
Overview
Class responsible to make the request to the FootStats API
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#resource_key ⇒ Object
readonly
Returns the value of attribute resource_key.
-
#resource_name ⇒ Object
readonly
Returns the value of attribute resource_name.
-
#response_body ⇒ Object
readonly
Returns the value of attribute response_body.
Instance Method Summary collapse
-
#initialize(resource, options = {}) ⇒ Request
constructor
A new instance of Request.
-
#parse(options = {}) ⇒ Response
Parse the “XML”/ “JSON”.
-
#post(options) ⇒ String
Make the post request to the request url.
-
#request_url ⇒ String
Return the request uri based on the resource.
-
#setup_params ⇒ Hash
Passing the setup params configured in your app.
Constructor Details
#initialize(resource, options = {}) ⇒ Request
Returns a new instance of Request.
11 12 13 14 15 16 |
# File 'lib/foot_stats/request.rb', line 11 def initialize(resource, ={}) @resource_name = resource.resource_name @resource_key = resource.resource_key @response_body = post() @logger = Setup.logger end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
9 10 11 |
# File 'lib/foot_stats/request.rb', line 9 def logger @logger end |
#resource_key ⇒ Object (readonly)
Returns the value of attribute resource_key.
9 10 11 |
# File 'lib/foot_stats/request.rb', line 9 def resource_key @resource_key end |
#resource_name ⇒ Object (readonly)
Returns the value of attribute resource_name.
9 10 11 |
# File 'lib/foot_stats/request.rb', line 9 def resource_name @resource_name end |
#response_body ⇒ Object (readonly)
Returns the value of attribute response_body.
9 10 11 |
# File 'lib/foot_stats/request.rb', line 9 def response_body @response_body end |
Instance Method Details
#parse(options = {}) ⇒ Response
Parse the “XML”/ “JSON”.
41 42 43 |
# File 'lib/foot_stats/request.rb', line 41 def parse( = {}) Response.new({resource_key: @resource_key, body: @response_body}.merge ) end |
#post(options) ⇒ String
Make the post request to the request url.
30 31 32 33 34 35 |
# File 'lib/foot_stats/request.rb', line 30 def post() log "POST #{request_url}" response = RestClient.post(request_url, setup_params.merge()) log "RESPONSE BODY:\n#{response}" response end |