fb_graph 1.8.6 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/Gemfile.lock +1 -1
  2. data/VERSION +1 -1
  3. data/lib/fb_graph/album.rb +5 -4
  4. data/lib/fb_graph/application.rb +2 -0
  5. data/lib/fb_graph/auth/cookie.rb +4 -3
  6. data/lib/fb_graph/connections/accounts.rb +6 -1
  7. data/lib/fb_graph/connections/docs.rb +14 -0
  8. data/lib/fb_graph/connections/inbox.rb +5 -2
  9. data/lib/fb_graph/connections/outbox.rb +17 -0
  10. data/lib/fb_graph/connections/reviews.rb +14 -0
  11. data/lib/fb_graph/connections/threads.rb +14 -0
  12. data/lib/fb_graph/doc.rb +18 -0
  13. data/lib/fb_graph/domain.rb +32 -0
  14. data/lib/fb_graph/group.rb +3 -4
  15. data/lib/fb_graph/insight.rb +0 -2
  16. data/lib/fb_graph/link.rb +1 -2
  17. data/lib/fb_graph/message.rb +1 -8
  18. data/lib/fb_graph/node.rb +3 -3
  19. data/lib/fb_graph/post.rb +14 -5
  20. data/lib/fb_graph/property.rb +13 -0
  21. data/lib/fb_graph/review.rb +20 -0
  22. data/lib/fb_graph/thread.rb +1 -2
  23. data/lib/fb_graph/user.rb +53 -44
  24. data/lib/fb_graph/video.rb +12 -3
  25. data/lib/fb_graph.rb +4 -0
  26. data/spec/fb_graph/album_spec.rb +2 -0
  27. data/spec/fb_graph/auth/cookie_spec.rb +18 -7
  28. data/spec/fb_graph/connections/accounts_spec.rb +13 -0
  29. data/spec/fb_graph/connections/docs_spec.rb +14 -0
  30. data/spec/fb_graph/connections/home_spec.rb +0 -1
  31. data/spec/fb_graph/connections/inbox_spec.rb +6 -3
  32. data/spec/fb_graph/connections/insights_spec.rb +2 -2
  33. data/spec/fb_graph/connections/likes_spec.rb +2 -2
  34. data/spec/fb_graph/connections/outbox_spec.rb +15 -0
  35. data/spec/fb_graph/connections/reviews_spec.rb +14 -0
  36. data/spec/fb_graph/connections/threads_spec.rb +12 -0
  37. data/spec/fb_graph/doc_spec.rb +27 -0
  38. data/spec/fb_graph/domain_spec.rb +23 -0
  39. data/spec/fb_graph/group_spec.rb +0 -18
  40. data/spec/fb_graph/link_spec.rb +0 -2
  41. data/spec/fb_graph/message_spec.rb +0 -2
  42. data/spec/fb_graph/node_spec.rb +2 -2
  43. data/spec/fb_graph/post_spec.rb +24 -2
  44. data/spec/fb_graph/user_spec.rb +0 -3
  45. data/spec/fb_graph/video_spec.rb +14 -20
  46. data/spec/helpers/webmock_helper.rb +1 -1
  47. data/spec/mock_json/applications/accounts/private.json +9 -0
  48. data/spec/mock_json/applications/reviews/public.json +354 -0
  49. data/spec/mock_json/domains/search_public.json +10 -0
  50. data/spec/mock_json/groups/docs/private.json +31 -0
  51. data/spec/mock_json/posts/no_comments.json +1 -2
  52. data/spec/mock_json/users/feed/arjun_private.json +0 -3
  53. data/spec/mock_json/users/feed/arjun_public.json +0 -3
  54. data/spec/mock_json/users/home/me_private.json +0 -22
  55. data/spec/mock_json/users/home/me_private_next.json +0 -24
  56. data/spec/mock_json/users/home/me_private_previous.json +0 -1
  57. data/spec/mock_json/users/inbox/me_private.json +43 -78
  58. data/spec/mock_json/users/outbox/me_private.json +51 -0
  59. data/spec/mock_json/users/posts/arjun_private.json +0 -4
  60. data/spec/mock_json/users/posts/arjun_public.json +0 -4
  61. data/spec/mock_json/users/tagged/arjun_private.json +0 -1
  62. data/spec/mock_json/users/tagged/arjun_public.json +0 -1
  63. data/spec/mock_json/users/threads/me_private.json +91 -0
  64. data/spec/mock_json/videos/private.json +78 -0
  65. metadata +74 -2
