Class: Thron::Response
- Inherits:
-
Object
- Object
- Thron::Response
- 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
-
#body ⇒ Object
Returns the value of attribute body.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#http_code ⇒ Object
readonly
Returns the value of attribute http_code.
-
#other_results ⇒ Object
readonly
Returns the value of attribute other_results.
-
#result_code ⇒ Object
readonly
Returns the value of attribute result_code.
-
#sso_code ⇒ Object
readonly
Returns the value of attribute sso_code.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
- #extra(options = {}) ⇒ Object
-
#initialize(raw_data) ⇒ Response
constructor
A new instance of Response.
- #is_200? ⇒ Boolean
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
#body ⇒ Object
Returns the value of attribute body.
6 7 8 |
# File 'lib/thron/response.rb', line 6 def body @body end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
7 8 9 |
# File 'lib/thron/response.rb', line 7 def error @error end |
#http_code ⇒ Object (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_results ⇒ Object (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_code ⇒ Object (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_code ⇒ Object (readonly)
Returns the value of attribute sso_code.
7 8 9 |
# File 'lib/thron/response.rb', line 7 def sso_code @sso_code end |
#total ⇒ Object (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( = {}) attribute = [:attribute].to_s name = attribute.snakecase self.class.send(:attr_reader, name) instance_variable_set(:"@#{name}", body.delete(attribute)) end |
#is_200? ⇒ Boolean
29 30 31 |
# File 'lib/thron/response.rb', line 29 def is_200? (@http_code.to_i / 100) == 2 end |