Class: SendGrid::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_http_client.rb

Overview

Holds the response from an API call.

Defined Under Namespace

Classes: Ratelimit

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#bodyObject (readonly)

  • Args :

    • response -> A NET::HTTP response object



55
56
57
# File 'lib/ruby_http_client.rb', line 55

def body
  @body
end

#headersObject (readonly)

  • Args :

    • response -> A NET::HTTP response object



55
56
57
# File 'lib/ruby_http_client.rb', line 55

def headers
  @headers
end

#status_codeObject (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_bodyObject

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

#ratelimitObject



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