fanswatch 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/Gemfile +4 -0
  4. data/README.md +3 -0
  5. data/Rakefile +5 -0
  6. data/bin/fanswatch +0 -0
  7. data/coverage/.last_run.json +5 -0
  8. data/coverage/.resultset.json +164 -0
  9. data/coverage/.resultset.json.lock +0 -0
  10. data/coverage/assets/0.10.0/application.css +799 -0
  11. data/coverage/assets/0.10.0/application.js +1707 -0
  12. data/coverage/assets/0.10.0/colorbox/border.png +0 -0
  13. data/coverage/assets/0.10.0/colorbox/controls.png +0 -0
  14. data/coverage/assets/0.10.0/colorbox/loading.gif +0 -0
  15. data/coverage/assets/0.10.0/colorbox/loading_background.png +0 -0
  16. data/coverage/assets/0.10.0/favicon_green.png +0 -0
  17. data/coverage/assets/0.10.0/favicon_red.png +0 -0
  18. data/coverage/assets/0.10.0/favicon_yellow.png +0 -0
  19. data/coverage/assets/0.10.0/loading.gif +0 -0
  20. data/coverage/assets/0.10.0/magnify.png +0 -0
  21. data/coverage/assets/0.10.0/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  22. data/coverage/assets/0.10.0/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  23. data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  24. data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  25. data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  26. data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  27. data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  28. data/coverage/assets/0.10.0/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  29. data/coverage/assets/0.10.0/smoothness/images/ui-icons_222222_256x240.png +0 -0
  30. data/coverage/assets/0.10.0/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  31. data/coverage/assets/0.10.0/smoothness/images/ui-icons_454545_256x240.png +0 -0
  32. data/coverage/assets/0.10.0/smoothness/images/ui-icons_888888_256x240.png +0 -0
  33. data/coverage/assets/0.10.0/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  34. data/coverage/index.html +1094 -0
  35. data/lib/fanswatch/attachment.rb +13 -0
  36. data/lib/fanswatch/fb_api.rb +63 -0
  37. data/lib/fanswatch/page.rb +32 -0
  38. data/lib/fanswatch/posting.rb +37 -0
  39. data/lib/fanswatch.rb +2 -0
  40. data/spec/fanswatch_spec.rb +88 -0
  41. data/spec/spec_helper.rb +17 -0
  42. metadata +241 -0
