Class: Coinsetter::Collection
- Inherits:
-
Object
- Object
- Coinsetter::Collection
- Defined in:
- lib/coinsetter/collection.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#model ⇒ Object
Returns the value of attribute model.
-
#module ⇒ Object
Returns the value of attribute module.
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#response ⇒ Object
Returns the value of attribute response.
-
#session_uuid ⇒ Object
Returns the value of attribute session_uuid.
Instance Method Summary collapse
- #create(options = {}, route = path, headers = {}) ⇒ Object
- #example ⇒ Object
- #get(id, route = path, options = {}, headers = {}) ⇒ Object
-
#initialize(uuid = nil) ⇒ Collection
constructor
A new instance of Collection.
- #list(route = path, options = {}, headers = {}) ⇒ Object
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
#model ⇒ Object
Returns the value of attribute model.
3 4 5 |
# File 'lib/coinsetter/collection.rb', line 3 def model @model end |
#module ⇒ Object
Returns the value of attribute module.
3 4 5 |
# File 'lib/coinsetter/collection.rb', line 3 def module @module end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/coinsetter/collection.rb', line 3 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
3 4 5 |
# File 'lib/coinsetter/collection.rb', line 3 def path @path end |
#response ⇒ Object
Returns the value of attribute response.
3 4 5 |
# File 'lib/coinsetter/collection.rb', line 3 def response @response end |
#session_uuid ⇒ Object
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(={}, route=path, headers={}) headers.merge!(session_uuid) self.response = Coinsetter::Net.post(route, , headers) parse end |
#example ⇒ Object
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, ={}, headers={}) headers.merge!(session_uuid) self.response = Coinsetter::Net.get("#{route}/#{id}", , 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, ={}, headers={}) headers.merge!(session_uuid) self.response = Coinsetter::Net.get(route, , headers) parse_collection end |