feedly 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 +18 -0
- data/.rspec +3 -0
- data/Gemfile +7 -0
- data/LICENSE +31 -0
- data/README.md +30 -0
- data/Rakefile +1 -0
- data/feedly.gemspec +25 -0
- data/lib/feedly.rb +241 -0
- data/lib/feedly/version.rb +3 -0
- data/sample/get_token.rb +26 -0
- data/sample/hello_world.rb +20 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b584ca76792a8ca8919d310b981dc0bc22e7d386
|
4
|
+
data.tar.gz: 3f496c753ef37b0948343fb891a162a895dfd4b2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9c08a509c391b84a8c9aaddb516d13573aa5f35b62432c8d730b14709770bc318e8a4521f7ab8e5873c16a50859925c0f48acaeb9706be8b93da61f493cb2eac
|
7
|
+
data.tar.gz: bd89f5ff9a383f16b93e9c157a31c0836c6fb60eded0c1253c2c52ed1ed697b6a8e4c6e43c2efc35b342ba9750847015366f267c6f82ad6aa1e6c1f371bd3170
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
Copyright 2013 Myuzu
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
Copyright 2013 kmdsbng
|
18
|
+
|
19
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
20
|
+
you may not use this file except in compliance with the License.
|
21
|
+
You may obtain a copy of the License at
|
22
|
+
|
23
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
24
|
+
|
25
|
+
Unless required by applicable law or agreed to in writing, software
|
26
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
27
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
28
|
+
See the License for the specific language governing permissions and
|
29
|
+
limitations under the License.
|
30
|
+
|
31
|
+
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Feedly
|
2
|
+
|
3
|
+
This gem can access to Feely Cloud API.
|
4
|
+
Supports GETS, POSTS, AUTH apis.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'feedly'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install feedly
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
TODO: Write usage instructions here
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
|
26
|
+
1. Fork it
|
27
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
28
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
29
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
30
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/feedly.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'feedly/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "feedly"
|
8
|
+
spec.version = Feedly::VERSION
|
9
|
+
spec.authors = ["Yoshihiro Kameda"]
|
10
|
+
spec.email = ["kameda.sbng@gmail.com"]
|
11
|
+
spec.description = %q{This gem can access to Feely Cloud API. Supports GETS, POSTS, AUTH apis.}
|
12
|
+
spec.summary = %q{Feedly Cloud API wrapper library.}
|
13
|
+
spec.homepage = "https://github.com/kmdsbng/feedly"
|
14
|
+
spec.license = "Apache2"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "pry"
|
25
|
+
end
|
data/lib/feedly.rb
ADDED
@@ -0,0 +1,241 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require "feedly/version"
|
3
|
+
require 'uri'
|
4
|
+
require 'net/http'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
class Feedly
|
8
|
+
class Error < StandardError; end
|
9
|
+
class BadRequest < StandardError; end
|
10
|
+
class AuthError < StandardError; end
|
11
|
+
class NotFound < StandardError; end
|
12
|
+
|
13
|
+
#API_URL = 'http://sandbox.feedly.com/v3/'
|
14
|
+
attr_reader :access_token
|
15
|
+
|
16
|
+
def initialize(option={})
|
17
|
+
@refresh_token = option[:refresh_token]
|
18
|
+
@access_token = option[:access_token]
|
19
|
+
@sandbox = option[:sandbox]
|
20
|
+
if !@access_token && @refresh_token
|
21
|
+
get_access_token_by_refrech_token
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def api_root
|
26
|
+
if @sandbox
|
27
|
+
'http://sandbox.feedly.com'
|
28
|
+
else
|
29
|
+
'http://cloud.feedly.com'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def client_id
|
34
|
+
@client_id if @client_id
|
35
|
+
if @sandbox
|
36
|
+
'sandbox'
|
37
|
+
else
|
38
|
+
'feedly'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def client_secret
|
43
|
+
@client_secret if @client_secret
|
44
|
+
if @sandbox
|
45
|
+
'QNFQRFCFM1IQCJB367ON'
|
46
|
+
else
|
47
|
+
'0XP4XQ07VVMDWBKUHTJM4WUQ'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def redirect_uri
|
52
|
+
@redirect_uri if @redirect_uri
|
53
|
+
if @sandbox
|
54
|
+
'http://localhost'
|
55
|
+
else
|
56
|
+
'https://cloud.feedly.com/feedly.html'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def auth_url
|
61
|
+
api_get_redirect('auth/auth',
|
62
|
+
:client_id => self.client_id,
|
63
|
+
:redirect_uri => self.redirect_uri,
|
64
|
+
:scope => 'https://cloud.feedly.com/subscriptions',
|
65
|
+
:response_type => 'code',
|
66
|
+
:provider => 'google',
|
67
|
+
:migrate => 'false')
|
68
|
+
end
|
69
|
+
|
70
|
+
require 'pry'
|
71
|
+
|
72
|
+
def get_token_by_code(code)
|
73
|
+
#https://sandbox.feedly.com/v3/auth/token -X POST -d 'client_id=sandbox&client_secret=QNFQRFCFM1IQCJB367ON&grant_type=authorization_code&redirect_uri=http%3A%2F%2Flocalhost&code=AQAACggvIv3qZbrjYmz-Grq3r0POtTpduXUuKDd-4fQeO-yZisHCGQRSmZ-FDEMndQVCalBzBZuyceyEH0jJDSbTD42eqJU2dzVFT_qt0ak3wknJhx3xvHXc55gcYtC2YURCm-PDsFmFhLBdKQcK1pBlT-JX6K35_xx2vAmt1wOu'
|
74
|
+
|
75
|
+
|
76
|
+
url = make_url('auth/token', {})
|
77
|
+
uri = URI(url)
|
78
|
+
req = Net::HTTP::Post.new(uri.request_uri)
|
79
|
+
req['Authorization'] = "OAuth #{self.access_token}"
|
80
|
+
req['Content-type'] = 'application/json'
|
81
|
+
req.set_form_data({
|
82
|
+
:refresh_token => @refresh_token,
|
83
|
+
:client_id => self.client_id,
|
84
|
+
:client_secret => self.client_secret,
|
85
|
+
:grant_type => 'authorization_code',
|
86
|
+
:redirect_uri => self.redirect_uri,
|
87
|
+
:code => code,
|
88
|
+
})
|
89
|
+
|
90
|
+
response = Net::HTTP.start(uri.hostname, uri.port) do |http|
|
91
|
+
http.request(req)
|
92
|
+
end
|
93
|
+
|
94
|
+
handle_errors(response)
|
95
|
+
JSON.parse(response.body)
|
96
|
+
end
|
97
|
+
|
98
|
+
def get_access_token_by_refrech_token
|
99
|
+
url = make_url('auth/token', {})
|
100
|
+
uri = URI(url)
|
101
|
+
req = Net::HTTP::Post.new(uri.request_uri)
|
102
|
+
req['Authorization'] = "OAuth #{self.access_token}"
|
103
|
+
req['Content-type'] = 'application/json'
|
104
|
+
#req.body = body.to_json
|
105
|
+
req.set_form_data({:refresh_token => @refresh_token, :client_id => 'sandbox', :client_secret => 'QNFQRFCFM1IQCJB367ON', :grant_type => 'refresh_token'})
|
106
|
+
|
107
|
+
response = Net::HTTP.start(uri.hostname, uri.port) do |http|
|
108
|
+
http.request(req)
|
109
|
+
end
|
110
|
+
|
111
|
+
handle_errors(response)
|
112
|
+
json = JSON.parse(response.body)
|
113
|
+
@access_token = json['access_token']
|
114
|
+
end
|
115
|
+
|
116
|
+
def api_get(path, argv={})
|
117
|
+
url = make_url(path, argv)
|
118
|
+
uri = URI(url)
|
119
|
+
req = Net::HTTP::Get.new(uri.request_uri)
|
120
|
+
req['Authorization'] = "OAuth #{self.access_token}"
|
121
|
+
|
122
|
+
response = Net::HTTP.start(uri.hostname, uri.port) do |http|
|
123
|
+
http.request(req)
|
124
|
+
end
|
125
|
+
|
126
|
+
handle_errors(response)
|
127
|
+
JSON.parse(response.body)
|
128
|
+
end
|
129
|
+
|
130
|
+
def api_get_redirect(path, argv={})
|
131
|
+
url = make_url(path, argv)
|
132
|
+
uri = URI(url)
|
133
|
+
req = Net::HTTP::Get.new(uri.request_uri)
|
134
|
+
req['Authorization'] = "OAuth #{self.access_token}"
|
135
|
+
|
136
|
+
response = Net::HTTP.start(uri.hostname, uri.port) do |http|
|
137
|
+
http.request(req)
|
138
|
+
end
|
139
|
+
|
140
|
+
if response.code.to_i == 302
|
141
|
+
return response['location']
|
142
|
+
end
|
143
|
+
|
144
|
+
handle_errors(response)
|
145
|
+
raise "Unknown state #{response.code}"
|
146
|
+
end
|
147
|
+
|
148
|
+
def api_post(path, body, argv={})
|
149
|
+
url = make_url(path, argv)
|
150
|
+
uri = URI(url)
|
151
|
+
req = Net::HTTP::Post.new(uri.request_uri)
|
152
|
+
req['Authorization'] = "OAuth #{self.access_token}"
|
153
|
+
req['Content-type'] = 'application/json'
|
154
|
+
req.body = body.to_json
|
155
|
+
|
156
|
+
response = Net::HTTP.start(uri.hostname, uri.port) do |http|
|
157
|
+
http.request(req)
|
158
|
+
end
|
159
|
+
|
160
|
+
handle_errors(response)
|
161
|
+
true
|
162
|
+
end
|
163
|
+
|
164
|
+
def api_delete(path, argv={})
|
165
|
+
url = make_url(path, argv)
|
166
|
+
uri = URI(url)
|
167
|
+
req = Net::HTTP::Delete.new(uri.request_uri)
|
168
|
+
req['Authorization'] = "OAuth #{self.access_token}"
|
169
|
+
|
170
|
+
response = Net::HTTP.start(uri.hostname, uri.port) do |http|
|
171
|
+
http.request(req)
|
172
|
+
end
|
173
|
+
|
174
|
+
handle_errors(response)
|
175
|
+
true
|
176
|
+
end
|
177
|
+
|
178
|
+
def get_profile
|
179
|
+
api_get('profile')
|
180
|
+
end
|
181
|
+
|
182
|
+
def get_preferences
|
183
|
+
api_get('preferences')
|
184
|
+
end
|
185
|
+
|
186
|
+
def get_categories
|
187
|
+
api_get('categories')
|
188
|
+
end
|
189
|
+
|
190
|
+
def get_subscriptions
|
191
|
+
api_get('subscriptions')
|
192
|
+
end
|
193
|
+
|
194
|
+
def get_topics
|
195
|
+
api_get('topics')
|
196
|
+
end
|
197
|
+
|
198
|
+
def get_tags
|
199
|
+
api_get('tags')
|
200
|
+
end
|
201
|
+
|
202
|
+
def get_search_feeds(q, n=20)
|
203
|
+
api_get('search/feeds', :q => q, :n => n)
|
204
|
+
end
|
205
|
+
|
206
|
+
def get_feeds(feed_id)
|
207
|
+
api_get('feeds/' + URI.encode_www_form_component(feed_id))
|
208
|
+
end
|
209
|
+
|
210
|
+
def post_subscriptions(feed_id)
|
211
|
+
api_post('subscriptions', {:id => feed_id})
|
212
|
+
end
|
213
|
+
|
214
|
+
def delete_subscriptions(feed_id)
|
215
|
+
api_delete('subscriptions/' + URI.encode_www_form_component(feed_id))
|
216
|
+
end
|
217
|
+
|
218
|
+
def make_url(path, argv)
|
219
|
+
base_url = api_root + '/v3/' + path
|
220
|
+
query = argv.map {|k, v|
|
221
|
+
"#{URI.encode_www_form_component(k)}=#{URI.encode_www_form_component(v)}"
|
222
|
+
}.join('&')
|
223
|
+
query.empty? ? base_url : base_url + '?' + query
|
224
|
+
end
|
225
|
+
|
226
|
+
def handle_errors(response)
|
227
|
+
raise BadRequest if 'null' == response.body
|
228
|
+
|
229
|
+
case response.code.to_i
|
230
|
+
when 200 then response.body
|
231
|
+
when 401 then raise AuthError
|
232
|
+
when 403 then raise AuthError
|
233
|
+
when 404 then raise NotFound
|
234
|
+
when 500 then raise Error
|
235
|
+
else
|
236
|
+
raise Error
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
|
data/sample/get_token.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'feedly'
|
3
|
+
|
4
|
+
def main
|
5
|
+
feedly = Feedly.new
|
6
|
+
puts '1. Access this url. Then redirect https://cloud.feedly.com/feedly.html?code=???&status= .'
|
7
|
+
puts feedly.auth_url
|
8
|
+
|
9
|
+
puts '2. Please input code'
|
10
|
+
print '> '
|
11
|
+
code = gets.chomp
|
12
|
+
|
13
|
+
token = feedly.get_token_by_code(code)
|
14
|
+
puts "OK. success to get tokens"
|
15
|
+
puts "access_token: " + token["access_token"]
|
16
|
+
puts "refresh_token: " + token["refresh_token"]
|
17
|
+
end
|
18
|
+
|
19
|
+
case $0
|
20
|
+
when __FILE__
|
21
|
+
main
|
22
|
+
when /spec[^\/]*$/
|
23
|
+
# {spec of the implementation}
|
24
|
+
end
|
25
|
+
|
26
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'feedly'
|
3
|
+
|
4
|
+
def main
|
5
|
+
access_token = ARGV[0]
|
6
|
+
f = Feedly.new(:access_token => access_token)
|
7
|
+
profile = f.get_profile
|
8
|
+
puts profile["fullName"] # MyName
|
9
|
+
puts profile["client"] # "Feedly sandbox client"
|
10
|
+
puts profile["email"] # "myaddress@example.com"
|
11
|
+
end
|
12
|
+
|
13
|
+
case $0
|
14
|
+
when __FILE__
|
15
|
+
main
|
16
|
+
when /spec[^\/]*$/
|
17
|
+
# {spec of the implementation}
|
18
|
+
end
|
19
|
+
|
20
|
+
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: feedly
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yoshihiro Kameda
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: This gem can access to Feely Cloud API. Supports GETS, POSTS, AUTH apis.
|
70
|
+
email:
|
71
|
+
- kameda.sbng@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .rspec
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- feedly.gemspec
|
83
|
+
- lib/feedly.rb
|
84
|
+
- lib/feedly/version.rb
|
85
|
+
- sample/get_token.rb
|
86
|
+
- sample/hello_world.rb
|
87
|
+
homepage: https://github.com/kmdsbng/feedly
|
88
|
+
licenses:
|
89
|
+
- Apache2
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.0.14
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Feedly Cloud API wrapper library.
|
111
|
+
test_files: []
|