Class: Cephalopod::Response

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/cephalopod/response.rb

Defined Under Namespace

Modules: Pagination

Instance Method Summary collapse

Constructor Details

#initialize(response:, repo:, &block) ⇒ Response

Returns a new instance of Response.



26
27
28
29
30
31
# File 'lib/cephalopod/response.rb', line 26

def initialize(response:, repo:, &block)
  @response = response
  @repo     = repo
  extend Pagination if paginated?
  super(block_given? ? yield(@response.body) : parse_response)
end

Instance Method Details

#paginated?Boolean

Returns:

  • (Boolean)


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

def paginated?
  @response.body.is_a?(Hash) && pagination_links? && @response.body.key?(:results)
end

#pagination_links?Boolean

Returns:

  • (Boolean)


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

def pagination_links?
  @response.body.key?(:next) || @response.body.key?(:previous)
end

#payloadObject



45
46
47
# File 'lib/cephalopod/response.rb', line 45

def payload
  @response.body
end

#queryObject



41
42
43
# File 'lib/cephalopod/response.rb', line 41

def query
  @query ||= URI::decode_www_form(@response.env.url.query).to_h.symbolize_keys
end