Class: M2X::Client::Response
- Inherits:
-
Object
- Object
- M2X::Client::Response
- Defined in:
- lib/m2x/response.rb
Overview
Response wrapper for M2X client
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #client_error? ⇒ Boolean
- #error? ⇒ Boolean
- #headers ⇒ Object
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
- #json ⇒ Object
- #raw ⇒ Object
- #server_error? ⇒ Boolean
- #status ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
5 6 7 |
# File 'lib/m2x/response.rb', line 5 def initialize(response) @response = response end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
3 4 5 |
# File 'lib/m2x/response.rb', line 3 def response @response end |
Instance Method Details
#client_error? ⇒ Boolean
29 30 31 |
# File 'lib/m2x/response.rb', line 29 def client_error? (400..499).include?(status) end |
#error? ⇒ Boolean
37 38 39 |
# File 'lib/m2x/response.rb', line 37 def error? client_error? || server_error? end |
#headers ⇒ Object
21 22 23 |
# File 'lib/m2x/response.rb', line 21 def headers @headers ||= @response.to_hash end |
#json ⇒ Object
13 14 15 |
# File 'lib/m2x/response.rb', line 13 def json @json ||= ::JSON.parse(raw) end |
#raw ⇒ Object
9 10 11 |
# File 'lib/m2x/response.rb', line 9 def raw @response.body end |
#server_error? ⇒ Boolean
33 34 35 |
# File 'lib/m2x/response.rb', line 33 def server_error? (500..599).include?(status) end |
#status ⇒ Object
17 18 19 |
# File 'lib/m2x/response.rb', line 17 def status @status ||= @response.code.to_i end |
#success? ⇒ Boolean
25 26 27 |
# File 'lib/m2x/response.rb', line 25 def success? (200..299).include?(status) end |