Class: InoreaderApi::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/inoreader/api/app.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ String

set auth toke or username/password

Parameters:

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

    a customizable set of options

  • username (Hash)

    a customizable set of options

  • password (Hash)

    a customizable set of options

  • return_httparty_response (Hash)

    a customizable set of options



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/inoreader/api/app.rb', line 13

def initialize(options={})
  # set default
  options = {
    :return_httparty_response => false
  }.merge(options)
  @auth_token = options.delete(:auth_token)
  if !@auth_token && options.has_key?(:username) && options.has_key?(:password)
    username = options.delete(:username)
    password = options.delete(:password)
    res = (username, password)
    @auth_token = res
  end

  InoreaderApi::Helper.return_httparty_response = options[:return_httparty_response]
end

Instance Method Details

#add_folder_subscription(s, a) ⇒ Object

add folder to subscription

Parameters:

  • s (String)

    stream id(feed/feed_url)

  • a (String)

    add subscription to folder



160
161
162
# File 'lib/inoreader/api/app.rb', line 160

def add_folder_subscription(s, a)
  edit_subscription :edit, s, nil, a
end

#add_subscription(url) ⇒ Object

add Subscription

Parameters:

  • url (String)

    specify the URL to add.



132
133
134
# File 'lib/inoreader/api/app.rb', line 132

def add_subscription(url)
  Helper.request '/reader/api/0/subscription/quickadd', {:query => {:T => @auth_token, quickadd: url}}, :post
end

#add_tag(items, add_tag = nil) ⇒ Object

add tag

Parameters:

  • items (String)

    Item IDs(short or long)

  • add_tag (String) (defaults to: nil)

    use SpecialTag or custom tag



112
113
114
# File 'lib/inoreader/api/app.rb', line 112

def add_tag(items, add_tag=nil)
  Helper.request '/reader/api/0/edit-tag', {:query => {:T => @auth_token, :i => items, :a => add_tag}}, :post
end

#auth_tokenObject

return to auth token



30
31
32
# File 'lib/inoreader/api/app.rb', line 30

def auth_token
  @auth_token
end

#disable_tag(tag_name) ⇒ Object

delete(disable) tag



105
106
107
# File 'lib/inoreader/api/app.rb', line 105

def disable_tag(tag_name)
  Helper.request '/reader/api/0/disable-tag', {:query => {:T => @auth_token, s: tag_name}}, :post
end

#edit_subscription(ac, s, t = nil, a = nil, r = nil) ⇒ Object

edit subscription

Parameters:

  • ac (String)

    action (‘edit’ or ‘subscribe’ or ‘unsubscribe’)

  • s (String)

    stream id(feed/feed_url)

  • t (String) (defaults to: nil)

    subscription title. Omit this parameter to keep the title unchanged

  • a (String) (defaults to: nil)

    add subscription to folder/tag.

  • r (String) (defaults to: nil)

    remove subscription from folder/tag.



142
143
144
145
146
147
148
# File 'lib/inoreader/api/app.rb', line 142

def edit_subscription(ac, s, t=nil, a=nil, r=nil)
  query = {:T => @auth_token, :ac => ac, :s => s}
  query[:t] = t unless t.nil?
  query[:a] = a unless a.nil?
  query[:r] = r unless r.nil?
  Helper.request '/reader/api/0/subscription/edit', {:query => query}, :post
end

#importObject

OPML Import



47
48
49
# File 'lib/inoreader/api/app.rb', line 47

def import
  # todo
end

#item_ids(feed = '', params = {}) ⇒ Object

get user item ids

See Also:



91
92
93
# File 'lib/inoreader/api/app.rb', line 91

def item_ids(feed='', params={})
  stream '/reader/api/0/stream/items/ids', feed, params
end

#items(feed = '', params = {}) ⇒ Object

get user items

See Also:



85
86
87
# File 'lib/inoreader/api/app.rb', line 85

def items(feed='', params={})
  stream '/reader/atom', feed, params
end

#mark_all_as_read(ts, s) ⇒ Object

mark all as read. mark as read, older than ts.

Parameters:

  • ts (String)

    microseconds.

  • s (String)

    Stream.



126
127
128
# File 'lib/inoreader/api/app.rb', line 126

def mark_all_as_read(ts, s)
  Helper.request '/reader/api/0/mark-all-as-read', {:query => {:T => @auth_token, :ts => ts, :s => s}}, :post
end

#preferences_listObject

preference list:current subscriptions sorting.



185
186
187
# File 'lib/inoreader/api/app.rb', line 185

def preferences_list
  Helper.request '/reader/api/0/preference/list', {:query => {:T => @auth_token}}
end

#remove_folder_subscription(s, r) ⇒ Object

remove folder to subscription

Parameters:

  • s (String)

    stream id(feed/feed_url)

  • r (String)

    remove subscription to folder



167
168
169
# File 'lib/inoreader/api/app.rb', line 167

def remove_folder_subscription(s, r)
  edit_subscription :edit, s, nil, nil, r
end

#remove_tag(items, remove_tag) ⇒ Object

