koala 1.2.1 → 1.3.0rc2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +3 -1
- data/.rspec +1 -0
- data/.travis.yml +4 -0
- data/.yardopts +3 -0
- data/CHANGELOG +25 -0
- data/Gemfile +14 -0
- data/Guardfile +6 -0
- data/koala.gemspec +3 -3
- data/lib/koala/api/batch_operation.rb +83 -0
- data/lib/koala/api/graph_api.rb +476 -0
- data/lib/koala/{graph_batch_api.rb → api/graph_batch_api.rb} +22 -17
- data/lib/koala/api/graph_collection.rb +107 -0
- data/lib/koala/api/legacy.rb +26 -0
- data/lib/koala/{rest_api.rb → api/rest_api.rb} +32 -13
- data/lib/koala/api.rb +93 -0
- data/lib/koala/http_service/multipart_request.rb +41 -0
- data/lib/koala/http_service/response.rb +18 -0
- data/lib/koala/http_service/uploadable_io.rb +187 -0
- data/lib/koala/http_service.rb +69 -20
- data/lib/koala/oauth.rb +150 -27
- data/lib/koala/realtime_updates.rb +89 -51
- data/lib/koala/test_users.rb +109 -33
- data/lib/koala/utils.rb +11 -4
- data/lib/koala/version.rb +1 -1
- data/lib/koala.rb +16 -96
- data/readme.md +9 -9
- data/spec/cases/api_spec.rb +19 -12
- data/spec/cases/error_spec.rb +10 -0
- data/spec/cases/graph_api_batch_spec.rb +100 -58
- data/spec/cases/graph_collection_spec.rb +23 -7
- data/spec/cases/http_service_spec.rb +5 -26
- data/spec/cases/koala_spec.rb +22 -4
- data/spec/cases/legacy_spec.rb +107 -0
- data/spec/cases/multipart_request_spec.rb +7 -7
- data/spec/cases/oauth_spec.rb +114 -44
- data/spec/cases/realtime_updates_spec.rb +154 -47
- data/spec/cases/test_users_spec.rb +268 -219
- data/spec/cases/uploadable_io_spec.rb +1 -1
- data/spec/cases/utils_spec.rb +29 -5
- data/spec/fixtures/mock_facebook_responses.yml +40 -29
- data/spec/spec_helper.rb +3 -0
- data/spec/support/custom_matchers.rb +28 -0
- data/spec/support/graph_api_shared_examples.rb +192 -14
- data/spec/support/koala_test.rb +10 -1
- data/spec/support/mock_http_service.rb +2 -2
- data/spec/support/rest_api_shared_examples.rb +5 -165
- metadata +76 -100
- data/lib/koala/batch_operation.rb +0 -74
- data/lib/koala/graph_api.rb +0 -270
- data/lib/koala/graph_collection.rb +0 -59
- data/lib/koala/multipart_request.rb +0 -35
- data/lib/koala/uploadable_io.rb +0 -181
- data/spec/cases/graph_and_rest_api_spec.rb +0 -22
- data/spec/cases/graph_api_spec.rb +0 -22
- data/spec/cases/rest_api_spec.rb +0 -22
data/lib/koala/test_users.rb
CHANGED
|
@@ -1,16 +1,34 @@
|
|
|
1
1
|
require 'koala'
|
|
2
|
-
|
|
3
2
|
module Koala
|
|
4
3
|
module Facebook
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
|
|
5
|
+
# Create and manage test users for your application.
|
|
6
|
+
# A test user is a user account associated with an app created for the purpose
|
|
7
|
+
# of testing the functionality of that app.
|
|
8
|
+
# You can use test users for manual or automated testing --
|
|
9
|
+
# Koala's live test suite uses test users to verify the library works with Facebook.
|
|
10
|
+
#
|
|
11
|
+
# @note the test user API is fairly slow compared to other interfaces
|
|
12
|
+
# (which makes sense -- it's creating whole new user accounts!).
|
|
13
|
+
#
|
|
14
|
+
# See http://developers.facebook.com/docs/test_users/.
|
|
15
|
+
class TestUsers
|
|
16
|
+
|
|
17
|
+
# The application API interface used to communicate with Facebook.
|
|
18
|
+
# @return [Koala::Facebook::API]
|
|
19
|
+
attr_reader :api
|
|
20
|
+
attr_reader :app_id, :app_access_token, :secret
|
|
21
|
+
|
|
22
|
+
# Create a new TestUsers instance.
|
|
23
|
+
# If you don't have your app's access token, provide the app's secret and
|
|
24
|
+
# Koala will make a request to Facebook for the appropriate token.
|
|
25
|
+
#
|
|
26
|
+
# @param options initialization options.
|
|
27
|
+
# @option options :app_id the application's ID.
|
|
28
|
+
# @option options :app_access_token an application access token, if known.
|
|
29
|
+
# @option options :secret the application's secret.
|
|
30
|
+
#
|
|
31
|
+
# @raise ArgumentError if the application ID and one of the app access token or the secret are not provided.
|
|
14
32
|
def initialize(options = {})
|
|
15
33
|
@app_id = options[:app_id]
|
|
16
34
|
@app_access_token = options[:app_access_token]
|
|
@@ -24,35 +42,81 @@ module Koala
|
|
|
24
42
|
oauth = Koala::Facebook::OAuth.new(@app_id, @secret)
|
|
25
43
|
@app_access_token = oauth.get_app_access_token
|
|
26
44
|
end
|
|
45
|
+
|
|
27
46
|
@api = API.new(@app_access_token)
|
|
28
47
|
end
|
|
29
48
|
|
|
49
|
+
# Create a new test user.
|
|
50
|
+
#
|
|
51
|
+
# @param installed whether the user has installed your app
|
|
52
|
+
# @param permissions a comma-separated string or array of permissions the user has granted (if installed)
|
|
53
|
+
# @param args any additional arguments for the create call (name, etc.)
|
|
54
|
+
# @param options (see Koala::Facebook::API#api)
|
|
55
|
+
#
|
|
56
|
+
# @return a hash of information for the new user (id, access token, login URL, etc.)
|
|
30
57
|
def create(installed, permissions = nil, args = {}, options = {})
|
|
31
58
|
# Creates and returns a test user
|
|
32
59
|
args['installed'] = installed
|
|
33
60
|
args['permissions'] = (permissions.is_a?(Array) ? permissions.join(",") : permissions) if installed
|
|
34
|
-
@api.graph_call(
|
|
61
|
+
@api.graph_call(test_user_accounts_path, args, "post", options)
|
|
35
62
|
end
|
|
36
63
|
|
|
37
|
-
|
|
38
|
-
|
|
64
|
+
# List all test users for the app.
|
|
65
|
+
#
|
|
66
|
+
# @param options (see Koala::Facebook::API#api)
|
|
67
|
+
#
|
|
68
|
+
# @return an array of hashes of user information (id, access token, etc.)
|
|
69
|
+
def list(options = {})
|
|
70
|
+
@api.graph_call(test_user_accounts_path, {}, "get", options)
|
|
39
71
|
end
|
|
40
72
|
|
|
41
|
-
|
|
73
|
+
# Delete a test user.
|
|
74
|
+
#
|
|
75
|
+
# @param test_user the user to delete; can be either a Facebook ID or the hash returned by {#create}
|
|
76
|
+
# @param options (see Koala::Facebook::API#api)
|
|
77
|
+
#
|
|
78
|
+
# @return true if successful, false (or an {Koala::Facebook::APIError APIError}) if not
|
|
79
|
+
def delete(test_user, options = {})
|
|
42
80
|
test_user = test_user["id"] if test_user.is_a?(Hash)
|
|
43
|
-
@api.delete_object(test_user)
|
|
81
|
+
@api.delete_object(test_user, options)
|
|
44
82
|
end
|
|
45
83
|
|
|
46
|
-
|
|
47
|
-
|
|
84
|
+
# Deletes all test users.
|
|
85
|
+
#
|
|
86
|
+
# @note if you have a lot of test users (> 20), this operation can take a long time.
|
|
87
|
+
#
|
|
88
|
+
# @param options (see Koala::Facebook::API#api)
|
|
89
|
+
#
|
|
90
|
+
# @return a list of the test users that have been deleted
|
|
91
|
+
def delete_all(options = {})
|
|
92
|
+
list(options).each {|u| delete(u, options)}
|
|
48
93
|
end
|
|
49
94
|
|
|
50
|
-
|
|
95
|
+
# Updates a test user's attributes.
|
|
96
|
+
#
|
|
97
|
+
# @note currently, only name and password can be changed;
|
|
98
|
+
# see {http://developers.facebook.com/docs/test_users/ the Facebook documentation}.
|
|
99
|
+
#
|
|
100
|
+
# @param test_user the user to update; can be either a Facebook ID or the hash returned by {#create}
|
|
101
|
+
# @param args the updates to make
|
|
102
|
+
# @param options (see Koala::Facebook::API#api)
|
|
103
|
+
#
|
|
104
|
+
# @return true if successful, false (or an {Koala::Facebook::APIError APIError}) if not
|
|
105
|
+
def update(test_user, args = {}, options = {})
|
|
51
106
|
test_user = test_user["id"] if test_user.is_a?(Hash)
|
|
52
|
-
@api.graph_call(test_user, args, "post",
|
|
107
|
+
@api.graph_call(test_user, args, "post", options)
|
|
53
108
|
end
|
|
54
109
|
|
|
55
|
-
|
|
110
|
+
# Make two test users friends.
|
|
111
|
+
#
|
|
112
|
+
# @note there's no way to unfriend test users; you can always just create a new one.
|
|
113
|
+
#
|
|
114
|
+
# @param user1_hash one of the users to friend; the hash must contain both ID and access token (as returned by {#create})
|
|
115
|
+
# @param user2_hash the other user to friend
|
|
116
|
+
# @param options (see Koala::Facebook::API#api)
|
|
117
|
+
#
|
|
118
|
+
# @return true if successful, false (or an {Koala::Facebook::APIError APIError}) if not
|
|
119
|
+
def befriend(user1_hash, user2_hash, options = {})
|
|
56
120
|
user1_id = user1_hash["id"] || user1_hash[:id]
|
|
57
121
|
user2_id = user2_hash["id"] || user2_hash[:id]
|
|
58
122
|
user1_token = user1_hash["access_token"] || user1_hash[:access_token]
|
|
@@ -67,35 +131,47 @@ module Koala
|
|
|
67
131
|
u1_graph_api = API.new(user1_token)
|
|
68
132
|
u2_graph_api = API.new(user2_token)
|
|
69
133
|
|
|
70
|
-
u1_graph_api.graph_call("#{user1_id}/friends/#{user2_id}", {}, "post") &&
|
|
71
|
-
u2_graph_api.graph_call("#{user2_id}/friends/#{user1_id}", {}, "post")
|
|
134
|
+
u1_graph_api.graph_call("#{user1_id}/friends/#{user2_id}", {}, "post", options) &&
|
|
135
|
+
u2_graph_api.graph_call("#{user2_id}/friends/#{user1_id}", {}, "post", options)
|
|
72
136
|
end
|
|
73
137
|
|
|
74
|
-
|
|
75
|
-
|
|
138
|
+
# Create a network of test users, all of whom are friends and have the same permissions.
|
|
139
|
+
#
|
|
140
|
+
# @note this call slows down dramatically the more users you create
|
|
141
|
+
# (test user calls are slow, and more users => more 1-on-1 connections to be made).
|
|
142
|
+
# Use carefully.
|
|
143
|
+
#
|
|
144
|
+
# @param network_size how many users to create
|
|
145
|
+
# @param installed whether the users have installed your app (see {#create})
|
|
146
|
+
# @param permissions what permissions the users have granted (see {#create})
|
|
147
|
+
# @param options (see Koala::Facebook::API#api)
|
|
148
|
+
#
|
|
149
|
+
# @return the list of users created
|
|
150
|
+
def create_network(network_size, installed = true, permissions = '', options = {})
|
|
151
|
+
users = (0...network_size).collect { create(installed, permissions, options) }
|
|
76
152
|
friends = users.clone
|
|
77
153
|
users.each do |user|
|
|
78
154
|
# Remove this user from list of friends
|
|
79
155
|
friends.delete_at(0)
|
|
80
156
|
# befriend all the others
|
|
81
157
|
friends.each do |friend|
|
|
82
|
-
befriend(user, friend)
|
|
158
|
+
befriend(user, friend, options)
|
|
83
159
|
end
|
|
84
160
|
end
|
|
85
161
|
return users
|
|
86
162
|
end
|
|
87
|
-
|
|
163
|
+
|
|
164
|
+
# The Facebook test users management URL for your application.
|
|
165
|
+
def test_user_accounts_path
|
|
166
|
+
@test_user_accounts_path ||= "/#{@app_id}/accounts/test-users"
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
# @private
|
|
170
|
+
# Legacy accessor for before GraphAPI was unified into API
|
|
88
171
|
def graph_api
|
|
89
172
|
Koala::Utils.deprecate("the TestUsers.graph_api accessor is deprecated and will be removed in a future version; please use .api instead.")
|
|
90
173
|
@api
|
|
91
174
|
end
|
|
92
|
-
|
|
93
|
-
protected
|
|
94
|
-
|
|
95
|
-
def accounts_path
|
|
96
|
-
@accounts_path ||= "/#{@app_id}/accounts/test-users"
|
|
97
|
-
end
|
|
98
|
-
|
|
99
175
|
end # TestUserMethods
|
|
100
176
|
end # Facebook
|
|
101
177
|
end # Koala
|
data/lib/koala/utils.rb
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
module Koala
|
|
2
2
|
module Utils
|
|
3
|
+
|
|
4
|
+
# @private
|
|
5
|
+
DEPRECATION_PREFIX = "KOALA: Deprecation warning: "
|
|
6
|
+
|
|
7
|
+
# Prints a deprecation message.
|
|
8
|
+
# Each individual message will only be printed once to avoid spamming.
|
|
3
9
|
def self.deprecate(message)
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
10
|
+
@posted_deprecations ||= []
|
|
11
|
+
unless @posted_deprecations.include?(message)
|
|
12
|
+
# only include each message once
|
|
13
|
+
Kernel.warn("#{DEPRECATION_PREFIX}#{message}")
|
|
14
|
+
@posted_deprecations << message
|
|
8
15
|
end
|
|
9
16
|
end
|
|
10
17
|
end
|
data/lib/koala/version.rb
CHANGED
data/lib/koala.rb
CHANGED
|
@@ -1,121 +1,40 @@
|
|
|
1
|
-
|
|
1
|
+
# useful tools
|
|
2
2
|
require 'digest/md5'
|
|
3
|
-
|
|
4
3
|
require 'multi_json'
|
|
5
4
|
|
|
6
|
-
# OpenSSL and Base64 are required to support signed_request
|
|
7
|
-
require 'openssl'
|
|
8
|
-
require 'base64'
|
|
9
|
-
|
|
10
5
|
# include koala modules
|
|
6
|
+
require 'koala/api'
|
|
11
7
|
require 'koala/oauth'
|
|
12
|
-
require 'koala/graph_api'
|
|
13
|
-
require 'koala/graph_batch_api'
|
|
14
|
-
require 'koala/batch_operation'
|
|
15
|
-
require 'koala/graph_collection'
|
|
16
|
-
require 'koala/rest_api'
|
|
17
8
|
require 'koala/realtime_updates'
|
|
18
9
|
require 'koala/test_users'
|
|
19
10
|
|
|
20
11
|
# HTTP module so we can communicate with Facebook
|
|
21
12
|
require 'koala/http_service'
|
|
22
|
-
require 'koala/multipart_request'
|
|
23
|
-
|
|
24
|
-
# add KoalaIO class
|
|
25
|
-
require 'koala/uploadable_io'
|
|
26
13
|
|
|
27
14
|
# miscellaneous
|
|
28
15
|
require 'koala/utils'
|
|
29
16
|
require 'koala/version'
|
|
30
17
|
|
|
31
18
|
module Koala
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
# Contributors: Alex Koppel, Chris Baclig, Rafi Jacoby, and the team at Context Optional
|
|
37
|
-
# http://github.com/arsduo/koala
|
|
38
|
-
|
|
39
|
-
# APIs
|
|
40
|
-
class API
|
|
41
|
-
# initialize with an access token
|
|
42
|
-
def initialize(access_token = nil)
|
|
43
|
-
@access_token = access_token
|
|
44
|
-
end
|
|
45
|
-
attr_reader :access_token
|
|
46
|
-
|
|
47
|
-
include GraphAPIMethods
|
|
48
|
-
include RestAPIMethods
|
|
49
|
-
|
|
50
|
-
def api(path, args = {}, verb = "get", options = {}, &error_checking_block)
|
|
51
|
-
# Fetches the given path in the Graph API.
|
|
52
|
-
args["access_token"] = @access_token || @app_access_token if @access_token || @app_access_token
|
|
53
|
-
|
|
54
|
-
# add a leading /
|
|
55
|
-
path = "/#{path}" unless path =~ /^\//
|
|
56
|
-
|
|
57
|
-
# make the request via the provided service
|
|
58
|
-
result = Koala.make_request(path, args, verb, options)
|
|
59
|
-
|
|
60
|
-
# Check for any 500 errors before parsing the body
|
|
61
|
-
# since we're not guaranteed that the body is valid JSON
|
|
62
|
-
# in the case of a server error
|
|
63
|
-
raise APIError.new({"type" => "HTTP #{result.status.to_s}", "message" => "Response body: #{result.body}"}) if result.status >= 500
|
|
64
|
-
|
|
65
|
-
# parse the body as JSON and run it through the error checker (if provided)
|
|
66
|
-
# Note: Facebook sometimes sends results like "true" and "false", which aren't strictly objects
|
|
67
|
-
# and cause MultiJson.decode to fail -- so we account for that by wrapping the result in []
|
|
68
|
-
body = MultiJson.decode("[#{result.body.to_s}]")[0]
|
|
69
|
-
yield body if error_checking_block
|
|
70
|
-
|
|
71
|
-
# if we want a component other than the body (e.g. redirect header for images), return that
|
|
72
|
-
options[:http_component] ? result.send(options[:http_component]) : body
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
# special enhanced APIs
|
|
77
|
-
class GraphBatchAPI < API
|
|
78
|
-
include GraphBatchAPIMethods
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
class RealtimeUpdates
|
|
82
|
-
include RealtimeUpdateMethods
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
class TestUsers
|
|
86
|
-
include TestUserMethods
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
# legacy support for old APIs
|
|
90
|
-
class OldAPI < API;
|
|
91
|
-
def initialize(*args)
|
|
92
|
-
Koala::Utils.deprecate("#{self.class.name} is deprecated and will be removed in a future version; please use the API class instead.")
|
|
93
|
-
super
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
class GraphAPI < OldAPI; end
|
|
97
|
-
class RestAPI < OldAPI; end
|
|
98
|
-
class GraphAndRestAPI < OldAPI; end
|
|
99
|
-
|
|
100
|
-
# Errors
|
|
101
|
-
|
|
102
|
-
class APIError < StandardError
|
|
103
|
-
attr_accessor :fb_error_type
|
|
104
|
-
def initialize(details = {})
|
|
105
|
-
self.fb_error_type = details["type"]
|
|
106
|
-
super("#{fb_error_type}: #{details["message"]}")
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
|
|
19
|
+
# A Ruby client library for the Facebook Platform.
|
|
20
|
+
# See http://github.com/arsduo/koala/wiki for a general introduction to Koala
|
|
21
|
+
# and the Graph API.
|
|
22
|
+
|
|
111
23
|
class KoalaError < StandardError; end
|
|
112
24
|
|
|
113
|
-
|
|
114
|
-
# finally, the few things defined on the Koala module itself
|
|
25
|
+
# Making HTTP requests
|
|
115
26
|
class << self
|
|
27
|
+
# Control which HTTP service framework Koala uses.
|
|
28
|
+
# Primarily used to switch between the mock-request framework used in testing
|
|
29
|
+
# and the live framework used in real life (and live testing).
|
|
30
|
+
# In theory, you could write your own HTTPService module if you need different functionality,
|
|
31
|
+
# but since the switch to {https://github.com/arsduo/koala/wiki/HTTP-Services Faraday} almost all such goals can be accomplished with middleware.
|
|
116
32
|
attr_accessor :http_service
|
|
117
33
|
end
|
|
118
34
|
|
|
35
|
+
# @private
|
|
36
|
+
# For current HTTPServices, switch the service as expected.
|
|
37
|
+
# For deprecated services (Typhoeus and Net::HTTP), print a warning and set the default Faraday adapter appropriately.
|
|
119
38
|
def self.http_service=(service)
|
|
120
39
|
if service.respond_to?(:deprecated_interface)
|
|
121
40
|
# if this is a deprecated module, support the old interface
|
|
@@ -128,6 +47,7 @@ module Koala
|
|
|
128
47
|
end
|
|
129
48
|
end
|
|
130
49
|
|
|
50
|
+
# An convenenient alias to Koala.http_service.make_request.
|
|
131
51
|
def self.make_request(path, args, verb, options = {})
|
|
132
52
|
http_service.make_request(path, args, verb, options)
|
|
133
53
|
end
|
data/readme.md
CHANGED
|
@@ -6,13 +6,8 @@ Koala
|
|
|
6
6
|
|
|
7
7
|
* Lightweight: Koala should be as light and simple as Facebook’s own libraries, providing API accessors and returning simple JSON.
|
|
8
8
|
* Fast: Koala should, out of the box, be quick. Out of the box, we use Facebook's faster read-only servers when possible and if available, the Typhoeus gem to make snappy Facebook requests. Of course, that brings us to our next topic:
|
|
9
|
-
* Flexible: Koala should be useful to everyone, regardless of their current configuration.
|
|
10
|
-
* Tested: Koala should have complete test coverage, so you can rely on it.
|
|
11
|
-
|
|
12
|
-
Facebook Changes on October 1, 2011
|
|
13
|
-
---
|
|
14
|
-
|
|
15
|
-
Koala 1.2 supports all of Facebook's new authentication schemes, which were introduced on October 1, 2011. If you have the appropriate calls to get_user_info_from_cookies (apps using the Javascript SDK) and/or parse_signed_params (for Canvas and tab apps), your application should work without a hitch. For more information, see Facebook's [OAuth 2.0 and HTTPS Migration](https://developers.facebook.com/docs/oauth2-https-migration/) guide.
|
|
9
|
+
* Flexible: Koala should be useful to everyone, regardless of their current configuration. We support JRuby, Rubinius, and REE as well as vanilla Ruby (1.8.7, 1.9.2, and 1.9.3), and use the Faraday library to provide complete flexibility over how HTTP requests are made.
|
|
10
|
+
* Tested: Koala should have complete test coverage, so you can rely on it. Our test coverage is complete and can be run against either mocked responses or the live Facebook servers; we're also on [Travis CI](travis-ci.org/arsduo/koala/).
|
|
16
11
|
|
|
17
12
|
Installation
|
|
18
13
|
---
|
|
@@ -35,7 +30,10 @@ The Graph API is the simple, slick new interface to Facebook's data. Using it w
|
|
|
35
30
|
profile = @graph.get_object("me")
|
|
36
31
|
friends = @graph.get_connections("me", "friends")
|
|
37
32
|
@graph.put_object("me", "feed", :message => "I am writing on my wall!")
|
|
38
|
-
|
|
33
|
+
|
|
34
|
+
# three-part queries are easy too!
|
|
35
|
+
@graph.get_connection("me", "mutualfriends/#{friend_id}")
|
|
36
|
+
|
|
39
37
|
# you can even use the new Timeline API
|
|
40
38
|
# see https://developers.facebook.com/docs/beta/opengraph/tutorial/
|
|
41
39
|
@graph.put_connections("me", "namespace:action", :object => object_url)
|
|
@@ -131,7 +129,7 @@ Koala makes it easy to interact with your applications using the RealtimeUpdates
|
|
|
131
129
|
You can do just about anything with your real-time update subscriptions using the RealtimeUpdates class:
|
|
132
130
|
|
|
133
131
|
# Add/modify a subscription to updates for when the first_name or last_name fields of any of your users is changed
|
|
134
|
-
@updates.subscribe("user", "first_name, last_name",
|
|
132
|
+
@updates.subscribe("user", "first_name, last_name", callback_url, verify_token)
|
|
135
133
|
|
|
136
134
|
# Get an array of your current subscriptions (one hash for each object you've subscribed to)
|
|
137
135
|
@updates.list_subscriptions
|
|
@@ -179,6 +177,8 @@ Some resources to help you as you play with Koala and the Graph API:
|
|
|
179
177
|
* The <a href="http://groups.google.com/group/koala-users">Koala users group</a> on Google Groups, the place for your Koala and API questions
|
|
180
178
|
* Facebook's <a href="http://developers.facebook.com/tools/explorer/">Graph API Explorer</a>, where you can play with the Graph API in your browser
|
|
181
179
|
* The Koala-powered <a href="http://oauth.twoalex.com" target="_blank">OAuth Playground</a>, where you can easily generate OAuth access tokens and any other data needed to test out the APIs or OAuth
|
|
180
|
+
* Follow Koala on <a href="http://www.facebook.com/pages/Koala/315368291823667">Facebook</a> and <a href="https://twitter.com/#!/koala_fb">Twitter</a> for SDK updates and occasional news about Facebook API changes.
|
|
181
|
+
|
|
182
182
|
|
|
183
183
|
Testing
|
|
184
184
|
-----
|
data/spec/cases/api_spec.rb
CHANGED
|
@@ -11,7 +11,7 @@ describe "Koala::Facebook::API" do
|
|
|
11
11
|
hash_not_including('access_token' => 1),
|
|
12
12
|
anything,
|
|
13
13
|
anything
|
|
14
|
-
).and_return(Koala::Response.new(200, "", ""))
|
|
14
|
+
).and_return(Koala::HTTPService::Response.new(200, "", ""))
|
|
15
15
|
|
|
16
16
|
@service.api('anything')
|
|
17
17
|
end
|
|
@@ -25,7 +25,7 @@ describe "Koala::Facebook::API" do
|
|
|
25
25
|
hash_including('access_token' => token),
|
|
26
26
|
anything,
|
|
27
27
|
anything
|
|
28
|
-
).and_return(Koala::Response.new(200, "", ""))
|
|
28
|
+
).and_return(Koala::HTTPService::Response.new(200, "", ""))
|
|
29
29
|
|
|
30
30
|
service.api('anything')
|
|
31
31
|
end
|
|
@@ -36,15 +36,22 @@ describe "Koala::Facebook::API" do
|
|
|
36
36
|
service.access_token.should == token
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
-
it "gets the attribute of a Koala::Response given by the http_component parameter" do
|
|
39
|
+
it "gets the attribute of a Koala::HTTPService::Response given by the http_component parameter" do
|
|
40
40
|
http_component = :method_name
|
|
41
41
|
|
|
42
42
|
response = mock('Mock KoalaResponse', :body => '', :status => 200)
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
result = stub("result")
|
|
44
|
+
response.stub(http_component).and_return(result)
|
|
45
45
|
Koala.stub(:make_request).and_return(response)
|
|
46
46
|
|
|
47
|
-
@service.api('anything', {}, 'get', :http_component => http_component)
|
|
47
|
+
@service.api('anything', {}, 'get', :http_component => http_component).should == result
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "returns the entire response if http_component => :response" do
|
|
51
|
+
http_component = :response
|
|
52
|
+
response = mock('Mock KoalaResponse', :body => '', :status => 200)
|
|
53
|
+
Koala.stub(:make_request).and_return(response)
|
|
54
|
+
@service.api('anything', {}, 'get', :http_component => http_component).should == response
|
|
48
55
|
end
|
|
49
56
|
|
|
50
57
|
it "returns the body of the request as JSON if no http_component is given" do
|
|
@@ -59,7 +66,7 @@ describe "Koala::Facebook::API" do
|
|
|
59
66
|
|
|
60
67
|
it "executes an error checking block if provided" do
|
|
61
68
|
body = '{}'
|
|
62
|
-
Koala.stub(:make_request).and_return(Koala::Response.new(200, body, {}))
|
|
69
|
+
Koala.stub(:make_request).and_return(Koala::HTTPService::Response.new(200, body, {}))
|
|
63
70
|
|
|
64
71
|
yield_test = mock('Yield Tester')
|
|
65
72
|
yield_test.should_receive(:pass)
|
|
@@ -71,29 +78,29 @@ describe "Koala::Facebook::API" do
|
|
|
71
78
|
end
|
|
72
79
|
|
|
73
80
|
it "raises an API error if the HTTP response code is greater than or equal to 500" do
|
|
74
|
-
Koala.stub(:make_request).and_return(Koala::Response.new(500, 'response body', {}))
|
|
81
|
+
Koala.stub(:make_request).and_return(Koala::HTTPService::Response.new(500, 'response body', {}))
|
|
75
82
|
|
|
76
83
|
lambda { @service.api('anything') }.should raise_exception(Koala::Facebook::APIError)
|
|
77
84
|
end
|
|
78
85
|
|
|
79
86
|
it "handles rogue true/false as responses" do
|
|
80
|
-
Koala.should_receive(:make_request).and_return(Koala::Response.new(200, 'true', {}))
|
|
87
|
+
Koala.should_receive(:make_request).and_return(Koala::HTTPService::Response.new(200, 'true', {}))
|
|
81
88
|
@service.api('anything').should be_true
|
|
82
89
|
|
|
83
|
-
Koala.should_receive(:make_request).and_return(Koala::Response.new(200, 'false', {}))
|
|
90
|
+
Koala.should_receive(:make_request).and_return(Koala::HTTPService::Response.new(200, 'false', {}))
|
|
84
91
|
@service.api('anything').should be_false
|
|
85
92
|
end
|
|
86
93
|
|
|
87
94
|
describe "with regard to leading slashes" do
|
|
88
95
|
it "adds a leading / to the path if not present" do
|
|
89
96
|
path = "anything"
|
|
90
|
-
Koala.should_receive(:make_request).with("/#{path}", anything, anything, anything).and_return(Koala::Response.new(200, 'true', {}))
|
|
97
|
+
Koala.should_receive(:make_request).with("/#{path}", anything, anything, anything).and_return(Koala::HTTPService::Response.new(200, 'true', {}))
|
|
91
98
|
@service.api(path)
|
|
92
99
|
end
|
|
93
100
|
|
|
94
101
|
it "doesn't change the path if a leading / is present" do
|
|
95
102
|
path = "/anything"
|
|
96
|
-
Koala.should_receive(:make_request).with(path, anything, anything, anything).and_return(Koala::Response.new(200, 'true', {}))
|
|
103
|
+
Koala.should_receive(:make_request).with(path, anything, anything, anything).and_return(Koala::HTTPService::Response.new(200, 'true', {}))
|
|
97
104
|
@service.api(path)
|
|
98
105
|
end
|
|
99
106
|
end
|
data/spec/cases/error_spec.rb
CHANGED
|
@@ -10,6 +10,16 @@ describe Koala::Facebook::APIError do
|
|
|
10
10
|
Koala::Facebook::APIError.instance_methods.map(&:to_sym).should include(:fb_error_type=)
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
+
it "has an accessor for raw_response" do
|
|
14
|
+
Koala::Facebook::APIError.instance_methods.map(&:to_sym).should include(:raw_response)
|
|
15
|
+
Koala::Facebook::APIError.instance_methods.map(&:to_sym).should include(:raw_response=)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "sets raw_response to the provided error details" do
|
|
19
|
+
error_response = {"type" => "foo", "other_details" => "bar"}
|
|
20
|
+
Koala::Facebook::APIError.new(error_response).raw_response.should == error_response
|
|
21
|
+
end
|
|
22
|
+
|
|
13
23
|
it "sets fb_error_type to details['type']" do
|
|
14
24
|
type = "foo"
|
|
15
25
|
Koala::Facebook::APIError.new("type" => type).fb_error_type.should == type
|