class DPLibrary::DocumentCollection

Attributes

count[RW]
documents[RW]
limit[RW]
offset[RW]

Public Class Methods

new(parameters) click to toggle source
Calls superclass method DPLibrary::Base::new
# File lib/DPLibrary/document_collection.rb, line 8
def initialize(parameters)
  json_response = find(parameters)

  response_values = super(json_response)

  set_method(response_values)
end

Private Instance Methods

create_documents(document_array) click to toggle source
# File lib/DPLibrary/document_collection.rb, line 51
def create_documents(document_array)
  documents = []

  document_array.each do |document|
    documents << Document.new(document)
  end

  documents
end
find(parameters) click to toggle source
# File lib/DPLibrary/document_collection.rb, line 18
def find(parameters)
  p = path!(parameters)
  get(p, parameters)
end
path!(parameters) click to toggle source

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

# File lib/DPLibrary/document_collection.rb, line 34
def path!(parameters)
  if parameters.include? :id
    id = parameters.delete(:id)
    "items/#{Array(id).join(',')}"
  else
    'items'
  end
end
set_method(values) click to toggle source
# File lib/DPLibrary/document_collection.rb, line 43
def set_method(values)
  self.count = values['count']
  self.offset = values['start']
  self.limit = values['limit']

  self.documents = create_documents(values['docs'])
end