Class: Zanox::Response
- Inherits:
-
Object
- Object
- Zanox::Response
- Defined in:
- lib/zanox/response.rb
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#initialize(response, original_params = []) ⇒ Response
constructor
A new instance of Response.
- #inspect ⇒ Object
- #method_missing(m, *args, &block) ⇒ Object
- #next_page ⇒ Object
- #previous_page ⇒ Object
Constructor Details
#initialize(response, original_params = []) ⇒ Response
Returns a new instance of Response.
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/zanox/response.rb', line 29 def initialize(response, original_params = []) @response = response @original_params = original_params status_code = @response.parsed_response['code'] if status_code if status_code >= 400 && status_code <= 499 raise API::AccessDeniedError, @response.parsed_response['message'] elsif status_code >= 100 && status_code <= 199 raise API::InvalidRequestError, @response.parsed_response['reason'] end end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/zanox/response.rb', line 61 def method_missing(m, *args, &block) key = m.to_s response = @response[key] || @response["@#{key}"] || @response[camelize(key)] results = if response.kind_of?(Hash) && response.length == 1 response.values.first # sugar to get items (i.e. programItems) else response end (key.end_with?('_item') || key.end_with?('_items')) && (!results || !results.kind_of?(Enumerable)) ? [] : results end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
27 28 29 |
# File 'lib/zanox/response.rb', line 27 def response @response end |
Instance Method Details
#inspect ⇒ Object
57 58 59 |
# File 'lib/zanox/response.rb', line 57 def inspect response end |