fb_graph 2.0.0.alpha → 2.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fb_graph (1.9.5)
4
+ fb_graph (2.0.0.beta)
5
5
  httpclient (>= 2.2.0.2)
6
6
  rack-oauth2 (>= 0.8.0)
7
7
 
@@ -9,9 +9,9 @@ GEM
9
9
  remote: http://rubygems.org/
10
10
  specs:
11
11
  abstract (1.0.0)
12
- actionpack (3.0.9)
13
- activemodel (= 3.0.9)
14
- activesupport (= 3.0.9)
12
+ actionpack (3.0.10)
13
+ activemodel (= 3.0.10)
14
+ activesupport (= 3.0.10)
15
15
  builder (~> 2.1.2)
16
16
  erubis (~> 2.6.6)
17
17
  i18n (~> 0.5.0)
@@ -19,11 +19,11 @@ GEM
19
19
  rack-mount (~> 0.6.14)
20
20
  rack-test (~> 0.5.7)
21
21
  tzinfo (~> 0.3.23)
22
- activemodel (3.0.9)
23
- activesupport (= 3.0.9)
22
+ activemodel (3.0.10)
23
+ activesupport (= 3.0.10)
24
24
  builder (~> 2.1.2)
25
25
  i18n (~> 0.5.0)
26
- activesupport (3.0.9)
26
+ activesupport (3.0.10)
27
27
  addressable (2.2.6)
28
28
  attr_required (0.0.3)
29
29
  bouncy-castle-java (1.5.0146.1)
@@ -37,11 +37,10 @@ GEM
37
37
  jruby-openssl (0.7.4)
38
38
  bouncy-castle-java
39
39
  json (1.5.3)
40
- json (1.5.3-java)
41
40
  rack (1.2.3)
42
41
  rack-mount (0.6.14)
43
42
  rack (>= 1.0.0)
44
- rack-oauth2 (0.8.7)
43
+ rack-oauth2 (0.9.2)
45
44
  activesupport (>= 2.3)
46
45
  attr_required (>= 0.0.3)
47
46
  httpclient (>= 2.2.0.2)
@@ -62,7 +61,7 @@ GEM
62
61
  diff-lcs (~> 1.1.2)
63
62
  rspec-mocks (2.6.0)
64
63
  tzinfo (0.3.29)
65
- webmock (1.6.4)
64
+ webmock (1.7.4)
66
65
  addressable (> 2.2.5, ~> 2.2)
67
66
  crack (>= 0.1.7)
68
67
 
data/README.rdoc CHANGED
@@ -8,11 +8,10 @@ A full-stack Facebook Graph API wrapper in Ruby.
8
8
 
9
9
  == Resources
10
10
 
