Sha256: c2da2176e4b68984d7b47bd667b3bb54828779ded4afd80e8b6271aab0cb51d4

Contents?: true

Size: 613 Bytes

Versions: 8

Compression:

Stored size: 613 Bytes

Contents

# ApiClient::Collection handle a collection of objects
class ApiClient::Collection
  include Enumerable

  attr_accessor :collection

  # Initialize a collection of given objects
  #
  # @param [Class] klass The class to instantiate the objects.
  # @param [String] resource_path The url to get the data.
  # @return [Collection] the collection of objects.
  def initialize(klass, resource_path)
    url = "#{ApiClient.config.path}#{resource_path}"
    @collection = ApiClient::Parser.response(ApiClient::Dispatcher.get(url), url)
    @collection.map! do |attributes|
      klass.new(attributes)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
api-client-2.3.0 lib/api-client/collection.rb
api-client-2.2.0 lib/api-client/collection.rb
api-client-2.1.0 lib/api-client/collection.rb
api-client-2.0.3 lib/api-client/collection.rb
api-client-2.0.2 lib/api-client/collection.rb
api-client-2.0.1 lib/api-client/collection.rb
api-client-2.0.0 lib/api-client/collection.rb
api-client-2.0.0.rc2 lib/api-client/collection.rb