fb_graph 1.2.3 → 1.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -2
- data/VERSION +1 -1
- data/fb_graph.gemspec +37 -10
- data/lib/fb_graph/action.rb +12 -0
- data/lib/fb_graph/auth/cookie.rb +1 -1
- data/lib/fb_graph/checkin.rb +7 -6
- data/lib/fb_graph/collection.rb +5 -5
- data/lib/fb_graph/group.rb +3 -1
- data/lib/fb_graph/link.rb +1 -0
- data/lib/fb_graph/location.rb +20 -0
- data/lib/fb_graph/node.rb +2 -5
- data/lib/fb_graph/page.rb +9 -3
- data/lib/fb_graph/post.rb +22 -2
- data/lib/fb_graph/privacy.rb +27 -0
- data/lib/fb_graph/searchable/result.rb +1 -1
- data/lib/fb_graph/serialization.rb +15 -0
- data/lib/fb_graph/targeting.rb +23 -0
- data/lib/fb_graph/venue.rb +3 -6
- data/lib/fb_graph.rb +10 -4
- data/spec/fake_json/applications/test_users/created.json +5 -0
- data/spec/fake_json/applications/test_users/private.json +14 -0
- data/spec/fake_json/pages/search_fb_graph.json +9 -0
- data/spec/fake_json/pages/search_google.json +133 -0
- data/spec/fake_json/posts/no_comments.json +31 -0
- data/spec/fake_json/token_response.json +1 -0
- data/spec/fake_json/users/checkins/posted.json +1 -0
- data/spec/fb_graph/application_spec.rb +16 -1
- data/spec/fb_graph/auth/cookie_spec.rb +19 -0
- data/spec/fb_graph/auth_spec.rb +15 -0
- data/spec/fb_graph/checkin_spec.rb +6 -1
- data/spec/fb_graph/collection_spec.rb +6 -0
- data/spec/fb_graph/connections/checkins_spec.rb +18 -0
- data/spec/fb_graph/connections/comments_spec.rb +24 -1
- data/spec/fb_graph/connections/feed_spec.rb +8 -2
- data/spec/fb_graph/connections/home_spec.rb +4 -1
- data/spec/fb_graph/connections/likes_spec.rb +2 -2
- data/spec/fb_graph/connections/posts_spec.rb +4 -1
- data/spec/fb_graph/connections/subscriptions_spec.rb +31 -0
- data/spec/fb_graph/connections/tagged_spec.rb +4 -1
- data/spec/fb_graph/connections/test_users_spec.rb +49 -0
- data/spec/fb_graph/exception_spec.rb +47 -0
- data/spec/fb_graph/location_spec.rb +28 -0
- data/spec/fb_graph/node_spec.rb +27 -0
- data/spec/fb_graph/page_spec.rb +7 -0
- data/spec/fb_graph/post_spec.rb +70 -1
- data/spec/fb_graph/privacy_spec.rb +33 -0
- data/spec/fb_graph/searchable_spec.rb +31 -0
- data/spec/fb_graph/seriarization_spec.rb +29 -0
- data/spec/fb_graph/targeting_spec.rb +34 -0
- data/spec/fb_graph/test_user_spec.rb +14 -8
- data/spec/helpers/fake_json_helper.rb +8 -0
- metadata +43 -12
@@ -0,0 +1,133 @@
|
|
1
|
+
{
|
2
|
+
"data": [
|
3
|
+
{
|
4
|
+
"name": "Oh Google, you always seem to know what i mean to spell....",
|
5
|
+
"category": "Product/service",
|
6
|
+
"id": "478312780400"
|
7
|
+
},
|
8
|
+
{
|
9
|
+
"name": "Life at Google",
|
10
|
+
"category": "Product/service",
|
11
|
+
"id": "152260356535"
|
12
|
+
},
|
13
|
+
{
|
14
|
+
"name": "\"What if Google didn't exist?\" \"Man we would all be screwed\"",
|
15
|
+
"category": "Product/service",
|
16
|
+
"id": "258151553148"
|
17
|
+
},
|
18
|
+
{
|
19
|
+
"name": "\"What if there was no Google\" \"I Dont know, Google it.\"",
|
20
|
+
"category": "Local business",
|
21
|
+
"id": "315611772266"
|
22
|
+
},
|
23
|
+
{
|
24
|
+
"name": "Hey Google, Pick Spokane",
|
25
|
+
"category": "Person",
|
26
|
+
"id": "355905206204"
|
27
|
+
},
|
28
|
+
{
|
29
|
+
"name": "ALABADO SEA GOOGLE QUE NOS SALVA DE TODAS!",
|
30
|
+
"category": "Product/service",
|
31
|
+
"id": "191277261935"
|
32
|
+
},
|
33
|
+
{
|
34
|
+
"name": "I love it when Google change their logo to match the occasion of the day :)",
|
35
|
+
"category": "Company",
|
36
|
+
"id": "227973269750"
|
37
|
+
},
|
38
|
+
{
|
39
|
+
"name": "\u00a1LAS 10 CONSULTAS MAS RARAS REALIZADAS A GOOGLE! [INCRE\u00cdBLE]",
|
40
|
+
"category": "Community",
|
41
|
+
"id": "139606819385330"
|
42
|
+
},
|
43
|
+
{
|
44
|
+
"name": "put \"lol limewire\" into google and click \"im feeling lucky\" join if u lol'd",
|
45
|
+
"category": "Local business",
|
46
|
+
"id": "342669873169"
|
47
|
+
},
|
48
|
+
{
|
49
|
+
"name": "Typing as many words to a song that you know in Google to find out the name.",
|
50
|
+
"category": "Community",
|
51
|
+
"id": "119407198076155"
|
52
|
+
},
|
53
|
+
{
|
54
|
+
"name": "Look who google street maps found...",
|
55
|
+
"category": "Community",
|
56
|
+
"id": "119445544745147"
|
57
|
+
},
|
58
|
+
{
|
59
|
+
"name": "Google ist dein Freund",
|
60
|
+
"category": "Website",
|
61
|
+
"id": "105524302803537"
|
62
|
+
},
|
63
|
+
{
|
64
|
+
"name": "Google Gibiyiz Ne Ararsan Var xd",
|
65
|
+
"category": "Community",
|
66
|
+
"id": "115676908477783"
|
67
|
+
},
|
68
|
+
{
|
69
|
+
"name": "google + sparknotes = high school diploma",
|
70
|
+
"category": "Local business",
|
71
|
+
"id": "106848852676615"
|
72
|
+
},
|
73
|
+
{
|
74
|
+
"name": "Yo tambien he buscado mi casa en Google Earth",
|
75
|
+
"category": "Local business",
|
76
|
+
"id": "48695860708"
|
77
|
+
},
|
78
|
+
{
|
79
|
+
"name": "I've probably learned more from Google than I have from school -.-'",
|
80
|
+
"category": "Local business",
|
81
|
+
"id": "260274425983"
|
82
|
+
},
|
83
|
+
{
|
84
|
+
"name": "\u0413\u043e\u043e\u0433\u043b\u0435",
|
85
|
+
"category": "Community",
|
86
|
+
"id": "152496591452340"
|
87
|
+
},
|
88
|
+
{
|
89
|
+
"name": "Wozu Gehirn, Google wei\u00df sowieso mehr",
|
90
|
+
"category": "Local business",
|
91
|
+
"id": "375712209431"
|
92
|
+
},
|
93
|
+
{
|
94
|
+
"name": "google street, this guy saw u coming! lol",
|
95
|
+
"category": "Product/service",
|
96
|
+
"id": "369449054859"
|
97
|
+
},
|
98
|
+
{
|
99
|
+
"name": "\u7528\u9999\u6e2fGoogle Map\u6709\u4eba\u5927\u64d4\u9732\u9ede\uff01\u516c\u773e\u5730\u65b9\u5927\u4fbf\uff01\u5169\u7c73\u5927\u5605\u947d\u77f3\uff01\u91cd\u6709......\u5629\uff01\uff01\uff01\u9ed0\u7dda\u35ce\uff1f\uff01",
|
100
|
+
"category": "Game",
|
101
|
+
"id": "136198153064149"
|
102
|
+
},
|
103
|
+
{
|
104
|
+
"name": "Google TV",
|
105
|
+
"category": "Product/service",
|
106
|
+
"id": "121370337893738"
|
107
|
+
},
|
108
|
+
{
|
109
|
+
"name": "amo a google por que hace el 90% de mis tareas xD",
|
110
|
+
"category": "Local business",
|
111
|
+
"id": "184832882621"
|
112
|
+
},
|
113
|
+
{
|
114
|
+
"name": "yo le pregunto todo a SAN GOOGLE",
|
115
|
+
"category": "Local business",
|
116
|
+
"id": "231162595339"
|
117
|
+
},
|
118
|
+
{
|
119
|
+
"name": "se te ven los cuernos desde google earth",
|
120
|
+
"category": "Local business",
|
121
|
+
"id": "108661389160054"
|
122
|
+
},
|
123
|
+
{
|
124
|
+
"name": "This scouse hating Manc got told by google!",
|
125
|
+
"category": "Local business",
|
126
|
+
"id": "332471411596"
|
127
|
+
}
|
128
|
+
],
|
129
|
+
"paging": {
|
130
|
+
"next": "http://graph.facebook.com/search?type=page&q=google&limit=25&offset=50",
|
131
|
+
"previous": "http://graph.facebook.com/search?type=page&q=google&limit=25&offset=0"
|
132
|
+
}
|
133
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
{
|
2
|
+
"id": "579612276_10150089741782277",
|
3
|
+
"from": {
|
4
|
+
"name": "Nov Matake",
|
5
|
+
"id": "579612276"
|
6
|
+
},
|
7
|
+
"message": "\u3067\u3076\u3055\u307f\u3063\u3066\u306e\u306b\u7533\u3057\u8fbc\u3093\u3060\u6642\u70b9\u3067\u75b2\u308c\u679c\u3066\u305f\u3002",
|
8
|
+
"icon": "http://photos-d.ak.fbcdn.net/photos-ak-snc1/v27562/23/2231777543/app_2_2231777543_9553.gif",
|
9
|
+
"actions": [
|
10
|
+
{
|
11
|
+
"name": "Comment",
|
12
|
+
"link": "http://www.facebook.com/579612276/posts/10150089741782277"
|
13
|
+
},
|
14
|
+
{
|
15
|
+
"name": "Like",
|
16
|
+
"link": "http://www.facebook.com/579612276/posts/10150089741782277"
|
17
|
+
},
|
18
|
+
{
|
19
|
+
"name": "@nov on Twitter",
|
20
|
+
"link": "http://twitter.com/nov?utm_source=fb&utm_medium=fb&utm_campaign=nov&utm_content=19294280413614080"
|
21
|
+
}
|
22
|
+
],
|
23
|
+
"privacy": {
|
24
|
+
"description": "Everyone",
|
25
|
+
"value": "EVERYONE"
|
26
|
+
},
|
27
|
+
"type": "status",
|
28
|
+
"created_time": "2010-12-27T07:31:30+0000",
|
29
|
+
"updated_time": "2010-12-27T07:31:30+0000",
|
30
|
+
"attribution": "Twitter"
|
31
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
access_token=token
|
@@ -0,0 +1 @@
|
|
1
|
+
{"id":"10150090286117277"}
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '../spec_helper')
|
2
2
|
|
3
3
|
describe FbGraph::Application, '.new' do
|
4
|
-
|
5
4
|
it 'should setup all supported attributes' do
|
6
5
|
attributes = {
|
7
6
|
:id => '12345',
|
@@ -19,5 +18,21 @@ describe FbGraph::Application, '.new' do
|
|
19
18
|
app.link.should == 'http://github.com/nov/fb_graph'
|
20
19
|
app.secret.should == 'sec sec'
|
21
20
|
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe FbGraph::Application, '.get_access_token' do
|
24
|
+
before do
|
25
|
+
fake_json :post, 'oauth/access_token', 'token_response'
|
26
|
+
@app = FbGraph::Application.new('client_id', :secret => 'client_secret')
|
27
|
+
end
|
22
28
|
|
29
|
+
it 'should POST oauth/token' do
|
30
|
+
@app.access_token.should be_nil
|
31
|
+
@app.get_access_token
|
32
|
+
@app.access_token.should == 'token'
|
33
|
+
end
|
34
|
+
|
35
|
+
after do
|
36
|
+
FakeWeb.clean_registry
|
37
|
+
end
|
23
38
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../../spec_helper')
|
2
|
+
|
3
|
+
describe FbGraph::Auth::Cookie, '.parse' do
|
4
|
+
before do
|
5
|
+
@client = OAuth2::Client.new('client_id', 'client_secret')
|
6
|
+
@cookie = {
|
7
|
+
'fbs_client_id' => "access_token=t&expires=0&secret=s&session_key=k&sig=f4bae8ec88ba11440e3bdcc1bcf78317&uid=12345"
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should parse fbs_APP_ID cookie' do
|
12
|
+
cookie = FbGraph::Auth::Cookie.parse(@client, @cookie)
|
13
|
+
cookie[:access_token].should == 't'
|
14
|
+
cookie[:expires].should == 0
|
15
|
+
cookie[:secret].should == 's'
|
16
|
+
cookie[:session_key].should == 'k'
|
17
|
+
cookie[:uid].should == '12345'
|
18
|
+
end
|
19
|
+
end
|
data/spec/fb_graph/auth_spec.rb
CHANGED
@@ -22,6 +22,21 @@ end
|
|
22
22
|
describe FbGraph::Auth, '.from_cookie' do
|
23
23
|
before do
|
24
24
|
@auth = FbGraph::Auth.new('client_id', 'client_secret')
|
25
|
+
@expires_at = Time.parse('2020-12-31 12:00:00')
|
26
|
+
@cookie = {
|
27
|
+
'fbs_client_id' => "access_token=t&expires=#{@expires_at.to_i}&secret=s&session_key=k&sig=b06a0540959470e731cc3bc2ef31a007&uid=12345"
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should fetch user and access_token from fbs_APP_ID cookie' do
|
32
|
+
@auth.access_token.should be_nil
|
33
|
+
@auth.user.should be_nil
|
34
|
+
@auth.from_cookie(@cookie)
|
35
|
+
@auth.access_token.token.should == 't'
|
36
|
+
@auth.access_token.expires_in.should be_close @expires_at - Time.now, 1
|
37
|
+
@auth.access_token.expires_at.should be_close @expires_at, 1
|
38
|
+
@auth.user.identifier.should == '12345'
|
39
|
+
@auth.user.access_token.token.should == 't'
|
25
40
|
end
|
26
41
|
|
27
42
|
context 'when invalid cookie given' do
|
@@ -1,7 +1,12 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '../spec_helper')
|
2
2
|
|
3
3
|
describe FbGraph::Checkin, '.new' do
|
4
|
-
|
4
|
+
it 'should accept String/Integer as place' do
|
5
|
+
checkin1 = FbGraph::Checkin.new(12345, :place => 123456)
|
6
|
+
checkin2 = FbGraph::Checkin.new(12345, :place => '123456')
|
7
|
+
checkin1.place.should == FbGraph::Place.new(123456)
|
8
|
+
checkin2.place.should == FbGraph::Place.new('123456')
|
9
|
+
end
|
5
10
|
end
|
6
11
|
|
7
12
|
describe FbGraph::Checkin, '.search' do
|
@@ -42,4 +42,10 @@ describe FbGraph::Collection, '.new' do
|
|
42
42
|
collection.next.should be_blank
|
43
43
|
end
|
44
44
|
|
45
|
+
it 'should raise error for invalid input' do
|
46
|
+
lambda do
|
47
|
+
FbGraph::Collection.new("STRING")
|
48
|
+
end.should raise_error(ArgumentError, 'Invalid collection')
|
49
|
+
end
|
50
|
+
|
45
51
|
end
|
@@ -105,3 +105,21 @@ describe FbGraph::Connections::Checkins, '#checkins' do
|
|
105
105
|
end
|
106
106
|
end
|
107
107
|
end
|
108
|
+
|
109
|
+
describe FbGraph::Connections::Checkins, '#checkin!' do
|
110
|
+
before do
|
111
|
+
fake_json :post, 'me/checkins', 'users/checkins/posted'
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should POST :user_id/checkins' do
|
115
|
+
checkin = FbGraph::User.me('token').checkin!(
|
116
|
+
:place => 'place_id',
|
117
|
+
:coordinates => {
|
118
|
+
:latitude => 30.26876,
|
119
|
+
:longitude => -97.74962
|
120
|
+
}.to_json
|
121
|
+
)
|
122
|
+
checkin.identifier.should == '10150090286117277'
|
123
|
+
checkin.place.should == FbGraph::Place.new('place_id')
|
124
|
+
end
|
125
|
+
end
|
@@ -2,7 +2,22 @@ require File.join(File.dirname(__FILE__), '../../spec_helper')
|
|
2
2
|
|
3
3
|
describe FbGraph::Connections::Comments, '#comments' do
|
4
4
|
context 'when included by FbGraph::Post' do
|
5
|
-
|
5
|
+
before do
|
6
|
+
fake_json :get, 'no_comments', 'posts/no_comments'
|
7
|
+
@post = FbGraph::Post.new('no_comments').fetch
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should use cached @_comments_ as default' do
|
11
|
+
lambda do
|
12
|
+
@post.comments
|
13
|
+
end.should_not raise_error(FakeWeb::NetConnectNotAllowedError)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should ignore cached @_comments_ when options are given' do
|
17
|
+
lambda do
|
18
|
+
@post.comments(:no_cache => true)
|
19
|
+
end.should_not request_to 'no_comments/comments'
|
20
|
+
end
|
6
21
|
end
|
7
22
|
end
|
8
23
|
|
@@ -84,4 +99,12 @@ describe FbGraph::Connections::Comments, '#like!' do
|
|
84
99
|
end
|
85
100
|
end
|
86
101
|
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe FbGraph::Connections::Comments, '#unlike!' do
|
105
|
+
it 'should DELETE /:object_id/likes' do
|
106
|
+
lambda do
|
107
|
+
FbGraph::Post.new('12345', :access_token => 'valid').unlike!
|
108
|
+
end.should request_to '12345/likes?access_token=valid', :delete
|
109
|
+
end
|
87
110
|
end
|
@@ -24,7 +24,10 @@ describe FbGraph::Connections::Feed, '#feed' do
|
|
24
24
|
:icon => 'http://static.ak.fbcdn.net/rsrc.php/z9XZ8/hash/976ulj6z.gif',
|
25
25
|
:created_time => '2010-04-25T04:05:32+0000',
|
26
26
|
:updated_time => '2010-04-25T04:05:32+0000',
|
27
|
-
:likes => 1
|
27
|
+
:likes => 1,
|
28
|
+
:privacy => {
|
29
|
+
:value => 'EVERYONE'
|
30
|
+
}
|
28
31
|
)
|
29
32
|
posts.each do |post|
|
30
33
|
post.should be_instance_of(FbGraph::Post)
|
@@ -50,7 +53,10 @@ describe FbGraph::Connections::Feed, '#feed' do
|
|
50
53
|
:icon => 'http://static.ak.fbcdn.net/rsrc.php/z9XZ8/hash/976ulj6z.gif',
|
51
54
|
:created_time => '2010-04-25T04:05:32+0000',
|
52
55
|
:updated_time => '2010-04-25T04:05:32+0000',
|
53
|
-
:likes => 1
|
56
|
+
:likes => 1,
|
57
|
+
:privacy => {
|
58
|
+
:value => 'EVERYONE'
|
59
|
+
}
|
54
60
|
)
|
55
61
|
posts.each do |post|
|
56
62
|
post.should be_instance_of(FbGraph::Post)
|
@@ -47,7 +47,10 @@ describe FbGraph::Connections::Home, '#home' do
|
|
47
47
|
:icon => 'http://photos-h.ak.fbcdn.net/photos-ak-sf2p/v43/23/2231777543/app_2_2231777543_2528.gif',
|
48
48
|
:attribution => 'Twitter',
|
49
49
|
:created_time => '2010-04-27T13:06:14+0000',
|
50
|
-
:updated_time => '2010-04-27T13:06:14+0000'
|
50
|
+
:updated_time => '2010-04-27T13:06:14+0000',
|
51
|
+
:privacy => {
|
52
|
+
:value => 'EVERYONE'
|
53
|
+
}
|
51
54
|
)
|
52
55
|
posts.each do |post|
|
53
56
|
post.should be_instance_of(FbGraph::Post)
|
@@ -54,10 +54,10 @@ describe FbGraph::Connections::Likes, '#likes' do
|
|
54
54
|
it 'should access to Graph API' do
|
55
55
|
lambda do
|
56
56
|
@status.likes(:no_cache => true) # :no_cache has no meaning, just putting some value as options
|
57
|
-
end.should
|
57
|
+
end.should request_to('115838235152172/likes?access_token=access_token&no_cache=true')
|
58
58
|
lambda do
|
59
59
|
@status.likes(:limit => 10)
|
60
|
-
end.should
|
60
|
+
end.should request_to('115838235152172/likes?access_token=access_token&limit=10')
|
61
61
|
end
|
62
62
|
|
63
63
|
context 'when next/previous are obviously blank' do
|
@@ -24,7 +24,10 @@ describe FbGraph::Connections::Posts, '#posts' do
|
|
24
24
|
:icon => 'http://static.ak.fbcdn.net/rsrc.php/z9XZ8/hash/976ulj6z.gif',
|
25
25
|
:created_time => '2010-04-25T04:05:32+0000',
|
26
26
|
:updated_time => '2010-04-25T04:05:32+0000',
|
27
|
-
:likes => 1
|
27
|
+
:likes => 1,
|
28
|
+
:privacy => {
|
29
|
+
:value => 'EVERYONE'
|
30
|
+
}
|
28
31
|
)
|
29
32
|
posts.each do |post|
|
30
33
|
post.should be_instance_of(FbGraph::Post)
|
@@ -15,4 +15,35 @@ describe FbGraph::Connections::Subscriptions, '#subscriptions' do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe FbGraph::Connections::Subscriptions, '#subscribe!' do
|
21
|
+
before do
|
22
|
+
@app = FbGraph::Application.new('fb_graph', :access_token => 'access_token')
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should POST to /:app_id/subscriptions' do
|
26
|
+
lambda do
|
27
|
+
@app.subscribe!(
|
28
|
+
:object => "user",
|
29
|
+
:fields => "name,email",
|
30
|
+
:callback_url => "http://fbgraphsample.heroku.com/subscription",
|
31
|
+
:verify_token => "Define by yourself"
|
32
|
+
)
|
33
|
+
end.should request_to 'fb_graph/subscriptions', :post
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe FbGraph::Connections::Subscriptions, '#unsubscribe!' do
|
38
|
+
before do
|
39
|
+
@app = FbGraph::Application.new('fb_graph', :access_token => 'access_token')
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should DELETE /:app_id/subscriptions' do
|
43
|
+
lambda do
|
44
|
+
@app.unsubscribe!(
|
45
|
+
:object => 'user'
|
46
|
+
)
|
47
|
+
end.should request_to 'fb_graph/subscriptions?access_token=access_token&object=user', :delete
|
48
|
+
end
|
18
49
|
end
|
@@ -31,7 +31,10 @@ describe FbGraph::Connections::Tagged, '#tagged' do
|
|
31
31
|
:icon => 'http://static.ak.fbcdn.net/rsrc.php/zB010/hash/9yvl71tw.gif',
|
32
32
|
:created_time => '2010-04-24T08:07:59+0000',
|
33
33
|
:updated_time => '2010-04-24T08:07:59+0000',
|
34
|
-
:likes => 1
|
34
|
+
:likes => 1,
|
35
|
+
:privacy => {
|
36
|
+
:value => 'EVERYONE'
|
37
|
+
}
|
35
38
|
)
|
36
39
|
posts.each do |post|
|
37
40
|
post.should be_instance_of(FbGraph::Post)
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../../spec_helper')
|
2
|
+
|
3
|
+
describe FbGraph::Connections::TestUsers, '#test_users' do
|
4
|
+
before do
|
5
|
+
@app = FbGraph::Application.new('client_id', :secret => 'secret')
|
6
|
+
fake_json(:get, 'client_id/accounts/test-users?access_token=access_token', 'applications/test_users/private')
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'when access_token is not given' do
|
10
|
+
it 'should get access_token first' do
|
11
|
+
lambda do
|
12
|
+
@app.test_users
|
13
|
+
end.should request_to('oauth/access_token', :post)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'when access_token is given' do
|
18
|
+
it 'should return test_users as FbGraph::TestUser' do
|
19
|
+
@app.access_token = 'access_token'
|
20
|
+
test_users = @app.test_users
|
21
|
+
test_users.each do |test_user|
|
22
|
+
test_user.should be_instance_of(FbGraph::TestUser)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe FbGraph::Connections::TestUsers, '#test_user!' do
|
29
|
+
before do
|
30
|
+
@app = FbGraph::Application.new('client_id', :secret => 'secret')
|
31
|
+
fake_json(:post, 'client_id/accounts/test-users', 'applications/test_users/created')
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'when access_token is not given' do
|
35
|
+
it 'should get access_token first' do
|
36
|
+
lambda do
|
37
|
+
@app.test_user!
|
38
|
+
end.should request_to('oauth/access_token', :post)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when access_token is given' do
|
43
|
+
it 'should return a FbGraph::TestUser' do
|
44
|
+
@app.access_token = 'access_token'
|
45
|
+
test_user = @app.test_user!
|
46
|
+
test_user.should be_instance_of FbGraph::TestUser
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../spec_helper')
|
2
|
+
|
3
|
+
describe FbGraph::Exception do
|
4
|
+
context 'when response body is given' do
|
5
|
+
it 'should setup message and type from error' do
|
6
|
+
err = FbGraph::Exception.new(400, 'This is the original message', {
|
7
|
+
:error => {
|
8
|
+
:type => 'SomeError',
|
9
|
+
:message => 'This is the error message'
|
10
|
+
}
|
11
|
+
}.to_json)
|
12
|
+
err.code.should == 400
|
13
|
+
err.type.should == 'SomeError'
|
14
|
+
err.message.should == 'This is the error message'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when response body is not given' do
|
19
|
+
it 'should not have type' do
|
20
|
+
err = FbGraph::Exception.new(400, 'This is the original message')
|
21
|
+
err.code.should == 400
|
22
|
+
err.type.should be_nil
|
23
|
+
err.message.should == 'This is the original message'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe FbGraph::BadRequest do
|
29
|
+
it 'should have 400 status code' do
|
30
|
+
err = FbGraph::BadRequest.new 'Bad Request'
|
31
|
+
err.code.should == 400
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe FbGraph::Unauthorized do
|
36
|
+
it 'should have 401 status code' do
|
37
|
+
err = FbGraph::Unauthorized.new 'Unauthorized'
|
38
|
+
err.code.should == 401
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe FbGraph::NotFound do
|
43
|
+
it 'should have 404 status code' do
|
44
|
+
err = FbGraph::NotFound.new 'Not Found'
|
45
|
+
err.code.should == 404
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../spec_helper')
|
2
|
+
|
3
|
+
describe FbGraph::Location, '.new' do
|
4
|
+
|
5
|
+
it 'should setup all supported attributes' do
|
6
|
+
attributes = {
|
7
|
+
:latitude => 30.2669,
|
8
|
+
:longitude => -97.7428
|
9
|
+
}
|
10
|
+
location = FbGraph::Location.new(attributes)
|
11
|
+
location.latitude.should == 30.2669
|
12
|
+
location.longitude.should == -97.7428
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
describe FbGraph::Location, '.to_hash' do
|
18
|
+
|
19
|
+
it 'should setup all supported attributes' do
|
20
|
+
attributes = {
|
21
|
+
:latitude => 30.2669,
|
22
|
+
:longitude => -97.7428
|
23
|
+
}
|
24
|
+
location = FbGraph::Location.new(attributes)
|
25
|
+
location.to_hash == attributes
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/spec/fb_graph/node_spec.rb
CHANGED
@@ -10,4 +10,31 @@ describe FbGraph::Node, '.new' do
|
|
10
10
|
FbGraph::Node.new('matake', :access_token => 'access_token').access_token.should == 'access_token'
|
11
11
|
end
|
12
12
|
|
13
|
+
end
|
14
|
+
|
15
|
+
describe FbGraph::Node, '#stringfy_access_token' do
|
16
|
+
it 'should support OAuth2::AccessToken' do
|
17
|
+
client = OAuth2::Client.new('client_id', 'client_secret')
|
18
|
+
node = FbGraph::Node.new('identifier', :access_token => OAuth2::AccessToken.new(client, 'token', 'secret'))
|
19
|
+
params = node.send :stringfy_access_token, {}
|
20
|
+
params[:access_token].should == 'token'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe FbGraph::Node, '#handle_response' do
|
25
|
+
it 'should handle null/false response' do
|
26
|
+
node = FbGraph::Node.new('identifier')
|
27
|
+
null_response = node.send :handle_response do
|
28
|
+
RestClient::Response.create 'null', nil, nil
|
29
|
+
end
|
30
|
+
null_response.should be_nil
|
31
|
+
lambda do
|
32
|
+
node.send :handle_response do
|
33
|
+
RestClient::Response.create 'false', nil, nil
|
34
|
+
end
|
35
|
+
end.should raise_error(
|
36
|
+
FbGraph::NotFound,
|
37
|
+
'Graph API returned false, so probably it means your requested object is not found.'
|
38
|
+
)
|
39
|
+
end
|
13
40
|
end
|
data/spec/fb_graph/page_spec.rb
CHANGED
@@ -41,6 +41,13 @@ describe FbGraph::Page, '.new' do
|
|
41
41
|
page = FbGraph::Page.new(12345, :founded => "2004")
|
42
42
|
page.founded.should == Date.new(2004, 1, 1)
|
43
43
|
end
|
44
|
+
|
45
|
+
it 'should allow invalid date as release_date' do
|
46
|
+
page1 = FbGraph::Page.new(12345, :release_date => "2010-04-23")
|
47
|
+
page1.release_date.should == Date.new(2010, 4, 23)
|
48
|
+
page2 = FbGraph::Page.new(12345, :release_date => "someday")
|
49
|
+
page2.release_date.should == 'someday'
|
50
|
+
end
|
44
51
|
end
|
45
52
|
|
46
53
|
describe FbGraph::Page, '.fetch' do
|