Class: Smarteru::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/smarteru/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dataObject (readonly)

Returns the value of attribute data.



3
4
5
# File 'lib/smarteru/response.rb', line 3

def data
  @data
end

#hashObject (readonly)

Hash representation of response data



19
20
21
# File 'lib/smarteru/response.rb', line 19

def hash
  @hash
end

#optsObject (readonly)

Returns the value of attribute opts.



3
4
5
# File 'lib/smarteru/response.rb', line 3

def opts
  @opts
end

Instance Method Details

#errorObject



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

#resultObject



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

Returns:

  • (Boolean)


24
25
26
27
28
# File 'lib/smarteru/response.rb', line 24

def success?
  hash[:smarter_u][:result] == 'Success'
rescue
  false
end