facebook_feed 1.0.1 → 1.0.4
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 +15 -0
- data/lib/facebook_feed.rb +2 -1
- data/lib/facebook_feed/errors/invalid_feed_downloader_error.rb +4 -0
- data/lib/facebook_feed/feed_downloader.rb +50 -25
- metadata +6 -11
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NTJhYjVjNDAyNTgwZjIwNTc0YWJlN2UxYzJkYjJlNmM5MzdjM2RiZQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MDQzOTMwY2U2NGFmNDEwMjFkYjZjNjAyMzIxNDEwZmNhYzVlMGY3OA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NTI4MmEyYjFlM2FiYTg4OTM1MThhODE1YmZjNzdmNDZlNjkxOWIyZGU4ZTVh
|
10
|
+
ZjJjN2Q2NzkxYjczNTJkN2Q1OThiODFkMjE1MzBiMTRiZWUyZDMzYzAzY2Yy
|
11
|
+
N2UyNGM0OGRmZjZkZTdjYTk0MGIyMWU0ZTA0NGY2NWRmNDQzMzc=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NTRlYTNhOWViYmRmZDU2NmE2M2ZjMTQzNDA4ZTliMWNmZTgyNTg4MzM3YmVk
|
14
|
+
MmFkNzhhNGNiNzA2NGU5NTU3ZDFjMzVkMzMyZmViZTQ3ZDU2NTY4OGUyOGE1
|
15
|
+
ZGUyMGQ5MjNmM2VhOTI4ZWI4ZjViY2E3YWI5OTMyYWE0Y2QwN2I=
|
data/lib/facebook_feed.rb
CHANGED
@@ -6,4 +6,5 @@ require 'facebook_feed/feed_downloader'
|
|
6
6
|
|
7
7
|
# Errors
|
8
8
|
require 'facebook_feed/errors/feed_error'
|
9
|
-
require 'facebook_feed/errors/invalid_credentials_error'
|
9
|
+
require 'facebook_feed/errors/invalid_credentials_error'
|
10
|
+
require 'facebook_feed/errors/invalid_feed_downloader_error'
|
@@ -6,12 +6,19 @@ module FacebookFeed
|
|
6
6
|
class FeedDownloader
|
7
7
|
attr_reader :access_token, :feed_id
|
8
8
|
|
9
|
+
# Initialize an instance of FeedDownloader like so
|
10
|
+
# opts = { :feed_id => 1234567, :access_token => 'ABCDEFGHI' }
|
11
|
+
# downloader = FeedDownloader.new(opts)
|
12
|
+
|
9
13
|
def initialize(args)
|
14
|
+
raise FacebookFeed::InvalidFeedDownloaderError, "FeedDownloader must be instantiated with a Ruby hash" unless args.is_a?(Hash)
|
15
|
+
unless (args.keys.length == 2) and args.keys.include?(:feed_id) and args.keys.include?(:access_token)
|
16
|
+
raise FacebookFeed::InvalidFeedDownloaderError, "FeedDownloader must be configured with a hash with two keys only: :feed_id and :access_token"
|
17
|
+
end
|
18
|
+
|
10
19
|
args.each do |k, v|
|
11
20
|
instance_variable_set("@#{k}", v) unless v.nil?
|
12
21
|
end
|
13
|
-
#feed_id = opts[:feed_id]
|
14
|
-
#access_token = opts[:access_token]
|
15
22
|
|
16
23
|
base_url = "https://graph.facebook.com/#{@feed_id}/feed?access_token=#{@access_token}"
|
17
24
|
@feed_urls = []
|
@@ -43,6 +50,7 @@ module FacebookFeed
|
|
43
50
|
feed_urls << content_hash["paging"]["next"] unless posts.empty?
|
44
51
|
end
|
45
52
|
|
53
|
+
# Returns a hash object of the JSON returned by the Facebook Graph API
|
46
54
|
def get_content_hash(url)
|
47
55
|
# TO-DO: Write code to authenticate server
|
48
56
|
content = RestClient::Resource.new(
|
@@ -56,6 +64,28 @@ module FacebookFeed
|
|
56
64
|
JSON.parse(content)
|
57
65
|
end
|
58
66
|
|
67
|
+
# Takes in a hash object of the JSON returned by the Facebook Graph API
|
68
|
+
# and returns an array of hash objects like the following:
|
69
|
+
# {
|
70
|
+
# :poster => 'Name of message poster',
|
71
|
+
# :message => 'Message text',
|
72
|
+
# :type => 'Type of post',
|
73
|
+
# :created_time => 'UTC time message was created',
|
74
|
+
# :updated_time => 'UTC time message was updated',
|
75
|
+
# :like_count => 'Number of likes the post has',
|
76
|
+
# :comment_count => 'Number of comments the post has',
|
77
|
+
# :comments => ['Array of comment data']
|
78
|
+
# }
|
79
|
+
#
|
80
|
+
# A comment datum is itself as a hash as well.
|
81
|
+
# It is like the following:
|
82
|
+
# {
|
83
|
+
# :commenter => 'Name of person who made the comment',
|
84
|
+
# :message => 'Comment text',
|
85
|
+
# :created_time => 'UTC time comment was made',
|
86
|
+
# :like_count => 'Number of likes the comment has'
|
87
|
+
# }
|
88
|
+
|
59
89
|
def extract_posts(content_hash)
|
60
90
|
posts = content_hash["data"]
|
61
91
|
return [] if posts.nil?
|
@@ -68,34 +98,29 @@ module FacebookFeed
|
|
68
98
|
doc[:type] = post["type"]
|
69
99
|
doc[:created_time] = post["created_time"]
|
70
100
|
doc[:updated_time] = post["updated_time"]
|
71
|
-
|
72
|
-
doc[:like_count] = post["likes"]["count"]
|
73
|
-
else
|
74
|
-
doc[:like_count] = 0
|
75
|
-
end
|
101
|
+
doc[:like_count] = post["likes"].nil? ? 0 : post["likes"]["count"]
|
76
102
|
|
77
103
|
# Store each comment's sender, time, number of likes, and
|
78
104
|
# the total number of comments for this post
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
else
|
95
|
-
comment_data[:like_count] = comment["likes"]
|
105
|
+
unless post["comments"].nil?
|
106
|
+
doc[:comment_count] = post["comments"]["count"]
|
107
|
+
# Check if data is not nil rather than comment count because
|
108
|
+
# there's a Facebook bug that doesn't log all comments even
|
109
|
+
# if comment number > 0
|
110
|
+
unless post["comments"]["data"].nil?
|
111
|
+
doc[:comments] = []
|
112
|
+
comments = post["comments"]["data"]
|
113
|
+
comments.each do |comment|
|
114
|
+
comment_data = {}
|
115
|
+
comment_data[:commenter] = comment["from"]["name"]
|
116
|
+
comment_data[:message] = comment["message"]
|
117
|
+
comment_data[:created_time] = comment["created_time"]
|
118
|
+
comment_data[:like_count] = comment["likes"] || 0
|
119
|
+
doc[:comments] << comment_data
|
96
120
|
end
|
97
|
-
doc[:comments] << comment_data
|
98
121
|
end
|
122
|
+
else
|
123
|
+
doc[:comment_count] = 0
|
99
124
|
end
|
100
125
|
docs << doc
|
101
126
|
end
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: facebook_feed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Carson Tang
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-04-18 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: json
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - '='
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - '='
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rest-client
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - '='
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - '='
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -54,28 +49,28 @@ files:
|
|
54
49
|
- lib/facebook_feed/feed_downloader.rb
|
55
50
|
- lib/facebook_feed/errors/feed_error.rb
|
56
51
|
- lib/facebook_feed/errors/invalid_credentials_error.rb
|
52
|
+
- lib/facebook_feed/errors/invalid_feed_downloader_error.rb
|
57
53
|
homepage: https://github.com/carsontang/facebook_feed
|
58
54
|
licenses: []
|
55
|
+
metadata: {}
|
59
56
|
post_install_message:
|
60
57
|
rdoc_options: []
|
61
58
|
require_paths:
|
62
59
|
- lib
|
63
60
|
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
-
none: false
|
65
61
|
requirements:
|
66
62
|
- - ! '>='
|
67
63
|
- !ruby/object:Gem::Version
|
68
64
|
version: '0'
|
69
65
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
-
none: false
|
71
66
|
requirements:
|
72
67
|
- - ! '>='
|
73
68
|
- !ruby/object:Gem::Version
|
74
69
|
version: '0'
|
75
70
|
requirements: []
|
76
71
|
rubyforge_project:
|
77
|
-
rubygems_version:
|
72
|
+
rubygems_version: 2.0.3
|
78
73
|
signing_key:
|
79
|
-
specification_version:
|
74
|
+
specification_version: 4
|
80
75
|
summary: Ruby bindings for Facebook feed APIs
|
81
76
|
test_files: []
|