secondHandler 0.0.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +68 -4
- data/lib/fb_data_handler.rb +49 -0
- data/lib/second_handler/version.rb +2 -2
- data/lib/second_handler.rb +46 -26
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f3ffc11bd8eef21c6b96d3e722657d50264fd48
|
4
|
+
data.tar.gz: 849d31fbb8c55b4113a37afd42496aeb2a72ce86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7872cccceaeaddf04cd2d87934053c05fed6dee4b141289a81c6aaaede1c88ab33f22a7f1e824f44453b61e1be85c560e14c8c96a90e953e15496639c5d62a8c
|
7
|
+
data.tar.gz: a7e97a7013053488ccda5b45d44f830e9f8790680c57b62a804db7671e57f7a704381d3624a15dfa2de3d65af7350bf4c38a994ec75771b32881e2f99b710937
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
data/README.md
CHANGED
@@ -19,13 +19,77 @@ $ second_handler fb --token 'facebook_dev_access_token' --id 'public_group_id'
|
|
19
19
|
```ruby
|
20
20
|
require 'second_handler'
|
21
21
|
fb = SecondHandler::FbGroupPost.new('access_token', 'group_id')
|
22
|
-
# fetch first page
|
22
|
+
# fetch first page (you **must** call this function first if you want to read posts)
|
23
23
|
page = fb.first_page
|
24
|
-
# get
|
25
|
-
content =
|
24
|
+
# get current content
|
25
|
+
content = fb.get_content
|
26
26
|
# get next page
|
27
|
-
page =
|
27
|
+
page = fb.next_page
|
28
|
+
|
29
|
+
fbp = SecondHandler::FbSinglePost.new('access_token', 'post_id')
|
30
|
+
fbp.get_post_basic #get post information
|
31
|
+
|
32
|
+
fbp.first_comment #fetch first comments
|
33
|
+
fbp.get_comment #get current page comments
|
34
|
+
fbp.next_page_comment #fetch next page comments
|
35
|
+
fbp.previous_page_comment #fetch previous page comments
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
```
|
40
|
+
**SecondHandler::FbGroupPost.get_content Hash sample**
|
41
|
+
```ruby
|
42
|
+
[{
|
43
|
+
"id"=>"0000000_0000000", #feed id
|
44
|
+
"message"=>"OOOO",
|
45
|
+
"updated_time"=>"2015-11-08T00:00:00+0000",
|
46
|
+
"attachments"=>[
|
47
|
+
{"height"=>720, "src"=>"", "width"=>405},...
|
48
|
+
], #post images
|
49
|
+
"from"=>{
|
50
|
+
"id"=>"000000000", #user's fbid
|
51
|
+
"name"=>"My name", #user's fbname
|
52
|
+
"picture"=>{"is_silhouette"=>false, "url"=>"http://www.example.com"} #user's profile picture
|
53
|
+
}
|
54
|
+
},....]
|
55
|
+
```
|
56
|
+
**SecondHandler::FbSinglePost.get_post_basic Hash sample**
|
57
|
+
```ruby
|
58
|
+
{
|
59
|
+
"id"=>"0000000_0000000", #feed id
|
60
|
+
"message"=>"OOOO",
|
61
|
+
"updated_time"=>"2015-11-08T00:00:00+0000",
|
62
|
+
"attachments"=>[
|
63
|
+
{"height"=>720, "src"=>"", "width"=>405},...
|
64
|
+
], #post images
|
65
|
+
"from"=>{
|
66
|
+
"id"=>"000000000", #user's fbid
|
67
|
+
"name"=>"My name", #user's fbname
|
68
|
+
"picture"=>{"is_silhouette"=>false, "url"=>"http://www.example.com"} #user's profile picture
|
69
|
+
}
|
70
|
+
}
|
28
71
|
```
|
72
|
+
**SecondHandler::FbSinglePost.get_comment Hash sample**
|
73
|
+
```ruby
|
74
|
+
[{
|
75
|
+
"id"=>"",
|
76
|
+
"message"=>"",
|
77
|
+
"created_time"=>"",
|
78
|
+
"from"=>{"id"=>"",
|
79
|
+
"name"=>"",
|
80
|
+
"picture"=>{"is_silhouette"=>false, "url"=>""}},
|
81
|
+
"like_count"=>0
|
82
|
+
},.....]
|
83
|
+
|
84
|
+
|
85
|
+
```
|
86
|
+
|
87
|
+
CHANGELOG
|
88
|
+
===
|
89
|
+
2016-1-5 bump to v1.0.0
|
90
|
+
- add single post comment func
|
91
|
+
- modify `SecondHandler::FbGroupPost.get_content` output (no backward support!!!)
|
92
|
+
|
29
93
|
|
30
94
|
## License
|
31
95
|
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module FbDataHandler
|
2
|
+
private
|
3
|
+
def attachment_helper (attach_hash, &func)
|
4
|
+
|
5
|
+
clean_data = []
|
6
|
+
|
7
|
+
if attach_hash && attach_hash["data"].first["media"] && attach_hash["data"].first["media"]["image"]
|
8
|
+
clean_data << attach_hash["data"].first["media"]["image"]
|
9
|
+
end
|
10
|
+
if attach_hash && attach_hash["data"].first["subattachments"] && attach_hash["data"].first["subattachments"]["data"]
|
11
|
+
attach_hash["data"].first["subattachments"]["data"].each do |item|
|
12
|
+
if item["media"] && item["media"]["image"]
|
13
|
+
clean_data << item["media"]["image"]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
clean_data
|
18
|
+
end
|
19
|
+
|
20
|
+
def clean_post_content (item)
|
21
|
+
{
|
22
|
+
"id" => item["id"],
|
23
|
+
"message" => item["message"],
|
24
|
+
"updated_time" => item["updated_time"],
|
25
|
+
"attachments" => attachment_helper(item["attachments"]),
|
26
|
+
"from" => {
|
27
|
+
"id" => item["from"]["id"],
|
28
|
+
"name" => item["from"]["name"],
|
29
|
+
"picture" => item["from"]["picture"]["data"],
|
30
|
+
},
|
31
|
+
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def clean_comment(item)
|
36
|
+
{
|
37
|
+
"id" => item["id"],
|
38
|
+
"message" => item["message"],
|
39
|
+
"created_time" => item["created_time"],
|
40
|
+
"from" => {
|
41
|
+
"id" => item["from"]["id"],
|
42
|
+
"name" => item["from"]["name"],
|
43
|
+
"picture" => item["from"]["picture"]["data"],
|
44
|
+
},
|
45
|
+
"like_count" => item["like_count"]
|
46
|
+
|
47
|
+
}
|
48
|
+
end
|
49
|
+
end
|
data/lib/second_handler.rb
CHANGED
@@ -1,15 +1,54 @@
|
|
1
1
|
require 'koala'
|
2
2
|
require 'json'
|
3
|
+
require_relative 'fb_data_handler'
|
3
4
|
|
4
5
|
module SecondHandler
|
6
|
+
|
7
|
+
class FbSinglePost
|
8
|
+
FB_POSTS_FIELDS = ["attachments{media,subattachments{media}}","id","message","updated_time","from{id,name,picture}", ]
|
9
|
+
include FbDataHandler
|
10
|
+
|
11
|
+
|
12
|
+
def initialize (access_token, post_id)
|
13
|
+
@graph = Koala::Facebook::API.new(access_token)
|
14
|
+
@post_id = post_id
|
15
|
+
end
|
16
|
+
def get_post_basic
|
17
|
+
@basic = @graph.get_object(@post_id, :fields => FB_POSTS_FIELDS)
|
18
|
+
clean_post_content(@basic)
|
19
|
+
end
|
20
|
+
|
21
|
+
def first_comment
|
22
|
+
@comment = @graph.get_connections(@post_id, "comments", :fields => ["from{name,id,picture}","id","message","created_time","like_count", ])
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_comment
|
26
|
+
@comment.map do |single_comment|
|
27
|
+
clean_comment(single_comment)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
def next_page_comment
|
31
|
+
@comment = @comment.next_page
|
32
|
+
end
|
33
|
+
|
34
|
+
def previous_page_comment
|
35
|
+
@comment = @comment.previous_page
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
5
40
|
class FbGroupPost
|
41
|
+
include FbDataHandler
|
42
|
+
|
43
|
+
FB_POSTS_FIELDS = ["attachments{media,subattachments{media}}","id","message","updated_time","from{id,name,picture}", ]
|
44
|
+
|
6
45
|
def initialize (access_token, group_id)
|
7
46
|
@graph = Koala::Facebook::API.new(access_token)
|
8
47
|
@group_id = group_id
|
9
48
|
end
|
10
49
|
|
11
50
|
def first_page
|
12
|
-
@feed = @graph.get_connections(@group_id, "feed", :fields =>
|
51
|
+
@feed = @graph.get_connections(@group_id, "feed", :fields => FB_POSTS_FIELDS)
|
13
52
|
end
|
14
53
|
|
15
54
|
def next_page
|
@@ -21,32 +60,13 @@ module SecondHandler
|
|
21
60
|
end
|
22
61
|
|
23
62
|
# return feed of current page infomation , including image
|
24
|
-
def get_content
|
25
|
-
@feed.map do |
|
26
|
-
|
27
|
-
tmp["id"] = item["id"]
|
28
|
-
tmp["message"] = item["message"]
|
29
|
-
tmp["updated_time"] = item["updated_time"]
|
30
|
-
tmp["attachments"] = attachment_helper(item["attachments"])
|
31
|
-
tmp
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
def attachment_helper (attach_hash)
|
39
|
-
ok_data = []
|
40
|
-
|
41
|
-
if attach_hash && attach_hash["data"].first["media"]
|
42
|
-
ok_data << attach_hash["data"].first["media"]
|
43
|
-
end
|
44
|
-
if attach_hash && attach_hash["data"].first["subattachments"] && attach_hash["data"].first["subattachments"]["data"]
|
45
|
-
attach_hash["data"].first["subattachments"]["data"].each do |item|
|
46
|
-
ok_data << item
|
47
|
-
end
|
63
|
+
def get_content (&func)
|
64
|
+
@feed.map do |single_post|
|
65
|
+
clean_post_content(single_post)
|
48
66
|
end
|
49
|
-
ok_data
|
50
67
|
end
|
68
|
+
|
69
|
+
|
51
70
|
end
|
71
|
+
|
52
72
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: secondHandler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sheng Jung Wu
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2016-01-05 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: minitest
|
@@ -62,11 +62,13 @@ executables:
|
|
62
62
|
extensions: []
|
63
63
|
extra_rdoc_files: []
|
64
64
|
files:
|
65
|
+
- ".gitignore"
|
65
66
|
- Gemfile
|
66
67
|
- LICENSE
|
67
68
|
- README.md
|
68
69
|
- Rakefile
|
69
70
|
- bin/second_handler
|
71
|
+
- lib/fb_data_handler.rb
|
70
72
|
- lib/second_handler.rb
|
71
73
|
- lib/second_handler/version.rb
|
72
74
|
- secondhandler.gemspec
|