Class: FootStats::Response
- Inherits:
-
Object
- Object
- FootStats::Response
- Defined in:
- lib/foot_stats/response.rb
Constant Summary collapse
- REGEX_PARSER =
/\{.*}/m
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#parsed_response ⇒ Object
Returns the value of attribute parsed_response.
-
#payload ⇒ Object
Returns the value of attribute payload.
-
#resource_key ⇒ Object
Returns the value of attribute resource_key.
Instance Method Summary collapse
-
#[](value) ⇒ Object
Attempt to fetch a key from resource.
-
#collect ⇒ Array
(also: #map)
Collect all the resources evaluate from FootStats.
-
#error ⇒ ErrorResponse
Return the error response object with the message if had errors.
-
#error? ⇒ True, False
Verifies if the response had errors.
-
#initialize(options = {}) ⇒ Response
constructor
A new instance of Response.
-
#readed ⇒ Object
Mark response as readed, storing payload at payload store.
-
#resource ⇒ Hash
Return the resource match by the resource key.
-
#updated? ⇒ Boolean
Verifies if response is up-to-date.
Constructor Details
#initialize(options = {}) ⇒ Response
Returns a new instance of Response.
6 7 8 9 10 11 12 |
# File 'lib/foot_stats/response.rb', line 6 def initialize(={}) @resource_key = .fetch(:resource_key) @body = .fetch(:body) @stream_key = [:stream_key] parse_response check_stream end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
3 4 5 |
# File 'lib/foot_stats/response.rb', line 3 def body @body end |
#parsed_response ⇒ Object
Returns the value of attribute parsed_response.
3 4 5 |
# File 'lib/foot_stats/response.rb', line 3 def parsed_response @parsed_response end |
#payload ⇒ Object
Returns the value of attribute payload.
3 4 5 |
# File 'lib/foot_stats/response.rb', line 3 def payload @payload end |
#resource_key ⇒ Object
Returns the value of attribute resource_key.
3 4 5 |
# File 'lib/foot_stats/response.rb', line 3 def resource_key @resource_key end |
Instance Method Details
#[](value) ⇒ Object
Attempt to fetch a key from resource.
67 68 69 |
# File 'lib/foot_stats/response.rb', line 67 def [](value) resource[value] end |
#collect ⇒ Array Also known as: map
Collect all the resources evaluate from FootStats
75 76 77 78 79 80 81 |
# File 'lib/foot_stats/response.rb', line 75 def collect if resource resource.collect { |resource_value| yield(resource_value) } else [] end end |
#error ⇒ ErrorResponse
Return the error response object with the message if had errors.
27 28 29 |
# File 'lib/foot_stats/response.rb', line 27 def error ErrorResponse.new(@parsed_response['Erro']['@Mensagem']) if error? end |
#error? ⇒ True, False
Verifies if the response had errors.
47 48 49 |
# File 'lib/foot_stats/response.rb', line 47 def error? @parsed_response['Erro'] != nil end |
#readed ⇒ Object
Mark response as readed, storing payload at payload store
15 16 17 18 19 20 21 |
# File 'lib/foot_stats/response.rb', line 15 def readed if @stream_key stream.store @payload else true end end |
#resource ⇒ Hash
Return the resource match by the resource key.
55 56 57 58 59 60 61 |
# File 'lib/foot_stats/response.rb', line 55 def resource if @resource_key @parsed_response[@resource_key] else @parsed_response end end |
#updated? ⇒ Boolean
Verifies if response is up-to-date
35 36 37 38 39 40 41 |
# File 'lib/foot_stats/response.rb', line 35 def updated? if @stream_key stream.updated?(@payload) else true end end |