fanswatch 0.0.0 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +5 -3
- data/LICENSE +21 -0
- data/README.md +5 -1
- data/Rakefile +6 -0
- data/bin/fanswatch +23 -0
- data/fanswatch.gemspec +32 -0
- data/lib/fanswatch/attachment.rb +2 -0
- data/lib/fanswatch/fb_api.rb +84 -20
- data/lib/fanswatch/feed.rb +22 -0
- data/lib/fanswatch/page.rb +10 -19
- data/lib/fanswatch/posting.rb +10 -11
- data/lib/fanswatch/version.rb +5 -0
- data/spec/fanswatch_spec.rb +56 -67
- data/spec/spec_helper.rb +29 -2
- metadata +6 -30
- data/coverage/.last_run.json +0 -5
- data/coverage/.resultset.json +0 -164
- data/coverage/.resultset.json.lock +0 -0
- data/coverage/assets/0.10.0/application.css +0 -799
- data/coverage/assets/0.10.0/application.js +0 -1707
- data/coverage/assets/0.10.0/colorbox/border.png +0 -0
- data/coverage/assets/0.10.0/colorbox/controls.png +0 -0
- data/coverage/assets/0.10.0/colorbox/loading.gif +0 -0
- data/coverage/assets/0.10.0/colorbox/loading_background.png +0 -0
- data/coverage/assets/0.10.0/favicon_green.png +0 -0
- data/coverage/assets/0.10.0/favicon_red.png +0 -0
- data/coverage/assets/0.10.0/favicon_yellow.png +0 -0
- data/coverage/assets/0.10.0/loading.gif +0 -0
- data/coverage/assets/0.10.0/magnify.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/coverage/index.html +0 -1094
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: baa57b5ab02aa703ce4960754ae21ee51cde80b4
|
4
|
+
data.tar.gz: 532b6ba17712bb1c50e58888d695c0ad91c66c91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f192d3c9847c0bf00f7944b204bb91b1ecafad9ac737bddbc092f07dc5cef22c092faa3890e5a73ddf54907137988b8089da89f63109c05f457bc62bf6885b5c
|
7
|
+
data.tar.gz: 13c153bc48d8ab0197d2a3a985317d4aee3ba803549557e731cc16c37e6f9af5aebbfad316b5ed66a02b8c273e6435b5a05901e81a4c420748663c5fc30552ca
|
data/.gitignore
CHANGED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT LICENSE
|
2
|
+
|
3
|
+
Copyright (c) Wei-Tang Lin <wtlin0711@gmail.com>
|
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
CHANGED
data/Rakefile
CHANGED
data/bin/fanswatch
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w(.. lib))
|
4
|
+
require 'fanswatch'
|
5
|
+
|
6
|
+
puts ENV['FB_CLIENT_ID']
|
7
|
+
|
8
|
+
page_id = ARGV[0] || ENV['FB_PAGE_ID']
|
9
|
+
unless page_id
|
10
|
+
puts 'USAGE: fanswatch [page_id]'
|
11
|
+
exit(1)
|
12
|
+
end
|
13
|
+
|
14
|
+
page = FansWatch::Page.find(id: page_id)
|
15
|
+
|
16
|
+
puts page.name
|
17
|
+
puts Array.new(page.name.length) { '-' }.join
|
18
|
+
page.feed.postings.first(3).each.with_index do |post, index|
|
19
|
+
print "#{index + 1}: "
|
20
|
+
puts post.message ? post.message : '(blank)'
|
21
|
+
puts "Attached: #{post.attachment.url}" if post.attachment
|
22
|
+
puts
|
23
|
+
end
|
data/fanswatch.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'fanswatch/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'fanswatch'
|
7
|
+
s.version = FansWatch::VERSION
|
8
|
+
|
9
|
+
s.summary = 'Gets posted content from public Facebook fans pages'
|
10
|
+
s.description = 'Extracts feed, postings, and attachments from FB fans pages'
|
11
|
+
s.authors = ['Wei-Tang Lin']
|
12
|
+
s.email = ['wtlin0711@gmail.com']
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
16
|
+
s.executables << 'fanswatch'
|
17
|
+
|
18
|
+
s.add_runtime_dependency 'http', '~> 2.0'
|
19
|
+
|
20
|
+
s.add_development_dependency 'minitest', '~> 5.9'
|
21
|
+
s.add_development_dependency 'minitest-rg', '~> 5.2'
|
22
|
+
s.add_development_dependency 'rake', '~> 11.3'
|
23
|
+
s.add_development_dependency 'vcr', '~> 3.0'
|
24
|
+
s.add_development_dependency 'webmock', '~> 2.1'
|
25
|
+
s.add_development_dependency 'simplecov', '~> 0.12'
|
26
|
+
s.add_development_dependency 'flog', '~> 4.4'
|
27
|
+
s.add_development_dependency 'flay', '~> 2.8'
|
28
|
+
s.add_development_dependency 'rubocop', '~> 0.42'
|
29
|
+
s.add_development_dependency 'codeclimate-test-reporter', '~> 0.6'
|
30
|
+
s.homepage = 'https://github.com/wtlin1228/FansWatch'
|
31
|
+
s.license = 'MIT'
|
32
|
+
end
|
data/lib/fanswatch/attachment.rb
CHANGED
data/lib/fanswatch/fb_api.rb
CHANGED
@@ -9,8 +9,6 @@ module FansWatch
|
|
9
9
|
FB_API_URL = URI.join(FB_URL, "#{API_VER}/")
|
10
10
|
FB_TOKEN_URL = URI.join(FB_API_URL, 'oauth/access_token')
|
11
11
|
|
12
|
-
attr_reader :access_token
|
13
|
-
|
14
12
|
def initialize(client_id:, client_secret:)
|
15
13
|
access_token_response =
|
16
14
|
HTTP.get(FB_TOKEN_URL,
|
@@ -20,44 +18,110 @@ module FansWatch
|
|
20
18
|
@access_token = JSON.load(access_token_response.to_s)['access_token']
|
21
19
|
end
|
22
20
|
|
23
|
-
def
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
21
|
+
def self.access_token
|
22
|
+
return @access_token if @access_token
|
23
|
+
|
24
|
+
access_token_response =
|
25
|
+
HTTP.get(FB_TOKEN_URL,
|
26
|
+
params: { client_id: config[:client_id],
|
27
|
+
client_secret: config[:client_secret],
|
28
|
+
grant_type: 'client_credentials' })
|
29
|
+
@access_token = access_token_response.parse['access_token']
|
28
30
|
end
|
29
31
|
|
30
|
-
def
|
31
|
-
|
32
|
+
def self.config=(credentials)
|
33
|
+
@config ? @config.update(credentials) : @config = credentials
|
32
34
|
end
|
33
35
|
|
34
|
-
def
|
35
|
-
|
36
|
+
def self.config
|
37
|
+
return @config if @config
|
38
|
+
@config = { client_id: ENV['FB_CLIENT_ID'],
|
39
|
+
client_secret: ENV['FB_CLIENT_SECRET'] }
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
# Get the fans page's name and id
|
44
|
+
# ex: @id="159425621565",
|
45
|
+
# @name="Inside 硬塞的網路趨勢觀察"
|
46
|
+
def self.page_info(page_id)
|
47
|
+
fb_resource(page_id)
|
36
48
|
end
|
37
49
|
|
38
|
-
|
50
|
+
# Get the collection of fans page's postings' (message, created_time and id)
|
51
|
+
# ex : {
|
52
|
+
# "message"=> "日前金管會確認 Apple Pay、Samsung Pay 等行動支付服務將可進入台灣市場運作後,Google 所提出 Android Pay 也確認將可進入台灣市場。而從相關說法透露,Android Pay 最快將會在近期內於台灣市場推行,但具體時間依然要等 Google 說明。",
|
53
|
+
# "created_time"=>"2016-11-22T05:58:05+0000",
|
54
|
+
# "id"=>"159425621565_10153840498126566"
|
55
|
+
# },
|
56
|
+
#
|
57
|
+
# .
|
58
|
+
# .
|
59
|
+
# .
|
60
|
+
#
|
61
|
+
# {
|
62
|
+
# "message"=>"橘子集團發表新的揪團通訊 App: BeanGo! 記者會",
|
63
|
+
# "created_time"=>"2016-11-22T05:38:12+0000",
|
64
|
+
# "id"=>"159425621565_10153840469861566"
|
65
|
+
# }
|
66
|
+
def self.page_feed(page_id)
|
39
67
|
feed_response =
|
40
68
|
HTTP.get(URI.join(fb_resource_url(page_id), 'feed'),
|
41
|
-
params: { access_token:
|
69
|
+
params: { access_token: access_token })
|
42
70
|
JSON.load(feed_response.to_s)['data']
|
43
71
|
end
|
44
72
|
|
45
|
-
|
73
|
+
# Get the single posting's basic information by posting id
|
74
|
+
# which we can get from page_feed
|
75
|
+
# ex : {
|
76
|
+
# "created_time"=>"2016-11-22T03:44:08+0000",
|
77
|
+
# "message"=>"網路中立性原則要求網路服務供應商及政府應平等處理所有網路上的資料,不差別對待或依不同用戶、內容、網站、平台、應用、接取裝置類型或通訊模式而差別收費。而這也是早逝的 RSS 共同開發者與 Reddit 創辦人 Aaron Swartz 長期以來所不斷捍衛的信念和目標。",
|
78
|
+
# "id"=>"159425621565_10153840361851566"
|
79
|
+
# }
|
80
|
+
def self.posting(posting_id)
|
81
|
+
fb_resource(posting_id)
|
82
|
+
end
|
83
|
+
|
84
|
+
# Get the attachment of a posting
|
85
|
+
# ex : {
|
86
|
+
# "description"=>"美國下一任總統川普正式任命兩名顧問,以幫助他完成在聯邦通信委員會監督(FCC)的過渡。這兩名顧問分別是 Jeff Eisenach 和 Mark Jamison,均是網路中立性原則的激烈反對者。",
|
87
|
+
# "media"=>
|
88
|
+
# {
|
89
|
+
# "image"=>
|
90
|
+
# {
|
91
|
+
# "height"=>720,
|
92
|
+
# "src"=>"https://external.xx.fbcdn.net/safe_image.php?d=AQBO6Ai9foDoVI1f&w=720&h=720&url=https%3A%2F%2Fwww.inside.com.tw%2Fwp-content%2Fuploads%2F2016%2F11%2F24343769071_d409f67726_k.jpg&cfs=1&sx=450&sy=0&sw=1365&sh=1365",
|
93
|
+
# "width"=>720
|
94
|
+
# }
|
95
|
+
# },
|
96
|
+
# "target"=>
|
97
|
+
# {
|
98
|
+
# "url"=>"https://www.facebook.com/l.php?u=https%3A%2F%2Fwww.inside.com.tw%2F2016%2F11%2F22%2Fdonald-j-trump-net-neutrality&h=ATO8VyRbirwfQAQraYgt8e1aQEoG6oAneIqomLzhe0gGVg_0iE5TAeJhKyhjRzwuCtvKy2mDXL6iSKtwmB6ABCLbyE8&s=1&enc=AZMg3ju-UJWf_VvBESGjeaIUYH7vIVJLQaULvMxBrH0BI7tKrX3KXKyvL-oU5dMdUzANLjxddUlsQOX7Auz-sChD"
|
99
|
+
# },
|
100
|
+
# "title"=>"川普的 FCC 團隊,可能會終結網路中立性原則",
|
101
|
+
# "type"=>"share",
|
102
|
+
# "url"=>"https://www.facebook.com/l.php?u=https%3A%2F%2Fwww.inside.com.tw%2F2016%2F11%2F22%2Fdonald-j-trump-net-neutrality&h=ATO8VyRbirwfQAQraYgt8e1aQEoG6oAneIqomLzhe0gGVg_0iE5TAeJhKyhjRzwuCtvKy2mDXL6iSKtwmB6ABCLbyE8&s=1&enc=AZMg3ju-UJWf_VvBESGjeaIUYH7vIVJLQaULvMxBrH0BI7tKrX3KXKyvL-oU5dMdUzANLjxddUlsQOX7Auz-sChD"
|
103
|
+
# }
|
104
|
+
|
105
|
+
def self.posting_attachments(posting_id)
|
46
106
|
attachments_response =
|
47
107
|
HTTP.get(URI.join(fb_resource_url(posting_id), 'attachments'),
|
48
|
-
params: { access_token:
|
108
|
+
params: { access_token: access_token })
|
49
109
|
JSON.load(attachments_response.to_s)['data'].first
|
50
110
|
end
|
51
111
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
112
|
private
|
56
113
|
|
57
|
-
def fb_resource_url(id)
|
114
|
+
def self.fb_resource_url(id)
|
58
115
|
URI.join(FB_API_URL, "/#{id}/")
|
59
116
|
end
|
60
|
-
|
117
|
+
|
118
|
+
def self.fb_resource(id)
|
119
|
+
response = HTTP.get(
|
120
|
+
fb_resource_url(id),
|
121
|
+
params: {access_token: access_token })
|
122
|
+
JSON.load(response.to_s)
|
123
|
+
end
|
124
|
+
|
61
125
|
end
|
62
126
|
end
|
63
127
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'fb_api'
|
3
|
+
require_relative 'posting'
|
4
|
+
|
5
|
+
module FansWatch
|
6
|
+
# Page feeds, with data and paging information
|
7
|
+
class Feed
|
8
|
+
attr_reader :postings
|
9
|
+
|
10
|
+
def initialize(feed_data:)
|
11
|
+
raw_feed = FansWatch::FbApi.page_feed(feed_data)
|
12
|
+
@postings = raw_feed.map do |post_data|
|
13
|
+
FansWatch::Posting.new(data: post_data)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def count
|
19
|
+
@postings.count
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/fanswatch/page.rb
CHANGED
@@ -1,31 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require_relative 'fb_api'
|
2
3
|
require_relative 'posting'
|
3
4
|
|
4
5
|
module FansWatch
|
5
6
|
# Main class to setup a Facebook group
|
6
7
|
class Page
|
7
|
-
attr_reader :name
|
8
|
+
attr_reader :name, :id, :feed
|
9
|
+
|
10
|
+
def initialize(page_data:)
|
11
|
+
@name = page_data['name']
|
12
|
+
@id = page_data['id']
|
13
|
+
@feed = Feed.new(feed_data: @id)
|
8
14
|
|
9
|
-
def initialize(fb_api, data:)
|
10
|
-
@fb_api = fb_api
|
11
|
-
@name = data['name']
|
12
|
-
@id = data['id']
|
13
15
|
end
|
14
|
-
|
15
|
-
def feed
|
16
|
-
return @feed if @feed
|
17
|
-
raw_feed = @fb_api.page_feed(@id)
|
18
|
-
@feed = raw_feed.map do |posting|
|
19
|
-
FansWatch::Posting.new(
|
20
|
-
@fb_api,
|
21
|
-
data: posting
|
22
|
-
)
|
23
|
-
end
|
24
|
-
end
|
25
16
|
|
26
|
-
def self.find(
|
27
|
-
page_data =
|
28
|
-
|
17
|
+
def self.find(id:)
|
18
|
+
page_data = FbApi.page_info(id)
|
19
|
+
page_data.include?('error') ? nil : new(page_data: page_data)
|
29
20
|
end
|
30
21
|
|
31
22
|
end
|
data/lib/fanswatch/posting.rb
CHANGED
@@ -1,36 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require_relative 'fb_api'
|
2
3
|
require_relative 'attachment'
|
3
4
|
|
4
5
|
module FansWatch
|
5
6
|
# Single posting on group's feed
|
6
7
|
class Posting
|
7
|
-
attr_reader :message, :created_time, :id
|
8
|
+
attr_reader :message, :created_time, :id, :attachment
|
8
9
|
|
9
|
-
def initialize(
|
10
|
-
@fb_api = fb_api
|
10
|
+
def initialize(data: nil)
|
11
11
|
load_data(data)
|
12
12
|
end
|
13
13
|
|
14
14
|
def attachment
|
15
15
|
return @attachment if @attachment
|
16
16
|
|
17
|
-
attached_data =
|
18
|
-
@attachment = Attachment.new(attached_data)
|
17
|
+
attached_data = FbApi.posting_attachments(@id)
|
19
18
|
end
|
20
19
|
|
21
|
-
def self.find(
|
22
|
-
posting_data =
|
23
|
-
new(
|
20
|
+
def self.find(id:)
|
21
|
+
posting_data = FbApi.posting(id)
|
22
|
+
new(data:posting_data)
|
24
23
|
end
|
25
24
|
|
26
25
|
private
|
27
26
|
|
28
27
|
def load_data(posting_data)
|
29
28
|
@id = posting_data['id']
|
30
|
-
# @updated_time = posting_data['updated_time']
|
31
29
|
@created_time = posting_data['created_time']
|
32
|
-
@message = posting_data['message']
|
33
|
-
|
30
|
+
@message = posting_data['message']
|
31
|
+
|
32
|
+
attached = attachment
|
34
33
|
@attachment = Attachment.new(attached) if attached
|
35
34
|
end
|
36
35
|
end
|
data/spec/fanswatch_spec.rb
CHANGED
@@ -2,87 +2,76 @@
|
|
2
2
|
require_relative 'spec_helper.rb'
|
3
3
|
|
4
4
|
describe 'FansWatch specifications' do
|
5
|
-
VCR.configure do |c|
|
6
|
-
c.cassette_library_dir = CASSETTES_FOLDER
|
7
|
-
c.hook_into :webmock
|
8
|
-
|
9
|
-
c.filter_sensitive_data('<ACCESS_TOKEN>'){CREDENTIALS[:access_token]}
|
10
|
-
c.filter_sensitive_data('<ACCESS_TOKEN_ESCAPED') do
|
11
|
-
URI.escape(CREDENTIALS[:access_token])
|
12
|
-
end
|
13
|
-
c.filter_sensitive_data('<CLIENT_ID>'){CREDENTIALS[:client_id]}
|
14
|
-
c.filter_sensitive_data('<CLIENT_SECRET>'){CREDENTIALS[:client_secret]}
|
15
|
-
end
|
16
|
-
|
17
5
|
before do
|
18
6
|
VCR.insert_cassette CASSETTE_FILE, record: :new_episodes
|
19
|
-
|
20
|
-
@fb_api = FansWatch::FbApi.new(
|
21
|
-
client_id: CREDENTIALS[:client_id],
|
22
|
-
client_secret: CREDENTIALS[:client_secret]
|
23
|
-
)
|
24
|
-
|
25
|
-
# @posting_with_msg_id = FB_RESULT['posting']['id']
|
26
7
|
end
|
27
8
|
|
28
9
|
after do
|
29
10
|
VCR.eject_cassette
|
30
11
|
end
|
31
12
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
)
|
37
|
-
|
38
|
-
fb_api.access_token.length.must_be :>, 0
|
39
|
-
end
|
40
|
-
|
41
|
-
|
42
|
-
it 'should be able to open a Facebook Page' do
|
43
|
-
page = FansWatch::Page.find(
|
44
|
-
@fb_api,
|
45
|
-
id: CREDENTIALS[:page_id]
|
46
|
-
)
|
47
|
-
|
48
|
-
page.name.length.must_be :>, 0
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'should get the lastest feed from an page' do
|
52
|
-
page = FansWatch::Page.find(
|
53
|
-
@fb_api,
|
54
|
-
id: CREDENTIALS[:page_id]
|
55
|
-
)
|
56
|
-
|
57
|
-
feed = page.feed
|
58
|
-
feed.count.must_be :>, 1
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'should get the information about postings on the feed' do
|
62
|
-
page = FansWatch::Page.find(
|
63
|
-
@fb_api,
|
64
|
-
id: CREDENTIALS[:page_id]
|
65
|
-
)
|
13
|
+
describe 'FbApi Credientials' do
|
14
|
+
it '(HAPPY) should get new access token with ENV credientials' do
|
15
|
+
FansWatch::FbApi.access_token.length.must_be :>, 0
|
16
|
+
end
|
66
17
|
|
67
|
-
|
68
|
-
|
18
|
+
it '(HAPPY) should get new access_token with file credientials' do
|
19
|
+
FansWatch::FbApi.config = { client_id: ENV['FB_CLIENT_ID'],
|
20
|
+
client_secret: ENV['FB_CLIENT_SECRET'] }
|
21
|
+
FansWatch::FbApi.access_token.length.must_be :>, 0
|
22
|
+
end
|
69
23
|
end
|
70
24
|
|
25
|
+
describe 'Finding Page information' do
|
26
|
+
describe 'Find a page' do
|
27
|
+
it '(HAPPY) should be able to fine a Facebook Page with proper page ID' do
|
28
|
+
page = FansWatch::Page.find(id: ENV['FB_PAGE_ID'])
|
71
29
|
|
72
|
-
|
73
|
-
|
74
|
-
post = posting.first
|
75
|
-
post_id = post['id']
|
76
|
-
attachment = FB_RESULT[:attachement].first
|
77
|
-
|
78
|
-
retrieved = FansWatch::Posting.find(@fb_api, id: post_id.to_s)
|
30
|
+
page.name.length.must_be :>, 0
|
31
|
+
end
|
79
32
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
33
|
+
it '(SAD) should return nil Page ID is invalid' do
|
34
|
+
page = FansWatch::Page.find(id: INVALID_PAGE_ID)
|
35
|
+
page.must_be_nil
|
36
|
+
end
|
37
|
+
end
|
85
38
|
|
39
|
+
describe 'Retrieving Page Feed' do
|
40
|
+
it '(HAPPY) should get the lastest feed from page with proper ID' do
|
41
|
+
page = FansWatch::Page.find(id: ENV['FB_PAGE_ID'])
|
42
|
+
|
43
|
+
feed = page.feed
|
44
|
+
feed.count.must_be :>, 1
|
45
|
+
end
|
46
|
+
|
47
|
+
it '(HAPPY) should get the postings on the feed with proper ID' do
|
48
|
+
page = FansWatch::Page.find(id: ENV['FB_PAGE_ID'])
|
49
|
+
|
50
|
+
page.feed.postings.each do |posting|
|
51
|
+
posting.id.wont_be_nil
|
52
|
+
posting.created_time.wont_be_nil
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
86
56
|
end
|
87
57
|
|
58
|
+
describe 'Finding Posting Information' do
|
59
|
+
it '(HAPPY) should find all parts of a full posting' do
|
60
|
+
posting = FB_RESULT[:feed].first
|
61
|
+
attachment = FB_RESULT[:posting][:attached]
|
62
|
+
attachment_description = attachment[:description]
|
63
|
+
attachment_url = attachment[:url]
|
64
|
+
retrieved = FansWatch::Posting.find(id: posting['id'])
|
65
|
+
|
66
|
+
retrieved.id.must_equal posting['id']
|
67
|
+
retrieved.created_time.must_equal posting['created_time']
|
68
|
+
retrieved.message.must_equal posting['message']
|
69
|
+
retrieved.attachment.wont_be_nil
|
70
|
+
retrieved.attachment.description.must_equal attachment_description
|
71
|
+
|
72
|
+
# FB will change the url
|
73
|
+
# retrieved.attachment.url.must_equal attachment_url
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
88
77
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -12,6 +12,33 @@ require_relative '../lib/fanswatch'
|
|
12
12
|
FIXTURES_FOLDER = 'spec/fixtures'
|
13
13
|
CASSETTES_FOLDER = "#{FIXTURES_FOLDER}/cassettes"
|
14
14
|
CASSETTE_FILE = 'facebook_api'
|
15
|
-
CREDENTIALS = YAML.load(File.read('config/credentials.yml'))
|
16
15
|
RESULT_FILE = "#{FIXTURES_FOLDER}/results.yml"
|
17
|
-
FB_RESULT = YAML.load(File.read(RESULT_FILE))
|
16
|
+
FB_RESULT = YAML.load(File.read(RESULT_FILE))
|
17
|
+
|
18
|
+
if File.file?('config/credentials.yml')
|
19
|
+
credentials = YAML.load(File.read('config/credentials.yml'))
|
20
|
+
ENV['FB_CLIENT_ID'] = credentials[:client_id]
|
21
|
+
ENV['FB_CLIENT_SECRET'] = credentials[:client_secret]
|
22
|
+
ENV['FB_ACCESS_TOKEN'] = credentials[:access_token]
|
23
|
+
ENV['FB_PAGE_ID'] = credentials[:page_id]
|
24
|
+
end
|
25
|
+
|
26
|
+
INVALID_PAGE_ID = 'error_page_id'
|
27
|
+
|
28
|
+
VCR.configure do |c|
|
29
|
+
c.cassette_library_dir = CASSETTES_FOLDER
|
30
|
+
c.hook_into :webmock
|
31
|
+
|
32
|
+
c.filter_sensitive_data('<ACCESS_TOKEN>') do
|
33
|
+
URI.unescape(ENV['FB_ACCESS_TOKEN'])
|
34
|
+
end
|
35
|
+
|
36
|
+
c.filter_sensitive_data('<ACCESS_TOKEN_ESCAPED>') do
|
37
|
+
ENV['FB_ACCESS_TOKEN']
|
38
|
+
end
|
39
|
+
|
40
|
+
c.filter_sensitive_data('<CLIENT_ID>') { ENV['FB_CLIENT_ID'] }
|
41
|
+
c.filter_sensitive_data('<CLIENT_SECRET>') { ENV['FB_CLIENT_SECRET'] }
|
42
|
+
|
43
|
+
c.ignore_hosts 'codeclimate.com'
|
44
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fanswatch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wei-Tang Lin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -174,42 +174,18 @@ extra_rdoc_files: []
|
|
174
174
|
files:
|
175
175
|
- ".gitignore"
|
176
176
|
- Gemfile
|
177
|
+
- LICENSE
|
177
178
|
- README.md
|
178
179
|
- Rakefile
|
179
180
|
- bin/fanswatch
|
180
|
-
-
|
181
|
-
- coverage/.resultset.json
|
182
|
-
- coverage/.resultset.json.lock
|
183
|
-
- coverage/assets/0.10.0/application.css
|
184
|
-
- coverage/assets/0.10.0/application.js
|
185
|
-
- coverage/assets/0.10.0/colorbox/border.png
|
186
|
-
- coverage/assets/0.10.0/colorbox/controls.png
|
187
|
-
- coverage/assets/0.10.0/colorbox/loading.gif
|
188
|
-
- coverage/assets/0.10.0/colorbox/loading_background.png
|
189
|
-
- coverage/assets/0.10.0/favicon_green.png
|
190
|
-
- coverage/assets/0.10.0/favicon_red.png
|
191
|
-
- coverage/assets/0.10.0/favicon_yellow.png
|
192
|
-
- coverage/assets/0.10.0/loading.gif
|
193
|
-
- coverage/assets/0.10.0/magnify.png
|
194
|
-
- coverage/assets/0.10.0/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png
|
195
|
-
- coverage/assets/0.10.0/smoothness/images/ui-bg_flat_75_ffffff_40x100.png
|
196
|
-
- coverage/assets/0.10.0/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png
|
197
|
-
- coverage/assets/0.10.0/smoothness/images/ui-bg_glass_65_ffffff_1x400.png
|
198
|
-
- coverage/assets/0.10.0/smoothness/images/ui-bg_glass_75_dadada_1x400.png
|
199
|
-
- coverage/assets/0.10.0/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png
|
200
|
-
- coverage/assets/0.10.0/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png
|
201
|
-
- coverage/assets/0.10.0/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png
|
202
|
-
- coverage/assets/0.10.0/smoothness/images/ui-icons_222222_256x240.png
|
203
|
-
- coverage/assets/0.10.0/smoothness/images/ui-icons_2e83ff_256x240.png
|
204
|
-
- coverage/assets/0.10.0/smoothness/images/ui-icons_454545_256x240.png
|
205
|
-
- coverage/assets/0.10.0/smoothness/images/ui-icons_888888_256x240.png
|
206
|
-
- coverage/assets/0.10.0/smoothness/images/ui-icons_cd0a0a_256x240.png
|
207
|
-
- coverage/index.html
|
181
|
+
- fanswatch.gemspec
|
208
182
|
- lib/fanswatch.rb
|
209
183
|
- lib/fanswatch/attachment.rb
|
210
184
|
- lib/fanswatch/fb_api.rb
|
185
|
+
- lib/fanswatch/feed.rb
|
211
186
|
- lib/fanswatch/page.rb
|
212
187
|
- lib/fanswatch/posting.rb
|
188
|
+
- lib/fanswatch/version.rb
|
213
189
|
- spec/fanswatch_spec.rb
|
214
190
|
- spec/spec_helper.rb
|
215
191
|
homepage: https://github.com/wtlin1228/FansWatch
|