Class: RenderAPI::Response

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/render_api/response.rb

Instance Method Summary collapse

Constructor Details

#initialize(http_response) ⇒ Response

Returns a new instance of Response.



9
10
11
# File 'lib/render_api/response.rb', line 9

def initialize(http_response)
  @http_response = http_response
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, **kwargs, &block) ⇒ Object (private)



59
60
61
62
63
# File 'lib/render_api/response.rb', line 59

def method_missing(name, *args, **kwargs, &block)
  return super unless respond_to_missing?(name, false)

  data_objects.first.public_send(name, *args, **kwargs, &block)
end

Instance Method Details

#dataObject



13
14
15
# File 'lib/render_api/response.rb', line 13

def data
  @data ||= http_response.parse(:json)
end

#each(&block) ⇒ Object



17
18
19
# File 'lib/render_api/response.rb', line 17

def each(&block)
  data_objects.each(&block)
end

#headersObject



21
22
23
# File 'lib/render_api/response.rb', line 21

def headers
  @headers ||= http_response.headers.to_h
end

#lengthObject



25
26
27
# File 'lib/render_api/response.rb', line 25

def length
  data_objects.length
end

#rate_limitObject



29
30
31
# File 'lib/render_api/response.rb', line 29

def rate_limit
  headers["Ratelimit-Limit"].to_i
end

#rate_limit_remainingObject



33
34
35
# File 'lib/render_api/response.rb', line 33

def rate_limit_remaining
  headers["Ratelimit-Remaining"].to_i
end

#rate_limit_resetObject



37
38
39
# File 'lib/render_api/response.rb', line 37

def rate_limit_reset
  headers["Ratelimit-Reset"].to_i
end