Class: Pipekit::Result

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource, response_data) ⇒ Result

Returns a new instance of Result.



5
6
7
8
9
# File 'lib/pipekit/result.rb', line 5

def initialize(resource, response_data)
  @response_data = response_data
  @resource = resource
  raise UnsuccessfulRequestError.new(response_data) unless success?
end

Class Method Details

.response(resource, response_data) ⇒ Object



29
30
31
# File 'lib/pipekit/result.rb', line 29

def self.response(resource, response_data)
  new(resource, response_data).response
end

Instance Method Details

#+(other) ⇒ Object



17
18
19
# File 'lib/pipekit/result.rb', line 17

def +(other)
  self.class.new(resource, other.merged_response(response_body))
end

#fetch_next_request?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/pipekit/result.rb', line 21

def fetch_next_request?
  Config.fetch(:request_all_pages, true) && pagination_data["more_items_in_collection"]
end

#next_startObject



25
26
27
# File 'lib/pipekit/result.rb', line 25

def next_start
  pagination_data["next_start"]
end

#responseObject



11
12
13
14
15
# File 'lib/pipekit/result.rb', line 11

def response
  raise ResourceNotFoundError.new(response_data) unless resource_found?
  return Response.new(resource, response_body) unless response_body.is_a? Array
  response_body.map { |data| Response.new(resource, data) }
end