Class: RaindropIo::Collection
- Defined in:
- lib/raindrop_io/collection.rb
Overview
System collections
Every user have several system non-removable collections. They are not contained in any API responses.
_id | Description |
---|---|
-1 | "Unsorted" collection |
-99 | "Trash" collection |
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
-
.all ⇒ Object
Get root collections + system collections GET https://api.raindrop.io/rest/v1/collections.
-
.childrens ⇒ Object
Get child collections.
-
.create!(attributes) ⇒ Object
POST https://api.raindrop.io/rest/v1/collection Create a new collection.
-
.find(collection_id) ⇒ Object
Get collection.
- .get_system_collections ⇒ Object
-
.remove(collection_id) ⇒ Object
DELETE https://api.raindrop.io/rest/v1/collection/id Remove an existing collection and all its descendants.
-
.stats ⇒ Object
Get system collections count.
Methods inherited from Base
delete, get, #initialize, #initialize_attributes, post, put, #to_h, #to_hash, #to_json
Constructor Details
This class inherits a constructor from RaindropIo::Base
Class Method Details
.all ⇒ Object
Get root collections + system collections GET https://api.raindrop.io/rest/v1/collections
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/raindrop_io/collection.rb', line 14 def all response = get("/collections") if response.status.success? && response.parse["items"] bag1 = response.parse["items"].map { |attributes| Collection.new(attributes) } bag2 = get_system_collections bag3 = childrens bag1 + bag2 + bag3 # combine them all else RaindropIo::ApiError.new response end end |
.childrens ⇒ Object
Get child collections
50 51 52 53 54 55 56 57 |
# File 'lib/raindrop_io/collection.rb', line 50 def childrens response = get("/collections/childrens") if response.status.success? && response.parse["items"] response.parse["items"].map { |attributes| Collection.new(attributes) } else RaindropIo::ApiError.new response end end |
.create!(attributes) ⇒ Object
Create collection
POST https://api.raindrop.io/rest/v1/collection Create a new collection
86 87 88 89 90 91 92 93 |
# File 'lib/raindrop_io/collection.rb', line 86 def create!(attributes) response = post("/collection", json: attributes) if response.status.success? && response.parse["item"] Collection.new response.parse["item"] else RaindropIo::ApiError.new response end end |
.find(collection_id) ⇒ Object
Get collection
62 63 64 65 66 67 68 69 |
# File 'lib/raindrop_io/collection.rb', line 62 def find(collection_id) response = get("/collection/#{collection_id}") if response.status.success? && response.parse["item"] Collection.new response.parse["item"] else RaindropIo::ApiError.new response end end |
.get_system_collections ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/raindrop_io/collection.rb', line 27 def get_system_collections rv = stats if rv["result"] == true rv["items"].map do |item| col = find(item["_id"]) case item["_id"] when -1 col.title = "Unsorted" when -99 col.title = "Trash" else col.title = "system collection #{item["_id"]}" if col.title.nil? end col end else RaindropIo::ApiError.new response end end |
.remove(collection_id) ⇒ Object
DELETE https://api.raindrop.io/rest/v1/collection/id Remove an existing collection and all its descendants.
97 98 99 100 101 102 103 104 |
# File 'lib/raindrop_io/collection.rb', line 97 def remove(collection_id) response = delete("/collection/#{collection_id}") if response.status.success? response.parse else RaindropIo::ApiError.new response end end |
.stats ⇒ Object
Get system collections count
74 75 76 77 78 79 80 81 |
# File 'lib/raindrop_io/collection.rb', line 74 def stats response = get("/user/stats") if response.status.success? response.parse else RaindropIo::ApiError.new response end end |