fanswatch 0.1.2 → 0.1.3
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 +4 -4
- data/README.md +51 -3
- data/fanswatch.gemspec +0 -1
- data/lib/fanswatch/fb_api.rb +13 -0
- data/lib/fanswatch/runner.rb +46 -0
- data/lib/fanswatch/version.rb +1 -1
- data/spec/spec_helper.rb +0 -3
- metadata +3 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: edb3f785533dba5470c392c2f72c6806cc377fef
|
4
|
+
data.tar.gz: 4a74de3d6e7af5c49a7986f3355e9a162eb4030c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b344ae198261f514b6e8c365df995ab255b040dfd6be8a12dd6a92ea95b9f3d8886deb6f49e06d282d63578267a8483ce87c0d38841f0828533c27c8a4e708d
|
7
|
+
data.tar.gz: ee994011f0b580671d5024d21f46ffa28db51fa383a0c58d464c7ed888032b504cef8c0ffa73c4c1ba2854993d7f6e66e51997d5f0d87f8a257466b4fd7c3635
|
data/README.md
CHANGED
@@ -1,7 +1,55 @@
|
|
1
1
|
# FansWatch
|
2
|
+
[](https://badge.fury.io/rb/fanswatch)
|
3
|
+
[](https://travis-ci.org/wtlin1228/FansWatch)
|
2
4
|
|
3
|
-
|
5
|
+
FaceGroup is a gem that specializes in getting data from public Facebook Pages.
|
4
6
|
|
5
|
-
##
|
7
|
+
## Installation
|
6
8
|
|
7
|
-
|
9
|
+
If you are working on a project, add this to your Gemfile: `gem 'fanswatch'`
|
10
|
+
|
11
|
+
For ad hoc installation from command line:
|
12
|
+
|
13
|
+
```$ gem install fanswatch```
|
14
|
+
|
15
|
+
## Setup Facebook Credentials
|
16
|
+
|
17
|
+
Please setup your Facebook developer credentials by creating an app profile on Facebook Developer: https://developers.facebook.com – you should get a "client ID" and "client secret".
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Require FaceGroup gem in your code: `require 'fanswatch'`
|
22
|
+
|
23
|
+
Supply your Facebook credentials to our library in one of two ways:
|
24
|
+
- Setup environment variables: `ENV[FB_CLIENT_ID]` and `ENV[FB_CLIENT_SECRET]`
|
25
|
+
- or, provide them directly to FansWatch:
|
26
|
+
|
27
|
+
```
|
28
|
+
FansWatch::FbApi.config = { client_id: ENV['FB_CLIENT_ID'],
|
29
|
+
client_secret: ENV['FB_CLIENT_SECRET'] }
|
30
|
+
```
|
31
|
+
|
32
|
+
See the following example code for more usage details:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
# Access the page
|
36
|
+
page = FansWatch::Page.find(
|
37
|
+
id: ENV['FB_PAGE_ID']
|
38
|
+
)
|
39
|
+
|
40
|
+
puts page.name
|
41
|
+
|
42
|
+
feed = page.feed
|
43
|
+
|
44
|
+
puts feed.count
|
45
|
+
|
46
|
+
page.feed.postings.each do |posting|
|
47
|
+
puts posting.id
|
48
|
+
puts posting.created_time
|
49
|
+
puts posting.message
|
50
|
+
if posting.attachment
|
51
|
+
puts posting.attachment.description
|
52
|
+
puts posting.attachment.url
|
53
|
+
end
|
54
|
+
end
|
55
|
+
```
|
data/fanswatch.gemspec
CHANGED
@@ -26,7 +26,6 @@ Gem::Specification.new do |s|
|
|
26
26
|
s.add_development_dependency 'flog', '~> 4.4'
|
27
27
|
s.add_development_dependency 'flay', '~> 2.8'
|
28
28
|
s.add_development_dependency 'rubocop', '~> 0.42'
|
29
|
-
s.add_development_dependency 'codeclimate-test-reporter', '~> 0.6'
|
30
29
|
s.homepage = 'https://github.com/wtlin1228/FansWatch'
|
31
30
|
s.license = 'MIT'
|
32
31
|
end
|
data/lib/fanswatch/fb_api.rb
CHANGED
@@ -39,6 +39,19 @@ module FansWatch
|
|
39
39
|
client_secret: ENV['FB_CLIENT_SECRET'] }
|
40
40
|
end
|
41
41
|
|
42
|
+
# Get page_id by url
|
43
|
+
# ex: http "https://graph.facebook.com/v2.8/cyberbuzz?
|
44
|
+
# access_token=1311663858901254|UhNPeFDGUdXZVJwagwNxBK49t-4"
|
45
|
+
#
|
46
|
+
# {
|
47
|
+
# "id": "159425621565",
|
48
|
+
# "name": "Inside 硬塞的網路趨勢觀察"
|
49
|
+
# }
|
50
|
+
def self.page_id(url)
|
51
|
+
fb_page_name = url.split('/')[3]
|
52
|
+
response = fb_resource(fb_page_name)
|
53
|
+
return response['id']
|
54
|
+
end
|
42
55
|
|
43
56
|
# Get the fans page's name and id
|
44
57
|
# ex: @id="159425621565",
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FansWatch
|
4
|
+
# Executable code for file(s) in bin/ folder
|
5
|
+
class Runner
|
6
|
+
def self.run!(args)
|
7
|
+
page_id = args[0] || ENV['FB_PAGE_ID']
|
8
|
+
puts page_id
|
9
|
+
unless page_id
|
10
|
+
puts 'USAGE: fanswatch [page_id]'
|
11
|
+
exit(1)
|
12
|
+
end
|
13
|
+
page = FansWatch::Page.find(id: page_id)
|
14
|
+
|
15
|
+
output_info(page)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.output_info(page)
|
19
|
+
page_name = page.name
|
20
|
+
separator = Array.new(page.name.length) { '-' }.join
|
21
|
+
page_info =
|
22
|
+
page.feed.postings.first(3).map.with_index do |post, index|
|
23
|
+
posting_info(post, index)
|
24
|
+
end.join
|
25
|
+
|
26
|
+
[page_name, separator, page_info].join("\n")
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.posting_info(post, index)
|
30
|
+
[
|
31
|
+
"#{index + 1}: ",
|
32
|
+
message_output(post.message),
|
33
|
+
'Attached: ' + attachment_output(post.attachment),
|
34
|
+
"\n\n"
|
35
|
+
].join
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.message_output(message)
|
39
|
+
message ? message : '(blank)'
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.attachment_output(attachment)
|
43
|
+
attachment ? attachment.url.to_s : '(none)'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/fanswatch/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require 'codeclimate-test-reporter'
|
3
|
-
CodeClimate::TestReporter.start
|
4
2
|
require 'simplecov'
|
5
3
|
SimpleCov.start
|
6
4
|
|
@@ -43,5 +41,4 @@ VCR.configure do |c|
|
|
43
41
|
c.filter_sensitive_data('<CLIENT_ID>') { ENV['FB_CLIENT_ID'] }
|
44
42
|
c.filter_sensitive_data('<CLIENT_SECRET>') { ENV['FB_CLIENT_SECRET'] }
|
45
43
|
|
46
|
-
c.ignore_hosts 'codeclimate.com'
|
47
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.1.
|
4
|
+
version: 0.1.3
|
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-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -150,20 +150,6 @@ dependencies:
|
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
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
153
|
description: Extracts feed, postings, and attachments from FB fans pages
|
168
154
|
email:
|
169
155
|
- wtlin0711@gmail.com
|
@@ -186,6 +172,7 @@ files:
|
|
186
172
|
- lib/fanswatch/feed.rb
|
187
173
|
- lib/fanswatch/page.rb
|
188
174
|
- lib/fanswatch/posting.rb
|
175
|
+
- lib/fanswatch/runner.rb
|
189
176
|
- lib/fanswatch/version.rb
|
190
177
|
- spec/fanswatch_spec.rb
|
191
178
|
- spec/fixtures/results.yml
|