Class: GnipApi::Response
- Inherits:
-
Object
- Object
- GnipApi::Response
- Defined in:
- lib/gnip_api/response.rb
Constant Summary collapse
- OK_STATUSES =
List of codes that are considered OK
[200, 201, 202, 203, 204, 205, 206, 207, 208, 226]
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #error_message ⇒ Object
-
#initialize(request, status, body, headers) ⇒ Response
constructor
A new instance of Response.
- #ok? ⇒ Boolean
- #request_method ⇒ Object
- #request_uri ⇒ Object
Constructor Details
permalink #initialize(request, status, body, headers) ⇒ Response
Returns a new instance of Response.
8 9 10 11 12 13 |
# File 'lib/gnip_api/response.rb', line 8 def initialize request, status, body, headers @status = status @body = body @headers = headers @request = request end |
Instance Attribute Details
permalink #body ⇒ Object (readonly)
Returns the value of attribute body.
6 7 8 |
# File 'lib/gnip_api/response.rb', line 6 def body @body end |
permalink #headers ⇒ Object (readonly)
Returns the value of attribute headers.
6 7 8 |
# File 'lib/gnip_api/response.rb', line 6 def headers @headers end |
permalink #request ⇒ Object (readonly)
Returns the value of attribute request.
6 7 8 |
# File 'lib/gnip_api/response.rb', line 6 def request @request end |
permalink #status ⇒ Object (readonly)
Returns the value of attribute status.
6 7 8 |
# File 'lib/gnip_api/response.rb', line 6 def status @status end |
Instance Method Details
permalink #error_message ⇒ Object
[View source]
27 28 29 30 31 32 33 |
# File 'lib/gnip_api/response.rb', line 27 def if @body && !@body.empty? parsed = GnipApi::JsonParser.parse(@body) return parsed['error']['message'] if parsed['error'] end return nil end |
permalink #ok? ⇒ Boolean
23 24 25 |
# File 'lib/gnip_api/response.rb', line 23 def ok? OK_STATUSES.include? @status end |
permalink #request_method ⇒ Object
[View source]
15 16 17 |
# File 'lib/gnip_api/response.rb', line 15 def request_method @request.request_method end |
permalink #request_uri ⇒ Object
[View source]
19 20 21 |
# File 'lib/gnip_api/response.rb', line 19 def request_uri @request.uri end |