forked from matryer/xbar-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeedly.rb
executable file
·51 lines (38 loc) · 1.29 KB
/
feedly.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env ruby
# <xbar.title>Feedly</xbar.title>
# <xbar.author>morizyun</xbar.author>
# <xbar.author.github>morizyun</xbar.author.github>
# <xbar.image>https://farm2.staticflickr.com/1541/25991545133_924f4a1a59_c.jpg</xbar.image>
require 'net/http'
require 'json'
ARTICLE_LIMIT = 20.freeze
## PROCEDURE TO GET AUTH TOKEN ##
# https://blog.morizyun.com/blog/feedly-feed-api-script-bitbar/index.html
FEEDLY_AUTH_TOKEN = 'YOUR access_token'.freeze
def get_json_by_feedly_api(url)
uri = URI(url)
req = Net::HTTP::Get.new(uri)
req['Authorization'] = "Bearer #{FEEDLY_AUTH_TOKEN}"
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(req) }
JSON.parse(res.body)
end
def feedly_feeds
# get profile
profile = get_json_by_feedly_api('https://cloud.feedly.com/v3/profile')
# get feed information in your profile
url = "https://cloud.feedly.com/v3/streams/contents?streamId=user/#{profile['id']}/category/global.all"
content = get_json_by_feedly_api(url)
return content['items']
end
def output(item)
puts "#{item['title']} | href=#{item['originId']}"
rescue => e
puts "An error occured: #{e}"
end
puts 'Feedly'
puts '---'
begin
feedly_feeds.each { |item| output(item) }
rescue
puts 'Content is currently unavailable. Please try resetting. | color=red'
end