koala 0.9.1 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ v0.10.0
2
+ -- Added test user module
3
+ -- Fixed bug when raising APIError after Facebook fails to exchange session keys
4
+ -- Made access_token accessible via the readonly access_token property on all our API classes
5
+
1
6
  v0.9.1
2
7
  -- Tests are now compatible with Ruby 1.9.2
3
8
  -- Added JSON to runtime dependencies
data/Manifest CHANGED
@@ -9,6 +9,7 @@ lib/koala/graph_api.rb
9
9
  lib/koala/http_services.rb
10
10
  lib/koala/realtime_updates.rb
11
11
  lib/koala/rest_api.rb
12
+ lib/koala/test_users.rb
12
13
  readme.md
13
14
  spec/facebook_data.yml
14
15
  spec/koala/api_base_tests.rb
@@ -23,6 +24,7 @@ spec/koala/oauth/oauth_tests.rb
23
24
  spec/koala/realtime_updates/realtime_updates_tests.rb
24
25
  spec/koala/rest_api/rest_api_no_access_token_tests.rb
25
26
  spec/koala/rest_api/rest_api_with_access_token_tests.rb
27
+ spec/koala/test_users/test_users_tests.rb
26
28
  spec/koala_spec.rb
27
29
  spec/koala_spec_helper.rb
28
30
  spec/koala_spec_without_mocks.rb
data/Rakefile CHANGED
@@ -4,14 +4,14 @@ require 'rake'
4
4
  require 'echoe'
5
5
 
6
6
  # gem management
7
- Echoe.new('koala', '0.9.1') do |p|
7
+ Echoe.new('koala', '0.10.0') do |p|
8
8
  p.summary = "A lightweight, flexible library for Facebook with support for the Graph API, the old REST API, realtime updates, and OAuth validation."
9
9
  p.description = "Koala is a lightweight, flexible Ruby SDK for Facebook. It allows read/write access to the social graph via the Graph API and the older REST API, as well as support for realtime updates and OAuth and Facebook Connect authentication. Koala is fully tested and supports Net::HTTP and Typhoeus connections out of the box and can accept custom modules for other services."
10
10
  p.url = "http://github.com/arsduo/koala"
11
11
  p.author = ["Alex Koppel", "Chris Baclig", "Rafi Jacoby", "Context Optional"]
12
12
  p.email = "alex@alexkoppel.com"
13
13
  p.ignore_pattern = ["tmp/*", "script/*", "pkg/*"]
14
- p.runtime_dependencies = ["json"]
14
+ p.runtime_dependencies = ["json >=1.0"]
15
15
  p.development_dependencies = []
16
16
  p.retain_gemspec = true
17
17
  end
data/koala.gemspec CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{koala}
5
- s.version = "0.9.1"
5
+ s.version = "0.10.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Alex Koppel, Chris Baclig, Rafi Jacoby, Context Optional"]
9
- s.date = %q{2010-10-13}
9
+ s.date = %q{2010-12-15}
10
10
  s.description = %q{Koala is a lightweight, flexible Ruby SDK for Facebook. It allows read/write access to the social graph via the Graph API and the older REST API, as well as support for realtime updates and OAuth and Facebook Connect authentication. Koala is fully tested and supports Net::HTTP and Typhoeus connections out of the box and can accept custom modules for other services.}
11
11
  s.email = %q{alex@alexkoppel.com}
