Sha256: 1e9e3f5968a4e0257fac198283ae83f7941a03b0afe96f11a987b174ac293aac

Contents?: true

Size: 670 Bytes

Versions: 1

Compression:

Stored size: 670 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] path The url of the api.
  # @param [String] resource_path The url to get the data.
  # @return [Collection] the collection of objects.
  def initialize(klass, path, resource_path)
    url = "#{ApiClient.config.path[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

1 entries across 1 versions & 1 rubygems

Version Path
api-client-2.4.0 lib/api-client/collection.rb