lib/pipekit/result.rb in pipekit-1.0.2 vs lib/pipekit/result.rb in pipekit-1.2.0
- old
+ new
@@ -1,22 +1,23 @@
# Understands how to represent the result of a request to the Pipedrive API
module Pipekit
class Result
- def initialize(response_data)
+ def initialize(resource, response_data)
@response_data = response_data
+ @resource = resource
raise UnsuccessfulRequestError.new(response_data) unless success?
end
- def response(resource)
+ 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
def +(other)
- self.class.new(other.merged_response(response_body))
+ self.class.new(resource, other.merged_response(response_body))
end
def fetch_next_request?
Config.fetch(:request_all_pages, true) && pagination_data["more_items_in_collection"]
end
@@ -24,11 +25,11 @@
def next_start
pagination_data["next_start"]
end
def self.response(resource, response_data)
- new(response_data).response(resource)
+ new(resource, response_data).response
end
protected
def merged_response(other_body)
@@ -37,10 +38,10 @@
end
end
private
- attr_reader :response_data
+ attr_reader :response_data, :resource
def pagination_data
response_data
.fetch("additional_data", {})
.fetch("pagination", {})