Class: Raindrop::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/raindrop/client.rb

Constant Summary collapse

BASE_URL =
"https://api.raindrop.io/rest/v1"

Instance Method Summary collapse

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_collectionsObject



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.message}"
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, tags, collection_id))
  end
  handle_response(response)
rescue Faraday::ConnectionFailed => e
  raise ApiError, "API request failed: #{e.message}"
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.message}"
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.message}"
end

#root_collectionsObject



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.message}"
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.message}"
end

#tags(collection_id: 0) ⇒ Object



54
55
56
57
58
59
# File 'lib/raindrop/client.rb', line 54

def tags(collection_id: 0)
  response = @connection.get("tags/#{collection_id}")
  handle_response(response)
rescue Faraday::ConnectionFailed => e
  raise ApiError, "API request failed: #{e.message}"
end