fb_graph 2.5.3 → 2.5.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.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fb_graph (2.4.20)
4
+ fb_graph (2.5.3)
5
5
  httpclient (>= 2.2.0.2)
6
6
  json
7
7
  rack-oauth2 (>= 0.14.4)
@@ -39,7 +39,7 @@ GEM
39
39
  erubis (2.7.0)
40
40
  hashie (1.2.0)
41
41
  hike (1.2.1)
42
- httpclient (2.2.7)
42
+ httpclient (2.3.0.1)
43
43
  i18n (0.6.1)
44
44
  journey (1.0.4)
45
45
  json (1.7.5)
@@ -47,7 +47,7 @@ GEM
47
47
  rack (1.4.1)
48
48
  rack-cache (1.2)
49
49
  rack (>= 0.4)
50
- rack-oauth2 (0.14.9)
50
+ rack-oauth2 (1.0.0)
51
51
  activesupport (>= 2.3)
52
52
  attr_required (>= 0.0.5)
53
53
  httpclient (>= 2.2.0.2)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.5.3
1
+ 2.5.4
@@ -103,5 +103,16 @@ module FbGraph
103
103
  end
104
104
  alias_method_chain :access_token, :auto_fetch
105
105
 
106
+ def debug_token(input_token)
107
+ _input_token_ = case input_token
108
+ when Rack::OAuth2::AccessToken::Legacy
109
+ input_token
110
+ else
111
+ Rack::OAuth2::AccessToken::Legacy.new(
112
+ :access_token => input_token
113
+ )
114
+ end
115
+ _input_token_.introspect access_token
116
+ end
106
117
  end
107
118
  end
data/lib/fb_graph/node.rb CHANGED
@@ -16,7 +16,7 @@ module FbGraph
16
16
 
17
17
  def fetch(options = {})
18
18
  options[:access_token] ||= self.access_token if self.access_token
19
- _fetched_ = get(options)
19
+ _fetched_ = get options
20
20
  _fetched_[:access_token] ||= options[:access_token]
21
21
  self.class.new(_fetched_[:id], _fetched_)
22
22
  end
data/lib/fb_graph.rb CHANGED
@@ -137,3 +137,5 @@ require 'fb_graph/klass'
137
137
  require 'fb_graph/project'
138
138
 
139
139
  require 'fb_graph/query'
140
+
141
+ require 'patch/rack/oauth2/access_token/introspectable'
@@ -0,0 +1,37 @@
1
+ module Rack
2
+ module OAuth2
3
+ class AccessToken
4
+ module Introspectable
5
+ class Result < FbGraph::Node
6
+ ATTRIBUTES = [:application, :user, :expires_at, :issued_at, :is_valid, :metadata, :scopes, :error]
7
+ attr_accessor *ATTRIBUTES
8
+
9
+ def initialize(identifier = nil, attributes = {})
10
+ super :debug_token, attributes
11
+ if (data = attributes[:data])
12
+ @application = FbGraph::Application.new data[:app_id], :name => data[:application]
13
+ @user = FbGraph::User.new data[:user_id]
14
+ @expires_at = Time.at data[:expires_at]
15
+ @issued_at = Time.at data[:issued_at] if data[:issued_at]
16
+ (ATTRIBUTES - [:application, :user, :expires_at, :issued_at]).each do |key|
17
+ self.send :"#{key}=", data[key]
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ def self.included(klass)
24
+ klass.send :attr_accessor, *Result::ATTRIBUTES
25
+ end
26
+
27
+ def introspect(app_token)
28
+ Result.new.fetch(
29
+ :access_token => app_token,
30
+ :input_token => access_token
31
+ )
32
+ end
33
+ end
34
+ AccessToken.send :include, Introspectable
35
+ end
36
+ end
37
+ end
@@ -1,3 +1,5 @@
1
+ require 'spec_helper'
2
+
1
3
  describe FbGraph::AdConnectionObject, '.new' do
2
4
  it 'should setup all supported attributes' do
