class Feedly
Constants
- VERSION
Attributes
access_token[R]
API_URL = ‘sandbox.feedly.com/v3/’
Public Class Methods
new(option={})
click to toggle source
# File lib/feedly.rb, line 15 def initialize(option={}) @refresh_token = option[:refresh_token] @access_token = option[:access_token] @sandbox = option[:sandbox] if !@access_token && @refresh_token get_access_token_by_refrech_token end end
Public Instance Methods
api_delete(path, argv={})
click to toggle source
# File lib/feedly.rb, line 163 def api_delete(path, argv={}) url = make_url(path, argv) uri = URI(url) req = Net::HTTP::Delete.new(uri.request_uri) req['Authorization'] = "OAuth #{self.access_token}" response = Net::HTTP.start(uri.hostname, uri.port) do |http| http.request(req) end handle_errors(response) true end
api_get(path, argv={})
click to toggle source
# File lib/feedly.rb, line 115 def api_get(path, argv={}) url = make_url(path, argv) uri = URI(url) req = Net::HTTP::Get.new(uri.request_uri) req['Authorization'] = "OAuth #{self.access_token}" response = Net::HTTP.start(uri.hostname, uri.port) do |http| http.request(req) end handle_errors(response) JSON.parse(response.body) end
api_get_redirect(path, argv={})
click to toggle source
# File lib/feedly.rb, line 129 def api_get_redirect(path, argv={}) url = make_url(path, argv) uri = URI(url) req = Net::HTTP::Get.new(uri.request_uri) req['Authorization'] = "OAuth #{self.access_token}" response = Net::HTTP.start(uri.hostname, uri.port) do |http| http.request(req) end if response.code.to_i == 302 return response['location'] end handle_errors(response) raise "Unknown state #{response.code}" end
api_post(path, body, argv={})
click to toggle source
# File lib/feedly.rb, line 147 def api_post(path, body, argv={}) url = make_url(path, argv) uri = URI(url) req = Net::HTTP::Post.new(uri.request_uri) req['Authorization'] = "OAuth #{self.access_token}" req['Content-type'] = 'application/json' req.body = body.to_json response = Net::HTTP.start(uri.hostname, uri.port) do |http| http.request(req) end handle_errors(response) true end
api_root()
click to toggle source
# File lib/feedly.rb, line 24 def api_root if @sandbox 'http://sandbox.feedly.com' else 'http://cloud.feedly.com' end end
auth_url()
click to toggle source
# File lib/feedly.rb, line 59 def auth_url api_get_redirect('auth/auth', :client_id => self.client_id, :redirect_uri => self.redirect_uri, :scope => 'https://cloud.feedly.com/subscriptions', :response_type => 'code', :provider => 'google', :migrate => 'false') end
client_id()
click to toggle source
# File lib/feedly.rb, line 32 def client_id @client_id if @client_id if @sandbox 'sandbox' else 'feedly' end end
client_secret()
click to toggle source
# File lib/feedly.rb, line 41 def client_secret @client_secret if @client_secret if @sandbox 'QNFQRFCFM1IQCJB367ON' else '0XP4XQ07VVMDWBKUHTJM4WUQ' end end
delete_subscriptions(feed_id)
click to toggle source
# File lib/feedly.rb, line 213 def delete_subscriptions(feed_id) api_delete('subscriptions/' + URI.encode_www_form_component(feed_id)) end
get_access_token_by_refrech_token()
click to toggle source
# File lib/feedly.rb, line 97 def get_access_token_by_refrech_token url = make_url('auth/token', {}) uri = URI(url) req = Net::HTTP::Post.new(uri.request_uri) req['Authorization'] = "OAuth #{self.access_token}" req['Content-type'] = 'application/json' #req.body = body.to_json req.set_form_data({:refresh_token => @refresh_token, :client_id => 'sandbox', :client_secret => 'QNFQRFCFM1IQCJB367ON', :grant_type => 'refresh_token'}) response = Net::HTTP.start(uri.hostname, uri.port) do |http| http.request(req) end handle_errors(response) json = JSON.parse(response.body) @access_token = json['access_token'] end
get_categories()
click to toggle source
# File lib/feedly.rb, line 185 def get_categories api_get('categories') end
get_feeds(feed_id)
click to toggle source
# File lib/feedly.rb, line 205 def get_feeds(feed_id) api_get('feeds/' + URI.encode_www_form_component(feed_id)) end
get_preferences()
click to toggle source
# File lib/feedly.rb, line 181 def get_preferences api_get('preferences') end
get_profile()
click to toggle source
# File lib/feedly.rb, line 177 def get_profile api_get('profile') end
get_search_feeds(q, n=20)
click to toggle source
# File lib/feedly.rb, line 201 def get_search_feeds(q, n=20) api_get('search/feeds', :q => q, :n => n) end
get_subscriptions()
click to toggle source
# File lib/feedly.rb, line 189 def get_subscriptions api_get('subscriptions') end
get_token_by_code(code)
click to toggle source
# File lib/feedly.rb, line 71 def get_token_by_code(code) #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' url = make_url('auth/token', {}) uri = URI(url) req = Net::HTTP::Post.new(uri.request_uri) req['Authorization'] = "OAuth #{self.access_token}" req['Content-type'] = 'application/json' req.set_form_data({ :refresh_token => @refresh_token, :client_id => self.client_id, :client_secret => self.client_secret, :grant_type => 'authorization_code', :redirect_uri => self.redirect_uri, :code => code, }) response = Net::HTTP.start(uri.hostname, uri.port) do |http| http.request(req) end handle_errors(response) JSON.parse(response.body) end
get_topics()
click to toggle source
# File lib/feedly.rb, line 193 def get_topics api_get('topics') end
handle_errors(response)
click to toggle source
# File lib/feedly.rb, line 225 def handle_errors(response) raise BadRequest if 'null' == response.body case response.code.to_i when 200 then response.body when 401 then raise AuthError when 403 then raise AuthError when 404 then raise NotFound when 500 then raise Error else raise Error end end
make_url(path, argv)
click to toggle source
# File lib/feedly.rb, line 217 def make_url(path, argv) base_url = api_root + '/v3/' + path query = argv.map {|k, v| "#{URI.encode_www_form_component(k)}=#{URI.encode_www_form_component(v)}" }.join('&') query.empty? ? base_url : base_url + '?' + query end
post_subscriptions(feed_id)
click to toggle source
# File lib/feedly.rb, line 209 def post_subscriptions(feed_id) api_post('subscriptions', {:id => feed_id}) end
redirect_uri()
click to toggle source
# File lib/feedly.rb, line 50 def redirect_uri @redirect_uri if @redirect_uri if @sandbox 'http://localhost' else 'https://cloud.feedly.com/feedly.html' end end