@@ -44,4 +44,17 @@ describe FbGraph::Connections::Accounts, '#accounts' do
44
44
  end
45
45
  end
46
46
  end
47
+
48
+ context 'when included by FbGraph::Application' do
49
+ it 'should return an array of TestUser' do
50
+ mock_graph :get, 'app/accounts', 'applications/accounts/private', :access_token => 'access_token_for_app' do
51
+ accounts = FbGraph::Application.new('app', :access_token => 'access_token_for_app').accounts
52
+ accounts.first.should == FbGraph::TestUser.new(
53
+ '100002527044219',
54
+ :access_token => '117950878254050|2.AQA7fQ_BuZqxAiHc.3600.1308646800.0-100002527044219|T1wRNmvnx5j5nw-2x00gZgdBjbo',
55
+ :login_url => 'https://www.facebook.com/platform/test_account_login.php?user_id=100002527044219&n=SOlkQGg6Icr5BeI'
56
+ )
57
+ end
58
+ end
59
+ end
47
60
  end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe FbGraph::Connections::Docs do
4
+ describe '#docs' do
5
+ it 'should return docs as FbGraph::Doc' do
6
+ mock_graph :get, 'my_group/docs', 'groups/docs/private', :access_token => 'access_token' do
7
+ docs = FbGraph::Group.new('my_group', :access_token => 'access_token').docs
8
+ docs.each do |doc|
9
+ doc.should be_instance_of(FbGraph::Doc)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -46,7 +46,6 @@ describe FbGraph::Connections::Home, '#home' do
46
46
  },
47
47
  :message => "こちらこそありがとうございました!僕はctrl+無変換ですwRT @_eskm: @pandeiro245 こないだの日曜はありがとうございました!面白い内容でした。ちなみにfnrirってCapsLockで起動ですが、英数変換と同じボタンでどうしてます?起動を違うボタンに変更",
48
48
  :icon => 'http://photos-h.ak.fbcdn.net/photos-ak-sf2p/v43/23/2231777543/app_2_2231777543_2528.gif',
49
- :attribution => 'Twitter',
50
49
  :created_time => '2010-04-27T13:06:14+0000',
51
50
  :updated_time => '2010-04-27T13:06:14+0000',
