Module: PocketApi

Defined in:
lib/pocket_api.rb,
lib/pocket_api/version.rb,
lib/pocket_api/connection.rb

Defined Under Namespace

Classes: Connection

Constant Summary collapse

VERSION =
"0.0.5"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.access_tokenObject

Returns the value of attribute access_token.



10
11
12
# File 'lib/pocket_api.rb', line 10

def access_token
  @access_token
end

.client_keyObject

Returns the value of attribute client_key.



9
10
11
# File 'lib/pocket_api.rb', line 9

def client_key
  @client_key
end

Class Method Details

.add(url, options = {}) ⇒ Object

Add API Options:

  • title

  • tags - comma-seperated list of tags

  • tweet_id - Twitter tweet_id



56
57
58
# File 'lib/pocket_api.rb', line 56

def add(url, options={})
  request(:post, '/v3/add', :body => {:url => url}.merge(options))
end

.configure(credentials = {}) ⇒ Object



12
13
14
15
# File 'lib/pocket_api.rb', line 12

def configure(credentials={})
  @client_key   = credentials[:client_key]
  @access_token = credentials[:access_token]
end

.modify(action, options = {}) ⇒ Object

Modify API Actions:

  • add

  • archive

  • readd - re-add

  • favorite

  • unfavorite

  • delete

  • tags_add

  • tags_remove

  • tags_replace

  • tags_clear

  • tags_rename



73
74
75
# File 'lib/pocket_api.rb', line 73

def modify(action, options={})
  request(:post, '/v3/send', :body => {:action => action}.merge(options))
end

.request(method, *arguments) ⇒ Object



78
79
80
81
82
83
84
85
86
# File 'lib/pocket_api.rb', line 78

def request(method, *arguments)
  arguments[1] ||= {}
  arguments[1][:body] ||= {}
  arguments[1][:body] = MultiJson.dump(arguments[1][:body].merge({:consumer_key => @client_key, :access_token => @access_token}))
  response = Connection.__send__(method.downcase.to_sym, *arguments)
  raise response.headers["X-Error"] if response.headers["X-Error"]

  response.parsed_response
end

.retrieve(options = {}) ⇒ Object

Retrieve API Options:

  • state unread = only return unread items (default) archive = only return archived items all = return both unread and archived items

  • favorite 0 = only return un-favorited items 1 = only return favorited items

  • tag tag_name = only return items tagged with tag_name untagged = only return untagged items

  • contentType article = only return articles video = only return videos or articles with embedded videos image = only return images

  • sort newest = return items in order of newest to oldest oldest = return items in order of oldest to newest title = return items in order of title alphabetically site = return items in order of url alphabetically

  • detailType simple = only return the titles and urls of each item complete = return all data about each item, including tags, images, authors, videos and more

  • search - search query

  • domain - search within a domain

  • since - timestamp of modifed items after a date

  • count - limit of items to return

  • offset - Used only with count; start returning from offset position of results



46
47
48
49
# File 'lib/pocket_api.rb', line 46

def retrieve(options={})
  response = request(:get, "/v3/get", {:body => options})
  response["list"]
end