3
5
  attributes = {
@@ -1,3 +1,5 @@
1
+ require 'spec_helper'
2
+
1
3
  describe FbGraph::AdKeyword, '.search' do
2
4
  it 'should perform a search' do
3
5
  mock_graph :get, 'search', 'ad_keywords/buffy_search', :params => {:q => 'buffy', :type => 'adkeyword'} do
@@ -1,3 +1,5 @@
1
+ require 'spec_helper'
2
+
1
3
  describe FbGraph::AdKeywordSuggestion, '.search' do
2
4
  it 'should perform a search' do
3
5
  mock_graph :get, 'search', 'ad_keyword_suggestions/buffy_suggestions', :params => {:keyword_list => 'buffy+the+vampire+slayer', :type => 'adkeywordsuggestion'} do
@@ -1,3 +1,5 @@
1
+ require 'spec_helper'
2
+
1
3
  describe FbGraph::AdKeywordValid, '.search' do
2
4
  it 'should perform a search' do
3
5
  mock_graph :get, 'search', 'ad_keyword_valids/tige_search', :params => {:keyword_list => 'tige', :type => 'adkeywordvalid'} do
@@ -195,4 +195,57 @@ describe FbGraph::Application do
195
195
  end
196
196
  end
197
197
  end
198
+
199
+ describe '#debug_token' do
200
+ before { app.access_token = 'app_token' }
201
+ let(:application) { FbGraph::Application.new(210798282372757, :name => 'gem sample') }
202
+ let(:user) { FbGraph::User.new(579612276) }
203
+ let(:scopes) { ['email'] }
204
+
205
+ shared_examples_for :token_debugger do
206
+ context 'when valid' do
207
+ it 'should return introspection result without error' do
208
+ mock_graph :get, 'debug_token', 'token_introspection/valid', :access_token => 'app_token', :params => {
209
+ :input_token => 'input_token'
210
+ } do
211
+ result = app.debug_token input_token
212
+ result.should be_instance_of Rack::OAuth2::AccessToken::Introspectable::Result
213
+ result.application.should == application
214
+ result.user.should == user
215
+ result.scopes.should == scopes
216
+ result.expires_at.should == Time.at(1350363600)
217
+ result.is_valid.should be_true
218
+ result.error.should be_nil
219
+ end
220
+ end
221
+ end
222
+
223
+ context 'when invalid' do
224
+ it 'should return introspection result with error' do
225
+ mock_graph :get, 'debug_token', 'token_introspection/invalid', :access_token => 'app_token', :params => {
226
+ :input_token => 'input_token'
227
+ } do
228
+ result = app.debug_token input_token
229
+ result.should be_instance_of Rack::OAuth2::AccessToken::Introspectable::Result
230
+ result.application.should == application
231
+ result.user.should == user
232
+ result.scopes.should == scopes
233
+ result.expires_at.should == Time.at(1350356400)
234
+ result.is_valid.should be_false
235
+ result.error.should be_a Hash
236
+ end
237
+ end
238
+ end
239
+ end
240
+
241
+ context 'when input_token is String' do
242
+ let(:input_token) { 'input_token' }
243
+ it_behaves_like :token_debugger
244
+ end
245
+
246
+ context 'when input_token is Rack::OAuth2::AccessToken::Legacy instance' do
247
+ let(:input_token) { Rack::OAuth2::AccessToken::Legacy.new :access_token => 'input_token' }
248
+ it_behaves_like :token_debugger
249
+ end
250
+ end
198
251
  end
@@ -0,0 +1,15 @@
1
+ {
2
+ "data": {
3
+ "app_id": 210798282372757,
4
+ "error": {
5
+ "message": "Error validating access token: Session has expired at unix time 1350356400. The current unix time is 1350357318.",
6
+ "code": 190,
7
+ "subcode": 463
8
+ },
9
+ "is_valid": false,
10
+ "application": "gem sample",
11
+ "user_id": 579612276,
12
+ "expires_at": 1350356400,
13
+ "scopes": ["email"]
14
+ }
15
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "data": {
3
+ "app_id": 210798282372757,
4
+ "is_valid": true,
5
+ "application": "gem sample",
6
+ "user_id": 579612276,
7
+ "expires_at": 1350363600,
8
+ "scopes": ["email"]
9
+ }
10
+ }
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.5.3
4
+ version: 2.5.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-10 00:00:00.000000000 Z
12
+ date: 2012-10-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httpclient
@@ -341,6 +341,7 @@ files:
341
341
  - lib/fb_graph/video.rb
342
342
  - lib/fb_graph/work.rb
343
343
  - lib/patch/rack/oauth2/access_token.rb
344
+ - lib/patch/rack/oauth2/access_token/introspectable.rb
344
345
  - lib/patch/rack/oauth2/client.rb
345
346
  - lib/patch/rack/oauth2/grant/fb_exchange_token.rb
346
347
  - lib/patch/rack/oauth2/util.rb
@@ -620,6 +621,8 @@ files:
620
621
  - spec/mock_json/thread/messages/private.json
621
622
  - spec/mock_json/thread/participants/private.json
622
623
  - spec/mock_json/thread/senders/private.json
624
+ - spec/mock_json/token_introspection/invalid.json
625
+ - spec/mock_json/token_introspection/valid.json
623
626
  - spec/mock_json/token_response.json
624
627
  - spec/mock_json/token_with_expiry.json
625
628
  - spec/mock_json/true.json
@@ -1006,6 +1009,8 @@ test_files:
1006
1009
  - spec/mock_json/thread/messages/private.json
1007
1010
  - spec/mock_json/thread/participants/private.json
1008
1011
  - spec/mock_json/thread/senders/private.json
1012
+ - spec/mock_json/token_introspection/invalid.json
1013
+ - spec/mock_json/token_introspection/valid.json
1009
1014
  - spec/mock_json/token_response.json
1010
1015
  - spec/mock_json/token_with_expiry.json
1011
1016
  - spec/mock_json/true.json