Class: RaindropIo::Raindrop

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

Overview

Raindrop class (a bookmark)

Instance Attribute Summary

Attributes inherited from Base

#attributes

Class Method Summary collapse

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

.default_page_sizeObject



7
8
9
# File 'lib/raindrop_io/raindrop.rb', line 7

def default_page_size
  25
end

.raindrop(raindrop_id) ⇒ Object

Get raindrop



33
34
35
36
37
38
39
40
# File 'lib/raindrop_io/raindrop.rb', line 33

def raindrop(raindrop_id)
  response = get("/raindrop/#{raindrop_id}")
  if response.status.success? && response.parse["item"]
    Raindrop.new response.parse["item"]
  else
    RaindropIo::ApiError.new response
  end
end

.raindrops(collection_id, options = {}) ⇒ Array<RaindropIo::Raindrop>

Get multiple raindrops in a collection

Parameters:

  • collection_id (String)

    The ID of the collection

  • options (Hash) (defaults to: {})

    Additional query parameters

Options Hash (options):

  • :sort (String)

    The sort order

  • :perpage (Integer)

    The number of raindrops per page

  • :page (Integer)

    The page number

  • :search (String)

    The search query

Returns:



20
21
22
23
24
25
26
27
28
29
# File 'lib/raindrop_io/raindrop.rb', line 20

def raindrops(collection_id, options = {})
  response = get("/raindrops/#{collection_id}", options)
  if response.status.success? && response.parse["items"]
    drops = response.parse["items"].map { |attributes| Raindrop.new(attributes) }
    total = response.parse["count"]
    {total: total, items: drops}
  else
    RaindropIo::ApiError.new response
  end
end

.remove(raindrop_id) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/raindrop_io/raindrop.rb', line 61

def remove(raindrop_id)
  response = delete("/raindrop/#{raindrop_id}")
  if response.status.success?
    true
  else
    RaindropIo::ApiError.new response
  end
end

.suggest(raindrop_id) ⇒ Object

Suggest collection and tags for existing bookmark GET https://api.raindrop.io/rest/v1/raindrop/id/suggest



80
81
82
83
84
85
86
87
# File 'lib/raindrop_io/raindrop.rb', line 80

def suggest(raindrop_id)
  response = get("/raindrop/#{raindrop_id}/suggest")
  if response.status.success? && response.parse["item"]
    response.parse["item"]
  else
    RaindropIo::ApiError.new response
  end
end

.update(raindrop_id, attributes) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/raindrop_io/raindrop.rb', line 44

def update(raindrop_id, attributes)
  # strip out any attributes not listed in the docs
  allowed = %w[created lastUpdate pleaseParse order important tags media
    cover collection type excerpt title link highlights extra_data]
  # extra_data is a hash of key-value pairs is a catch all for unkown attributes,
  # since we don't know about them, we'll not pass them to the API for now.
  attrs = attributes.except(*allowed)[:data]
  response = put("/raindrop/#{raindrop_id}", json: attrs)
  if response.status.success? && response.parse["item"]
    Raindrop.new response.parse["item"]
  else
    RaindropIo::ApiError.new response
  end
end