Class: Pingen::Response
- Inherits:
-
Object
- Object
- Pingen::Response
- Defined in:
- lib/pingen/response.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#json ⇒ Object
Returns the value of attribute json.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(json, code) ⇒ Response
constructor
A new instance of Response.
- #ok? ⇒ Boolean
Constructor Details
#initialize(json, code) ⇒ Response
Returns a new instance of Response.
13 14 15 16 |
# File 'lib/pingen/response.rb', line 13 def initialize(json, code) @json = json @code = code end |
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
5 6 7 |
# File 'lib/pingen/response.rb', line 5 def code @code end |
#json ⇒ Object
Returns the value of attribute json.
5 6 7 |
# File 'lib/pingen/response.rb', line 5 def json @json end |
Class Method Details
.from(response) ⇒ Object
7 8 9 10 11 |
# File 'lib/pingen/response.rb', line 7 def self.from(response) new(JSON.parse(response.body, symbolize_names: true), response.code.to_i) rescue JSON::ParserError new(response.body, response.code.to_i) end |
Instance Method Details
#ok? ⇒ Boolean
18 19 20 |
# File 'lib/pingen/response.rb', line 18 def ok? code == 200 end |