Class: Coinsetter::Collection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uuid = nil) ⇒ Collection

Returns a new instance of Collection.



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

def initialize(uuid=nil)
  self.session_uuid = uuid ? {'coinsetter-client-session-id' => uuid} : {}
  self.module = self.class.name.singularize.underscore
  split_module = self.module.split('/')
  split_module.shift
  self.name   = split_module.join('/')
  self.model  = self.module.camelize.constantize
  last = split_module.pop
  self.path = (split_module + [last.camelize(:lower)]).join('/')
end

Instance Attribute Details

#modelObject

Returns the value of attribute model.



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

def model
  @model
end

#moduleObject

Returns the value of attribute module.



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

def module
  @module
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#pathObject

Returns the value of attribute path.



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

def path
  @path
end

#responseObject

Returns the value of attribute response.



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

def response
  @response
end

#session_uuidObject

Returns the value of attribute session_uuid.



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

def session_uuid
  @session_uuid
end

Instance Method Details

#create(options = {}, route = path, headers = {}) ⇒ Object



16
17
18
19
20
21
# File 'lib/coinsetter/collection.rb', line 16

def create(options={}, route=path, headers={})
  headers.merge!(session_uuid)
  self.response = Coinsetter::Net.post(route, options, headers)

  parse
end

#exampleObject



37
38
39
# File 'lib/coinsetter/collection.rb', line 37

def example
  JSON.generate({error: "Something went wrong."})
end

#get(id, route = path, options = {}, headers = {}) ⇒ Object



30
31
32
33
34
35
# File 'lib/coinsetter/collection.rb', line 30

def get(id, route=path, options={}, headers={})
  headers.merge!(session_uuid)
  self.response = Coinsetter::Net.get("#{route}/#{id}", options, headers)

  parse
end

#list(route = path, options = {}, headers = {}) ⇒ Object



23
24
25
26
27
28
# File 'lib/coinsetter/collection.rb', line 23

def list(route=path, options={}, headers={})
  headers.merge!(session_uuid)
  self.response = Coinsetter::Net.get(route, options, headers)

  parse_collection
end