@@ -0,0 +1,13 @@
1
+ module FansWatch
2
+ # Attached URL to Posting
3
+ class Attachment
4
+ attr_reader :description, :url
5
+
6
+ def initialize(data)
7
+ return unless data
8
+ @description = data['description']
9
+ @url = data['url']
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,63 @@
1
+ require 'http'
2
+ require 'json'
3
+
4
+ module FansWatch
5
+ # Service for all FB API calls
6
+ class FbApi
7
+ FB_URL = 'https://graph.facebook.com'
8
+ API_VER = 'v2.8'
9
+ FB_API_URL = URI.join(FB_URL, "#{API_VER}/")
10
+ FB_TOKEN_URL = URI.join(FB_API_URL, 'oauth/access_token')
11
+
12
+ attr_reader :access_token
13
+
14
+ def initialize(client_id:, client_secret:)
15
+ access_token_response =
16
+ HTTP.get(FB_TOKEN_URL,
17
+ params: { client_id: client_id,
18
+ client_secret: client_secret,
19
+ grant_type: 'client_credentials' })
20
+ @access_token = JSON.load(access_token_response.to_s)['access_token']
21
+ end
22
+
23
+ def fb_resource(id)
24
+ response = HTTP.get(
25
+ fb_resource_url(id),
26
+ params: {access_token: @access_token })
27
+ JSON.load(response.to_s)
28
+ end
29
+
30
+ def page_info(page_id)
31
+ fb_resource(page_id)
32
+ end
33
+
34
+ def posting(posting_id)
35
+ fb_resource(posting_id)
36
+ end
37
+
38
+ def page_feed(page_id)
39
+ feed_response =
40
+ HTTP.get(URI.join(fb_resource_url(page_id), 'feed'),
41
+ params: { access_token: @access_token })
42
+ JSON.load(feed_response.to_s)['data']
43
+ end
44
+
45
+ def posting_attachments(posting_id)
46
+ attachments_response =
47
+ HTTP.get(URI.join(fb_resource_url(posting_id), 'attachments'),
48
+ params: { access_token: @access_token })
49
+ JSON.load(attachments_response.to_s)['data'].first
50
+ end
51
+
52
+
53
+
54
+
55
+ private
56
+
57
+ def fb_resource_url(id)
58
+ URI.join(FB_API_URL, "/#{id}/")
59
+ end
60
+
61
+ end
62
+ end
63
+
@@ -0,0 +1,32 @@
1
+ require_relative 'fb_api'
2
+ require_relative 'posting'
3
+
4
+ module FansWatch
5
+ # Main class to setup a Facebook group
6
+ class Page
7
+ attr_reader :name
8
+
9
+ def initialize(fb_api, data:)
10
+ @fb_api = fb_api
11
+ @name = data['name']
12
+ @id = data['id']
13
+ 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
+
26
+ def self.find(fb_api, id:)
27
+ page_data = fb_api.page_info(id)
28
+ new(fb_api, data: page_data)
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,37 @@
1
+ require_relative 'fb_api'
2
+ require_relative 'attachment'
3
+
4
+ module FansWatch
5
+ # Single posting on group's feed
6
+ class Posting
7
+ attr_reader :message, :created_time, :id
8
+
9
+ def initialize(fb_api, data: nil)
10
+ @fb_api = fb_api
11
+ load_data(data)
12
+ end
13
+
14
+ def attachment
15
+ return @attachment if @attachment
16
+
17
+ attached_data = @fb_api.posting_attachments(@id)
18
+ @attachment = Attachment.new(attached_data)
19
+ end
20
+
21
+ def self.find(fb_api, id:)
22
+ posting_data = fb_api.posting(id)
23
+ new(fb_api, data:posting_data)
24
+ end
25
+
26
+ private
27
+
28
+ def load_data(posting_data)
29
+ @id = posting_data['id']
30
+ # @updated_time = posting_data['updated_time']
31
+ @created_time = posting_data['created_time']
32
+ @message = posting_data['message']
33
+ attached = posting_data['attachment']
34
+ @attachment = Attachment.new(attached) if attached
35
+ end
36
+ end
37
+ end
data/lib/fanswatch.rb ADDED
@@ -0,0 +1,2 @@
1
+ files = Dir.glob(File.join(File.dirname(__FILE__), 'fanswatch/*.rb'))
2
+ files.each { |lib| require_relative lib }
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'spec_helper.rb'
3
+
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
+ before do
18
+ 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
+ end
27
+
28
+ after do
29
+ VCR.eject_cassette
30
+ end
31
+
32
+ it 'should be able to get a new access token' do
33
+ fb_api = FansWatch::FbApi.new(
34
+ client_id: CREDENTIALS[:client_id],
35
+ client_secret: CREDENTIALS[:client_secret]
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
+ )
66
+
67
+ posting = page.feed.first
68
+ posting.message.length.must_be :>, 0
69
+ end
70
+
71
+
72
+ it 'should find all parts of a full posting' do
73
+ posting = FB_RESULT[:feed]
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)
79
+
80
+ retrieved.id.must_equal post_id
81
+ retrieved.created_time.must_equal post['created_time']
82
+ retrieved.message.must_equal post['message']
83
+ retrieved.attachment.wont_be_nil
84
+ retrieved.attachment.description.must_equal attachment[1][0]['description']
85
+
86
+ end
87
+
88
+ end
@@ -0,0 +1,17 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'yaml'
5
+ require 'minitest/autorun'
6
+ require 'minitest/rg'
7
+ require 'vcr'
8
+ require 'webmock'
9
+
10
+ require_relative '../lib/fanswatch'
11
+
12
+ FIXTURES_FOLDER = 'spec/fixtures'
13
+ CASSETTES_FOLDER = "#{FIXTURES_FOLDER}/cassettes"
14
+ CASSETTE_FILE = 'facebook_api'
15
+ CREDENTIALS = YAML.load(File.read('config/credentials.yml'))
16
+ RESULT_FILE = "#{FIXTURES_FOLDER}/results.yml"
17
+ FB_RESULT = YAML.load(File.read(RESULT_FILE))
metadata ADDED
@@ -0,0 +1,241 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fanswatch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Wei-Tang Lin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-11-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: http
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest-rg
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '11.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '11.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: vcr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.1'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.12'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.12'
111
+ - !ruby/object:Gem::Dependency
112
+ name: flog
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '4.4'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '4.4'
125
+ - !ruby/object:Gem::Dependency
126
+ name: flay
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '2.8'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '2.8'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.42'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.42'
153
+ - !ruby/object:Gem::Dependency
154
+ name: codeclimate-test-reporter
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '0.6'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '0.6'
167
+ description: Extracts feed, postings, and attachments from FB fans pages
168
+ email:
169
+ - wtlin0711@gmail.com
170
+ executables:
171
+ - fanswatch
172
+ extensions: []
173
+ extra_rdoc_files: []
174
+ files:
175
+ - ".gitignore"
176
+ - Gemfile
177
+ - README.md
178
+ - Rakefile
179
+ - bin/fanswatch
180
+ - coverage/.last_run.json
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
208
+ - lib/fanswatch.rb
209
+ - lib/fanswatch/attachment.rb
210
+ - lib/fanswatch/fb_api.rb
211
+ - lib/fanswatch/page.rb
212
+ - lib/fanswatch/posting.rb
213
+ - spec/fanswatch_spec.rb
214
+ - spec/spec_helper.rb
215
+ homepage: https://github.com/wtlin1228/FansWatch
216
+ licenses:
217
+ - MIT
218
+ metadata: {}
219
+ post_install_message:
220
+ rdoc_options: []
221
+ require_paths:
222
+ - lib
223
+ required_ruby_version: !ruby/object:Gem::Requirement
224
+ requirements:
225
+ - - ">="
226
+ - !ruby/object:Gem::Version
227
+ version: '0'
228
+ required_rubygems_version: !ruby/object:Gem::Requirement
229
+ requirements:
230
+ - - ">="
231
+ - !ruby/object:Gem::Version
232
+ version: '0'
233
+ requirements: []
234
+ rubyforge_project:
235
+ rubygems_version: 2.6.8
236
+ signing_key:
237
+ specification_version: 4
238
+ summary: Gets posted content from public Facebook fans pages
239
+ test_files:
240
+ - spec/fanswatch_spec.rb
241
+ - spec/spec_helper.rb