Class: Theoldreader::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/theoldreader/api.rb,
lib/theoldreader/api/version.rb

Overview

:nodoc:

Constant Summary collapse

HOST =
'theoldreader.com'
BASE_PATH =
'/reader/api/0/'
ENDPOINTS =
{
  'accounts/ClientLogin' => { method: 'post', params: %w(client Email Passwd), default_params: { accountType: 'HOSTED_OR_GOOGLE', service: 'reader' }},
  'status' => { method: 'get' },
  'token' => { method: 'get' },
  'user-info' => { method: 'get' },
  'preference/list' => { method: 'get' },
  'friend/list' => { method: 'get' },
  'friend/edit' => { method: 'post', params: %w(action u) },
  'comment/edit' => { method: 'post', params: %w(action i comment) },
  'tag/list' => { method: 'get' },
  'preference/stream/list' => { method: 'get' },
  'preference/stream/set' => { method: 'post' },
  'rename-tag' => { method: 'post', params: %w(s dest) },
  'disable-tag' => { method: 'post', params: %w(s) },
  'unread-count' => { method: 'get' },
  'subscription/list' => { method: 'get' },
  'subscription/quickadd' => { method: 'post', params: %w(quickadd) },
  'subscription/edit' => { method: 'post', params: %w(ac s t a r) },
  'stream/items/ids' => { method: 'get', params: %w(s xt n r c nt ot) },
  'stream/items/contents' => { method: 'post', params: %w(i output) },
  'stream/contents' => { method: 'get', params: %w(s xt n r c nt ot output) },
  'mark-all-as-read' => { method: 'post', params: %w(s ts) },
  'edit-tag' => { method: 'post', params: %w(i a r annotation) },
  '/reader/subscriptions/export' => { method: 'get', params: %w(output) }
}.freeze
VERSION =
'0.1.0'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_token = nil, http_options = {}) ⇒ Api

Returns a new instance of Api.



37
38
39
40
# File 'lib/theoldreader/api.rb', line 37

def initialize(api_token = nil, http_options = {})
  @api_token = api_token
  @http_options = http_options
end

Instance Attribute Details

#api_tokenObject

Returns the value of attribute api_token.



35
36
37
# File 'lib/theoldreader/api.rb', line 35

def api_token
  @api_token
end

#http_optionsObject

Returns the value of attribute http_options.



35
36
37
# File 'lib/theoldreader/api.rb', line 35

def http_options
  @http_options
end

Instance Method Details

#call(endpoint, params = {}, headers = {}) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/theoldreader/api.rb', line 42

def call(endpoint, params = {}, headers = {})
  guard_wrong_endpoint(endpoint)
  call!(
    ENDPOINTS[endpoint][:method], path(endpoint),
    build_options(endpoint, params), headers
  )
end

#call!(verb, endpoint, params = {}, headers = {}) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/theoldreader/api.rb', line 50

def call!(verb, endpoint, params = {}, headers = {})
  response = conn.send(
    verb, endpoint, params, auth_header.merge(headers)
  )
  handle_erros(response)
  prepare_response(response)
end