Sha256: c34e0963b7216d79dc64aa3ff04dfa6d51151ec1ef990147fb496de0d144d270

Contents?: true

Size: 927 Bytes

Versions: 5

Compression:

Stored size: 927 Bytes

Contents

module Bitso
  class Collection
    attr_accessor :access_token, :module, :name, :model, :path

    def initialize(api_prefix="/api")
      self.access_token = Bitso.key

      self.module = self.class.to_s.singularize.underscore
      self.name   = self.module.split('/').last
      self.model  = self.module.camelize.constantize
      self.path   = "#{api_prefix}/#{self.name.pluralize}"
    end

    def all(options = {})
      Bitso::Helper.parse_objects! Bitso::Net::get(self.path).to_str, self.model
    end

    def create(options = {})
      Bitso::Helper.parse_object! Bitso::Net::post(self.path, options).to_str, self.model
    end

    def find(id, options = {})
      Bitso::Helper.parse_object! Bitso::Net::get("#{self.path}/#{id}").to_str, self.model
    end

    def update(id, options = {})
      Bitso::Helper.parse_object! Bitso::Net::patch("#{self.path}/#{id}", options).to_str, self.model
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
bitso-0.1.5 lib/bitso/collection.rb
bitso-0.1.4 lib/bitso/collection.rb
bitso-0.1.3 lib/bitso/collection.rb
bitso-0.1.2 lib/bitso/collection.rb
bitso-0.1.1 lib/bitso/collection.rb