Class: Smarteru::Response
- Inherits:
-
Object
- Object
- Smarteru::Response
- Defined in:
- lib/smarteru/response.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#hash ⇒ Object
readonly
Hash representation of response data.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
- #error ⇒ Object
-
#initialize(res, opts = {}) ⇒ Response
constructor
Initializes an API response.
- #result ⇒ Object
-
#success? ⇒ Boolean
Return true/false based on the API response status.
Constructor Details
#initialize(res, opts = {}) ⇒ Response
Initializes an API response
Attributes
-
resp
- RestClient response from the API
9 10 11 12 13 14 15 16 |
# File 'lib/smarteru/response.rb', line 9 def initialize(res, opts = {}) @data = res opts[:parser] ||= Nori.new( parser: :rexml, convert_tags_to: lambda { |tag| tag.snakecase.to_sym } ) @opts = opts end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
3 4 5 |
# File 'lib/smarteru/response.rb', line 3 def data @data end |
#hash ⇒ Object (readonly)
Hash representation of response data
19 20 21 |
# File 'lib/smarteru/response.rb', line 19 def hash @hash end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
3 4 5 |
# File 'lib/smarteru/response.rb', line 3 def opts @opts end |
Instance Method Details
#error ⇒ Object
34 35 36 37 |
# File 'lib/smarteru/response.rb', line 34 def error errors = hash[:smarter_u][:errors] errors.is_a?(Hash) ? errors : nil end |
#result ⇒ Object
30 31 32 |
# File 'lib/smarteru/response.rb', line 30 def result hash[:smarter_u][:info] end |
#success? ⇒ Boolean
Return true/false based on the API response status
24 25 26 27 28 |
# File 'lib/smarteru/response.rb', line 24 def success? hash[:smarter_u][:result] == 'Success' rescue false end |