koala 0.10.0 → 1.0.0.beta2.1
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/CHANGELOG +34 -7
- data/Manifest +8 -1
- data/Rakefile +4 -4
- data/koala.gemspec +10 -8
- data/lib/koala/graph_api.rb +188 -123
- data/lib/koala/http_services.rb +92 -22
- data/lib/koala/rest_api.rb +73 -6
- data/lib/koala/test_users.rb +18 -5
- data/lib/koala/uploadable_io.rb +115 -0
- data/lib/koala.rb +81 -72
- data/readme.md +18 -12
- data/spec/facebook_data.yml +18 -14
- data/spec/koala/assets/beach.jpg +0 -0
- data/spec/koala/graph_and_rest_api/graph_and_rest_api_no_token_tests.rb +5 -1
- data/spec/koala/graph_and_rest_api/graph_and_rest_api_with_token_tests.rb +8 -3
- data/spec/koala/graph_api/graph_api_no_access_token_tests.rb +13 -62
- data/spec/koala/graph_api/graph_api_tests.rb +85 -0
- data/spec/koala/graph_api/graph_api_with_access_token_tests.rb +167 -123
- data/spec/koala/http_services/http_service_tests.rb +51 -0
- data/spec/koala/http_services/net_http_service_tests.rb +339 -0
- data/spec/koala/http_services/typhoeus_service_tests.rb +162 -0
- data/spec/koala/live_testing_data_helper.rb +1 -1
- data/spec/koala/oauth/oauth_tests.rb +19 -85
- data/spec/koala/rest_api/rest_api_no_access_token_tests.rb +5 -74
- data/spec/koala/rest_api/rest_api_tests.rb +118 -0
- data/spec/koala/rest_api/rest_api_with_access_token_tests.rb +5 -3
- data/spec/koala/test_users/test_users_tests.rb +49 -48
- data/spec/koala/uploadable_io/uploadable_io_tests.rb +246 -0
- data/spec/koala_spec_helper.rb +32 -6
- data/spec/koala_spec_without_mocks.rb +3 -3
- data/spec/mock_facebook_responses.yml +43 -20
- data/spec/mock_http_service.rb +16 -3
- metadata +39 -8
- data/spec/koala/net_http_service_tests.rb +0 -186
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
# fake MIME::Types
|
|
2
|
+
module Koala::MIME
|
|
3
|
+
module Types
|
|
4
|
+
def self.type_for(type)
|
|
5
|
+
# this should be faked out in tests
|
|
6
|
+
nil
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class UploadableIOTests < Test::Unit::TestCase
|
|
12
|
+
include Koala
|
|
13
|
+
|
|
14
|
+
VALID_PATH = File.join(File.dirname(__FILE__), "..", "assets", "beach.jpg")
|
|
15
|
+
|
|
16
|
+
describe UploadableIO do
|
|
17
|
+
shared_examples_for "MIME::Types can't return results" do
|
|
18
|
+
{
|
|
19
|
+
"jpg" => "image/jpeg",
|
|
20
|
+
"jpeg" => "image/jpeg",
|
|
21
|
+
"png" => "image/png",
|
|
22
|
+
"gif" => "image/gif"
|
|
23
|
+
}.each_pair do |extension, mime_type|
|
|
24
|
+
it "should properly get content types for #{extension} using basic analysis" do
|
|
25
|
+
path = "filename.#{extension}"
|
|
26
|
+
if @koala_io_params[0].is_a?(File)
|
|
27
|
+
@koala_io_params[0].stub!(:path).and_return(path)
|
|
28
|
+
else
|
|
29
|
+
@koala_io_params[0] = path
|
|
30
|
+
end
|
|
31
|
+
UploadableIO.new(*@koala_io_params).content_type.should == mime_type
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "should get content types for #{extension} using basic analysis with file names with more than one dot" do
|
|
35
|
+
path = "file.name.#{extension}"
|
|
36
|
+
if @koala_io_params[0].is_a?(File)
|
|
37
|
+
@koala_io_params[0].stub!(:path).and_return(path)
|
|
38
|
+
else
|
|
39
|
+
@koala_io_params[0] = path
|
|
40
|
+
end
|
|
41
|
+
UploadableIO.new(*@koala_io_params).content_type.should == mime_type
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
describe "if the MIME type can't be determined" do
|
|
46
|
+
before :each do
|
|
47
|
+
path = "badfile.badextension"
|
|
48
|
+
if @koala_io_params[0].is_a?(File)
|
|
49
|
+
@koala_io_params[0].stub!(:path).and_return(path)
|
|
50
|
+
else
|
|
51
|
+
@koala_io_params[0] = path
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "should throw an exception if the MIME type can't be determined and the HTTP service requires content type" do
|
|
56
|
+
Koala.stub!(:multipart_requires_content_type?).and_return(true)
|
|
57
|
+
lambda { UploadableIO.new(*@koala_io_params) }.should raise_exception(KoalaError)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "should just have @content_type == nil if the HTTP service doesn't require content type" do
|
|
61
|
+
Koala.stub!(:multipart_requires_content_type?).and_return(false)
|
|
62
|
+
UploadableIO.new(*@koala_io_params).content_type.should be_nil
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
shared_examples_for "determining a mime type" do
|
|
68
|
+
describe "if MIME::Types is available" do
|
|
69
|
+
it "should return an UploadIO with MIME::Types-determined type if the type exists" do
|
|
70
|
+
type_result = ["type"]
|
|
71
|
+
Koala::MIME::Types.stub(:type_for).and_return(type_result)
|
|
72
|
+
UploadableIO.new(*@koala_io_params).content_type.should == type_result.first
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
describe "if MIME::Types is unavailable" do
|
|
77
|
+
before :each do
|
|
78
|
+
# fake that MIME::Types doesn't exist
|
|
79
|
+
Koala::MIME::Types.stub(:type_for).and_raise(NameError)
|
|
80
|
+
end
|
|
81
|
+
it_should_behave_like "MIME::Types can't return results"
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
describe "if MIME::Types can't find the result" do
|
|
85
|
+
before :each do
|
|
86
|
+
# fake that MIME::Types doesn't exist
|
|
87
|
+
Koala::MIME::Types.stub(:type_for).and_return([])
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it_should_behave_like "MIME::Types can't return results"
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
describe "the constructor" do
|
|
95
|
+
describe "when given a file path" do
|
|
96
|
+
before(:each) do
|
|
97
|
+
@koala_io_params = [
|
|
98
|
+
File.open(VALID_PATH)
|
|
99
|
+
]
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
describe "and a content type" do
|
|
103
|
+
before :each do
|
|
104
|
+
@koala_io_params.concat([stub("image/jpg")])
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it "should return an UploadIO with the same file path" do
|
|
108
|
+
stub_path = @koala_io_params[0] = "/stub/path/to/file"
|
|
109
|
+
UploadableIO.new(*@koala_io_params).io_or_path.should == stub_path
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it "should return an UploadIO with the same content type" do
|
|
113
|
+
stub_type = @koala_io_params[1] = stub('Content Type')
|
|
114
|
+
UploadableIO.new(*@koala_io_params).content_type.should == stub_type
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
describe "and no content type" do
|
|
119
|
+
it_should_behave_like "determining a mime type"
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
describe "when given a File object" do
|
|
124
|
+
before(:each) do
|
|
125
|
+
@koala_io_params = [
|
|
126
|
+
File.open(VALID_PATH)
|
|
127
|
+
]
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
describe "and a content type" do
|
|
131
|
+
before :each do
|
|
132
|
+
@koala_io_params.concat(["image/jpg"])
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
it "should return an UploadIO with the same io" do
|
|
136
|
+
UploadableIO.new(*@koala_io_params).io_or_path.should == @koala_io_params[0]
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
it "should return an UplaodIO with the same content_type" do
|
|
140
|
+
content_stub = @koala_io_params[1] = stub('Content Type')
|
|
141
|
+
UploadableIO.new(*@koala_io_params).content_type.should == content_stub
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
describe "and no content type" do
|
|
146
|
+
it_should_behave_like "determining a mime type"
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
describe "when given a Rails 3 ActionDispatch::Http::UploadedFile" do
|
|
151
|
+
before(:each) do
|
|
152
|
+
@tempfile = stub('Tempfile', :path => true)
|
|
153
|
+
@uploaded_file = stub('ActionDispatch::Http::UploadedFile',
|
|
154
|
+
:content_type => true,
|
|
155
|
+
:tempfile => @tempfile
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
@uploaded_file.stub!(:respond_to?).with(:path).and_return(true)
|
|
159
|
+
@uploaded_file.stub!(:respond_to?).with(:content_type).and_return(true)
|
|
160
|
+
@uploaded_file.stub!(:respond_to?).with(:tempfile).and_return(@tempfile)
|
|
161
|
+
@tempfile.stub!(:respond_to?).with(:path).and_return(true)
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
it "should get the content type via the content_type method" do
|
|
165
|
+
expected_content_type = stub('Content Type')
|
|
166
|
+
@uploaded_file.should_receive(:content_type).and_return(expected_content_type)
|
|
167
|
+
UploadableIO.new(@uploaded_file).content_type.should == expected_content_type
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
it "should get the path from the tempfile associated with the UploadedFile" do
|
|
171
|
+
expected_path = stub('Tempfile')
|
|
172
|
+
@tempfile.should_receive(:path).and_return(expected_path)
|
|
173
|
+
UploadableIO.new(@uploaded_file).io_or_path.should == expected_path
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
describe "when given a Sinatra file parameter hash" do
|
|
178
|
+
before(:each) do
|
|
179
|
+
@file_hash = {
|
|
180
|
+
:type => "type",
|
|
181
|
+
:tempfile => "Tempfile"
|
|
182
|
+
}
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
it "should get the content type from the :type key" do
|
|
186
|
+
expected_content_type = stub('Content Type')
|
|
187
|
+
@file_hash[:type] = expected_content_type
|
|
188
|
+
|
|
189
|
+
uploadable = UploadableIO.new(@file_hash)
|
|
190
|
+
uploadable.content_type.should == expected_content_type
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
it "should get the io_or_path from the :tempfile key" do
|
|
194
|
+
expected_file = stub('File')
|
|
195
|
+
@file_hash[:tempfile] = expected_file
|
|
196
|
+
|
|
197
|
+
uploadable = UploadableIO.new(@file_hash)
|
|
198
|
+
uploadable.io_or_path.should == expected_file
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
describe "for files with with recognizable MIME types" do
|
|
203
|
+
# what that means is tested below
|
|
204
|
+
it "should accept a file object alone" do
|
|
205
|
+
params = [
|
|
206
|
+
VALID_PATH
|
|
207
|
+
]
|
|
208
|
+
lambda { UploadableIO.new(*params) }.should_not raise_exception(KoalaError)
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
it "should accept a file path alone" do
|
|
212
|
+
params = [
|
|
213
|
+
VALID_PATH
|
|
214
|
+
]
|
|
215
|
+
lambda { UploadableIO.new(*params) }.should_not raise_exception(KoalaError)
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
describe "getting an UploadableIO" do
|
|
221
|
+
before(:each) do
|
|
222
|
+
@upload_io = stub("UploadIO")
|
|
223
|
+
UploadIO.stub!(:new).with(anything, anything, anything).and_return(@upload_io)
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
it "should call the constructor with the content type, file name, and a dummy file name" do
|
|
227
|
+
UploadIO.should_receive(:new).with(VALID_PATH, "content/type", anything).and_return(@upload_io)
|
|
228
|
+
UploadableIO.new(VALID_PATH, "content/type").to_upload_io.should == @upload_io
|
|
229
|
+
end
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
describe "getting a file" do
|
|
233
|
+
it "should return the File if initialized with a file" do
|
|
234
|
+
f = File.new(VALID_PATH)
|
|
235
|
+
UploadableIO.new(f).to_file.should == f
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
it "should open up and return a file corresponding to the path if io_or_path is a path" do
|
|
239
|
+
path = VALID_PATH
|
|
240
|
+
result = stub("File")
|
|
241
|
+
File.should_receive(:open).with(path).and_return(result)
|
|
242
|
+
UploadableIO.new(path).to_file.should == result
|
|
243
|
+
end
|
|
244
|
+
end
|
|
245
|
+
end # describe UploadableIO
|
|
246
|
+
end # class
|
data/spec/koala_spec_helper.rb
CHANGED
|
@@ -5,15 +5,15 @@ if defined?(RUBY_VERSION) && RUBY_VERSION =~ /1\.9/
|
|
|
5
5
|
Rspec.configure do |c|
|
|
6
6
|
c.mock_with :rspec
|
|
7
7
|
end
|
|
8
|
-
|
|
8
|
+
|
|
9
9
|
else
|
|
10
10
|
# Ruby 1.8.x
|
|
11
11
|
require 'test/unit'
|
|
12
12
|
require 'rubygems'
|
|
13
|
-
|
|
14
|
-
require 'spec/test/unit'
|
|
15
13
|
end
|
|
16
14
|
|
|
15
|
+
require 'yaml'
|
|
16
|
+
|
|
17
17
|
# load the libraries
|
|
18
18
|
require 'koala'
|
|
19
19
|
|
|
@@ -23,10 +23,12 @@ require 'koala/live_testing_data_helper'
|
|
|
23
23
|
# API tests
|
|
24
24
|
require 'koala/api_base_tests'
|
|
25
25
|
|
|
26
|
+
require 'koala/graph_api/graph_api_tests'
|
|
26
27
|
require 'koala/graph_api/graph_collection_tests'
|
|
27
28
|
require 'koala/graph_api/graph_api_no_access_token_tests'
|
|
28
29
|
require 'koala/graph_api/graph_api_with_access_token_tests'
|
|
29
30
|
|
|
31
|
+
require 'koala/rest_api/rest_api_tests'
|
|
30
32
|
require 'koala/rest_api/rest_api_no_access_token_tests'
|
|
31
33
|
require 'koala/rest_api/rest_api_with_access_token_tests'
|
|
32
34
|
|
|
@@ -39,10 +41,34 @@ require 'koala/oauth/oauth_tests'
|
|
|
39
41
|
# Subscriptions tests
|
|
40
42
|
require 'koala/realtime_updates/realtime_updates_tests'
|
|
41
43
|
|
|
42
|
-
# Services tests
|
|
43
|
-
require 'koala/net_http_service_tests'
|
|
44
|
-
|
|
45
44
|
# Test users tests
|
|
46
45
|
require 'koala/test_users/test_users_tests'
|
|
47
46
|
|
|
47
|
+
# KoalaIO tests
|
|
48
|
+
require 'koala/uploadable_io/uploadable_io_tests'
|
|
48
49
|
|
|
50
|
+
# Services tests
|
|
51
|
+
require 'koala/http_services/http_service_tests'
|
|
52
|
+
require 'koala/http_services/net_http_service_tests'
|
|
53
|
+
begin
|
|
54
|
+
require 'koala/http_services/typhoeus_service_tests'
|
|
55
|
+
rescue LoadError
|
|
56
|
+
puts "Typhoeus tests will not be run because Typhoeus is not installed."
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
module KoalaTest
|
|
60
|
+
def self.validate_user_info(token)
|
|
61
|
+
print "Validating permissions for live testing..."
|
|
62
|
+
# make sure we have the necessary permissions
|
|
63
|
+
api = Koala::Facebook::GraphAndRestAPI.new(token)
|
|
64
|
+
uid = api.get_object("me")["id"]
|
|
65
|
+
perms = api.fql_query("select read_stream, publish_stream, user_photos from permissions where uid = #{uid}")[0]
|
|
66
|
+
perms.each_pair do |perm, value|
|
|
67
|
+
unless value == 1
|
|
68
|
+
puts "failed!\n" # put a new line after the print above
|
|
69
|
+
raise ArgumentError, "Your access token must have the read_stream, publish_stream, and user_photos permissions. You have: #{perms.inspect}"
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
puts "done!"
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -6,8 +6,6 @@ require 'koala_spec_helper'
|
|
|
6
6
|
# specs to run. See facebook_data.yml for more information.
|
|
7
7
|
|
|
8
8
|
# load testing data (see note in readme.md)
|
|
9
|
-
# I'm seeing a bug with spec and gets where the facebook_test_suite.rb file gets read in when gets is called
|
|
10
|
-
# until that's solved, we'll need to store/update tokens in the access_token file
|
|
11
9
|
$testing_data = YAML.load_file(File.join(File.dirname(__FILE__), 'facebook_data.yml')) rescue {}
|
|
12
10
|
|
|
13
11
|
unless $testing_data["oauth_token"]
|
|
@@ -16,4 +14,6 @@ end
|
|
|
16
14
|
|
|
17
15
|
unless $testing_data["oauth_test_data"] && $testing_data["oauth_test_data"]["code"] && $testing_data["oauth_test_data"]["secret"]
|
|
18
16
|
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
|
-
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
KoalaTest.validate_user_info $testing_data["oauth_token"]
|
|
@@ -49,8 +49,12 @@ graph_api:
|
|
|
49
49
|
|
|
50
50
|
test_user_no_perms: &test_user_no_perms
|
|
51
51
|
post:
|
|
52
|
-
with_token: '{"id": "777777777", "access_token":"
|
|
53
|
-
|
|
52
|
+
with_token: '{"id": "777777777", "access_token":"<%= ACCESS_TOKEN %>", "login_url":"https://www.facebook.com/platform/test_account.."}'
|
|
53
|
+
|
|
54
|
+
test_user_befriended: &test_user_befriended
|
|
55
|
+
post:
|
|
56
|
+
with_token: 'true'
|
|
57
|
+
|
|
54
58
|
# -- Stubbed Responses --
|
|
55
59
|
root:
|
|
56
60
|
ids=contextoptional,naitik:
|
|
@@ -79,10 +83,18 @@ graph_api:
|
|
|
79
83
|
message=Hello, world, from the test suite delete method!:
|
|
80
84
|
post:
|
|
81
85
|
with_token: '{"id": "FEED_ITEM_DELETE"}'
|
|
82
|
-
link=http://
|
|
86
|
+
link=http://oauth.twoalex.com/&message=Hello, world, from the test suite again!&name=OAuth Playground:
|
|
83
87
|
post:
|
|
84
88
|
with_token: '{"id": "FEED_ITEM_CONTEXT"}'
|
|
85
|
-
|
|
89
|
+
/me/photos:
|
|
90
|
+
source=[FILE]:
|
|
91
|
+
post:
|
|
92
|
+
<<: *token_required
|
|
93
|
+
with_token: '{"id": "MOCK_PHOTO"}'
|
|
94
|
+
message=This is the test message&source=[FILE]:
|
|
95
|
+
post:
|
|
96
|
+
<<: *token_required
|
|
97
|
+
with_token: '{"id": "MOCK_PHOTO"}'
|
|
86
98
|
/koppel:
|
|
87
99
|
no_args:
|
|
88
100
|
get:
|
|
@@ -226,7 +238,7 @@ graph_api:
|
|
|
226
238
|
no_args:
|
|
227
239
|
<<: *item_deleted
|
|
228
240
|
get:
|
|
229
|
-
with_token: '{"link":"http://
|
|
241
|
+
with_token: '{"link":"http://oauth.twoalex.com/", "name": "OAuth Playground"}'
|
|
230
242
|
|
|
231
243
|
/FEED_ITEM_CATS:
|
|
232
244
|
no_args:
|
|
@@ -237,12 +249,23 @@ graph_api:
|
|
|
237
249
|
/FEED_ITEM_DELETE:
|
|
238
250
|
no_args:
|
|
239
251
|
<<: *item_deleted
|
|
240
|
-
|
|
252
|
+
|
|
253
|
+
/FEED_ITEM_DELETE/likes:
|
|
254
|
+
no_args:
|
|
255
|
+
<<: *item_deleted
|
|
256
|
+
post:
|
|
257
|
+
with_token: 'true'
|
|
258
|
+
|
|
241
259
|
/MOCK_COMMENT:
|
|
242
260
|
no_args:
|
|
243
261
|
<<: *item_deleted
|
|
244
262
|
get:
|
|
245
263
|
with_token: "{\"message\": \"it\'s my comment!\"}"
|
|
264
|
+
/MOCK_PHOTO:
|
|
265
|
+
no_args:
|
|
266
|
+
<<: *item_deleted
|
|
267
|
+
get:
|
|
268
|
+
with_token: "{\"name\": \"This is the test message\"}"
|
|
246
269
|
|
|
247
270
|
# -- Mock Test User Responses --
|
|
248
271
|
/<%= APP_ID %>/accounts/test-users:
|
|
@@ -252,18 +275,24 @@ graph_api:
|
|
|
252
275
|
<<: *test_user_no_perms
|
|
253
276
|
installed=true&permissions=read_stream:
|
|
254
277
|
post:
|
|
255
|
-
with_token: '{"id": "999999999", "access_token":"
|
|
278
|
+
with_token: '{"id": "999999999", "access_token":"<%= ACCESS_TOKEN %>", "login_url":"https://www.facebook.com/platform/test_account.."}'
|
|
256
279
|
installed=true&permissions=read_stream,user_interests:
|
|
257
280
|
post:
|
|
258
|
-
with_token: '{"id": "888888888", "access_token":"
|
|
281
|
+
with_token: '{"id": "888888888", "access_token":"<%= ACCESS_TOKEN %>", "login_url":"https://www.facebook.com/platform/test_account.."}'
|
|
259
282
|
no_args:
|
|
260
283
|
get:
|
|
261
|
-
with_token: '{"data":[{"id": "999999999", "access_token":"
|
|
284
|
+
with_token: '{"data":[{"id": "999999999", "access_token":"<%= ACCESS_TOKEN %>", "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
285
|
|
|
263
286
|
/999999999:
|
|
264
287
|
no_args:
|
|
265
288
|
<<: *item_deleted
|
|
266
289
|
|
|
290
|
+
/999999999/friends/888888888:
|
|
291
|
+
no_args:
|
|
292
|
+
post:
|
|
293
|
+
with_token: 'true'
|
|
294
|
+
|
|
295
|
+
|
|
267
296
|
/9999999991:
|
|
268
297
|
no_args:
|
|
269
298
|
delete:
|
|
@@ -273,17 +302,11 @@ graph_api:
|
|
|
273
302
|
no_args:
|
|
274
303
|
<<: *item_deleted
|
|
275
304
|
|
|
276
|
-
/
|
|
305
|
+
/888888888/friends/999999999:
|
|
277
306
|
no_args:
|
|
278
|
-
<<: *
|
|
307
|
+
<<: *test_user_befriended
|
|
279
308
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
get:
|
|
283
|
-
with_token: 'true'
|
|
284
|
-
|
|
285
|
-
/888888888/friends/999999999:
|
|
309
|
+
|
|
310
|
+
/777777777:
|
|
286
311
|
no_args:
|
|
287
|
-
|
|
288
|
-
with_token: 'true'
|
|
289
|
-
|
|
312
|
+
<<: *item_deleted
|
data/spec/mock_http_service.rb
CHANGED
|
@@ -33,6 +33,8 @@ module Koala
|
|
|
33
33
|
def self.included(base)
|
|
34
34
|
base.class_eval do
|
|
35
35
|
|
|
36
|
+
include Koala::HTTPService
|
|
37
|
+
|
|
36
38
|
def self.make_request(path, args, verb, options = {})
|
|
37
39
|
path = 'root' if path == '' || path == '/'
|
|
38
40
|
verb ||= 'get'
|
|
@@ -43,7 +45,7 @@ module Koala
|
|
|
43
45
|
args.delete('format')
|
|
44
46
|
|
|
45
47
|
# Create a hash key for the arguments
|
|
46
|
-
args = args
|
|
48
|
+
args = create_params_key(args)
|
|
47
49
|
|
|
48
50
|
begin
|
|
49
51
|
response = RESPONSES[server][path][args][verb][with_token]
|
|
@@ -62,8 +64,7 @@ module Koala
|
|
|
62
64
|
# Raises an error message with the place in the data YML
|
|
63
65
|
# to place a mock as well as a URL to request from
|
|
64
66
|
# Facebook's servers for the actual data
|
|
65
|
-
# (Don't forget to replace ACCESS_TOKEN with a real access token)
|
|
66
|
-
|
|
67
|
+
# (Don't forget to replace ACCESS_TOKEN with a real access token)
|
|
67
68
|
data_trace = [server, path, args, verb, with_token] * ': '
|
|
68
69
|
|
|
69
70
|
args = args == 'no_args' ? '' : "#{args}&"
|
|
@@ -76,6 +77,18 @@ module Koala
|
|
|
76
77
|
response_object
|
|
77
78
|
end
|
|
78
79
|
|
|
80
|
+
protected
|
|
81
|
+
def self.create_params_key(params_hash)
|
|
82
|
+
if params_hash.empty?
|
|
83
|
+
'no_args'
|
|
84
|
+
else
|
|
85
|
+
params_hash.sort{ |a,b| a[0].to_s <=> b[0].to_s}.map do |arr|
|
|
86
|
+
arr[1] = '[FILE]' if arr[1].kind_of?(Koala::UploadableIO)
|
|
87
|
+
arr.join('=')
|
|
88
|
+
end.join('&')
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
79
92
|
end # class_eval
|
|
80
93
|
end # included
|
|
81
94
|
end
|
metadata
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: koala
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
|
|
4
|
+
hash: 124392909
|
|
5
|
+
prerelease: 6
|
|
5
6
|
segments:
|
|
7
|
+
- 1
|
|
6
8
|
- 0
|
|
7
|
-
- 10
|
|
8
9
|
- 0
|
|
9
|
-
|
|
10
|
+
- beta
|
|
11
|
+
- 2
|
|
12
|
+
- 1
|
|
13
|
+
version: 1.0.0.beta2.1
|
|
10
14
|
platform: ruby
|
|
11
15
|
authors:
|
|
12
16
|
- Alex Koppel, Chris Baclig, Rafi Jacoby, Context Optional
|
|
@@ -14,22 +18,39 @@ autorequire:
|
|
|
14
18
|
bindir: bin
|
|
15
19
|
cert_chain: []
|
|
16
20
|
|
|
17
|
-
date:
|
|
21
|
+
date: 2011-04-06 00:00:00 +02:00
|
|
18
22
|
default_executable:
|
|
19
23
|
dependencies:
|
|
20
24
|
- !ruby/object:Gem::Dependency
|
|
21
25
|
name: json
|
|
22
26
|
prerelease: false
|
|
23
27
|
requirement: &id001 !ruby/object:Gem::Requirement
|
|
28
|
+
none: false
|
|
24
29
|
requirements:
|
|
25
30
|
- - ">="
|
|
26
31
|
- !ruby/object:Gem::Version
|
|
32
|
+
hash: 15
|
|
27
33
|
segments:
|
|
28
34
|
- 1
|
|
29
35
|
- 0
|
|
30
36
|
version: "1.0"
|
|
31
37
|
type: :runtime
|
|
32
38
|
version_requirements: *id001
|
|
39
|
+
- !ruby/object:Gem::Dependency
|
|
40
|
+
name: multipart-post
|
|
41
|
+
prerelease: false
|
|
42
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
|
43
|
+
none: false
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
hash: 15
|
|
48
|
+
segments:
|
|
49
|
+
- 1
|
|
50
|
+
- 0
|
|
51
|
+
version: "1.0"
|
|
52
|
+
type: :runtime
|
|
53
|
+
version_requirements: *id002
|
|
33
54
|
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.
|
|
34
55
|
email: alex@alexkoppel.com
|
|
35
56
|
executables: []
|
|
@@ -45,6 +66,7 @@ extra_rdoc_files:
|
|
|
45
66
|
- lib/koala/realtime_updates.rb
|
|
46
67
|
- lib/koala/rest_api.rb
|
|
47
68
|
- lib/koala/test_users.rb
|
|
69
|
+
- lib/koala/uploadable_io.rb
|
|
48
70
|
files:
|
|
49
71
|
- CHANGELOG
|
|
50
72
|
- LICENSE
|
|
@@ -58,21 +80,28 @@ files:
|
|
|
58
80
|
- lib/koala/realtime_updates.rb
|
|
59
81
|
- lib/koala/rest_api.rb
|
|
60
82
|
- lib/koala/test_users.rb
|
|
83
|
+
- lib/koala/uploadable_io.rb
|
|
61
84
|
- readme.md
|
|
62
85
|
- spec/facebook_data.yml
|
|
63
86
|
- spec/koala/api_base_tests.rb
|
|
87
|
+
- spec/koala/assets/beach.jpg
|
|
64
88
|
- spec/koala/graph_and_rest_api/graph_and_rest_api_no_token_tests.rb
|
|
65
89
|
- spec/koala/graph_and_rest_api/graph_and_rest_api_with_token_tests.rb
|
|
66
90
|
- spec/koala/graph_api/graph_api_no_access_token_tests.rb
|
|
91
|
+
- spec/koala/graph_api/graph_api_tests.rb
|
|
67
92
|
- spec/koala/graph_api/graph_api_with_access_token_tests.rb
|
|
68
93
|
- spec/koala/graph_api/graph_collection_tests.rb
|
|
94
|
+
- spec/koala/http_services/http_service_tests.rb
|
|
95
|
+
- spec/koala/http_services/net_http_service_tests.rb
|
|
96
|
+
- spec/koala/http_services/typhoeus_service_tests.rb
|
|
69
97
|
- spec/koala/live_testing_data_helper.rb
|
|
70
|
-
- spec/koala/net_http_service_tests.rb
|
|
71
98
|
- spec/koala/oauth/oauth_tests.rb
|
|
72
99
|
- spec/koala/realtime_updates/realtime_updates_tests.rb
|
|
73
100
|
- spec/koala/rest_api/rest_api_no_access_token_tests.rb
|
|
101
|
+
- spec/koala/rest_api/rest_api_tests.rb
|
|
74
102
|
- spec/koala/rest_api/rest_api_with_access_token_tests.rb
|
|
75
103
|
- spec/koala/test_users/test_users_tests.rb
|
|
104
|
+
- spec/koala/uploadable_io/uploadable_io_tests.rb
|
|
76
105
|
- spec/koala_spec.rb
|
|
77
106
|
- spec/koala_spec_helper.rb
|
|
78
107
|
- spec/koala_spec_without_mocks.rb
|
|
@@ -88,21 +117,23 @@ rdoc_options:
|
|
|
88
117
|
- --inline-source
|
|
89
118
|
- --title
|
|
90
119
|
- Koala
|
|
91
|
-
- --main
|
|
92
|
-
- readme.md
|
|
93
120
|
require_paths:
|
|
94
121
|
- lib
|
|
95
122
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
123
|
+
none: false
|
|
96
124
|
requirements:
|
|
97
125
|
- - ">="
|
|
98
126
|
- !ruby/object:Gem::Version
|
|
127
|
+
hash: 3
|
|
99
128
|
segments:
|
|
100
129
|
- 0
|
|
101
130
|
version: "0"
|
|
102
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
|
+
none: false
|
|
103
133
|
requirements:
|
|
104
134
|
- - ">="
|
|
105
135
|
- !ruby/object:Gem::Version
|
|
136
|
+
hash: 11
|
|
106
137
|
segments:
|
|
107
138
|
- 1
|
|
108
139
|
- 2
|
|
@@ -110,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
110
141
|
requirements: []
|
|
111
142
|
|
|
112
143
|
rubyforge_project: koala
|
|
113
|
-
rubygems_version: 1.
|
|
144
|
+
rubygems_version: 1.4.2
|
|
114
145
|
signing_key:
|
|
115
146
|
specification_version: 3
|
|
116
147
|
summary: A lightweight, flexible library for Facebook with support for the Graph API, the old REST API, realtime updates, and OAuth validation.
|