fb_graph2 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/VERSION +1 -1
- data/lib/fb_graph2.rb +2 -1
- data/lib/fb_graph2/edge/admins.rb +17 -0
- data/lib/fb_graph2/edge/blocked.rb +24 -0
- data/lib/fb_graph2/edge/comments.rb +12 -1
- data/lib/fb_graph2/edge/global_brand_children.rb +12 -0
- data/lib/fb_graph2/edge/likes.rb +14 -3
- data/lib/fb_graph2/edge/locations.rb +14 -0
- data/lib/fb_graph2/edge/milestones.rb +12 -0
- data/lib/fb_graph2/edge/offers.rb +12 -0
- data/lib/fb_graph2/edge/promotable_posts.rb +12 -0
- data/lib/fb_graph2/milestone.rb +9 -0
- data/lib/fb_graph2/node.rb +8 -1
- data/lib/fb_graph2/offer.rb +10 -0
- data/lib/fb_graph2/page.rb +18 -0
- data/lib/fb_graph2/photo.rb +3 -0
- data/lib/fb_graph2/post.rb +2 -0
- data/lib/fb_graph2/user.rb +3 -1
- data/lib/fb_graph2/util.rb +13 -0
- data/spec/fb_graph2/edge/accounts_spec.rb +7 -5
- data/spec/fb_graph2/edge/comments_spec.rb +56 -0
- data/spec/fb_graph2/edge/feed_spec.rb +10 -2
- data/spec/fb_graph2/edge/likes_spec.rb +95 -0
- data/spec/fb_graph2/edge/photos_spec.rb +29 -0
- data/spec/fb_graph2/node_spec.rb +8 -0
- data/spec/mock_json/blank_collection.json +1 -0
- data/spec/mock_json/post/comments.json +20 -0
- data/spec/mock_json/post/liked_and_commented.json +59 -0
- data/spec/mock_json/post/likes.json +15 -0
- data/spec/mock_json/true.json +1 -0
- data/spec/mock_json/user/accounts.json +1 -1
- data/spec/mock_json/user/feed.json +274 -0
- data/spec/mock_json/user/likes.json +33 -0
- data/spec/mock_json/user/photos.json +542 -0
- metadata +23 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3b9b96bd354676b41303ec71bb42e5a37f83e79
|
4
|
+
data.tar.gz: 353b8100ce89c4e3b96f832e209d4612357ff44a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 215b26018c47fa99f1da5d3cd07caaf5ff2c62e15b2bcc289a02dfccd43bacdc0d29bb34706ab568c265189ea5bbc2508733a3cf8f69d3d144b3ebf63c57bc7e
|
7
|
+
data.tar.gz: 80c709b966450c3afeb9795b15a5aef28c420cde256bac977bb685654800270c14e27359f6a411769ef345a51b01288861654fbd567e488b9c83b4bcbde6c569
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# FbGraph2
|
2
2
|
|
3
|
-
|
3
|
+
Similar to [fb_graph gem](https://github.com/nov/fb_graph), but supports Graph API v2.0+.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,7 +18,7 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
See [fb_graph2 Wiki](https://github.com/nov/fb_graph2/wiki).
|
22
22
|
|
23
23
|
## Contributing
|
24
24
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/lib/fb_graph2.rb
CHANGED
@@ -2,12 +2,13 @@ require 'active_support/all'
|
|
2
2
|
require 'rack/oauth2'
|
3
3
|
|
4
4
|
module FbGraph2
|
5
|
-
cattr_accessor :api_version, :gem_version, :logger, :debugging, :_http_config_
|
5
|
+
cattr_accessor :api_version, :gem_version, :logger, :debugging, :_http_config_, :object_classes
|
6
6
|
|
7
7
|
self.api_version = 'v2.0'
|
8
8
|
self.gem_version = File.read(File.join(__dir__, '../VERSION')).delete("\n\r")
|
9
9
|
self.logger = Logger.new(STDOUT)
|
10
10
|
self.logger.progname = 'FbGraph2'
|
11
|
+
self.object_classes = Array.new
|
11
12
|
|
12
13
|
class << self
|
13
14
|
def root_url
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module FbGraph2
|
2
|
+
class Edge
|
3
|
+
module Admins
|
4
|
+
def admins(params = {})
|
5
|
+
users = self.edge :admins, params
|
6
|
+
users.collect do |user|
|
7
|
+
User.new(user[:id], user).authenticate self.access_token
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def admin?(user, params = {})
|
12
|
+
users = self.edge :admins, params, edge_scope: user
|
13
|
+
users.present?
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module FbGraph2
|
2
|
+
class Edge
|
3
|
+
module Blocked
|
4
|
+
def blocked(params = {})
|
5
|
+
users = self.edge :blocked, params
|
6
|
+
users.collect do |user|
|
7
|
+
User.new(user[:id], user).authenticate self.access_token
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def block!(user, params = {})
|
12
|
+
self.post params.merge(
|
13
|
+
user_id: Util.as_identifier(user)
|
14
|
+
), edge: :blocked
|
15
|
+
end
|
16
|
+
|
17
|
+
def unblock!(user, params = {})
|
18
|
+
self.delete params.merge(
|
19
|
+
user_id: Util.as_identifier(user)
|
20
|
+
), edge: :blocked
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,8 +1,19 @@
|
|
1
1
|
module FbGraph2
|
2
2
|
class Edge
|
3
3
|
module Comments
|
4
|
+
def assign(attributes)
|
5
|
+
super
|
6
|
+
if attributes.include?(:comments)
|
7
|
+
@_cached_comments = Collection.new attributes[:comments]
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
4
11
|
def comments(params = {})
|
5
|
-
comments =
|
12
|
+
comments = if @_cached_comments.present? && params.blank?
|
13
|
+
@_cached_comments
|
14
|
+
else
|
15
|
+
self.edge :comments, params
|
16
|
+
end
|
6
17
|
comments.collect do |comment|
|
7
18
|
Comment.new(comment[:id], comment).authenticate self.access_token
|
8
19
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module FbGraph2
|
2
|
+
class Edge
|
3
|
+
module GlobalBrandChildren
|
4
|
+
def global_brand_children(params = {})
|
5
|
+
pages = self.edge :global_brand_children, params
|
6
|
+
pages.collect do |page|
|
7
|
+
Page.new(page[:id], page).authenticate self.access_token
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/fb_graph2/edge/likes.rb
CHANGED
@@ -9,15 +9,26 @@ module FbGraph2
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
def liked?(
|
13
|
-
pages = self.edge :likes, params, edge_scope:
|
12
|
+
def liked?(page, params = {})
|
13
|
+
pages = self.edge :likes, params, edge_scope: page
|
14
14
|
pages.present?
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
module LikeeContext
|
19
|
+
def assign(attributes)
|
20
|
+
super
|
21
|
+
if attributes.include?(:likes)
|
22
|
+
@_cached_likes = Collection.new attributes[:likes]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
19
26
|
def likes(params = {})
|
20
|
-
users =
|
27
|
+
users = if @_cached_likes.present? && params.blank?
|
28
|
+
@_cached_likes
|
29
|
+
else
|
30
|
+
self.edge :likes, params
|
31
|
+
end
|
21
32
|
users.collect do |user|
|
22
33
|
User.new(user[:id], user).authenticate self.access_token
|
23
34
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module FbGraph2
|
2
|
+
class Edge
|
3
|
+
module Locations
|
4
|
+
def locations(params = {})
|
5
|
+
pages = self.edge :locations, params
|
6
|
+
pages.collect do |page|
|
7
|
+
Page.new(page[:id], page).authenticate self.access_token
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# TODO: add, delete and update locations
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module FbGraph2
|
2
|
+
class Edge
|
3
|
+
module Milestones
|
4
|
+
def milestones(params = {})
|
5
|
+
milestones = self.edge :milestones, params
|
6
|
+
milestones.collect do |milestone|
|
7
|
+
Milestone.new(milestone[:id], milestone).authenticate self.access_token
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/fb_graph2/node.rb
CHANGED
@@ -4,6 +4,7 @@ module FbGraph2
|
|
4
4
|
|
5
5
|
def self.inherited(klass)
|
6
6
|
klass.include AttributeAssigner
|
7
|
+
FbGraph2.object_classes << klass
|
7
8
|
end
|
8
9
|
|
9
10
|
def initialize(id, attributes = {})
|
@@ -36,6 +37,12 @@ module FbGraph2
|
|
36
37
|
)
|
37
38
|
end
|
38
39
|
|
40
|
+
def edges
|
41
|
+
@edges ||= self.class.included_modules.select do |_module_|
|
42
|
+
_module_.name =~ /FbGraph2::Edge/
|
43
|
+
end.collect(&:instance_methods).sort
|
44
|
+
end
|
45
|
+
|
39
46
|
def destroy(params = {}, options = {})
|
40
47
|
delete params, options
|
41
48
|
end
|
@@ -75,7 +82,7 @@ module FbGraph2
|
|
75
82
|
File.join [
|
76
83
|
File.join(FbGraph2.root_url, id.to_s),
|
77
84
|
options[:edge],
|
78
|
-
options[:edge_scope]
|
85
|
+
Util.as_identifier(options[:edge_scope])
|
79
86
|
].compact.collect(&:to_s)
|
80
87
|
end
|
81
88
|
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module FbGraph2
|
2
|
+
class Offer < Node
|
3
|
+
register_attributes(
|
4
|
+
raw: [:claim_limit, :coupon_type, :image_url, :published, :redemption_code, :redemption_link, :terms, :title, :message],
|
5
|
+
time: [:created_time, :expiration_time, :reminder_time],
|
6
|
+
timestamp: [:scheduled_publish_time],
|
7
|
+
page: [:from]
|
8
|
+
)
|
9
|
+
end
|
10
|
+
end
|
data/lib/fb_graph2/page.rb
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
module FbGraph2
|
2
2
|
class Page < Node
|
3
|
+
include Edge::Admins
|
4
|
+
include Edge::Albums
|
5
|
+
include Edge::Blocked
|
6
|
+
include Edge::Events
|
7
|
+
include Edge::Feed
|
8
|
+
include Edge::GlobalBrandChildren
|
9
|
+
include Edge::Links
|
10
|
+
include Edge::Locations
|
11
|
+
include Edge::Milestones
|
12
|
+
include Edge::Offers
|
13
|
+
include Edge::Picture
|
14
|
+
include Edge::Photos
|
15
|
+
include Edge::Posts
|
16
|
+
include Edge::PromotablePosts
|
17
|
+
include Edge::Statuses
|
18
|
+
include Edge::Tagged
|
19
|
+
include Edge::Videos
|
20
|
+
|
3
21
|
register_attributes(
|
4
22
|
raw: [
|
5
23
|
:about, :attire, :band_members, :booking_agent, :can_post, :category, :checkins, :company_overview,
|
data/lib/fb_graph2/photo.rb
CHANGED
data/lib/fb_graph2/post.rb
CHANGED
data/lib/fb_graph2/user.rb
CHANGED
@@ -36,7 +36,9 @@ module FbGraph2
|
|
36
36
|
:middle_name, :name, :name_format, :political, :quotes, :relationship_status, :religion,
|
37
37
|
:timezone, :third_party_id, :verified, :website,
|
38
38
|
# NOTE: in family edge context
|
39
|
-
:relationship
|
39
|
+
:relationship,
|
40
|
+
# NOTE: in page admin context
|
41
|
+
:perms, :role
|
40
42
|
],
|
41
43
|
time: [:updated_time], # NOTE: undocumented attribute
|
42
44
|
date: [:birthday],
|
@@ -4,14 +4,16 @@ describe FbGraph2::Edge::Accounts do
|
|
4
4
|
context 'included in User' do
|
5
5
|
describe '#accounts' do
|
6
6
|
let(:me) { FbGraph2::User.me('token') }
|
7
|
-
it 'should return
|
7
|
+
it 'should return an Array of FbGraph2::Page with page token' do
|
8
8
|
accounts = mock_graph :get, 'me/accounts', 'user/accounts', access_token: 'token' do
|
9
9
|
me.accounts
|
10
10
|
end
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
accounts.should_not be_blank
|
12
|
+
accounts.each do |account|
|
13
|
+
account.should be_instance_of FbGraph2::Page
|
14
|
+
account.access_token.should == 'page_token'
|
15
|
+
end
|
16
|
+
accounts.first.name.should == 'Identity Conference #idcon'
|
15
17
|
end
|
16
18
|
end
|
17
19
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FbGraph2::Edge::Comments do
|
4
|
+
context 'included in Post' do
|
5
|
+
let(:post) { FbGraph2::Post.new('post_id').authenticate('token') }
|
6
|
+
|
7
|
+
describe '#comments' do
|
8
|
+
context 'when cached' do
|
9
|
+
let(:fetched) do
|
10
|
+
mock_graph :get, 'post_id', 'post/liked_and_commented', access_token: 'token' do
|
11
|
+
post.fetch
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'without params' do
|
16
|
+
it 'should not call API' do
|
17
|
+
expect do
|
18
|
+
fetched.comments
|
19
|
+
end.not_to request_to "#{fetched.id}/comments"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'with params' do
|
24
|
+
it 'should call API' do
|
25
|
+
expect do
|
26
|
+
fetched.comments no_cache: true
|
27
|
+
end.to request_to "#{fetched.id}/comments"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'otherwise' do
|
33
|
+
it 'should return an Array of FbGraph2::Post' do
|
34
|
+
comments = mock_graph :get, 'post_id/comments', 'post/comments', access_token: 'token' do
|
35
|
+
post.comments
|
36
|
+
end
|
37
|
+
comments.should_not be_blank
|
38
|
+
comments.each do |comment|
|
39
|
+
comment.should be_instance_of FbGraph2::Comment
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#comment!' do
|
46
|
+
it 'should return FbGraph2::Post with posted params' do
|
47
|
+
comment = mock_graph :post, 'post_id/comments', 'success_with_id', access_token: 'token' do
|
48
|
+
post.comment! message: 'hello'
|
49
|
+
end
|
50
|
+
comment.should be_instance_of FbGraph2::Comment
|
51
|
+
comment.id.should == 'created_object_id'
|
52
|
+
comment.message.should == 'hello'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -5,10 +5,18 @@ describe FbGraph2::Edge::Feed do
|
|
5
5
|
let(:me) { FbGraph2::User.me('token') }
|
6
6
|
|
7
7
|
describe '#feed' do
|
8
|
-
it
|
8
|
+
it 'should return an Array of FbGraph2::Post' do
|
9
|
+
posts = mock_graph :get, 'me/feed', 'user/feed', access_token: 'token' do
|
10
|
+
me.feed
|
11
|
+
end
|
12
|
+
posts.should_not be_blank
|
13
|
+
posts.each do |post|
|
14
|
+
post.should be_instance_of FbGraph2::Post
|
15
|
+
end
|
16
|
+
end
|
9
17
|
end
|
10
18
|
|
11
|
-
describe 'feed!' do
|
19
|
+
describe '#feed!' do
|
12
20
|
it 'should return FbGraph2::Post with posted params' do
|
13
21
|
post = mock_graph :post, 'me/feed', 'success_with_id', access_token: 'token' do
|
14
22
|
me.feed! message: 'hello'
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FbGraph2::Edge::Likes do
|
4
|
+
context 'included in User' do
|
5
|
+
let(:me) { FbGraph2::User.me('token') }
|
6
|
+
|
7
|
+
describe '#likes' do
|
8
|
+
it 'should return an Array of FbGraph2::Page' do
|
9
|
+
likes = mock_graph :get, 'me/likes', 'user/likes', access_token: 'token' do
|
10
|
+
me.likes
|
11
|
+
end
|
12
|
+
likes.should_not be_blank
|
13
|
+
likes.each do |like|
|
14
|
+
like.should be_instance_of FbGraph2::Page
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#liked?' do
|
20
|
+
context 'liked' do
|
21
|
+
it do
|
22
|
+
mock_graph :get, 'me/likes/page_id', 'user/likes', access_token: 'token' do
|
23
|
+
me.liked? 'page_id'
|
24
|
+
end.should be_true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'otherwise' do
|
29
|
+
it do
|
30
|
+
mock_graph :get, 'me/likes/page_id', 'blank_collection', access_token: 'token' do
|
31
|
+
me.liked? 'page_id'
|
32
|
+
end.should be_false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'included in Post' do
|
39
|
+
let(:post) { FbGraph2::Post.new('post_id').authenticate('token') }
|
40
|
+
|
41
|
+
describe '#likes' do
|
42
|
+
context 'when cached' do
|
43
|
+
let(:fetched) do
|
44
|
+
mock_graph :get, 'post_id', 'post/liked_and_commented', access_token: 'token' do
|
45
|
+
post.fetch
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'without params' do
|
50
|
+
it 'should not call API' do
|
51
|
+
expect do
|
52
|
+
fetched.likes
|
53
|
+
end.not_to request_to "#{fetched.id}/likes"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'with params' do
|
58
|
+
it 'should call API' do
|
59
|
+
expect do
|
60
|
+
fetched.likes no_cache: true
|
61
|
+
end.to request_to "#{fetched.id}/likes"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'otherwise' do
|
67
|
+
it 'should return an Array of FbGraph2::User' do
|
68
|
+
likes = mock_graph :get, 'post_id/likes', 'post/likes', access_token: 'token' do
|
69
|
+
post.likes
|
70
|
+
end
|
71
|
+
likes.should_not be_blank
|
72
|
+
likes.each do |like|
|
73
|
+
like.should be_instance_of FbGraph2::User
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe '#like!' do
|
80
|
+
it 'should return true' do
|
81
|
+
mock_graph :post, 'post_id/likes', 'true', access_token: 'token' do
|
82
|
+
post.like!
|
83
|
+
end.should be_true
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe '#unlike!' do
|
88
|
+
it 'should return true' do
|
89
|
+
mock_graph :delete, 'post_id/likes', 'true', access_token: 'token' do
|
90
|
+
post.unlike!
|
91
|
+
end.should be_true
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|