Class: Thron::Response

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

Constant Summary collapse

ERROR_KEY =
'errorDescription'
ID_REGEX =
/\A\w{8}-\w{4}-\w{4}-\w{4}-\w{12}\Z/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_data) ⇒ Response

Returns a new instance of Response.



12
13
14
15
16
17
18
19
20
# File 'lib/thron/response.rb', line 12

def initialize(raw_data)
  @http_code     = raw_data.code
  @body          = fetch(raw_data)
  @result_code   = @body.delete('resultCode')
  @sso_code      = @body.delete('ssoCode')
  @total         = @body.delete('totalResults')
  @other_results = @body.delete('otherResults') { false }
  @error         = @body.delete(ERROR_KEY)
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



6
7
8
# File 'lib/thron/response.rb', line 6

def body
  @body
end

#errorObject (readonly)

Returns the value of attribute error.



7
8
9
# File 'lib/thron/response.rb', line 7

def error
  @error
end

#http_codeObject (readonly)

Returns the value of attribute http_code.



7
8
9
# File 'lib/thron/response.rb', line 7

def http_code
  @http_code
end

#other_resultsObject (readonly)

Returns the value of attribute other_results.



7
8
9
# File 'lib/thron/response.rb', line 7

def other_results
  @other_results
end

#result_codeObject (readonly)

Returns the value of attribute result_code.



7
8
9
# File 'lib/thron/response.rb', line 7

def result_code
  @result_code
end

#sso_codeObject (readonly)

Returns the value of attribute sso_code.



7
8
9
# File 'lib/thron/response.rb', line 7

def sso_code
  @sso_code
end

#totalObject (readonly)

Returns the value of attribute total.



7
8
9
# File 'lib/thron/response.rb', line 7

def total
  @total
end

Instance Method Details

#extra(options = {}) ⇒ Object



22
23
24
25
26
27
# File 'lib/thron/response.rb', line 22

def extra(options = {})
  attribute = options[:attribute].to_s
  name = attribute.snakecase 
  self.class.send(:attr_reader, name)
  instance_variable_set(:"@#{name}", body.delete(attribute))
end

#is_200?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/thron/response.rb', line 29

def is_200?
  (@http_code.to_i / 100) == 2
end