Class: SendGrid::Response
- Inherits:
-
Object
- Object
- SendGrid::Response
- Defined in:
- lib/ruby_http_client.rb
Overview
Holds the response from an API call.
Defined Under Namespace
Classes: Ratelimit
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
-
Args : -
response
-> A NET::HTTP response object.
-
-
#headers ⇒ Object
readonly
-
Args : -
response
-> A NET::HTTP response object.
-
-
#status_code ⇒ Object
readonly
-
Args : -
response
-> A NET::HTTP response object.
-
Instance Method Summary collapse
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
-
#parsed_body ⇒ Object
Returns the body as a hash.
- #ratelimit ⇒ Object
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
57 58 59 60 61 |
# File 'lib/ruby_http_client.rb', line 57 def initialize(response) @status_code = response.code @body = response.body @headers = response.to_hash end |
Instance Attribute Details
#body ⇒ Object (readonly)
-
Args :
-
response
-> A NET::HTTP response object
-
55 56 57 |
# File 'lib/ruby_http_client.rb', line 55 def body @body end |
#headers ⇒ Object (readonly)
-
Args :
-
response
-> A NET::HTTP response object
-
55 56 57 |
# File 'lib/ruby_http_client.rb', line 55 def headers @headers end |
#status_code ⇒ Object (readonly)
-
Args :
-
response
-> A NET::HTTP response object
-
55 56 57 |
# File 'lib/ruby_http_client.rb', line 55 def status_code @status_code end |
Instance Method Details
#parsed_body ⇒ Object
Returns the body as a hash
65 66 67 |
# File 'lib/ruby_http_client.rb', line 65 def parsed_body @parsed_body ||= JSON.parse(@body, symbolize_names: true) end |
#ratelimit ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/ruby_http_client.rb', line 69 def ratelimit return @ratelimit unless @ratelimit.nil? limit = headers['X-RateLimit-Limit'] remaining = headers['X-RateLimit-Remaining'] reset = headers['X-RateLimit-Reset'] # Guard against possibility that one (or probably, all) of the # needed headers were not returned. @ratelimit = Ratelimit.new(limit, remaining, reset) if limit && remaining && reset @ratelimit end |