fb_graph2 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/fb_graph2/auth.rb +8 -0
- data/lib/fb_graph2/node.rb +0 -4
- data/lib/fb_graph2/token_metadata.rb +45 -0
- data/spec/fb_graph2/auth_spec.rb +52 -0
- data/spec/fb_graph2/node_spec.rb +0 -8
- data/spec/fb_graph2/token_metadata_spec.rb +51 -0
- data/spec/mock_json/token_metadata/app_token.json +6 -0
- data/spec/mock_json/token_metadata/invalid_token.json +15 -0
- data/spec/mock_json/token_metadata/page_token.json +11 -0
- data/spec/mock_json/token_metadata/user_token.json +10 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cddc565f9eb2a8125c00fdfb3cf4c8d2f1d2b84
|
4
|
+
data.tar.gz: a788672856bc6f8f1d093c6450125cffe5693bcc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dff9208b8d5be73b7befd8be218b9cbe75c11be12df3f7848aa27681b0642d4e5a6569d50b8dc446a53ee2bed75795cd1e47b269c6f8508a4f9eb65464b88bd3
|
7
|
+
data.tar.gz: f9dc3900db23c416d8f923b9a45edfd731c228820ef76db95c6607ef52c0df77e0edefc989b7a2c78b581e1e1f48f02d9a9c5551f1bda2d78116b1112024e1af
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/lib/fb_graph2/auth.rb
CHANGED
@@ -29,5 +29,13 @@ module FbGraph2
|
|
29
29
|
rescue Rack::OAuth2::Client::Error => e
|
30
30
|
raise Exception.detect(e.status, e.response)
|
31
31
|
end
|
32
|
+
|
33
|
+
def debug_token!(input_token)
|
34
|
+
token_metadata = TokenMetadata.new
|
35
|
+
token_metadata.authenticate access_token!
|
36
|
+
token_metadata.fetch(
|
37
|
+
input_token: input_token.to_s
|
38
|
+
)
|
39
|
+
end
|
32
40
|
end
|
33
41
|
end
|
data/lib/fb_graph2/node.rb
CHANGED
@@ -23,10 +23,6 @@ module FbGraph2
|
|
23
23
|
self.class.new(attributes[:id], attributes).authenticate access_token
|
24
24
|
end
|
25
25
|
|
26
|
-
def self.fetch(identifier, params = {}, options = {})
|
27
|
-
new(identifier).fetch params, options
|
28
|
-
end
|
29
|
-
|
30
26
|
def edge(edge, params = {}, options = {})
|
31
27
|
Edge.new(
|
32
28
|
self,
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module FbGraph2
|
2
|
+
class TokenMetadata < Node
|
3
|
+
register_attributes(
|
4
|
+
raw: [
|
5
|
+
:app_id, :application, :error, :is_valid, :metadata, :profile_id, :scopes, :user_id
|
6
|
+
],
|
7
|
+
timestamp: [:expires_at, :issued_at],
|
8
|
+
custom: [:app, :user, :page]
|
9
|
+
)
|
10
|
+
|
11
|
+
def initialize(attributes = {})
|
12
|
+
super :debug_token, attributes
|
13
|
+
if app_id
|
14
|
+
@app = App.new app_id
|
15
|
+
end
|
16
|
+
if user_id
|
17
|
+
@user = User.new user_id
|
18
|
+
end
|
19
|
+
if profile_id
|
20
|
+
@page = Page.new profile_id
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def fetch(params = {}, options = {})
|
25
|
+
attributes = get params, options
|
26
|
+
self.class.new(attributes[:data]).authenticate access_token
|
27
|
+
end
|
28
|
+
|
29
|
+
def valid?
|
30
|
+
!!is_valid
|
31
|
+
end
|
32
|
+
|
33
|
+
def app_token?
|
34
|
+
app.present? && user.blank? && page.blank?
|
35
|
+
end
|
36
|
+
|
37
|
+
def user_token?
|
38
|
+
app.present? && user.present? && page.blank?
|
39
|
+
end
|
40
|
+
|
41
|
+
def page_token?
|
42
|
+
app.present? && user.present? && page.present?
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/spec/fb_graph2/auth_spec.rb
CHANGED
@@ -22,6 +22,58 @@ describe FbGraph2::Auth do
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
describe '#debug_token!' do
|
26
|
+
before do
|
27
|
+
mock_graph :post, 'oauth/access_token', 'token_response', params: {
|
28
|
+
grant_type: 'client_credentials',
|
29
|
+
client_id: 'client_id',
|
30
|
+
client_secret: 'client_secret'
|
31
|
+
}, disable_api_versioning: true
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'when user_token given' do
|
35
|
+
subject do
|
36
|
+
mock_graph :get, 'debug_token', 'token_metadata/user_token', params: {
|
37
|
+
input_token: 'user_token'
|
38
|
+
} do
|
39
|
+
instance.debug_token! 'user_token'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
it { should be_instance_of FbGraph2::TokenMetadata }
|
43
|
+
its(:app) { should be_instance_of FbGraph2::App }
|
44
|
+
its(:user) { should be_instance_of FbGraph2::User }
|
45
|
+
its(:page) { should be_nil }
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'when app_token given' do
|
49
|
+
subject do
|
50
|
+
mock_graph :get, 'debug_token', 'token_metadata/app_token', params: {
|
51
|
+
input_token: 'app_token'
|
52
|
+
} do
|
53
|
+
instance.debug_token! 'app_token'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
it { should be_instance_of FbGraph2::TokenMetadata }
|
57
|
+
its(:app) { should be_instance_of FbGraph2::App }
|
58
|
+
its(:user) { should be_nil }
|
59
|
+
its(:page) { should be_nil }
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'when page_token given' do
|
63
|
+
subject do
|
64
|
+
mock_graph :get, 'debug_token', 'token_metadata/page_token', params: {
|
65
|
+
input_token: 'page_token'
|
66
|
+
} do
|
67
|
+
instance.debug_token! 'page_token'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
it { should be_instance_of FbGraph2::TokenMetadata }
|
71
|
+
its(:app) { should be_instance_of FbGraph2::App }
|
72
|
+
its(:user) { should be_instance_of FbGraph2::User }
|
73
|
+
its(:page) { should be_instance_of FbGraph2::Page }
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
25
77
|
context 'when error occured' do
|
26
78
|
it do
|
27
79
|
expect do
|
data/spec/fb_graph2/node_spec.rb
CHANGED
@@ -61,14 +61,6 @@ describe FbGraph2::Node do
|
|
61
61
|
it { should_not respond_to :register_attributes }
|
62
62
|
it { should_not respond_to :registered_attributes }
|
63
63
|
it { should_not respond_to :registered_attributes= }
|
64
|
-
|
65
|
-
describe '.fetch' do
|
66
|
-
it 'should call API' do
|
67
|
-
expect do
|
68
|
-
klass.fetch 'foo'
|
69
|
-
end.to request_to 'foo'
|
70
|
-
end
|
71
|
-
end
|
72
64
|
end
|
73
65
|
|
74
66
|
context 'instance' do
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FbGraph2::TokenMetadata do
|
4
|
+
let(:app_token) do
|
5
|
+
attributes = mock_json 'token_metadata/app_token'
|
6
|
+
FbGraph2::TokenMetadata.new attributes[:data]
|
7
|
+
end
|
8
|
+
let(:user_token) do
|
9
|
+
attributes = mock_json 'token_metadata/user_token'
|
10
|
+
FbGraph2::TokenMetadata.new attributes[:data]
|
11
|
+
end
|
12
|
+
let(:page_token) do
|
13
|
+
attributes = mock_json 'token_metadata/page_token'
|
14
|
+
FbGraph2::TokenMetadata.new attributes[:data]
|
15
|
+
end
|
16
|
+
let(:invalid_token) do
|
17
|
+
attributes = mock_json 'token_metadata/invalid_token'
|
18
|
+
FbGraph2::TokenMetadata.new attributes[:data]
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when app_token' do
|
22
|
+
subject { app_token }
|
23
|
+
its(:app_token?) { should == true }
|
24
|
+
its(:user_token?) { should == false }
|
25
|
+
its(:page_token?) { should == false }
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'when user_token' do
|
29
|
+
subject { user_token }
|
30
|
+
its(:app_token?) { should == false }
|
31
|
+
its(:user_token?) { should == true }
|
32
|
+
its(:page_token?) { should == false }
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'when page_token' do
|
36
|
+
subject { page_token }
|
37
|
+
its(:app_token?) { should == false }
|
38
|
+
its(:user_token?) { should == false }
|
39
|
+
its(:page_token?) { should == true }
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when valid' do
|
43
|
+
subject { user_token }
|
44
|
+
its(:valid?) { should == true }
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'when invalid' do
|
48
|
+
subject { invalid_token }
|
49
|
+
its(:valid?) { should == false }
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
{
|
2
|
+
"data": {
|
3
|
+
"error": {
|
4
|
+
"message": "Error validating access token: This may be because the user logged out or may be due to a system error.",
|
5
|
+
"code": 190,
|
6
|
+
"subcode": 467
|
7
|
+
},
|
8
|
+
"app_id": "210798282372757",
|
9
|
+
"is_valid": false,
|
10
|
+
"application": "gem sample",
|
11
|
+
"user_id": "579612276",
|
12
|
+
"expires_at": 1409655600,
|
13
|
+
"scopes": ["public_profile", "basic_info", "read_stream", "read_mailbox", "read_page_mailboxes", "rsvp_event", "email", "ads_management", "ads_read", "read_insights", "manage_notifications", "read_friendlists", "manage_pages", "publish_actions", "user_birthday", "user_religion_politics", "user_relationships", "user_relationship_details", "user_hometown", "user_location", "user_likes", "user_activities", "user_interests", "user_education_history", "user_work_history", "user_website", "user_groups", "user_events", "user_photos", "user_videos", "user_friends", "user_about_me", "user_status", "user_games_activity", "user_tagged_places", "user_actions.books", "user_actions.music", "user_actions.video", "user_actions.news"]
|
14
|
+
}
|
15
|
+
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fb_graph2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nov matake
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|
@@ -281,6 +281,7 @@ files:
|
|
281
281
|
- lib/fb_graph2/struct/work.rb
|
282
282
|
- lib/fb_graph2/tagged_profile.rb
|
283
283
|
- lib/fb_graph2/thread.rb
|
284
|
+
- lib/fb_graph2/token_metadata.rb
|
284
285
|
- lib/fb_graph2/translation.rb
|
285
286
|
- lib/fb_graph2/user.rb
|
286
287
|
- lib/fb_graph2/util.rb
|
@@ -343,6 +344,7 @@ files:
|
|
343
344
|
- spec/fb_graph2/page_spec.rb
|
344
345
|
- spec/fb_graph2/request_filter/authenticator_spec.rb
|
345
346
|
- spec/fb_graph2/request_filter/debugger_spec.rb
|
347
|
+
- spec/fb_graph2/token_metadata_spec.rb
|
346
348
|
- spec/fb_graph2/user_spec.rb
|
347
349
|
- spec/fb_graph2/util_spec.rb
|
348
350
|
- spec/fb_graph2_spec.rb
|
@@ -378,6 +380,10 @@ files:
|
|
378
380
|
- spec/mock_json/post/shared_posts.json
|
379
381
|
- spec/mock_json/success_true.json
|
380
382
|
- spec/mock_json/success_with_id.json
|
383
|
+
- spec/mock_json/token_metadata/app_token.json
|
384
|
+
- spec/mock_json/token_metadata/invalid_token.json
|
385
|
+
- spec/mock_json/token_metadata/page_token.json
|
386
|
+
- spec/mock_json/token_metadata/user_token.json
|
381
387
|
- spec/mock_json/token_response.json
|
382
388
|
- spec/mock_json/true.json
|
383
389
|
- spec/mock_json/user/accounts.json
|