52
51
  :privacy => {
@@ -1,11 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe FbGraph::Connections::Inbox, '#inbox' do
4
- it 'should return threads as FbGraph::Thread' do
5
- mock_graph :get, 'me/threads', 'users/inbox/me_private', :access_token => 'access_token' do
4
+ # NOTE:
5
+ # This connection returns Post instead of Thread for now.
6
+ # See inbox.rb for more details.
7
+ it 'should return threads as FbGraph::Post' do
8
+ mock_graph :get, 'me/inbox', 'users/inbox/me_private', :access_token => 'access_token' do
6
9
  threads = FbGraph::User.me('access_token').inbox
7
10
  threads.each do |thread|
8
- thread.should be_instance_of(FbGraph::Thread)
11
+ thread.should be_instance_of(FbGraph::Post)
9
12
  end
10
13
  end
11
14
  end
@@ -94,8 +94,8 @@ describe FbGraph::Connections::Insights do
94
94
  it 'should used for pagination' do
95
95
  mock_graph :get, 'FbGraph/insights/page_like_adds/day', 'pages/insights/page_like_adds/day/FbGraph_private', :access_token => 'access_token' do
96
96
  insights = FbGraph::Page.new('FbGraph').insights(:access_token => 'access_token', :metrics => :page_like_adds, :period => :day)
97
- expect { insights.next }.should request_to 'FbGraph/insights/page_like_adds/day?oauth_token=access_token&since=1292065709&until=1292324909'
98
- expect { insights.previous }.should request_to 'FbGraph/insights/page_like_adds/day?oauth_token=access_token&since=1291547309&until=1291806509'
97
+ expect { insights.next }.should request_to 'FbGraph/insights/page_like_adds/day?access_token=access_token&since=1292065709&until=1292324909'
98
+ expect { insights.previous }.should request_to 'FbGraph/insights/page_like_adds/day?access_token=access_token&since=1291547309&until=1291806509'
99
99
  end
100
100
  end
101
101
  end
@@ -55,10 +55,10 @@ describe FbGraph::Connections::Likes, '#likes' do
55
55
  it 'should access to Graph API' do
56
56
  lambda do
57
57
  @status.likes(:no_cache => true) # :no_cache has no meaning, just putting some value as options
58
- end.should request_to('115838235152172/likes?no_cache=true')
58
+ end.should request_to('115838235152172/likes?access_token=access_token&no_cache=true')
59
59
  lambda do
60
60
  @status.likes(:limit => 10)
61
- end.should request_to('115838235152172/likes?limit=10')
61
+ end.should request_to('115838235152172/likes?access_token=access_token&limit=10')
62
62
  end
63
63
 
64
64
  context 'when next/previous are obviously blank' do
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe FbGraph::Connections::Outbox, '#outbox' do
4
+ # NOTE:
5
+ # This connection returns Post instead of Thread for now.
6
+ # See outbox.rb for more details.
7
+ it 'should return threads as FbGraph::Post' do
8
+ mock_graph :get, 'me/outbox', 'users/outbox/me_private', :access_token => 'access_token' do
9
+ threads = FbGraph::User.me('access_token').outbox
10
+ threads.each do |thread|
11
+ thread.should be_instance_of(FbGraph::Post)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe FbGraph::Connections::Reviews do
4
+ describe '#reviews' do
5
+ it 'should return reviews as FbGraph::Review' do
6
+ mock_graph :get, 'my_app/reviews', 'applications/reviews/public' do
7
+ reviews = FbGraph::Application.new('my_app').reviews
8
+ reviews.each do |review|
9
+ review.should be_instance_of(FbGraph::Review)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe FbGraph::Connections::Threads, '#threads' do
4
+ it 'should return threads as FbGraph::Thread' do
5
+ mock_graph :get, 'me/threads', 'users/threads/me_private', :access_token => 'access_token' do
6
+ threads = FbGraph::User.me('access_token').threads
7
+ threads.each do |thread|
8
+ thread.should be_instance_of(FbGraph::Thread)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe FbGraph::Doc do
4
+ describe '.new' do
5
+ let :attributes do
6
+ {
7
+ :id => '12345',
8
+ :from => {
9
+ :id => '123456',
10
+ :name => 'Nov Matake'
11
+ },
12
+ :subject => 'Subject',
13
+ :icon => 'https://s-static.ak.facebook.com/rsrc.php/v1/yi/r/-64q65AWgXb.png',
14
+ :updated_time => '2011-03-12T02:43:04+0000',
15
+ :revision => 207279219287628
16
+ }
17
+ end
18
+ it 'should setup all supported attributes' do
19
+ doc = FbGraph::Doc.new(attributes[:id], attributes)
20
+ doc.identifier.should == '12345'
21
+ doc.from.should == FbGraph::User.new('123456', :name => 'Nov Matake')
22
+ doc.subject.should == 'Subject'
23
+ doc.icon.should == 'https://s-static.ak.facebook.com/rsrc.php/v1/yi/r/-64q65AWgXb.png'
24
+ doc.revision.should == 207279219287628
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe FbGraph::Domain do
4
+ describe '.search' do
5
+ let :results do
6
+ mock_graph :get, '/', 'domains/search_public', :params => {
7
+ :domains => 'apple.com,fake.com'
8
+ } do
9
+ FbGraph::Domain.search('apple.com')
10
+ end
11
+ end
12
+
13
+ it 'should return array of FbGraph::Domain' do
14
+ results.each do |result|
15
+ result.should be_instance_of(FbGraph::Domain)
16
+ end
17
+ end
18
+
19
+ it 'should ignore fake.com' do
20
+ results.collect(&:name).should_not include 'fake.com'
21
+ end
22
+ end
23
+ end
@@ -12,15 +12,6 @@ describe FbGraph::Group, '.new' do
12
12
  :name => 'group 1',
13
13
  :description => 'a group for fb_graph test',
14
14
  :link => 'http://www.facebook.com/group/12345',
15
- :venue => {
16
- :street => 'Sakuragaoka',
17
- :city => 'Shibuya',
18
- :state => 'Tokyo',
19
- :zip => '150-0031',
20
- :country => 'Japan',
21
- :latitude => '35.685',
22
- :longitude => '139.751'
23
- },
24
15
  :privacy => 'OPEN',
25
16
  :updated_time => '2010-01-02T15:37:41+0000'
26
17
  }
