Sha256: 5113bac3a74dccde1c2bd1d6fff9ae52aab26cee4895211e5d5e5bf74fc1cf6e

Contents?: true

Size: 964 Bytes

Versions: 6

Compression:

Stored size: 964 Bytes

Contents

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

    def initialize(api_prefix="/api")
      self.access_token = Bitstamp.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 = {})
      Bitstamp::Helper.parse_objects! Bitstamp::Net::get(self.path).body_str, self.model
    end

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

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

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
bitstamp-0.2.5 lib/bitstamp/collection.rb
bitstamp-0.2.4 lib/bitstamp/collection.rb
bitstamp-0.2.3 lib/bitstamp/collection.rb
bitstamp-0.2.2 lib/bitstamp/collection.rb
bitstamp-0.2.1 lib/bitstamp/collection.rb
bitstamp-0.2.0 lib/bitstamp/collection.rb