fb_graph 2.3.0 → 2.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,27 +1,27 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fb_graph (2.2.6)
4
+ fb_graph (2.3.0)
5
5
  httpclient (>= 2.2.0.2)
6
6
  rack-oauth2 (>= 0.9.4)
7
7
 
8
8
  GEM
9
9
  remote: http://rubygems.org/
10
10
  specs:
11
- actionpack (3.2.0)
12
- activemodel (= 3.2.0)
13
- activesupport (= 3.2.0)
11
+ actionpack (3.2.1)
12
+ activemodel (= 3.2.1)
13
+ activesupport (= 3.2.1)
14
14
  builder (~> 3.0.0)
15
15
  erubis (~> 2.7.0)
16
- journey (~> 1.0.0)
16
+ journey (~> 1.0.1)
17
17
  rack (~> 1.4.0)
18
18
  rack-cache (~> 1.1)
19
19
  rack-test (~> 0.6.1)
20
20
  sprockets (~> 2.1.2)
21
- activemodel (3.2.0)
22
- activesupport (= 3.2.0)
21
+ activemodel (3.2.1)
22
+ activesupport (= 3.2.1)
23
23
  builder (~> 3.0.0)
24
- activesupport (3.2.0)
24
+ activesupport (3.2.1)
25
25
  i18n (~> 0.6)
26
26
  multi_json (~> 1.0)
27
27
  addressable (2.2.6)
@@ -39,13 +39,13 @@ GEM
39
39
  hike (1.2.1)
40
40
  httpclient (2.2.4)
41
41
  i18n (0.6.0)
42
- journey (1.0.0)
42
+ journey (1.0.1)
43
43
  json (1.6.5)
44
44
  multi_json (1.0.4)
45
- rack (1.4.0)
45
+ rack (1.4.1)
46
46
  rack-cache (1.1)
47
47
  rack (>= 0.4)
48
- rack-oauth2 (0.11.0)
48
+ rack-oauth2 (0.12.2)
49
49
  activesupport (>= 2.3)
50
50
  attr_required (>= 0.0.3)
51
51
  httpclient (>= 2.2.0.2)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.3.0
1
+ 2.3.1
@@ -1,6 +1,8 @@
1
1
  require 'httpclient'
2
2
  require 'rack/oauth2'
3
3
  require 'patch/rack/oauth2/util'
4
+ require 'patch/rack/oauth2/client'
5
+ require 'patch/rack/oauth2/access_token'
4
6
 
5
7
  module FbGraph
