Class: Bitstamp::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/bitstamp/collection.rb

Direct Known Subclasses

Orders, UserTransactions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_prefix = "/api") ⇒ Collection

Returns a new instance of Collection.



5
6
7
8
9
10
11
12
# File 'lib/bitstamp/collection.rb', line 5

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

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



3
4
5
# File 'lib/bitstamp/collection.rb', line 3

def access_token
  @access_token
end

#modelObject

Returns the value of attribute model.



3
4
5
# File 'lib/bitstamp/collection.rb', line 3

def model
  @model
end

#moduleObject

Returns the value of attribute module.



3
4
5
# File 'lib/bitstamp/collection.rb', line 3

def module
  @module
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/bitstamp/collection.rb', line 3

def name
  @name
end

#pathObject

Returns the value of attribute path.



3
4
5
# File 'lib/bitstamp/collection.rb', line 3

def path
  @path
end

Instance Method Details

#all(options = {}) ⇒ Object



14
15
16
# File 'lib/bitstamp/collection.rb', line 14

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

#create(options = {}) ⇒ Object



18
19
20
# File 'lib/bitstamp/collection.rb', line 18

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

#find(id, options = {}) ⇒ Object



22
23
24
# File 'lib/bitstamp/collection.rb', line 22

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

#update(id, options = {}) ⇒ Object



26
27
28
# File 'lib/bitstamp/collection.rb', line 26

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