remove tag

Parameters:

  • items (Array)

    Item IDs(short or long)

  • remove_tag (String)

    SpecialTag or custom tag



119
120
121
# File 'lib/inoreader/api/app.rb', line 119

def remove_tag(items, remove_tag)
  Helper.request '/reader/api/0/edit-tag', {:query => {:T => @auth_token, :i => items, :r => remove_tag}}, :post
end

#rename_subscription(s, t) ⇒ Object

rename subscription title

Parameters:

  • s (String)

    stream id(feed/feed_url)

  • t (String)

    subscription new title.



153
154
155
# File 'lib/inoreader/api/app.rb', line 153

def rename_subscription(s, t)
  edit_subscription :edit, s, t
end

#rename_tag(source, dest) ⇒ Object

rename tag

Parameters:

  • source

    source tag

  • dest

    dest tag



100
101
102
# File 'lib/inoreader/api/app.rb', line 100

def rename_tag(source, dest)
  Helper.request '/reader/api/0/rename-tag', {:query => {:T => @auth_token, s: source, dest: dest}}, :post
end

#set_stream_preferences(s, k, v) ⇒ Object

Parameters:

  • s (String)

    stream id. root or folder name

  • k (String)

    key

  • v (String)

    value



197
198
199
200
# File 'lib/inoreader/api/app.rb', line 197

def set_stream_preferences(s, k, v)
  query = {:query => {:T => @auth_token, :s => s, :k => k, :v => v}}
  Helper.request '/reader/api/0/preference/stream/set', query, :post
end

#set_subscription_ordering(s, v) ⇒ Object

Set stream preferences. now is “subscription-ordering” only :P

Parameters:

  • s (String)

    stream id. ‘root’ or folder name

  • v (String)

    sorting value



205
206
207
# File 'lib/inoreader/api/app.rb', line 205

def set_subscription_ordering(s, v)
  set_stream_preferences(s, 'subscription-ordering', v)
end

#stream(path, feed = '', params = {}) ⇒ Object

stream

output format : json only

Parameters:

  • path (String)

    request path

  • feed (String) (defaults to: '')

    id of subscription

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

    request Parameters

Options Hash (params):

  • :n (Number)

    Number of items. (default 20, max 1000)

  • :r (String)

    Order. (default is newest first. ‘o’ is oldest first)

  • :ot (String)

    Start time (unix timestamp. ex.1389756192)

  • :xt (String)

    Exclude Target. (ex. ‘user/-/state/com.google/read’)

  • :it (String)

    Include Target. (‘user/-/state/com.google/read(,starred,like)’)

  • :c (String)

    Continuation.



77
78
79
80
81
# File 'lib/inoreader/api/app.rb', line 77

def stream(path, feed='', params={})
  query = {:query => params.merge!(:T => @auth_token, :output => 'json')}
  feed_name = feed.empty? ? '' : ('/' + feed)
  Helper.request "#{path}#{feed_name}", query
end

#stream_preferences_listObject

Stream preferences list



190
191
192
# File 'lib/inoreader/api/app.rb', line 190

def stream_preferences_list
  Helper.request '/reader/api/0/preference/stream/list', {:query => {:T => @auth_token}}
end

#subscribe(s, a) ⇒ Object

subscribe (=add Subscription)

Parameters:

  • s (String)

    stream id(feed/feed_url)

  • a (String)

    folder name



180
181
182
# File 'lib/inoreader/api/app.rb', line 180

def subscribe(s, a)
  edit_subscription :subscribe, s, nil, a
end

#tokenString

get token

Returns:

  • (String)

    token. ex.“aFP4xIm2Ow.…”



42
43
44
# File 'lib/inoreader/api/app.rb', line 42

def token
  Helper.request '/reader/api/0/token', {:query => {:T => @auth_token}}
end

#unread_countersObject

get unread counters



52
53
54
# File 'lib/inoreader/api/app.rb', line 52

def unread_counters
  Helper.request '/reader/api/0/unread-count?output=json', {:query => {:T => @auth_token}}
end

#unsubscribe(s) ⇒ Object

unsubscribe

Parameters:

  • s (String)

    stream id(feed/feed_url)



173
174
175
# File 'lib/inoreader/api/app.rb', line 173

def unsubscribe(s)
  edit_subscription :unsubscribe, s
end

#user_infoString

get user info

Returns:

  • (String)

    json string “”userName“:”user_name“, …”



36
37
38
# File 'lib/inoreader/api/app.rb', line 36

def 
  Helper.request '/reader/api/0/user-info', {:query => {:T => @auth_token}}
end

#user_subscriptionObject

get user subscriptions



57
58
59
# File 'lib/inoreader/api/app.rb', line 57

def user_subscription
  Helper.request '/reader/api/0/subscription/list', {:query => {:T => @auth_token}}
end

#user_tags_foldersObject

get user tags/folders



62
63
64
# File 'lib/inoreader/api/app.rb', line 62

def user_tags_folders
  Helper.request '/reader/api/0/tag/list', {:query => {:T => @auth_token}}
end