fb_graph 0.7.2 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -8,7 +8,7 @@ A full-stack Facebook Graph API wrapper in Ruby.
8
8
 
9
9
  == Resources
10
10
 
11
- * View RDoc on RDoc.info (http://rdoc.info/projects/nov/fb_graph)
11
+ * View RDoc on RDoc.info (http://rdoc.info/github/nov/fb_graph/master/frames)
12
12
  * View Source on GitHub (http://github.com/nov/fb_graph)
13
13
  * Report Issues on GitHub (http://github.com/nov/fb_graph/issues)
14
14
  * Facebook fan page (http://www.facebook.com/pages/FbGraph/117513961602338)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.2
1
+ 0.7.3
data/fb_graph.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{fb_graph}
8
- s.version = "0.7.2"
8
+ s.version = "0.7.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["nov matake"]
12
- s.date = %q{2010-09-04}
12
+ s.date = %q{2010-09-07}
13
13
  s.description = %q{A Ruby wrapper for Facebook Graph API}
14
14
  s.email = %q{nov@matake.jp}
15
15
  s.extra_rdoc_files = [
@@ -37,6 +37,7 @@ Gem::Specification.new do |s|
37
37
  "lib/fb_graph/comparison.rb",
38
38
  "lib/fb_graph/connection.rb",
39
39
  "lib/fb_graph/connections.rb",
40
+ "lib/fb_graph/connections/accounts.rb",
40
41
  "lib/fb_graph/connections/activities.rb",
41
42
  "lib/fb_graph/connections/albums.rb",
42
43
  "lib/fb_graph/connections/attending.rb",
@@ -109,6 +110,9 @@ Gem::Specification.new do |s|
109
110
  "spec/fake_json/posts/likes/post_without_access_token.json",
110
111
  "spec/fake_json/posts/platform_private.json",
111
112
  "spec/fake_json/posts/platform_public.json",
113
+ "spec/fake_json/users/accounts/matake_private.json",
114
+ "spec/fake_json/users/accounts/matake_private_with_manage_pages_permission.json",
115
+ "spec/fake_json/users/accounts/matake_public.json",
112
116
  "spec/fake_json/users/activities/arjun_private.json",
113
117
  "spec/fake_json/users/activities/arjun_public.json",
114
118
  "spec/fake_json/users/albums/matake_private.json",
@@ -162,6 +166,7 @@ Gem::Specification.new do |s|
162
166
  "spec/fb_graph/collection_spec.rb",
163
167
  "spec/fb_graph/comment_spec.rb",
164
168
  "spec/fb_graph/connection_spec.rb",
169
+ "spec/fb_graph/connections/accounts_spec.rb",
165
170
  "spec/fb_graph/connections/activities_spec.rb",
166
171
  "spec/fb_graph/connections/albums_spec.rb",
167
172
  "spec/fb_graph/connections/attending_spec.rb",
@@ -222,6 +227,7 @@ Gem::Specification.new do |s|
222
227
  "spec/fb_graph/collection_spec.rb",
223
228
  "spec/fb_graph/comment_spec.rb",
224
229
  "spec/fb_graph/connection_spec.rb",
230
+ "spec/fb_graph/connections/accounts_spec.rb",
225
231
  "spec/fb_graph/connections/activities_spec.rb",
226
232
  "spec/fb_graph/connections/albums_spec.rb",
227
233
  "spec/fb_graph/connections/attending_spec.rb",
@@ -0,0 +1,22 @@
1
+ module FbGraph
2
+ module Connections
3
+ module Accounts
4
+ # == Fetching Pages owned by the current user.
5
+ #
6
+ # If the manage_pages permission has been granted,
7
+ # this connection also yields access_tokens that can be used to query the Graph API on behalf of the page.
8
+ #
9
+ # ref) http://developers.facebook.com/docs/reference/api/user
10
+ #
11
+ # FbGraph::User.me(ACCESS_TOKEN).accounts
12
+ # => array of FbGraph::Page
13
+ def accounts(options = {})
14
+ accounts = self.connection(:accounts, options)
15
+ accounts.map! do |account|
16
+ account[:access_token] ||= options[:access_token] || self.access_token
17
+ FbGraph::Page.new(account.delete(:id), account)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,6 +1,32 @@
1
1
  module FbGraph
2
2
  module Connections
3
3
  module Feed
4
+ # == Fetching Wall posts
5
+ #
6
+ # === User Wall
7
+ #
8
+ # FbGraph::User.new(username).feed
9
+ # # => Array of FbGraph::Post
10
+ #
11
+ # === Page Wall
12
+ #
13
+ # FbGraph::Page.new(page_id).feed
14
+ # # => Array of FbGraph::Post
15
+ #
16
+ # === Application Wall
17
+ #
18
+ # FbGraph::Application.new(page_id).feed
19
+ # # => Array of FbGraph::Post
20
+ #
21
+ # === Event Wall
22
+ #
23
+ # FbGraph::Event.new(page_id).feed
24
+ # # => Array of FbGraph::Post
25
+ #
26
+ # === Group Wall
27
+ #
28
+ # FbGraph::Group.new(page_id).feed
29
+ # # => Array of FbGraph::Post
4
30
  def feed(options = {})
5
31
  posts = self.connection(:feed, options)
6
32
  posts.map! do |post|
@@ -10,6 +36,49 @@ module FbGraph
10
36
  end
11
37
  end
12
38
 
39
+ # == Updating Wall
40
+ #
41
+ # * See supported arguments here http://developers.facebook.com/docs/reference/api/post
42
+ # * You need admin user's access_token to update Page/Application/Event/Group wall as itself
43
+ #
44
+ # === User Wall
45
+ #
46
+ # me = FbGraph::User.me(ACCESS_TOKEN)
47
+ # me.feed!(
48
+ # :message => 'Updating via FbGraph'
49
+ # )
50
+ #
51
+ # === Page Wall
52
+ #
53
+ # page = FbGraph::Page.new(page_id)
54
+ # page.feed!(
55
+ # :access_token => ACCESS_TOKEN,
56
+ # :message => 'Updating via FbGraph'
57
+ # )
58
+ #
59
+ # === Application Wall
60
+ #
61
+ # application = FbGraph::Page.new(application_id)
62
+ # application.feed!(
63
+ # :access_token => ACCESS_TOKEN,
64
+ # :message => 'Updating via FbGraph'
65
+ # )
66
+ #
67
+ # === Event Wall
68
+ #
69
+ # event = FbGraph::Event.new(event_id)
70
+ # event.feed!(
71
+ # :access_token => ACCESS_TOKEN,
72
+ # :message => 'Updating via FbGraph'
73
+ # )
74
+ #
75
+ # === Group Wall
76
+ #
77
+ # group = FbGraph::Group.new(group_id)
78
+ # group.feed!(
79
+ # :access_token => ACCESS_TOKEN,
80
+ # :message => 'Updating via FbGraph'
81
+ # )
13
82
  def feed!(options = {})
14
83
  post = post(options.merge(:connection => 'feed'))
15
84
  Post.new(post.delete(:id), options.merge(post).merge(
data/lib/fb_graph/node.rb CHANGED
@@ -103,7 +103,7 @@ module FbGraph
103
103
  _response_ = JSON.parse(response.body).with_indifferent_access
104
104
  if _response_[:error]
105
105
  case _response_[:error][:type]
106
- when 'OAuthAccessTokenException', 'QueryParseException'
106
+ when 'OAuthAccessTokenException', 'QueryParseException', 'OAuthInvalidRequestException'
107
107
  raise FbGraph::Unauthorized.new(_response_[:error][:message])
108
108
  else
109
109
  raise FbGraph::BadRequest.new("#{_response_[:error][:type]} :: #{_response_[:error][:message]}")
data/lib/fb_graph/user.rb CHANGED
@@ -21,18 +21,15 @@ module FbGraph
21
21
  include Connections::Links
22
22
  include Connections::Notes
23
23
  include Connections::Events
24
+ # --
24
25
  # TODO
25
26
  # include Connections::Inbox
26
27
  # include Connections::Outbox
27
28
  # include Connections::Updates
28
- # include Connections::Accounts
29
+ include Connections::Accounts
30
+ # ++
29
31
  extend Searchable
30
32
 
31
- # TODO:
32
- # include Connections::Inbox
33
- # include Connections::Outbox
34
- # include Connections::Updates
35
-
36
33
  attr_accessor :first_name, :last_name, :name, :link, :about, :birthday, :work, :education, :email, :website, :hometown, :location, :bio, :quotes, :gender, :interested_in, :meeting_for, :relationship_status, :religion, :political, :verified, :significant_other, :timezone, :updated_time
37
34
 
38
35
  def initialize(identifier, options = {})
@@ -0,0 +1,14 @@
1
+ {
2
+ "data": [
3
+ {
4
+ "name": "OAuth.jp",
5
+ "category": "Technology",
6
+ "id": "140478125968442"
7
+ },
8
+ {
9
+ "name": "FbGraph",
10
+ "category": "Technology",
11
+ "id": "117513961602338"
12
+ }
13
+ ]
14
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "data": [
3
+ {
4
+ "name": "OAuth.jp",
5
+ "category": "Technology",
6
+ "id": "140478125968442",
7
+ "access_token": "access_token_for_oauth_jp"
8
+ },
9
+ {
10
+ "name": "FbGraph",
11
+ "category": "Technology",
12
+ "id": "117513961602338",
13
+ "access_token": "access_token_for_fb_graph"
14
+ }
15
+ ]
16
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "error": {
3
+ "type": "OAuthInvalidRequestException",
4
+ "message": "An active access token must be used to query information about the current user."
5
+ }
6
+ }
@@ -0,0 +1,47 @@
1
+ require File.join(File.dirname(__FILE__), '../../spec_helper')
2
+
3
+ context 'when included by FbGraph::User' do
4
+ describe FbGraph::Connections::Accounts, '#accounts' do
5
+ before(:all) do
6
+ fake_json(:get, 'matake/accounts', 'users/accounts/matake_public')
7
+ fake_json(:get, 'matake/accounts?access_token=access_token', 'users/accounts/matake_private')
8
+ fake_json(:get, 'matake/accounts?access_token=access_token_with_manage_pages_permission', 'users/accounts/matake_private_with_manage_pages_permission')
9
+ end
10
+
11
+ context 'when no access_token given' do
12
+ it 'should raise FbGraph::Unauthorized' do
13
+ lambda do
14
+ FbGraph::User.new('matake').accounts
15
+ end.should raise_exception(FbGraph::Unauthorized)
16
+ end
17
+ end
18
+
19
+ context 'when access_token is given' do
20
+ it 'should return accounts as FbGraph::Page' do
21
+ accounts = FbGraph::User.new('matake', :access_token => 'access_token').accounts
22
+ accounts.class.should == FbGraph::Connection
23
+ accounts.first.should == FbGraph::Page.new(
24
+ '140478125968442',
25
+ :access_token => 'access_token',
26
+ :name => 'OAuth.jp',
27
+ :category => 'Technology'
28
+ )
29
+ accounts.each do |account|
30
+ account.should be_instance_of(FbGraph::Page)
31
+ end
32
+ end
33
+
34
+ context 'when manage_pages permission given' do
35
+ it 'should has special access_token behalf of the page' do
36
+ accounts = FbGraph::User.new('matake', :access_token => 'access_token_with_manage_pages_permission').accounts
37
+ accounts.first.should == FbGraph::Page.new(
38
+ '140478125968442',
39
+ :access_token => 'access_token_for_oauth_jp',
40
+ :name => 'OAuth.jp',
41
+ :category => 'Technology'
42
+ )
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fb_graph
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 2
10
- version: 0.7.2
9
+ - 3
10
+ version: 0.7.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - nov matake
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-04 00:00:00 +09:00
18
+ date: 2010-09-07 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -149,6 +149,7 @@ files:
149
149
  - lib/fb_graph/comparison.rb
150
150
  - lib/fb_graph/connection.rb
151
151
  - lib/fb_graph/connections.rb
152
+ - lib/fb_graph/connections/accounts.rb
152
153
  - lib/fb_graph/connections/activities.rb
153
154
  - lib/fb_graph/connections/albums.rb
154
155
  - lib/fb_graph/connections/attending.rb
@@ -221,6 +222,9 @@ files:
221
222
  - spec/fake_json/posts/likes/post_without_access_token.json
222
223
  - spec/fake_json/posts/platform_private.json
223
224
  - spec/fake_json/posts/platform_public.json
225
+ - spec/fake_json/users/accounts/matake_private.json
226
+ - spec/fake_json/users/accounts/matake_private_with_manage_pages_permission.json
227
+ - spec/fake_json/users/accounts/matake_public.json
224
228
  - spec/fake_json/users/activities/arjun_private.json
225
229
  - spec/fake_json/users/activities/arjun_public.json
226
230
  - spec/fake_json/users/albums/matake_private.json
@@ -274,6 +278,7 @@ files:
274
278
  - spec/fb_graph/collection_spec.rb
275
279
  - spec/fb_graph/comment_spec.rb
276
280
  - spec/fb_graph/connection_spec.rb
281
+ - spec/fb_graph/connections/accounts_spec.rb
277
282
  - spec/fb_graph/connections/activities_spec.rb
278
283
  - spec/fb_graph/connections/albums_spec.rb
279
284
  - spec/fb_graph/connections/attending_spec.rb
@@ -362,6 +367,7 @@ test_files:
362
367
  - spec/fb_graph/collection_spec.rb
363
368
  - spec/fb_graph/comment_spec.rb
364
369
  - spec/fb_graph/connection_spec.rb
370
+ - spec/fb_graph/connections/accounts_spec.rb
365
371
  - spec/fb_graph/connections/activities_spec.rb
366
372
  - spec/fb_graph/connections/albums_spec.rb
367
373
  - spec/fb_graph/connections/attending_spec.rb