11
- * View RDoc on RDoc.info (http://rdoc.info/github/nov/fb_graph)
12
- * View Source on GitHub (http://github.com/nov/fb_graph)
13
- * Report Issues on GitHub (http://github.com/nov/fb_graph/issues)
14
- * Q&A on Google Groups (https://groups.google.com/group/fb_graph)
15
- * Facebook Page (http://www.facebook.com/pages/FbGraph/117513961602338)
11
+ * View Source on GitHub (https://github.com/nov/fb_graph)
12
+ * Report Issues on GitHub (https://github.com/nov/fb_graph/issues)
13
+ * Subscribe Update Info (https://www.facebook.com/FbGraph)
14
+ * Q&A on Google Groups (http://groups.google.com/group/fb_graph)
16
15
 
17
16
  == Examples
18
17
 
@@ -113,7 +112,7 @@ https://github.com/nov/fb_graph/wiki
113
112
  me.feed!(
114
113
  :message => 'Updating via FbGraph',
115
114
  :picture => 'https://graph.facebook.com/matake/picture',
116
- :link => 'http://github.com/nov/fb_graph',
115
+ :link => 'https://github.com/nov/fb_graph',
117
116
  :name => 'FbGraph',
118
117
  :description => 'A Ruby wrapper for Facebook Graph API'
119
118
  )
@@ -142,7 +141,7 @@ https://github.com/nov/fb_graph/wiki
142
141
 
143
142
  me = FbGraph::User.me(ACCESS_TOKEN)
144
143
  link = me.link!(
145
- :link => 'http://github.com/nov/fb_graph',
144
+ :link => 'https://github.com/nov/fb_graph',
146
145
  :message => 'A Ruby wrapper for Facebook Graph API.'
147
146
  )
148
147
 
@@ -202,7 +201,7 @@ https://github.com/nov/fb_graph/wiki
202
201
 
203
202
  Both Facebook JavaScript SDK and normal OAuth2 flow is supported.
204
203
  Below I show simple sample code.
205
- You can also see http://github.com/nov/fb_graph_sample for more details Rails3 sample application.
204
+ You can also see https://github.com/nov/fb_graph_sample for more details Rails3 sample application.
206
205
 
207
206
  ==== JavaScript SDK
208
207
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0.alpha
1
+ 2.0.0.beta
@@ -0,0 +1,33 @@
1
+ module FbGraph
2
+ module Connections
3
+ module Blocked
4
+ def blocked(options = {})
5
+ blocked = self.connection :blocked, options
6
+ blocked.map! do |user|
7
+ User.new(user[:id], user.merge(
8
+ :access_token => options[:access_token] || self.access_token
9
+ ))
10
+ end
11
+ end
12
+
13
+ def blocked?(user, options = {})
14
+ blocked = self.connection :blocked, options.merge(:connection_scope => user.identifier)
15
+ blocked.present?
16
+ end
17
+
18
+ def block!(*users)
19
+ options = users.extract_options!
20
+ blocked = post options.merge(:connection => :blocked, :uid => Array(users).collect(&:identifier).join(','))
21
+ blocked.delete_if do |user_id, succeeded|
22
+ !succeeded
23
+ end.keys.map! do |user_id|
24
+ User.new(user_id, :access_token => options[:access_token] || self.access_token)
25
+ end
26
+ end
27
+
28
+ def unblock!(user, options = {})
29
+ delete options.merge(:connection => :blocked, :connection_scope => user.identifier)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -19,6 +19,11 @@ module FbGraph
19
19
  end
20
20
  end
21
21
 
22
+ def like?(page, options = {})
23
+ like = self.connection :likes, options.merge(:connection_scope => page.identifier)
24
+ like.present?
25
+ end
26
+
22
27
  # NOTE: likes! is defined in fb_graph/connections/comments.rb
23
28
  end
24
29
  end
data/lib/fb_graph/page.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  module FbGraph
2
2
  class Page < Node
3
3
  include Connections::Albums
4
+ include Connections::Blocked
4
5
  include Connections::Checkins
5
6
  include Connections::Events
6
7
  include Connections::Feed
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe FbGraph::Connections::Blocked do
4
+ let(:page) { FbGraph::Page.new(117513961602338, :access_token => 'access_token') }
5
+ let(:user) { FbGraph::User.new(579612276) }
6
+
7
+ describe '#blocked' do
8
+ it 'should return blocked users as FbGraph::User' do
9
+ mock_graph :get, '117513961602338/blocked', 'pages/blocked/index', :access_token => 'access_token' do
10
+ users = page.blocked
11
+ users.each do |user|
12
+ user.should be_a FbGraph::User
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ describe '#blocked?' do
19
+ context 'when blocked' do
20
+ it 'should retrun true' do
21
+ mock_graph :get, '117513961602338/blocked/579612276', 'pages/blocked/show_blocked', :access_token => 'access_token' do
22
+ page.blocked?(user).should be_true
23
+ end
24
+ end
25
+ end
26
+
27
+ context 'otherwise' do
28
+ it 'should retrun false' do
29
+ mock_graph :get, '117513961602338/blocked/579612276', 'pages/blocked/show_non_blocked', :access_token => 'access_token' do
30
+ page.blocked?(user).should be_false
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ describe '#block!' do
37
+ it 'should return blocked users as FbGraph::User' do
38
+ mock_graph :post, '117513961602338/blocked', 'pages/blocked/create', :access_token => 'access_token', :params => {
39
+ :uid => '579612276'
40
+ } do
41
+ blocked = page.block! user
42
+ blocked.each do |user|
43
+ user.should be_a FbGraph::User
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ describe '#unblock!' do
50
+ it 'should return true' do
51
+ mock_graph :delete, '117513961602338/blocked/579612276', 'true', :access_token => 'access_token' do
52
+ page.unblock!(user).should be_true
53
+ end
54
+ end
55
+ end
56
+ end
@@ -1,71 +1,95 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require 'spec_helper'
3
3
 
4
- describe FbGraph::Connections::Likes, '#likes' do
5
- context 'when included by FbGraph::User' do
6
- context 'when no access_token given' do
7
- it 'should raise FbGraph::Unauthorized' do
8
- mock_graph :get, 'arjun/likes', 'users/likes/arjun_public', :status => [401, 'Unauthorized'] do
9
- lambda do
10
- FbGraph::User.new('arjun').likes
11
- end.should raise_exception(FbGraph::Unauthorized)
4
+ describe FbGraph::Connections::Likes do
5
+ describe '#likes' do
6
+ context 'when included by FbGraph::User' do
7
+ context 'when no access_token given' do
8
+ it 'should raise FbGraph::Unauthorized' do
9
+ mock_graph :get, 'arjun/likes', 'users/likes/arjun_public', :status => [401, 'Unauthorized'] do
10
+ lambda do
11
+ FbGraph::User.new('arjun').likes
12
+ end.should raise_exception(FbGraph::Unauthorized)
13
+ end
12
14
  end
13
15
  end
14
- end
15
16
 
16
- context 'when access_token is given' do
17
- it 'should return liked pages as FbGraph::Page' do
18
- mock_graph :get, 'arjun/likes', 'users/likes/arjun_private', :access_token => 'access_token' do
19
- likes = FbGraph::User.new('arjun', :access_token => 'access_token').likes
20
- likes.first.should == FbGraph::Page.new(
21
- '378209722137',
22
- :access_token => 'access_token',
23
- :name => 'Doing Things at the Last Minute',
24
- :category => '活動'
25
- )
26
- likes.each do |like|
27
- like.should be_instance_of(FbGraph::Page)
17
+ context 'when access_token is given' do
18
+ it 'should return liked pages as FbGraph::Page' do
19
+ mock_graph :get, 'arjun/likes', 'users/likes/arjun_private', :access_token => 'access_token' do
20
+ likes = FbGraph::User.new('arjun', :access_token => 'access_token').likes
21
+ likes.first.should == FbGraph::Page.new(
22
+ '378209722137',
23
+ :access_token => 'access_token',
24
+ :name => 'Doing Things at the Last Minute',
25
+ :category => '活動'
26
+ )
27
+ likes.each do |like|
28
+ like.should be_instance_of(FbGraph::Page)
29
+ end
28
30
  end
29
31
  end
30
32
  end
31
33
  end
32
- end
33
34
 
34
- context 'when included by FbGraph::Status' do
35
- context 'when cached collection exists' do
36
- before do
37
- mock_graph :get, 'with_likes', 'statuses/with_likes', :access_token => 'access_token' do
38
- @status = FbGraph::Status.new('with_likes').fetch(:access_token => 'access_token')
35
+ context 'when included by FbGraph::Status' do
36
+ context 'when cached collection exists' do
37
+ before do
38
+ mock_graph :get, 'with_likes', 'statuses/with_likes', :access_token => 'access_token' do
39
+ @status = FbGraph::Status.new('with_likes').fetch(:access_token => 'access_token')
40
+ end
39
41
  end
40
- end
41
42
 
42
- context 'when no options given' do
43
- it 'should not access to Graph API' do
44
- @status.likes.should == [FbGraph::User.new(
45
- '604578140',
46
- :access_token => 'access_token',
47
- :name => 'K Hiromi'
48
- )]
49
- @status.likes.next.should == []
50
- @status.likes.previous.should == []
43
+ context 'when no options given' do
44
+ it 'should not access to Graph API' do
45
+ @status.likes.should == [FbGraph::User.new(
46
+ '604578140',
47
+ :access_token => 'access_token',
48
+ :name => 'K Hiromi'
49
+ )]
50
+ @status.likes.next.should == []
51
+ @status.likes.previous.should == []
52
+ end
53
+ end
54
+
55
+ context 'when any options given' do
56
+ it 'should access to Graph API' do
57
+ lambda do
58
+ @status.likes(:no_cache => true) # :no_cache has no meaning, just putting some value as options
59
+ end.should request_to('115838235152172/likes?access_token=access_token&no_cache=true')
60
+ lambda do
61
+ @status.likes(:limit => 10)
62
+ end.should request_to('115838235152172/likes?access_token=access_token&limit=10')
63
+ end
64
+
65
+ context 'when next/previous are obviously blank' do
66
+ it 'should not access to Graph API' do
67
+ @status.likes.next(:no_cache => true).should == []
68
+ @status.likes.previous(:no_cache => true).should == []
69
+ end
70
+ end
51
71
  end
52
72
  end
73
+ end
74
+ end
75
+
76
+ describe '#like?' do
77
+ let(:user) { FbGraph::User.new(579612276, :access_token => 'access_token') }
78
+ let(:fb_graph) { FbGraph::Page.new(117513961602338) }
79
+ let(:poken) { FbGraph::Page.new(1234567890) }
53
80
 
54
- context 'when any options given' do
55
- it 'should access to Graph API' do
56
- lambda do
57
- @status.likes(:no_cache => true) # :no_cache has no meaning, just putting some value as options
58
- end.should request_to('115838235152172/likes?access_token=access_token&no_cache=true')
59
- lambda do
60
- @status.likes(:limit => 10)
61
- end.should request_to('115838235152172/likes?access_token=access_token&limit=10')
81
+ context 'when liked' do
82
+ it 'should retrun true' do
83
+ mock_graph :get, '579612276/likes/117513961602338', 'users/likes/fb_graph', :access_token => 'access_token' do
84
+ user.like?(fb_graph).should be_true
62
85
  end
86
+ end
87
+ end
63
88
 
64
- context 'when next/previous are obviously blank' do
65
- it 'should not access to Graph API' do
66
- @status.likes.next(:no_cache => true).should == []
67
- @status.likes.previous(:no_cache => true).should == []
68
- end
89
+ context 'otherwise' do
90
+ it 'should retrun true' do
91
+ mock_graph :get, '579612276/likes/1234567890', 'users/likes/poken', :access_token => 'access_token' do
92
+ user.like?(poken).should be_false
69
93
  end
70
94
  end
71
95
  end
@@ -0,0 +1 @@
1
+ {"579612276":true}
@@ -0,0 +1,10 @@
1
+ {
2
+ "data": [{
3
+ "name": "Jr Nov",
4
+ "id": "1575327134"
5
+ },
6
+ {
7
+ "name": "Nov Matake",
8
+ "id": "579612276"
9
+ }]
10
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "data": [{
3
+ "name": "Nov Matake",
4
+ "id": "579612276"
5
+ }]
6
+ }
@@ -0,0 +1 @@
1
+ {"data": []}
@@ -0,0 +1 @@
1
+ {"data":[{"name":"FbGraph", "category":"Software", "id":"117513961602338", "created_time":"2010-04-30T06:48:21+0000"}]}
@@ -0,0 +1 @@
1
+ {"data":[]}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fb_graph
3
3
  version: !ruby/object:Gem::Version
4
- hash: -1851332194
4
+ hash: 31098209
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
9
  - 0
10
- - alpha
11
- version: 2.0.0.alpha
10
+ - beta
11
+ version: 2.0.0.beta
12
12
  platform: ruby
13
13
  authors:
14
14
  - nov matake
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-08-10 00:00:00 Z
19
+ date: 2011-08-22 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: httpclient
@@ -168,6 +168,7 @@ files:
168
168
  - lib/fb_graph/connections/albums.rb
169
169
  - lib/fb_graph/connections/app_requests.rb
170
170
  - lib/fb_graph/connections/attending.rb
171
+ - lib/fb_graph/connections/blocked.rb
171
172
  - lib/fb_graph/connections/books.rb
172
173
  - lib/fb_graph/connections/checkins.rb
173
174
  - lib/fb_graph/connections/comments.rb
@@ -269,6 +270,7 @@ files:
269
270
  - spec/fb_graph/connections/albums_spec.rb
270
271
  - spec/fb_graph/connections/app_requests_spec.rb
271
272
  - spec/fb_graph/connections/attending_spec.rb
273
+ - spec/fb_graph/connections/blocked_spec.rb
272
274
  - spec/fb_graph/connections/books_spec.rb
273
275
  - spec/fb_graph/connections/checkins_spec.rb
274
276
  - spec/fb_graph/connections/comments_spec.rb
@@ -377,6 +379,10 @@ files:
377
379
  - spec/mock_json/events/noreply/smartday_private.json
378
380
  - spec/mock_json/groups/docs/private.json
379
381
  - spec/mock_json/groups/members/emacs_private.json
382
+ - spec/mock_json/pages/blocked/create.json
383
+ - spec/mock_json/pages/blocked/index.json
384
+ - spec/mock_json/pages/blocked/show_blocked.json
385
+ - spec/mock_json/pages/blocked/show_non_blocked.json
380
386
  - spec/mock_json/pages/categories/local_business.json
381
387
  - spec/mock_json/pages/categories/movie.json
382
388
  - spec/mock_json/pages/categories/music.json
@@ -467,6 +473,8 @@ files:
467
473
  - spec/mock_json/users/interests/matake_private.json
468
474
  - spec/mock_json/users/likes/arjun_private.json
469
475
  - spec/mock_json/users/likes/arjun_public.json
476
+ - spec/mock_json/users/likes/fb_graph.json
477
+ - spec/mock_json/users/likes/poken.json
470
478
  - spec/mock_json/users/links/matake_private.json
471
479
  - spec/mock_json/users/links/post_with_valid_access_token.json
472
480
  - spec/mock_json/users/me_private.json
@@ -539,6 +547,7 @@ test_files:
539
547
  - spec/fb_graph/connections/albums_spec.rb
540
548
  - spec/fb_graph/connections/app_requests_spec.rb
541
549
  - spec/fb_graph/connections/attending_spec.rb
550
+ - spec/fb_graph/connections/blocked_spec.rb
542
551
  - spec/fb_graph/connections/books_spec.rb
543
552
  - spec/fb_graph/connections/checkins_spec.rb
544
553
  - spec/fb_graph/connections/comments_spec.rb
@@ -647,6 +656,10 @@ test_files:
647
656
  - spec/mock_json/events/noreply/smartday_private.json
648
657
  - spec/mock_json/groups/docs/private.json
649
658
  - spec/mock_json/groups/members/emacs_private.json
659
+ - spec/mock_json/pages/blocked/create.json
660
+ - spec/mock_json/pages/blocked/index.json
661
+ - spec/mock_json/pages/blocked/show_blocked.json
662
+ - spec/mock_json/pages/blocked/show_non_blocked.json
650
663
  - spec/mock_json/pages/categories/local_business.json
651
664
  - spec/mock_json/pages/categories/movie.json
652
665
  - spec/mock_json/pages/categories/music.json
@@ -737,6 +750,8 @@ test_files:
737
750
  - spec/mock_json/users/interests/matake_private.json
738
751
  - spec/mock_json/users/likes/arjun_private.json
739
752
  - spec/mock_json/users/likes/arjun_public.json
753
+ - spec/mock_json/users/likes/fb_graph.json
754
+ - spec/mock_json/users/likes/poken.json
740
755
  - spec/mock_json/users/links/matake_private.json
741
756
  - spec/mock_json/users/links/post_with_valid_access_token.json
742
757
  - spec/mock_json/users/me_private.json