@@ -30,15 +21,6 @@ describe FbGraph::Group, '.new' do
30
21
  group.name.should == 'group 1'
31
22
  group.description.should == 'a group for fb_graph test'
32
23
  group.link.should == 'http://www.facebook.com/group/12345'
33
- group.venue.should == FbGraph::Venue.new(
34
- :street => 'Sakuragaoka',
35
- :city => 'Shibuya',
36
- :state => 'Tokyo',
37
- :zip => '150-0031',
38
- :country => 'Japan',
39
- :latitude => '35.685',
40
- :longitude => '139.751'
41
- )
42
24
  group.privacy.should == 'OPEN'
43
25
  group.updated_time.should == Time.parse('2010-01-02T15:37:41+0000')
44
26
  end
@@ -11,7 +11,6 @@ describe FbGraph::Link, '.new' do
11
11
  },
12
12
  :link => 'http://www.facebook.com/link/12345',
13
13
  :name => 'name',
14
- :caption => 'caption',
15
14
  :description => 'description',
16
15
  :icon => 'http://static.ak.fbcdn.net/rsrc.php/zB010/hash/9yvl71tw.gif',
17
16
  :picture => 'http://i.ytimg.com/vi/JA068qeB0oM/2.jpg',
@@ -23,7 +22,6 @@ describe FbGraph::Link, '.new' do
23
22
  link.from.should == FbGraph::User.new('23456', :name => 'nov matake')
24
23
  link.link.should == 'http://www.facebook.com/link/12345'
25
24
  link.name.should == 'name'
26
- link.caption.should == 'caption'
27
25
  link.description.should == 'description'
28
26
  link.icon.should == 'http://static.ak.fbcdn.net/rsrc.php/zB010/hash/9yvl71tw.gif'
29
27
  link.picture.should == 'http://i.ytimg.com/vi/JA068qeB0oM/2.jpg'
@@ -4,7 +4,6 @@ describe FbGraph::Message, '.new' do
4
4
  it 'should setup all supported attributes' do
