Class: Checkmobi::SDK::Response
- Inherits:
-
Object
- Object
- Checkmobi::SDK::Response
- Defined in:
- lib/checkmobi/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#code ⇒ Object
Returns the value of attribute code.
Instance Method Summary collapse
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
- #to_h ⇒ Object
-
#to_h! ⇒ Hash
Replace @body with Ruby Hash.
-
#to_yaml ⇒ String
Return response as Yaml.
-
#to_yaml! ⇒ String
Replace @body with YAML.
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
7 8 9 10 |
# File 'lib/checkmobi/response.rb', line 7 def initialize(response) @body = response.body @code = response.code end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
5 6 7 |
# File 'lib/checkmobi/response.rb', line 5 def body @body end |
#code ⇒ Object
Returns the value of attribute code.
5 6 7 |
# File 'lib/checkmobi/response.rb', line 5 def code @code end |
Instance Method Details
#to_h ⇒ Object
12 13 14 15 16 |
# File 'lib/checkmobi/response.rb', line 12 def to_h JSON.parse(@body) rescue => err raise err end |
#to_h! ⇒ Hash
Replace @body with Ruby Hash
21 22 23 24 25 |
# File 'lib/checkmobi/response.rb', line 21 def to_h! @body = JSON.parse(@body) rescue => err raise ParseError.new(err), err end |
#to_yaml ⇒ String
Return response as Yaml
30 31 32 33 34 |
# File 'lib/checkmobi/response.rb', line 30 def to_yaml YAML.dump(to_h) rescue => err raise err end |
#to_yaml! ⇒ String
Replace @body with YAML
39 40 41 42 43 |
# File 'lib/checkmobi/response.rb', line 39 def to_yaml! @body = YAML.dump(to_h) rescue => err raise ParseError.new(err), err end |