Sha256: 86f4f32562059efb3557921053c8b2b0ff62867e6cddbac0c2a17f960cb6f497
Contents?: true
Size: 1.33 KB
Versions: 1
Compression:
Stored size: 1.33 KB
Contents
module DPLibrary class DocumentCollection < Base attr_accessor :count, :offset, :limit, :documents def initialize(parameters) json_response = find(parameters) response_values = super(json_response) set_method(response_values) end private def find(parameters) p = path!(parameters) get(p, parameters) end ## # Return the appropriate URI path, which depends upon whether IDs are given # # Remove an `id' parameter from the parameters if it exists, because it # will become part of the path, and should not be included in the # querystring parameters. # # @param [Hash] parameters Query parameters # @return [String] # @api private # def path!(parameters) if parameters.include? :id id = parameters.delete(:id) "items/#{Array(id).join(',')}" else 'items' end end def set_method(values) self.count = values['count'] self.offset = values['start'] self.limit = values['limit'] self.documents = create_documents(values['docs']) end def create_documents(document_array) documents = [] document_array.each do |document| documents << Document.new(document) end documents end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
DPLibrary-0.1.0 | lib/DPLibrary/document_collection.rb |