Class: KintoBox::KintoCollection
- Inherits:
-
Object
- Object
- KintoBox::KintoCollection
- Includes:
- KintoObject
- Defined in:
- lib/kinto_box/kinto_collection.rb
Instance Attribute Summary collapse
-
#bucket ⇒ Object
readonly
Returns the value of attribute bucket.
-
#id ⇒ Object
Returns the value of attribute id.
Instance Method Summary collapse
- #create_record(data) ⇒ Object
-
#initialize(bucket, collection_id) ⇒ KintoCollection
constructor
A new instance of KintoCollection.
- #list_records ⇒ Object
- #record(record_id, return_ref = false) ⇒ Object
Methods included from KintoObject
#add_permission, #delete, #info, #permissions, #replace_permission, #update
Constructor Details
#initialize(bucket, collection_id) ⇒ KintoCollection
Returns a new instance of KintoCollection.
11 12 13 14 15 16 17 |
# File 'lib/kinto_box/kinto_collection.rb', line 11 def initialize (bucket, collection_id) raise ArgumentError if bucket.nil? || collection_id.nil? @kinto_client = bucket.kinto_client @bucket = bucket @id = collection_id @url_path = "/buckets/#{bucket.id}/collections/#{@id}" end |
Instance Attribute Details
#bucket ⇒ Object (readonly)
Returns the value of attribute bucket.
9 10 11 |
# File 'lib/kinto_box/kinto_collection.rb', line 9 def bucket @bucket end |
#id ⇒ Object
Returns the value of attribute id.
8 9 10 |
# File 'lib/kinto_box/kinto_collection.rb', line 8 def id @id end |
Instance Method Details
#create_record(data) ⇒ Object
29 30 31 32 33 |
# File 'lib/kinto_box/kinto_collection.rb', line 29 def create_record(data) resp = @kinto_client.post("#{@url_path}/records", { 'data' => data}) record_id = resp['data']['id'] record(record_id, true) end |
#list_records ⇒ Object
25 26 27 |
# File 'lib/kinto_box/kinto_collection.rb', line 25 def list_records @kinto_client.get("#{@url_path}/records") end |
#record(record_id, return_ref = false) ⇒ Object
19 20 21 22 23 |
# File 'lib/kinto_box/kinto_collection.rb', line 19 def record (record_id, return_ref = false) record = KintoRecord.new(self, record_id) return record if return_ref record.info end |