5
5
  attributes = {
6
6
  :id => "12345",
7
- :subject => "test",
8
7
  :created_time => "2011-02-04T15:11:05+0000",
9
8
  :tags => {
10
9
  :data => [{
@@ -33,7 +32,6 @@ describe FbGraph::Message, '.new' do
33
32
  }
34
33
  message = FbGraph::Message.new(attributes.delete(:id), attributes)
35
34
  message.identifier.should == '12345'
36
- message.subject.should == 'test'
37
35
  message.message.should == 'test test'
38
36
  message.created_time.should == Time.parse('2011-02-04T15:11:05+0000')
39
37
  message.tags.should == [
@@ -26,14 +26,14 @@ describe FbGraph::Node do
26
26
  client = Rack::OAuth2::Client.new(:identifier => 'client_id', :secret => 'client_secret')
27
27
  node = FbGraph::Node.new('identifier', :access_token => Rack::OAuth2::AccessToken::Legacy.new(:access_token => 'token'))
28
28
  params = node.send :build_params, {}
29
- params[:oauth_token].should == 'token'
29
+ params[:access_token].should == 'token'
30
30
  end
31
31
 
32
32
  it 'should support OAuth2::AccessToken as options[:access_token]' do
33
33
  client = Rack::OAuth2::Client.new(:identifier => 'client_id', :secret => 'client_secret')
34
34
  node = FbGraph::Node.new('identifier')
35
35
  params = node.send :build_params, {:access_token => Rack::OAuth2::AccessToken::Legacy.new(:access_token => 'token')}
36
- params[:oauth_token].should == 'token'
36
+ params[:access_token].should == 'token'
37
37
  end
38
38
  end
39
39
 
@@ -11,7 +11,7 @@ describe FbGraph::Post, '.new' do
11
11
  },
12
12
  :icon => "http://photos-d.ak.fbcdn.net/photos-ak-snc1/v27562/23/2231777543/app_2_2231777543_9553.gif",
13
13
  :type => "status",
14
- :attribution => "Twitter",
14
+ :object_id => "12345",
15
15
  :actions => [{
16
16
  :name => "Comment",
17
17
  :link => "http://www.facebook.com/579612276/posts/10150089741782277"
@@ -22,6 +22,21 @@ describe FbGraph::Post, '.new' do
22
22
  :name => "@nov on Twitter",
23
23
  :link => "http://twitter.com/nov?utm_source=fb&utm_medium=fb&utm_campaign=nov&utm_content=19294280413614080"
24
24
  }],
25
+ :application => {
26
+ :name => "Twitter",
27
+ :id => "2231777543"
28
+ },
29
+ :properties => [
30
+ {
31
+ :name => "Source",
32
+ :text => "TechCrunch Japan",
33
+ :href => "http://jp.techcrunch.com/"
34
+ },
35
+ {
36
+ :name => "Published",
37
+ :text => "2011-06-22 05:11:18 GMT"
38
+ }
39
+ ],
25
40
  :privacy => {
26
41
  :value => "EVERYONE",
27
42
  :description => "Everyone"
@@ -38,7 +53,10 @@ describe FbGraph::Post, '.new' do
38
53
  post.from.should == FbGraph::User.new("579612276", :name => 'Nov Matake')
39
54
  post.icon.should == 'http://photos-d.ak.fbcdn.net/photos-ak-snc1/v27562/23/2231777543/app_2_2231777543_9553.gif'
40
55
  post.type.should == 'status'
41
- post.attribution.should == 'Twitter'
56
+ post.graph_object_id.should == '12345'
57
+ post.properties.each do |property|
58
+ property.should be_a FbGraph::Property
59
+ end
42
60
  post.actions.should == [
43
61
  FbGraph::Action.new(
44
62
  :name => "Comment",
@@ -53,6 +71,10 @@ describe FbGraph::Post, '.new' do
53
71
  :link => "http://twitter.com/nov?utm_source=fb&utm_medium=fb&utm_campaign=nov&utm_content=19294280413614080"
54
72
  )
55
73
  ]
74
+ post.application.should == FbGraph::Application.new(
75
+ "2231777543",
76
+ :name => "Twitter"
77
+ )
56
78
  post.privacy.should == FbGraph::Privacy.new(
57
79
  :value => "EVERYONE",
58
80
  :description => "Everyone"
@@ -2,7 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  describe FbGraph::User, '.new' do
4
4
  it 'should setup all supported attributes' do
5
- # TODO: add more attributes
6
5
  attributes = {
7
6
  :id => '12345',
8
7
  :address => {
@@ -49,7 +48,6 @@ describe FbGraph::User, '.fetch' do
49
48
  mock_graph :get, 'me', 'users/me_private', :access_token => 'access_token' do
50
49
  user = FbGraph::User.me('access_token').fetch
51
50
  user.interested_in.should == ['female']
52
- user.meeting_for.should == ['Friendship', 'Networking']
53
51
  user.relationship_status.should == 'Married'
54
52
  user.website.should == 'http://matake.jp'
55
53
  user.religion.should be_nil
@@ -137,7 +135,6 @@ describe FbGraph::User, '.fetch' do
137
135
  user.website.should == nil
138
136
  user.hometown.should == FbGraph::Page.new(109533479072558, :name => 'Minnetonka, Minnesota')
139
137
  user.interested_in.should == ['female']
140
- user.meeting_for.should == ['Friendship']
141
138
  user.relationship_status.should == 'In a Relationship'
142
139
  user.religion.should == 'zorp'
143
140
  user.political.should == 'Liberal'
@@ -3,26 +3,20 @@ require 'spec_helper'
3
3
  describe FbGraph::Video, '.new' do
4
4
 
5
5
  it 'should setup all supported attributes' do
6
- attributes = {
7
- :id => '12345',
8
- :from => {
9
- :id => '23456',
10
- :name => 'nov matake'
11
- },
12
- :message => 'check this out!',
13
- :description => 'Smart.fm learning engine details',
14
- :length => 3600,
15
- :created_time => '2010-01-02T15:37:40+0000',
16
- :updated_time => '2010-01-02T15:37:41+0000'
17
- }
18
- video = FbGraph::Video.new(attributes.delete(:id), attributes)
19
- video.identifier.should == '12345'
20
- video.from.should == FbGraph::User.new('23456', :name => 'nov matake')
21
- video.message.should == 'check this out!'
22
- video.description.should == 'Smart.fm learning engine details'
23
- video.length.should == 3600
24
- video.created_time.should == Time.parse('2010-01-02T15:37:40+0000')
25
- video.updated_time.should == Time.parse('2010-01-02T15:37:41+0000')
6
+ mock_graph :get, 'video', 'videos/private', :access_token => 'access_token' do
7
+ video = FbGraph::Video.new('video', :access_token => 'access_token').fetch
8
+ video.from.should be_a FbGraph::User
9
+ video.tags.should be_a Array
10
+ video.tags.each do |tag|
11
+ tag.should be_a FbGraph::Tag
12
+ end
13
+ [:name, :description, :embed_html, :icon, :source].each do |attribute|
14
+ video.send(attribute).should be_a String
15
+ end
16
+ [:created_time, :updated_time].each do |attribute|
17
+ video.send(attribute).should be_a Time
18
+ end
19
+ end
26
20
  end
27
21
 
28
22
  it 'should support page as from' do
@@ -48,7 +48,7 @@ module WebMockHelper
48
48
  request = {}
49
49
  if options[:access_token]
50
50
  options[:params] ||= {}
51
- options[:params][:oauth_token] = options[:access_token].to_s
51
+ options[:params][:access_token] = options[:access_token].to_s
52
52
  end
53
53
  if options[:params]
54
54
  case method
@@ -0,0 +1,9 @@
1
+ {
2
+ "data": [
3
+ {
4
+ "id": "100002527044219",
5
+ "access_token": "117950878254050|2.AQA7fQ_BuZqxAiHc.3600.1308646800.0-100002527044219|T1wRNmvnx5j5nw-2x00gZgdBjbo",
6
+ "login_url": "https://www.facebook.com/platform/test_account_login.php?user_id=100002527044219&n=SOlkQGg6Icr5BeI"
7
+ }
8
+ ]
9
+ }