theoldreader-api 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +112 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/theoldreader/api.rb +144 -0
- data/lib/theoldreader/api/version.rb +5 -0
- data/theoldreader-api.gemspec +27 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5a7b1508c70f8afe65833e5fbd8f31333f451443
|
4
|
+
data.tar.gz: cb606e24bb3108aed1d340e02376a556a88a9804
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f93692c353a6164464e7a6d0c180ee2fb65fd0f32155b998e413211e21637a20a37d1df1db30e509a05326307b6bb20803e9922429007e7a3892fa9926d9e483
|
7
|
+
data.tar.gz: 7501fff2026baf97076709d4cebc30934ec5bf9f2fc4a1473cff2e5b4d0c650c839adbf11037232287f621396fc7375a0b489f8d18cebdb9b80249bbc24e7ef3
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Ilia Zemskov
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
# Theoldreader::Api
|
2
|
+
|
3
|
+
Ruby wrapper for [Theoldreader's API](https://github.com/theoldreader/api).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'theoldreader-api'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install theoldreader-api
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Authentication
|
24
|
+
First you need to [obtain a token](https://github.com/theoldreader/api#authentication) for theoldreader user:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
|
28
|
+
require 'theoldreader-api'
|
29
|
+
|
30
|
+
Theoldreader::Api.new.accounts_clientlogin(
|
31
|
+
Email: 'test@krasnoukhov.com', Passwd: '...', client: 'YourAppName'
|
32
|
+
)
|
33
|
+
=> {"SID"=>"none", "LSID"=>"none", "Auth"=>"LyTEJPvTJiSPrCxLu46d"}
|
34
|
+
```
|
35
|
+
|
36
|
+
With this token you have access to all other methods of Theoldreader's API.
|
37
|
+
|
38
|
+
### Generic
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
api = Theoldreader::Api.new("LyTEJPvTJiSPrCxLu46d")
|
42
|
+
|
43
|
+
api.call!('get', '/reader/api/0/user-info', {output: 'json'})
|
44
|
+
```
|
45
|
+
|
46
|
+
`call!` will pass every option you provide directly to Theoldreader's Api.
|
47
|
+
|
48
|
+
### Shortcut
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
api.call('user-info')
|
52
|
+
|
53
|
+
api.call('subscription/quickadd', quickadd: 'http://xkcd.com')
|
54
|
+
|
55
|
+
api.call('tag/list')
|
56
|
+
|
57
|
+
api.call('/reader/subscriptions/export')
|
58
|
+
|
59
|
+
```
|
60
|
+
|
61
|
+
`call` will filter your options to include only those listed in specification for the given endpoint.
|
62
|
+
|
63
|
+
`call` accepts endpoints from `Theoldreader::Api::ENDPOINTS.keys` as its first
|
64
|
+
|
65
|
+
`Theoldreader::Api::ENDPOINTS` includes all available methods from Theoldreader's API (with 'reader/api/0/' being left out), except those three wich returns specific atom feeds (https://theoldreader.com/reader/atom/...). You can access them if you want with `call!`
|
66
|
+
|
67
|
+
### Shortcuts for shortcuts
|
68
|
+
|
69
|
+
If you mentally process your endpoint through `.downcase.sub(%r{^/+}, '').gsub(%r{[-/]}, '_')` you should also get available method for Api.
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
# to get userinfo
|
73
|
+
api.user_info
|
74
|
+
|
75
|
+
# to add new feed
|
76
|
+
api.subscription_quickadd(quickadd: 'http://xkcd.com')
|
77
|
+
|
78
|
+
# to get the last two unread items
|
79
|
+
api.stream_contents(
|
80
|
+
s: 'user/-/state/com.google/reading-list',
|
81
|
+
xt: 'user/-/state/com.google/read',
|
82
|
+
n: 2
|
83
|
+
)
|
84
|
+
```
|
85
|
+
|
86
|
+
Works only for keys listed in `Theoldreader::Api::ENDPOINTS.keys`
|
87
|
+
|
88
|
+
## Advanced Usage
|
89
|
+
|
90
|
+
You can change [faraday](https://github.com/lostisland/faraday) adapter:
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
require 'net/http/persistent'
|
94
|
+
|
95
|
+
Theoldreader::Api.new('LyTEJPvTJiSPrCxLu46d', {adapter: :net_http_persistent})
|
96
|
+
```
|
97
|
+
|
98
|
+
And you can use API via http instead of https:
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
Theoldreader::Api.new('LyTEJPvTJiSPrCxLu46d', {use_ssl: false})
|
102
|
+
```
|
103
|
+
|
104
|
+
## Contributing
|
105
|
+
|
106
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ilzoff/theoldreader-api.
|
107
|
+
|
108
|
+
|
109
|
+
## License
|
110
|
+
|
111
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
112
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "theoldreader/api"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
require 'theoldreader/api/version'
|
2
|
+
require 'faraday'
|
3
|
+
require 'multi_json'
|
4
|
+
|
5
|
+
module Theoldreader
|
6
|
+
class Api #:nodoc:
|
7
|
+
HOST = 'theoldreader.com'
|
8
|
+
BASE_PATH = '/reader/api/0/'
|
9
|
+
ENDPOINTS = {
|
10
|
+
'accounts/ClientLogin' => { method: 'post', params: %w(client Email Passwd), default_params: { accountType: 'HOSTED_OR_GOOGLE', service: 'reader' }},
|
11
|
+
'status' => { method: 'get' },
|
12
|
+
'token' => { method: 'get' },
|
13
|
+
'user-info' => { method: 'get' },
|
14
|
+
'preference/list' => { method: 'get' },
|
15
|
+
'friend/list' => { method: 'get' },
|
16
|
+
'friend/edit' => { method: 'post', params: %w(action u) },
|
17
|
+
'comment/edit' => { method: 'post', params: %w(action i comment) },
|
18
|
+
'tag/list' => { method: 'get' },
|
19
|
+
'preference/stream/list' => { method: 'get' },
|
20
|
+
'preference/stream/set' => { method: 'post' },
|
21
|
+
'rename-tag' => { method: 'post', params: %w(s dest) },
|
22
|
+
'disable-tag' => { method: 'post', params: %w(s) },
|
23
|
+
'unread-count' => { method: 'get' },
|
24
|
+
'subscription/list' => { method: 'get' },
|
25
|
+
'subscription/quickadd' => { method: 'post', params: %w(quickadd) },
|
26
|
+
'subscription/edit' => { method: 'post', params: %w(ac s t a r) },
|
27
|
+
'stream/items/ids' => { method: 'get', params: %w(s xt n r c nt ot) },
|
28
|
+
'stream/items/contents' => { method: 'post', params: %w(i output) },
|
29
|
+
'stream/contents' => { method: 'get', params: %w(s xt n r c nt ot output) },
|
30
|
+
'mark-all-as-read' => { method: 'post', params: %w(s ts) },
|
31
|
+
'edit-tag' => { method: 'post', params: %w(i a r annotation) },
|
32
|
+
'/reader/subscriptions/export' => { method: 'get', params: %w(output) }
|
33
|
+
}.freeze
|
34
|
+
|
35
|
+
attr_accessor :api_token, :http_options
|
36
|
+
|
37
|
+
def initialize(api_token = nil, http_options = {})
|
38
|
+
@api_token = api_token
|
39
|
+
@http_options = http_options
|
40
|
+
end
|
41
|
+
|
42
|
+
def call(endpoint, params = {}, headers = {})
|
43
|
+
guard_wrong_endpoint(endpoint)
|
44
|
+
call!(
|
45
|
+
ENDPOINTS[endpoint][:method], path(endpoint),
|
46
|
+
build_options(endpoint, params), headers
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
def call!(verb, endpoint, params = {}, headers = {})
|
51
|
+
response = conn.send(
|
52
|
+
verb, endpoint, params, auth_header.merge(headers)
|
53
|
+
)
|
54
|
+
handle_erros(response)
|
55
|
+
prepare_response(response)
|
56
|
+
end
|
57
|
+
|
58
|
+
ENDPOINTS.keys.each do |e|
|
59
|
+
method_name = e.downcase.sub(%r{^/+}, '').gsub(%r{[-/]}, '_').to_sym
|
60
|
+
define_method method_name do |*args|
|
61
|
+
call(e, *args)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def conn
|
68
|
+
@conn ||= Faraday.new(url: "#{protocol}://#{HOST}") do |faraday|
|
69
|
+
faraday.request :url_encoded
|
70
|
+
faraday.adapter http_options[:adapter] || Faraday.default_adapter
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def guard_wrong_endpoint(endpoint)
|
75
|
+
fail Exceptions::WrongEndpoint unless ENDPOINTS.keys.include?(endpoint)
|
76
|
+
end
|
77
|
+
|
78
|
+
def build_options(endpoint, params)
|
79
|
+
default_params(endpoint).merge(sanitize_params(endpoint, params))
|
80
|
+
end
|
81
|
+
|
82
|
+
def protocol
|
83
|
+
http_options[:use_ssl] == false ? 'http' : 'https'
|
84
|
+
end
|
85
|
+
|
86
|
+
def path(endpoint)
|
87
|
+
(endpoint.start_with?('/') ? '' : BASE_PATH) + endpoint
|
88
|
+
end
|
89
|
+
|
90
|
+
def default_params(endpoint)
|
91
|
+
{ output: 'json' }.merge(ENDPOINTS[endpoint][:default_params] || {})
|
92
|
+
end
|
93
|
+
|
94
|
+
def sanitize_params(endpoint, params)
|
95
|
+
return {} unless ENDPOINTS[endpoint][:params]
|
96
|
+
params.delete_if do |key, _|
|
97
|
+
!ENDPOINTS[endpoint][:params].include?(key.to_s)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def handle_erros(response)
|
102
|
+
fail(
|
103
|
+
Exceptions::ResponseError.new(response),
|
104
|
+
'Theoldreader API has returned the error'
|
105
|
+
) unless response.status == 200
|
106
|
+
end
|
107
|
+
|
108
|
+
def prepare_response(response)
|
109
|
+
MultiJson.load(response.body.to_s)
|
110
|
+
rescue MultiJson::LoadError
|
111
|
+
response.body
|
112
|
+
end
|
113
|
+
|
114
|
+
def auth_header
|
115
|
+
api_token.nil? ? {} : { 'Authorization' => "GoogleLogin auth=#{api_token}" }
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
module Exceptions
|
120
|
+
class ResponseError < StandardError
|
121
|
+
attr_reader :response
|
122
|
+
|
123
|
+
def initialize(response)
|
124
|
+
@response = response
|
125
|
+
end
|
126
|
+
|
127
|
+
def to_s
|
128
|
+
super + format(' (%s)', data.map { |k, v| %(#{k}: "#{v}") }.join(', '))
|
129
|
+
end
|
130
|
+
|
131
|
+
private
|
132
|
+
|
133
|
+
def data
|
134
|
+
@data ||= begin
|
135
|
+
MultiJson.load(response.body)
|
136
|
+
rescue MultiJson::DecodeError
|
137
|
+
{ uri: response.env.url.to_s, errors: response.body.to_s }
|
138
|
+
end.merge(code: response.status)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
class WrongEndpoint < StandardError
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'theoldreader/api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'theoldreader-api'
|
8
|
+
spec.version = Theoldreader::Api::VERSION
|
9
|
+
spec.authors = ['Ilia Zemskov']
|
10
|
+
spec.email = ['il.zoff@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = "Ruby wrapper for Theoldreader's API"
|
13
|
+
spec.homepage = 'https://github.com/ilzoff/theoldreader-api'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = 'exe'
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'faraday'
|
22
|
+
spec.add_dependency 'multi_json'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
+
spec.add_development_dependency 'rspec'
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: theoldreader-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ilia Zemskov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: multi_json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.10'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.10'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- il.zoff@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/console
|
98
|
+
- bin/setup
|
99
|
+
- lib/theoldreader/api.rb
|
100
|
+
- lib/theoldreader/api/version.rb
|
101
|
+
- theoldreader-api.gemspec
|
102
|
+
homepage: https://github.com/ilzoff/theoldreader-api
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.4.5.1
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: Ruby wrapper for Theoldreader's API
|
126
|
+
test_files: []
|