Class: Raindrop::Client
- Inherits:
-
Object
- Object
- Raindrop::Client
- Defined in:
- lib/raindrop/client.rb
Constant Summary collapse
- BASE_URL =
"https://api.raindrop.io/rest/v1"
Instance Method Summary collapse
- #child_collections ⇒ Object
- #create_raindrop(link, title: nil, excerpt: nil, note: nil, tags: [], collection_id: nil) ⇒ Object
- #delete_raindrop(id) ⇒ Object
- #get_raindrop(id) ⇒ Object
-
#initialize(token:, connection: nil) ⇒ Client
constructor
A new instance of Client.
- #root_collections ⇒ Object
- #search_raindrops(query, collection_id: 0, perpage: 10, page: 0) ⇒ Object
- #tags(collection_id: 0) ⇒ Object
Constructor Details
#initialize(token:, connection: nil) ⇒ Client
Returns a new instance of Client.
12 13 14 15 |
# File 'lib/raindrop/client.rb', line 12 def initialize(token:, connection: nil) @token = token @connection = connection || default_connection end |
Instance Method Details
#child_collections ⇒ Object
68 69 70 71 72 73 |
# File 'lib/raindrop/client.rb', line 68 def child_collections response = @connection.get("collections/childrens") handle_response(response) rescue Faraday::ConnectionFailed => e raise ApiError, "API request failed: #{e.}" end |
#create_raindrop(link, title: nil, excerpt: nil, note: nil, tags: [], collection_id: nil) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/raindrop/client.rb', line 37 def create_raindrop(link, title: nil, excerpt: nil, note: nil, tags: [], collection_id: nil) response = @connection.post("raindrop") do |request| request.headers["Content-Type"] = "application/json" request.body = JSON.generate(create_raindrop_body(link, title, excerpt, note, , collection_id)) end handle_response(response) rescue Faraday::ConnectionFailed => e raise ApiError, "API request failed: #{e.}" end |
#delete_raindrop(id) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/raindrop/client.rb', line 47 def delete_raindrop(id) response = @connection.delete("raindrop/#{id}") handle_response(response) rescue Faraday::ConnectionFailed => e raise ApiError, "API request failed: #{e.}" end |
#get_raindrop(id) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/raindrop/client.rb', line 30 def get_raindrop(id) response = @connection.get("raindrop/#{id}") handle_response(response) rescue Faraday::ConnectionFailed => e raise ApiError, "API request failed: #{e.}" end |
#root_collections ⇒ Object
61 62 63 64 65 66 |
# File 'lib/raindrop/client.rb', line 61 def root_collections response = @connection.get("collections") handle_response(response) rescue Faraday::ConnectionFailed => e raise ApiError, "API request failed: #{e.}" end |
#search_raindrops(query, collection_id: 0, perpage: 10, page: 0) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/raindrop/client.rb', line 17 def search_raindrops(query, collection_id: 0, perpage: 10, page: 0) response = @connection.get("raindrops/#{collection_id}") do |request| request.params.update( "search" => query, "perpage" => perpage, "page" => page ) end handle_response(response) rescue Faraday::ConnectionFailed => e raise ApiError, "API request failed: #{e.}" end |
#tags(collection_id: 0) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/raindrop/client.rb', line 54 def (collection_id: 0) response = @connection.get("tags/#{collection_id}") handle_response(response) rescue Faraday::ConnectionFailed => e raise ApiError, "API request failed: #{e.}" end |