12
- s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "lib/koala.rb", "lib/koala/graph_api.rb", "lib/koala/http_services.rb", "lib/koala/realtime_updates.rb", "lib/koala/rest_api.rb"]
13
- s.files = ["CHANGELOG", "LICENSE", "Manifest", "Rakefile", "init.rb", "koala.gemspec", "lib/koala.rb", "lib/koala/graph_api.rb", "lib/koala/http_services.rb", "lib/koala/realtime_updates.rb", "lib/koala/rest_api.rb", "readme.md", "spec/facebook_data.yml", "spec/koala/api_base_tests.rb", "spec/koala/graph_and_rest_api/graph_and_rest_api_no_token_tests.rb", "spec/koala/graph_and_rest_api/graph_and_rest_api_with_token_tests.rb", "spec/koala/graph_api/graph_api_no_access_token_tests.rb", "spec/koala/graph_api/graph_api_with_access_token_tests.rb", "spec/koala/graph_api/graph_collection_tests.rb", "spec/koala/live_testing_data_helper.rb", "spec/koala/net_http_service_tests.rb", "spec/koala/oauth/oauth_tests.rb", "spec/koala/realtime_updates/realtime_updates_tests.rb", "spec/koala/rest_api/rest_api_no_access_token_tests.rb", "spec/koala/rest_api/rest_api_with_access_token_tests.rb", "spec/koala_spec.rb", "spec/koala_spec_helper.rb", "spec/koala_spec_without_mocks.rb", "spec/mock_facebook_responses.yml", "spec/mock_http_service.rb"]
12
+ s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "lib/koala.rb", "lib/koala/graph_api.rb", "lib/koala/http_services.rb", "lib/koala/realtime_updates.rb", "lib/koala/rest_api.rb", "lib/koala/test_users.rb"]
13
+ s.files = ["CHANGELOG", "LICENSE", "Manifest", "Rakefile", "init.rb", "koala.gemspec", "lib/koala.rb", "lib/koala/graph_api.rb", "lib/koala/http_services.rb", "lib/koala/realtime_updates.rb", "lib/koala/rest_api.rb", "lib/koala/test_users.rb", "readme.md", "spec/facebook_data.yml", "spec/koala/api_base_tests.rb", "spec/koala/graph_and_rest_api/graph_and_rest_api_no_token_tests.rb", "spec/koala/graph_and_rest_api/graph_and_rest_api_with_token_tests.rb", "spec/koala/graph_api/graph_api_no_access_token_tests.rb", "spec/koala/graph_api/graph_api_with_access_token_tests.rb", "spec/koala/graph_api/graph_collection_tests.rb", "spec/koala/live_testing_data_helper.rb", "spec/koala/net_http_service_tests.rb", "spec/koala/oauth/oauth_tests.rb", "spec/koala/realtime_updates/realtime_updates_tests.rb", "spec/koala/rest_api/rest_api_no_access_token_tests.rb", "spec/koala/rest_api/rest_api_with_access_token_tests.rb", "spec/koala/test_users/test_users_tests.rb", "spec/koala_spec.rb", "spec/koala_spec_helper.rb", "spec/koala_spec_without_mocks.rb", "spec/mock_facebook_responses.yml", "spec/mock_http_service.rb"]
14
14
  s.homepage = %q{http://github.com/arsduo/koala}
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Koala", "--main", "readme.md"]
16
16
  s.require_paths = ["lib"]
@@ -23,11 +23,11 @@ Gem::Specification.new do |s|
23
23
  s.specification_version = 3
24
24
 
25
25
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
26
- s.add_runtime_dependency(%q<json>, [">= 0"])
26
+ s.add_runtime_dependency(%q<json>, [">= 1.0"])
27
27
  else
28
- s.add_dependency(%q<json>, [">= 0"])
28
+ s.add_dependency(%q<json>, [">= 1.0"])
29
29
  end
30
30
  else
31
- s.add_dependency(%q<json>, [">= 0"])
31
+ s.add_dependency(%q<json>, [">= 1.0"])
32
32
  end
33
33
  end
data/lib/koala.rb CHANGED
@@ -17,8 +17,12 @@ require 'koala/graph_api'
17
17
  # add REST API methods
18
18
  require 'koala/rest_api'
19
19
 
20
+ # add realtime update methods
20
21
  require 'koala/realtime_updates'
21
22
 
23
+ # add test user methods
24
+ require 'koala/test_users'
25
+
22
26
  module Koala
23
27
 
24
28
  module Facebook
@@ -48,6 +52,7 @@ module Koala
48
52
  def initialize(access_token = nil)
49
53
  @access_token = access_token
50
54
  end
55
+ attr_reader :access_token
51
56
 
52
57
  def api(path, args = {}, verb = "get", options = {}, &error_checking_block)
53
58
  # Fetches the given path in the Graph API.
@@ -98,6 +103,12 @@ module Koala
98
103
  include RealtimeUpdateMethods
99
104
  end
100
105
 
106
+ class TestUsers < API
107
+ include TestUserMethods
108
+ # make the Graph API accessible in case someone wants to make other calls to interact with their users
109
+ attr_reader :graph_api
110
+ end
111
+
101
112
  class APIError < Exception
102
113
  attr_accessor :fb_error_type
103
114
  def initialize(details = {})
@@ -223,7 +234,10 @@ module Koala
223
234
 
224
235
  # Facebook returns an empty body in certain error conditions
225
236
  if response == ""
226
- raise APIError.new("ArgumentError", "get_token_from_session_key received an error (empty response body) for sessions #{sessions.inspect}!")
237
+ raise APIError.new({
238
+ "type" => "ArgumentError",
239
+ "message" => "get_token_from_session_key received an error (empty response body) for sessions #{sessions.inspect}!"
240
+ })
227
241
  end
228
242
 
229
243
  JSON.parse(response)
@@ -0,0 +1,72 @@
1
+ require 'koala'
2
+
3
+ module Koala
4
+ module Facebook
5
+ module TestUserMethods
6
+
7
+ def initialize(options = {})
8
+ @app_id = options[:app_id]
9
+ @app_access_token = options[:app_access_token]
10
+ @secret = options[:secret]
11
+ unless @app_id && (@app_access_token || @secret) # make sure we have what we need
12
+ raise ArgumentError, "Initialize must receive a hash with :app_id and either :app_access_token or :secret! (received #{options.inspect})"
13
+ end
14
+
15
+ # fetch the access token if we're provided a secret
16
+ if @secret && !@app_access_token
17
+ oauth = Koala::Facebook::OAuth.new(@app_id, @secret)
18
+ @app_access_token = oauth.get_app_access_token
19
+ end
20
+ @graph_api = GraphAPI.new(@app_access_token)
21
+ end
22
+
23
+ def create(installed, permissions = nil)
24
+ # Creates and returns a test user
25
+ args = {'installed' => installed}
26
+ args['permissions'] = (permissions.is_a?(Array) ? permissions.join(",") : permissions) if installed
27
+ result = @graph_api.graph_call(accounts_path, args, "post")
28
+ end
29
+
30
+ def list
31
+ @graph_api.graph_call(accounts_path)["data"]
32
+ end
33
+
34
+ def delete(test_user)
35
+ test_user = test_user["id"] if test_user.is_a?(Hash)
36
+ @graph_api.delete_object(test_user)
37
+ end
38
+
39
+ def delete_all
40
+ list.each {|u| delete u }
41
+ end
42
+
43
+ def befriend(user1, user2)
44
+ user1 = user1["id"] if user1.is_a?(Hash)
45
+ user2 = user2["id"] if user2.is_a?(Hash)
46
+ @graph_api.graph_call("/#{user1}/friends/#{user2}") && @graph_api.graph_call("/#{user2}/friends/#{user1}")
47
+ end
48
+
49
+ def create_network(network_size, installed = true, permissions = '')
50
+ network_size = 50 if network_size > 50 # FB's max is 50
51
+ users = (0...network_size).collect { create(installed, permissions) }
52
+ friends = users.clone
53
+ users.each do |user|
54
+ # Remove this user from list of friends
55
+ friends.delete_at(0)
56
+ # befriend all the others
57
+ friends.each do |friend|
58
+ befriend(user, friend)
59
+ end
60
+ end
61
+ return users
62
+ end
63
+
64
+ protected
65
+
66
+ def accounts_path
67
+ @accounts_path ||= "/#{@app_id}/accounts/test-users"
68
+ end
69
+
70
+ end # TestUserMethods
71
+ end # Facebook
72
+ end # Koala
data/readme.md CHANGED
@@ -56,10 +56,11 @@ We reserve the right to expand the built-in REST API coverage to additional conv
56
56
  OAuth
57
57
  -----
58
58
  You can use the Graph and REST APIs without an OAuth access token, but the real magic happens when you provide Facebook an OAuth token to prove you're authenticated. Koala provides an OAuth class to make that process easy:
59
- @oauth = Koala::Facebook::OAuth.new(app_id, code, callback_url)
59
+ @oauth = Koala::Facebook::OAuth.new(app_id, app_secret, callback_url)
60
60
 
61
61
  If your application uses Koala and the Facebook [JavaScript SDK](http://github.com/facebook/connect-js) (formerly Facebook Connect), you can use the OAuth class to parse the cookies:
62
- @oauth.get_user_from_cookie(cookies)
62
+ @oauth.get_user_from_cookies(cookies) # gets the user's ID
63
+ @oauth.get_user_info_from_cookies(cookies) # parses and returns the entire hash
63
64
 
64
65
  And if you have to use the more complicated [redirect-based OAuth process](http://developers.facebook.com/docs/authentication/), Koala helps out there, too:
65
66
  # generate authenticating URL
@@ -5,18 +5,18 @@
5
5
 
6
6
  # You must supply this value yourself to test the GraphAPI class.
7
7
  # Your OAuth token should have publish_stream and read_stream permissions.
8
- oauth_token: 119908831367602|2.5GL0_XdFnxzqsiXeHxJ_FQ__.3600.1286535600-2905623|24AaBQnKkMvvMlNNKdJn4GxRWWQ
8
+ oauth_token:
9
9
 
10
10
  # for testing the OAuth class
11
11
  # baseline app
12
12
  oauth_test_data:
13
13
  # You must supply this value yourself, since they will expire.
14
- code: 2.5GL0_XdFnxzqsiXeHxJ_FQ__.3600.1286535600-2905623|Hae8o6zcuXr9E_UXm0LdoCN4ML8
14
+ code:
15
15
  # easiest way to get session keys: use multiple test accounts with the Javascript login at http://oauth.twoalex.com
16
- session_key: 2.5GL0_XdFnxzqsiXeHxJ_FQ__.3600.1286535600-2905623
16
+ session_key:
17
17
  multiple_session_keys:
18
- - 2.5GL0_XdFnxzqsiXeHxJ_FQ__.3600.1286535600-2905623
19
- - 2.5GL0_XdFnxzqsiXeHxJ_FQ__.3600.1286535600-2905623
18
+ -
19
+ -
20
20
 
21
21
  # These values will work out of the box
22
22
  app_id: 119908831367602
@@ -30,6 +30,12 @@ class ApiBaseTests < Test::Unit::TestCase
30
30
  service.api('anything')
31
31
  end
32
32
 
33
+ it "should have an attr_reader for access token" do
34
+ token = 'adfadf'
35
+ service = Koala::Facebook::API.new token
36
+ service.access_token.should == token
37
+ end
38
+
33
39
  it "should get the attribute of a Koala::Response given by the http_component parameter" do
34
40
  http_component = :method_name
35
41
 
@@ -8,14 +8,34 @@ module LiveTestingDataHelper
8
8
  before :each do
9
9
  @token = $testing_data["oauth_token"]
10
10
  raise Exception, "Must supply access token to run FacebookWithAccessTokenTests!" unless @token
11
+ # track temporary objects created
12
+ @temporary_object_ids = []
11
13
  end
12
14
 
13
15
  after :each do
14
16
  # clean up any temporary objects
15
- if @temporary_object_id
16
- puts "\nCleaning up temporary object #{@temporary_object_id.to_s}"
17
- result = @api.delete_object(@temporary_object_id)
18
- raise "Unable to clean up temporary Graph object #{@temporary_object_id}!" unless result
17
+ @temporary_object_ids << @temporary_object_id if @temporary_object_id
18
+ count = @temporary_object_ids.length
19
+ errors = []
20
+
21
+ if count > 0
22
+ print "\nCleaning up #{count} temporary #{count > 1 ? "objects" : "object"}..."
23
+ @temporary_object_ids.each do |id|
24
+ # get our API
25
+ api = @api || (@test_users ? @test_users.graph_api : nil)
26
+ raise "Unable to locate API when passed temporary object to delete!" unless api
27
+
28
+ # delete the object
29
+ result = (api.delete_object(id) rescue false)
30
+ # if we errored out or Facebook returned false, track that
31
+ errors << id unless result
32
+ end
33
+
34
+ if errors.length == 0
35
+ puts "done."
36
+ else
37
+ puts "cleaned up #{count - errors.length} objects, but errored out on the following:\n #{errors.join(", ")}"
38
+ end
19
39
  end
20
40
  end
21
41
  end
@@ -291,6 +291,11 @@ class FacebookOAuthTests < Test::Unit::TestCase
291
291
  # it should return nil for each of the invalid ones
292
292
  result.each_with_index {|r, index| index > 0 ? r.should(be_a(Hash)) : r.should(be_nil)}
293
293
  end
294
+
295
+ it "should throw an APIError if Facebook returns an empty body (as happens for instance when the API breaks)" do
296
+ @oauth.should_receive(:fetch_token_string).and_return("")
297
+ lambda { @oauth.get_token_info_from_session_keys(@oauth_data["multiple_session_keys"]) }.should raise_error(Koala::Facebook::APIError)
298
+ end
294
299
  end
295
300
 
296
301
  describe "with get_tokens_from_session_keys" do
@@ -0,0 +1,215 @@
1
+ class TestUsersTests < Test::Unit::TestCase
2
+ include Koala
3
+
4
+ describe "Koala TestUsers with access token" do
5
+ include LiveTestingDataHelper
6
+
7
+ before :all do
8
+ # get oauth data
9
+ @oauth_data = $testing_data["oauth_test_data"]
10
+ @app_id = @oauth_data["app_id"]
11
+ @secret = @oauth_data["secret"]
12
+ @app_access_token = @oauth_data["app_access_token"]
13
+
14
+ # check OAuth data
15
+ unless @app_id && @secret && @app_access_token
16
+ raise Exception, "Must supply OAuth app id, secret, app_access_token, and callback to run live subscription tests!"
17
+ end
18
+
19
+ @is_mock = defined?(Koala::IS_MOCK) && Koala::IS_MOCK
20
+ end
21
+
22
+ describe "when initializing" do
23
+ # basic initialization
24
+ it "should initialize properly with an app_id and an app_access_token" do
25
+ test_users = Facebook::TestUsers.new(:app_id => @app_id, :app_access_token => @app_access_token)
26
+ test_users.should be_a(Facebook::TestUsers)
27
+ end
28
+
29
+ # init with secret / fetching the token
30
+ it "should initialize properly with an app_id and a secret" do
31
+ test_users = Facebook::TestUsers.new(:app_id => @app_id, :secret => @secret)
32
+ test_users.should be_a(Facebook::TestUsers)
33
+ end
34
+
35
+ it "should use the OAuth class to fetch a token when provided an app_id and a secret" do
36
+ oauth = Facebook::OAuth.new(@app_id, @secret)
37
+ token = oauth.get_app_access_token
38
+ oauth.should_receive(:get_app_access_token).and_return(token)
39
+ Facebook::OAuth.should_receive(:new).with(@app_id, @secret).and_return(oauth)
40
+ test_users = Facebook::TestUsers.new(:app_id => @app_id, :secret => @secret)
41
+ end
42
+ end
43
+
44
+ describe "when used without network" do
45
+ before :each do
46
+ @test_users = Facebook::TestUsers.new({:app_access_token => @app_access_token, :app_id => @app_id})
47
+ end
48
+
49
+ # TEST USER MANAGEMENT
50
+ it "should create a test user when not given installed" do
51
+ result = @test_users.create(false)
52
+ @temporary_object_id = result["id"]
53
+ result.should be_a(Hash)
54
+ (result["id"] && result["access_token"] && result["login_url"]).should
55
+ end
56
+
57
+ it "should create a test user when not given installed, ignoring permissions" do
58
+ result = @test_users.create(false, "read_stream")
59
+ @temporary_object_id = result["id"]
60
+ result.should be_a(Hash)
61
+ (result["id"] && result["access_token"] && result["login_url"]).should
62
+ end
63
+
64
+ it "should accept permissions as a string" do
65
+ @test_users.graph_api.should_receive(:graph_call).with(anything, hash_including("permissions" => "read_stream,publish_stream"), anything)
66
+ result = @test_users.create(true, "read_stream,publish_stream")
67
+ end
68
+
69
+ it "should accept permissions as an array" do
70
+ @test_users.graph_api.should_receive(:graph_call).with(anything, hash_including("permissions" => "read_stream,publish_stream"), anything)
71
+ result = @test_users.create(true, ["read_stream", "publish_stream"])
72
+ end
73
+
74
+ it "should create a test user when given installed and a permission" do
75
+ result = @test_users.create(true, "read_stream")
76
+ @temporary_object_id = result["id"]
77
+ result.should be_a(Hash)
78
+ (result["id"] && result["access_token"] && result["login_url"]).should
79
+ end
80
+
81
+ describe "with a user to delete" do
82
+ before :each do
83
+ @user1 = @test_users.create(true, "read_stream")
84
+ @user2 = @test_users.create(true, "read_stream,user_interests")
85
+ end
86
+
87
+ after :each do
88
+ print "\nCleaning up test users..."
89
+ @test_users.delete(@user1) if @user1
90
+ @test_users.delete(@user2) if @user2
91
+ puts "done."
92
+ end
93
+
94
+ it "should delete a user by id" do
95
+ @test_users.delete(@user1['id']).should be_true
96
+ @user1 = nil
97
+ end
98
+
99
+ it "should delete a user by hash" do
100
+ @test_users.delete(@user2).should be_true
101
+ @user2 = nil
102
+ end
103
+
104
+ it "should not delete users when provided a false ID" do
105
+ lambda { @test_users.delete("#{@user1['id']}1") }.should raise_exception(Koala::Facebook::APIError)
106
+ end
107
+ end
108
+
109
+ describe "with delete_all" do
110
+ it "should delete all users found by the list commnand" do
111
+ array = [1, 2, 3]
112
+ @test_users.should_receive(:list).and_return(array)
113
+ array.each {|i| @test_users.should_receive(:delete).with(i) }
114
+ @test_users.delete_all
115
+ end
116
+ end
117
+
118
+ describe "with existing users" do
119
+ before :each do
120
+ @user1 = @test_users.create(true, "read_stream")
121
+ @user2 = @test_users.create(true, "read_stream,user_interests")
122
+ end
123
+
124
+ after :each do
125
+ @test_users.delete(@user1)
126
+ @test_users.delete(@user2)
127
+ end
128
+
129
+ it "should list test users" do
130
+ result = @test_users.list
131
+ result.should be_an(Array)
132
+ first_user, second_user = result[0], result[1]
133
+ (first_user["id"] && first_user["access_token"] && first_user["login_url"]).should
134
+ (second_user["id"] && second_user["access_token"] && second_user["login_url"]).should
135
+ end
136
+
137
+ it "should make two users into friends by id" do
138
+ result = @test_users.befriend(@user1['id'], @user2['id'])
139
+ result.should be_true
140
+ end
141
+
142
+ it "should make two users into friends by hash" do
143
+ result = @test_users.befriend(@user1, @user2)
144
+ result.should be_true
145
+ end
146
+
147
+ end # with existing users
148
+
149
+ end # when used without network
150
+
151
+ describe "when creating a network of friends" do
152
+ before :each do
153
+ @test_users = Facebook::TestUsers.new({:app_access_token => @app_access_token, :app_id => @app_id})
154
+ @network = []
155
+
156
+ if @is_mock
157
+ id_counter = 999999900
158
+ @test_users.stub!(:create).and_return do
159
+ id_counter += 1
160
+ {"id" => id_counter, "access_token" => "119908831367602|o3wswWQ88LYjEC9-ukR_gjRIOMw.", "login_url" => "https://www.facebook.com/platform/test_account.."}
161
+ end
162
+ @test_users.stub!(:befriend).and_return(true)
163
+ @test_users.stub!(:delete).and_return(true)
164
+ end
165
+ end
166
+
167
+ describe "tests that create users" do
168
+ before :each do
169
+ print "\nCleaning up test user network..."
170
+ test_users = Facebook::TestUsers.new({:app_access_token => @app_access_token, :app_id => @app_id})
171
+ test_users.delete_all
172
+ puts "done!"
173
+ end
174
+
175
+ after :each do
176
+ print "\nCleaning up test user network..."
177
+ test_users = Facebook::TestUsers.new({:app_access_token => @app_access_token, :app_id => @app_id})
178
+ test_users.delete_all
179
+ puts "done!"
180
+ end
181
+
182
+ it "should create a 2 person network" do
183
+ @network = @test_users.create_network(2)
184
+ @network.should be_a(Array)
185
+ @network.size.should == 2
186
+ end
187
+
188
+ it "should create a 50 person network" do
189
+ puts "\nStarting 50-person network test (this may take several minutes)..."
190
+ @network = @test_users.create_network(50)
191
+ @network.should be_a(Array)
192
+ @network.size.should == 50
193
+ puts "done!"
194
+ end
195
+ end
196
+
197
+ it "should limit to a 50 person network" do
198
+ @test_users.should_receive(:create).exactly(50).times
199
+ @test_users.stub!(:befriend)
200
+ @network = @test_users.create_network(51)
201
+ end
202
+
203
+ it "should pass on the installed and permissions parameters to create" do
204
+ perms = ["read_stream", "offline_access"]
205
+ installed = false
206
+ count = 25
207
+ @test_users.should_receive(:create).exactly(count).times.with(installed, perms)
208
+ @test_users.stub!(:befriend)
209
+ @network = @test_users.create_network(count, installed, perms)
210
+ end
211
+
212
+ end # when creating network
213
+
214
+ end # describe Koala TestUsers
215
+ end # class
@@ -42,4 +42,7 @@ require 'koala/realtime_updates/realtime_updates_tests'
42
42
  # Services tests
43
43
  require 'koala/net_http_service_tests'
44
44
 
45
+ # Test users tests
46
+ require 'koala/test_users/test_users_tests'
47
+
45
48
 
@@ -15,5 +15,5 @@ unless $testing_data["oauth_token"]
15
15
  end
16
16
 
17
17
  unless $testing_data["oauth_test_data"] && $testing_data["oauth_test_data"]["code"] && $testing_data["oauth_test_data"]["secret"]
18
- puts "Cookie tests will fail until you store valid data for the cookie hash, app_id, and app secret in facebook_data.yml"
18
+ puts "OAuth code tests will fail until you store valid data for the user's OAuth code and the app secret in facebook_data.yml"
19
19
  end
@@ -46,6 +46,10 @@ graph_api:
46
46
  # Subscription error response
47
47
  verification_error: &verification_error
48
48
  with_token: '{"error": {"type": "OAuthException", "message": "Error validating verification code."}}'
49
+
50
+ test_user_no_perms: &test_user_no_perms
51
+ post:
52
+ with_token: '{"id": "777777777", "access_token":"119908831367602|o3wswWQ88LYjEC9-ukR_gjRIOMw.", "login_url":"https://www.facebook.com/platform/test_account.."}'
49
53
 
50
54
  # -- Stubbed Responses --
51
55
  root:
@@ -238,4 +242,48 @@ graph_api:
238
242
  no_args:
239
243
  <<: *item_deleted
240
244
  get:
241
- with_token: "{\"message\": \"it\'s my comment!\"}"
245
+ with_token: "{\"message\": \"it\'s my comment!\"}"
246
+
247
+ # -- Mock Test User Responses --
248
+ /<%= APP_ID %>/accounts/test-users:
249
+ installed=false:
250
+ <<: *test_user_no_perms
251
+ installed=false&permissions=read_stream:
252
+ <<: *test_user_no_perms
253
+ installed=true&permissions=read_stream:
254
+ post:
255
+ with_token: '{"id": "999999999", "access_token":"119908831367602|o3wswWQ88LYjEC9-ukR_gjRIOMw.", "login_url":"https://www.facebook.com/platform/test_account.."}'
256
+ installed=true&permissions=read_stream,user_interests:
257
+ post:
258
+ with_token: '{"id": "888888888", "access_token":"119908831367602|o3wswWQ88LYjEC9-ukR_gjRIOMw.", "login_url":"https://www.facebook.com/platform/test_account.."}'
259
+ no_args:
260
+ get:
261
+ with_token: '{"data":[{"id": "999999999", "access_token":"119908831367602|o3wswWQ88LYjEC9-ukR_gjRIOMw.", "login_url":"https://www.facebook.com/platform/test_account.."}, {"id": "888888888", "access_token":"119908831367602|o3wswWQ88LYjEC9-ukR_gjRIOMw.", "login_url":"https://www.facebook.com/platform/test_account.."}]}'
262
+
263
+ /999999999:
264
+ no_args:
265
+ <<: *item_deleted
266
+
267
+ /9999999991:
268
+ no_args:
269
+ delete:
270
+ with_token: '{"error": {"type": "OAuthException", "message": "Error validating verification code."}}'
271
+
272
+ /888888888:
273
+ no_args:
274
+ <<: *item_deleted
275
+
276
+ /777777777:
277
+ no_args:
278
+ <<: *item_deleted
279
+
280
+ /999999999/friends/888888888:
281
+ no_args:
282
+ get:
283
+ with_token: 'true'
284
+
285
+ /888888888/friends/999999999:
286
+ no_args:
287
+ get:
288
+ with_token: 'true'
289
+
@@ -4,6 +4,7 @@ require 'yaml'
4
4
  module Koala
5
5
  module MockHTTPService
6
6
  # Mocks all HTTP requests for with koala_spec_with_mocks.rb
7
+ IS_MOCK = true # this lets our tests figure out if we want to stub methods
7
8
 
8
9
  # Mocked values to be included in TEST_DATA used in specs
9
10
  ACCESS_TOKEN = '*'
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 9
8
- - 1
9
- version: 0.9.1
7
+ - 10
8
+ - 0
9
+ version: 0.10.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Alex Koppel, Chris Baclig, Rafi Jacoby, Context Optional
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-13 00:00:00 -05:00
17
+ date: 2010-12-15 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -25,8 +25,9 @@ dependencies:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  segments:
28
+ - 1
28
29
  - 0
29
- version: "0"
30
+ version: "1.0"
30
31
  type: :runtime
31
32
  version_requirements: *id001
32
33
  description: Koala is a lightweight, flexible Ruby SDK for Facebook. It allows read/write access to the social graph via the Graph API and the older REST API, as well as support for realtime updates and OAuth and Facebook Connect authentication. Koala is fully tested and supports Net::HTTP and Typhoeus connections out of the box and can accept custom modules for other services.
@@ -43,6 +44,7 @@ extra_rdoc_files:
43
44
  - lib/koala/http_services.rb
44
45
  - lib/koala/realtime_updates.rb
45
46
  - lib/koala/rest_api.rb
47
+ - lib/koala/test_users.rb
46
48
  files:
47
49
  - CHANGELOG
48
50
  - LICENSE
@@ -55,6 +57,7 @@ files:
55
57
  - lib/koala/http_services.rb
56
58
  - lib/koala/realtime_updates.rb
57
59
  - lib/koala/rest_api.rb
60
+ - lib/koala/test_users.rb
58
61
  - readme.md
59
62
  - spec/facebook_data.yml
60
63
  - spec/koala/api_base_tests.rb
@@ -69,6 +72,7 @@ files:
69
72
  - spec/koala/realtime_updates/realtime_updates_tests.rb
70
73
  - spec/koala/rest_api/rest_api_no_access_token_tests.rb
71
74
  - spec/koala/rest_api/rest_api_with_access_token_tests.rb
75
+ - spec/koala/test_users/test_users_tests.rb
72
76
  - spec/koala_spec.rb
73
77
  - spec/koala_spec_helper.rb
74
78
  - spec/koala_spec_without_mocks.rb