6
8
  VERSION = ::File.read(
@@ -27,7 +27,7 @@ module FbGraph
27
27
  def authorize_uri(canvas_uri, options = {})
28
28
  endpoint = URI.parse SignedRequest::OAUTH_DIALOG_ENDPOINT
29
29
  params = options.merge(
30
- :client_id => self.client.identifier,
30
+ :client_id => client.identifier,
31
31
  :redirect_uri => canvas_uri
32
32
  )
33
33
  params[:scope] = Array(params[:scope]).join(',') if params[:scope].present?
@@ -50,17 +50,13 @@ module FbGraph
50
50
  self
51
51
  end
52
52
 
53
- def from_session_key(session_key)
54
- response = HTTPClient.new.post "#{ROOT_URL}/oauth/exchange_sessions", {:client_id => @client.identifier, :client_secret => @client.secret, :sessions => session_key}
55
- if response.body && self.data = JSON.parse(response.body)
56
- if self.data[0]
57
- self.access_token = build_access_token(self.data[0].with_indifferent_access)
58
- else
59
- # If the session key is unknown or there's an error, Facebook returns null
60
- self.access_token = nil
61
- end
62
- end
53
+ def exchange_token!(access_token)
54
+ raise Unauthorized.new('No Access Token') unless access_token
55
+ client.fb_exchange_token = access_token
56
+ self.access_token = client.access_token!
63
57
  self
58
+ rescue Rack::OAuth2::Client::Error => e
59
+ raise Exception.new(e.status, e.message)
64
60
  end
65
61
 
66
62
  private
@@ -18,7 +18,8 @@ module FbGraph
18
18
  # NOTE: Graph API returns {"data":{"to":[null]}} sometimes... :(
19
19
  collection[:data].delete_if(&:nil?)
20
20
 
21
- result = replace(collection[:data])
21
+ replace collection[:data]
22
+
22
23
  if (summary = collection[:summary]).present?
23
24
  @total_count = summary[:total_count]
24
25
  @unread_count = summary[:unread_count]
@@ -0,0 +1,14 @@
1
+ module FbGraph
2
+ module Connections
3
+ module SubscribedTo
4
+ def subscribed_to(options = {})
5
+ subscribees = self.connection :subscribedto, options
6
+ subscribees.map! do |subscribee|
7
+ User.new subscribee[:id], subscribee.merge(
8
+ :access_token => options[:access_token] || self.access_token
9
+ )
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module FbGraph
2
+ module Connections
3
+ module Subscribers
4
+ def subscribers(options = {})
5
+ subscribers = self.connection :subscribers, options
6
+ subscribers.map! do |subscriber|
7
+ User.new subscriber[:id], subscriber.merge(
8
+ :access_token => options[:access_token] || self.access_token
9
+ )
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -13,6 +13,11 @@ module FbGraph
13
13
  def tab!(options = {})
14
14
  post options.merge(:connection => :tabs)
15
15
  end
16
+
17
+ def tab?(application, options = {})
18
+ tab = self.connection :tabs, options.merge(:connection_scope => application.identifier)
19
+ tab.present?
20
+ end
16
21
  end
17
22
  end
18
23
  end
@@ -35,6 +35,8 @@ module FbGraph
35
35
  include Connections::Questions
36
36
  include Connections::Scores
37
37
  include Connections::Statuses
38
+ include Connections::SubscribedTo
39
+ include Connections::Subscribers
38
40
  include Connections::Tagged
39
41
  include Connections::Television
40
42
  include Connections::Threads
@@ -0,0 +1,11 @@
1
+ module Rack
2
+ module OAuth2
3
+ class AccessToken
4
+ def initialize_with_expires_support(attributes = {})
5
+ initialize_without_expires_support attributes
6
+ self.expires_in ||= attributes[:expires]
7
+ end
8
+ alias_method_chain :initialize, :expires_support
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ require 'patch/rack/oauth2/grant/fb_exchange_token'
2
+
3
+ module Rack
4
+ module OAuth2
5
+ class Client
6
+ def fb_exchange_token=(access_token)
7
+ @grant = Grant::FbExchangeToken.new(
8
+ :fb_exchange_token => access_token
9
+ )
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module Rack
2
+ module OAuth2
3
+ class Client
4
+ class Grant
5
+ class FbExchangeToken < Grant
6
+ attr_required :fb_exchange_token
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -162,26 +162,13 @@ describe FbGraph::Auth do
162
162
  end
163
163
  end
164
164
 
165
- describe "#from_session_key" do
166
- let(:session_key) { 'my_session_key'}
167
-
168
- it "should exchange the session key for an oauth token" do
169
- mock_graph :post, '/oauth/exchange_sessions', 'exchange_sessions_response' do
170
- auth.access_token.should be_nil
171
-
172
- auth.from_session_key(session_key)
173
- auth.access_token.should be_a Rack::OAuth2::AccessToken::Legacy
174
- auth.access_token.access_token.should == "my_oauth_token"
175
- end
176
- end
177
-
178
-
179
- it "should handle null responses" do
180
- mock_graph :post, '/oauth/exchange_sessions', 'exchange_sessions_null_response' do
181
- auth.access_token.should be_nil
182
-
183
- auth.from_session_key(session_key)
184
- auth.access_token.should be_nil
165
+ describe "#exchange_token!" do
166
+ it 'should get new token' do
167
+ mock_graph :post, '/oauth/access_token', 'token_with_expiry' do
168
+ auth.exchange_token! 'old_token'
169
+ puts auth.access_token
170
+ auth.access_token.access_token.should == 'new_token'
171
+ auth.access_token.expires_in.should == 3600
185
172
  end
186
173
  end
187
174
  end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe FbGraph::Connections::SubscribedTo do
4
+ it 'should return subscribees as FbGraph::User' do
5
+ mock_graph :get, 'me/subscribedto', 'users/subscribed_to/sample', :access_token => 'access_token' do
6
+ subscribees = FbGraph::User.me('access_token').subscribed_to
7
+ subscribees.each do |subscribee|
8
+ subscribee.should be_instance_of FbGraph::User
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe FbGraph::Connections::Subscribers do
4
+ it 'should return subscribers as FbGraph::User' do
5
+ mock_graph :get, 'me/subscribers', 'users/subscribers/sample', :access_token => 'access_token' do
6
+ subscribers = FbGraph::User.me('access_token').subscribers
7
+ subscribers.each do |subscriber|
8
+ subscriber.should be_instance_of FbGraph::User
9
+ end
10
+ end
11
+ end
12
+ end
@@ -22,4 +22,26 @@ describe FbGraph::Connections::Tabs do
22
22
  end
23
23
  end
24
24
  end
25
+
26
+ describe '#tab?' do
27
+ context 'when installed' do
28
+ it 'shoud return true' do
29
+ mock_graph :get, 'FbGraph/tabs/wall', 'pages/tabs/wall', :access_token => 'page_token' do
30
+ page.tab?(
31
+ FbGraph::Application.new('wall')
32
+ ).should be_true
33
+ end
34
+ end
35
+ end
36
+
37
+ context 'otherwise' do
38
+ it 'shoud return false' do
39
+ mock_graph :get, 'FbGraph/tabs/app_id', 'pages/tabs/blank', :access_token => 'page_token' do
40
+ page.tab?(
41
+ FbGraph::Application.new('app_id')
42
+ ).should be_false
43
+ end
44
+ end
45
+ end
46
+ end
25
47
  end
@@ -0,0 +1,3 @@
1
+ {
2
+ "data": []
3
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "data": [
3
+ {
4
+ "id": "117513961602338/tabs/wall",
5
+ "name": "Wall",
6
+ "link": "https://www.facebook.com/FbGraph?sk=wall",
7
+ "is_permanent": true,
8
+ "position": 0,
9
+ "type": "profile_tab"
10
+ }
11
+ ]
12
+ }
@@ -1 +1 @@
1
- access_token=token&expires=3600
1
+ access_token=new_token&expires=3600
@@ -0,0 +1,11 @@
1
+ {
2
+ "data": [
3
+ {
4
+ "name": "Kristopher Tate",
5
+ "id": "503975854"
6
+ }
7
+ ],
8
+ "paging": {
9
+ "next": "https://graph.facebook.com/me/subscribedto?format=json&limit=5000&offset=5000&__after_id=503975854"
10
+ }
11
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "data": [
3
+ {
4
+ "name": "Kunal Gandhre",
5
+ "id": "1396637703"
6
+ },
7
+ {
8
+ "name": "Adnan S.",
9
+ "id": "717005001"
10
+ }
11
+ ],
12
+ "paging": {
13
+ "next": "https://graph.facebook.com/me/subscribers?format=json&limit=5000&offset=5000&__after_id=708124104"
14
+ }
15
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fb_graph
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-25 00:00:00.000000000Z
12
+ date: 2012-02-01 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httpclient
16
- requirement: &70111210190500 !ruby/object:Gem::Requirement
16
+ requirement: &70200070860660 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.2.0.2
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70111210190500
24
+ version_requirements: *70200070860660
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rack-oauth2
27
- requirement: &70111210190000 !ruby/object:Gem::Requirement
27
+ requirement: &70200070859240 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.9.4
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70111210190000
35
+ version_requirements: *70200070859240
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &70111210189500 !ruby/object:Gem::Requirement
38
+ requirement: &70200070858020 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0.8'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70111210189500
46
+ version_requirements: *70200070858020
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: cover_me
49
- requirement: &70111210188980 !ruby/object:Gem::Requirement
49
+ requirement: &70200070857480 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.2.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70111210188980
57
+ version_requirements: *70200070857480
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rspec
60
- requirement: &70111210188320 !ruby/object:Gem::Requirement
60
+ requirement: &70200070856760 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '2'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70111210188320
68
+ version_requirements: *70200070856760
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: webmock
71
- requirement: &70111210187720 !ruby/object:Gem::Requirement
71
+ requirement: &70200070855580 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 1.6.2
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70111210187720
79
+ version_requirements: *70200070855580
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: actionpack
82
- requirement: &70111210180600 !ruby/object:Gem::Requirement
82
+ requirement: &70200070853500 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: 3.0.6
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70111210180600
90
+ version_requirements: *70200070853500
91
91
  description: A full-stack Facebook Graph API wrapper in Ruby.
92
92
  email: nov@matake.jp
93
93
  executables: []
@@ -198,6 +198,8 @@ files:
198
198
  - lib/fb_graph/connections/senders.rb
199
199
  - lib/fb_graph/connections/settings.rb
200
200
  - lib/fb_graph/connections/statuses.rb
201
+ - lib/fb_graph/connections/subscribed_to.rb
202
+ - lib/fb_graph/connections/subscribers.rb
201
203
  - lib/fb_graph/connections/subscriptions.rb
202
204
  - lib/fb_graph/connections/tabs.rb
203
205
  - lib/fb_graph/connections/tagged.rb
@@ -264,6 +266,9 @@ files:
264
266
  - lib/fb_graph/venue.rb
265
267
  - lib/fb_graph/video.rb
266
268
  - lib/fb_graph/work.rb
269
+ - lib/patch/rack/oauth2/access_token.rb
270
+ - lib/patch/rack/oauth2/client.rb
271
+ - lib/patch/rack/oauth2/grant/fb_exchange_token.rb
267
272
  - lib/patch/rack/oauth2/util.rb
268
273
  - spec/fb_graph/achievement_spec.rb
269
274
  - spec/fb_graph/ad_account_spec.rb
@@ -346,6 +351,8 @@ files:
346
351
  - spec/fb_graph/connections/senders_spec.rb
347
352
  - spec/fb_graph/connections/settings_spec.rb
348
353
  - spec/fb_graph/connections/statuses_spec.rb
354
+ - spec/fb_graph/connections/subscribed_to_spec.rb
355
+ - spec/fb_graph/connections/subscribers_spec.rb
349
356
  - spec/fb_graph/connections/subscriptions_spec.rb
350
357
  - spec/fb_graph/connections/tabs_spec.rb
351
358
  - spec/fb_graph/connections/tagged_spec.rb
@@ -446,8 +453,6 @@ files:
446
453
  - spec/mock_json/events/maybe/post_with_valid_access_token.json
447
454
  - spec/mock_json/events/maybe/smartday_private.json
448
455
  - spec/mock_json/events/noreply/smartday_private.json
449
- - spec/mock_json/exchange_sessions_null_response.json
450
- - spec/mock_json/exchange_sessions_response.json
451
456
  - spec/mock_json/friend_lists/members/sample.json
452
457
  - spec/mock_json/groups/docs/private.json
453
458
  - spec/mock_json/groups/members/emacs_private.json
@@ -480,7 +485,9 @@ files:
480
485
  - spec/mock_json/pages/settings/sample.json
481
486
  - spec/mock_json/pages/statuses/platform_private.json
482
487
  - spec/mock_json/pages/statuses/platform_public.json
488
+ - spec/mock_json/pages/tabs/blank.json
483
489
  - spec/mock_json/pages/tabs/fb_graph.json
490
+ - spec/mock_json/pages/tabs/wall.json
484
491
  - spec/mock_json/pages/with_token.json
485
492
  - spec/mock_json/photos/sample.json
486
493
  - spec/mock_json/photos/with_tags.json
@@ -582,6 +589,8 @@ files:
582
589
  - spec/mock_json/users/scores/sample.json
583
590
  - spec/mock_json/users/statuses/arjun_private.json
584
591
  - spec/mock_json/users/statuses/arjun_public.json
592
+ - spec/mock_json/users/subscribed_to/sample.json
593
+ - spec/mock_json/users/subscribers/sample.json
585
594
  - spec/mock_json/users/tagged/arjun_private.json
586
595
  - spec/mock_json/users/tagged/arjun_public.json
587
596
  - spec/mock_json/users/television/matake_private.json
@@ -699,6 +708,8 @@ test_files:
699
708
  - spec/fb_graph/connections/senders_spec.rb
700
709
  - spec/fb_graph/connections/settings_spec.rb
701
710
  - spec/fb_graph/connections/statuses_spec.rb
711
+ - spec/fb_graph/connections/subscribed_to_spec.rb
712
+ - spec/fb_graph/connections/subscribers_spec.rb
702
713
  - spec/fb_graph/connections/subscriptions_spec.rb
703
714
  - spec/fb_graph/connections/tabs_spec.rb
704
715
  - spec/fb_graph/connections/tagged_spec.rb
@@ -799,8 +810,6 @@ test_files:
799
810
  - spec/mock_json/events/maybe/post_with_valid_access_token.json
800
811
  - spec/mock_json/events/maybe/smartday_private.json
801
812
  - spec/mock_json/events/noreply/smartday_private.json
802
- - spec/mock_json/exchange_sessions_null_response.json
803
- - spec/mock_json/exchange_sessions_response.json
804
813
  - spec/mock_json/friend_lists/members/sample.json
805
814
  - spec/mock_json/groups/docs/private.json
806
815
  - spec/mock_json/groups/members/emacs_private.json
@@ -833,7 +842,9 @@ test_files:
833
842
  - spec/mock_json/pages/settings/sample.json
834
843
  - spec/mock_json/pages/statuses/platform_private.json
835
844
  - spec/mock_json/pages/statuses/platform_public.json
845
+ - spec/mock_json/pages/tabs/blank.json
836
846
  - spec/mock_json/pages/tabs/fb_graph.json
847
+ - spec/mock_json/pages/tabs/wall.json
837
848
  - spec/mock_json/pages/with_token.json
838
849
  - spec/mock_json/photos/sample.json
839
850
  - spec/mock_json/photos/with_tags.json
@@ -935,6 +946,8 @@ test_files:
935
946
  - spec/mock_json/users/scores/sample.json
936
947
  - spec/mock_json/users/statuses/arjun_private.json
937
948
  - spec/mock_json/users/statuses/arjun_public.json
949
+ - spec/mock_json/users/subscribed_to/sample.json
950
+ - spec/mock_json/users/subscribers/sample.json
938
951
  - spec/mock_json/users/tagged/arjun_private.json
939
952
  - spec/mock_json/users/tagged/arjun_public.json
940
953
  - spec/mock_json/users/television/matake_private.json
@@ -1,5 +0,0 @@
1
- [
2
- {
3
- "access_token": "my_oauth_token"
4
- }
5
- ]