koala 1.1.0 → 1.2.0
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/.travis.yml +2 -1
- data/CHANGELOG +36 -0
- data/Gemfile +6 -2
- data/Rakefile +0 -1
- data/koala.gemspec +7 -8
- data/lib/koala/batch_operation.rb +15 -15
- data/lib/koala/graph_api.rb +85 -73
- data/lib/koala/graph_batch_api.rb +21 -11
- data/lib/koala/graph_collection.rb +13 -8
- data/lib/koala/http_service.rb +176 -0
- data/lib/koala/oauth.rb +34 -24
- data/lib/koala/realtime_updates.rb +21 -18
- data/lib/koala/rest_api.rb +1 -1
- data/lib/koala/test_users.rb +33 -17
- data/lib/koala/uploadable_io.rb +49 -43
- data/lib/koala/utils.rb +11 -0
- data/lib/koala/version.rb +3 -0
- data/lib/koala.rb +47 -45
- data/readme.md +58 -38
- data/spec/cases/{api_base_spec.rb → api_spec.rb} +27 -2
- data/spec/cases/error_spec.rb +32 -0
- data/spec/cases/graph_and_rest_api_spec.rb +12 -21
- data/spec/cases/graph_api_batch_spec.rb +92 -119
- data/spec/cases/graph_api_spec.rb +11 -14
- data/spec/cases/graph_collection_spec.rb +116 -0
- data/spec/cases/http_service_spec.rb +446 -0
- data/spec/cases/koala_spec.rb +36 -37
- data/spec/cases/oauth_spec.rb +318 -212
- data/spec/cases/realtime_updates_spec.rb +45 -31
- data/spec/cases/rest_api_spec.rb +23 -7
- data/spec/cases/test_users_spec.rb +123 -75
- data/spec/cases/uploadable_io_spec.rb +77 -36
- data/spec/cases/utils_spec.rb +10 -0
- data/spec/fixtures/facebook_data.yml +26 -24
- data/spec/fixtures/mock_facebook_responses.yml +131 -101
- data/spec/spec_helper.rb +29 -5
- data/spec/support/graph_api_shared_examples.rb +80 -120
- data/spec/support/json_testing_fix.rb +35 -11
- data/spec/support/koala_test.rb +187 -0
- data/spec/support/mock_http_service.rb +8 -5
- data/spec/support/ordered_hash.rb +205 -0
- data/spec/support/rest_api_shared_examples.rb +37 -37
- data/spec/support/uploadable_io_shared_examples.rb +2 -8
- metadata +72 -83
- data/lib/koala/http_services/net_http_service.rb +0 -92
- data/lib/koala/http_services/typhoeus_service.rb +0 -37
- data/lib/koala/http_services.rb +0 -46
- data/spec/cases/http_services/http_service_spec.rb +0 -129
- data/spec/cases/http_services/net_http_service_spec.rb +0 -532
- data/spec/cases/http_services/typhoeus_service_spec.rb +0 -152
- data/spec/support/live_testing_data_helper.rb +0 -40
- data/spec/support/setup_mocks_or_live.rb +0 -51
|
@@ -13,42 +13,41 @@ describe "Koala::UploadableIO" do
|
|
|
13
13
|
tempfile = stub('Tempfile', :path => "foo")
|
|
14
14
|
uploaded_file = stub('ActionDispatch::Http::UploadedFile',
|
|
15
15
|
:content_type => true,
|
|
16
|
-
:tempfile => tempfile
|
|
16
|
+
:tempfile => tempfile,
|
|
17
|
+
:original_filename => "bar"
|
|
17
18
|
)
|
|
18
19
|
tempfile.stub!(:respond_to?).with(:path).and_return(true)
|
|
19
20
|
|
|
20
21
|
[tempfile, uploaded_file]
|
|
21
22
|
end
|
|
22
|
-
|
|
23
|
+
|
|
23
24
|
def sinatra_mocks
|
|
24
|
-
{:type => "type", :tempfile => "Tempfile"}
|
|
25
|
+
{:type => "type", :tempfile => "Tempfile", :filename => "foo.bar"}
|
|
25
26
|
end
|
|
26
|
-
|
|
27
|
+
|
|
27
28
|
describe "the constructor" do
|
|
28
29
|
describe "when given a file path" do
|
|
29
30
|
before(:each) do
|
|
30
|
-
@
|
|
31
|
+
@path = BEACH_BALL_PATH
|
|
32
|
+
@koala_io_params = [@path]
|
|
31
33
|
end
|
|
32
34
|
|
|
33
35
|
describe "and a content type" do
|
|
34
36
|
before :each do
|
|
35
|
-
@
|
|
37
|
+
@stub_type = stub("image/jpg")
|
|
38
|
+
@koala_io_params.concat([@stub_type])
|
|
36
39
|
end
|
|
37
40
|
|
|
38
|
-
it "
|
|
39
|
-
|
|
40
|
-
Koala::UploadableIO.new(*@koala_io_params).io_or_path.should == stub_path
|
|
41
|
+
it "returns an UploadIO with the same file path" do
|
|
42
|
+
Koala::UploadableIO.new(*@koala_io_params).io_or_path.should == @path
|
|
41
43
|
end
|
|
42
44
|
|
|
43
|
-
it "
|
|
44
|
-
|
|
45
|
-
Koala::UploadableIO.new(*@koala_io_params).content_type.should == stub_type
|
|
45
|
+
it "returns an UploadIO with the same content type" do
|
|
46
|
+
Koala::UploadableIO.new(*@koala_io_params).content_type.should == @stub_type
|
|
46
47
|
end
|
|
47
48
|
|
|
48
|
-
it "
|
|
49
|
-
|
|
50
|
-
@koala_io_params[0].stub!(:read)
|
|
51
|
-
Koala::UploadableIO.new(*@koala_io_params).requires_base_http_service.should be_true
|
|
49
|
+
it "returns an UploadIO with the file's name" do
|
|
50
|
+
Koala::UploadableIO.new(*@koala_io_params).filename.should == File.basename(@path)
|
|
52
51
|
end
|
|
53
52
|
end
|
|
54
53
|
|
|
@@ -59,7 +58,8 @@ describe "Koala::UploadableIO" do
|
|
|
59
58
|
|
|
60
59
|
describe "when given a File object" do
|
|
61
60
|
before(:each) do
|
|
62
|
-
@
|
|
61
|
+
@file = File.open(BEACH_BALL_PATH)
|
|
62
|
+
@koala_io_params = [@file]
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
describe "and a content type" do
|
|
@@ -67,14 +67,18 @@ describe "Koala::UploadableIO" do
|
|
|
67
67
|
@koala_io_params.concat(["image/jpg"])
|
|
68
68
|
end
|
|
69
69
|
|
|
70
|
-
it "
|
|
70
|
+
it "returns an UploadIO with the same io" do
|
|
71
71
|
Koala::UploadableIO.new(*@koala_io_params).io_or_path.should == @koala_io_params[0]
|
|
72
72
|
end
|
|
73
73
|
|
|
74
|
-
it "
|
|
74
|
+
it "returns an UploadableIO with the same content_type" do
|
|
75
75
|
content_stub = @koala_io_params[1] = stub('Content Type')
|
|
76
76
|
Koala::UploadableIO.new(*@koala_io_params).content_type.should == content_stub
|
|
77
77
|
end
|
|
78
|
+
|
|
79
|
+
it "returns an UploadableIO with the right filename" do
|
|
80
|
+
Koala::UploadableIO.new(*@koala_io_params).filename.should == File.basename(@file.path)
|
|
81
|
+
end
|
|
78
82
|
end
|
|
79
83
|
|
|
80
84
|
describe "and no content type" do
|
|
@@ -82,21 +86,53 @@ describe "Koala::UploadableIO" do
|
|
|
82
86
|
end
|
|
83
87
|
end
|
|
84
88
|
|
|
89
|
+
describe "when given an IO object" do
|
|
90
|
+
before(:each) do
|
|
91
|
+
@io = StringIO.open("abcdefgh")
|
|
92
|
+
@koala_io_params = [@io]
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
describe "and a content type" do
|
|
96
|
+
before :each do
|
|
97
|
+
@koala_io_params.concat(["image/jpg"])
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it "returns an UploadableIO with the same io" do
|
|
101
|
+
Koala::UploadableIO.new(*@koala_io_params).io_or_path.should == @koala_io_params[0]
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it "returns an UploadableIO with the same content_type" do
|
|
105
|
+
content_stub = @koala_io_params[1] = stub('Content Type')
|
|
106
|
+
Koala::UploadableIO.new(*@koala_io_params).content_type.should == content_stub
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
describe "and no content type" do
|
|
111
|
+
it "raises an exception" do
|
|
112
|
+
lambda { Koala::UploadableIO.new(*@koala_io_params) }.should raise_exception(Koala::KoalaError)
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
85
117
|
describe "when given a Rails 3 ActionDispatch::Http::UploadedFile" do
|
|
86
118
|
before(:each) do
|
|
87
119
|
@tempfile, @uploaded_file = rails_3_mocks
|
|
88
120
|
end
|
|
89
121
|
|
|
90
|
-
it "
|
|
122
|
+
it "gets the path from the tempfile associated with the UploadedFile" do
|
|
123
|
+
expected_path = stub('Tempfile')
|
|
124
|
+
@tempfile.should_receive(:path).and_return(expected_path)
|
|
125
|
+
Koala::UploadableIO.new(@uploaded_file).io_or_path.should == expected_path
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
it "gets the content type via the content_type method" do
|
|
91
129
|
expected_content_type = stub('Content Type')
|
|
92
130
|
@uploaded_file.should_receive(:content_type).and_return(expected_content_type)
|
|
93
131
|
Koala::UploadableIO.new(@uploaded_file).content_type.should == expected_content_type
|
|
94
132
|
end
|
|
95
133
|
|
|
96
|
-
it "
|
|
97
|
-
|
|
98
|
-
@tempfile.should_receive(:path).and_return(expected_path)
|
|
99
|
-
Koala::UploadableIO.new(@uploaded_file).io_or_path.should == expected_path
|
|
134
|
+
it "gets the filename from the UploadedFile" do
|
|
135
|
+
Koala::UploadableIO.new(@uploaded_file).filename.should == @uploaded_file.original_filename
|
|
100
136
|
end
|
|
101
137
|
end
|
|
102
138
|
|
|
@@ -105,7 +141,15 @@ describe "Koala::UploadableIO" do
|
|
|
105
141
|
@file_hash = sinatra_mocks
|
|
106
142
|
end
|
|
107
143
|
|
|
108
|
-
it "
|
|
144
|
+
it "gets the io_or_path from the :tempfile key" do
|
|
145
|
+
expected_file = stub('File')
|
|
146
|
+
@file_hash[:tempfile] = expected_file
|
|
147
|
+
|
|
148
|
+
uploadable = Koala::UploadableIO.new(@file_hash)
|
|
149
|
+
uploadable.io_or_path.should == expected_file
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
it "gets the content type from the :type key" do
|
|
109
153
|
expected_content_type = stub('Content Type')
|
|
110
154
|
@file_hash[:type] = expected_content_type
|
|
111
155
|
|
|
@@ -113,12 +157,9 @@ describe "Koala::UploadableIO" do
|
|
|
113
157
|
uploadable.content_type.should == expected_content_type
|
|
114
158
|
end
|
|
115
159
|
|
|
116
|
-
it "
|
|
117
|
-
expected_file = stub('File')
|
|
118
|
-
@file_hash[:tempfile] = expected_file
|
|
119
|
-
|
|
160
|
+
it "gets the content type from the :type key" do
|
|
120
161
|
uploadable = Koala::UploadableIO.new(@file_hash)
|
|
121
|
-
uploadable.
|
|
162
|
+
uploadable.filename.should == @file_hash[:filename]
|
|
122
163
|
end
|
|
123
164
|
end
|
|
124
165
|
|
|
@@ -148,7 +189,7 @@ describe "Koala::UploadableIO" do
|
|
|
148
189
|
Koala::UploadableIO.new(BEACH_BALL_PATH, "content/type").to_upload_io.should == @upload_io
|
|
149
190
|
end
|
|
150
191
|
end
|
|
151
|
-
|
|
192
|
+
|
|
152
193
|
context "if a filename was provided" do
|
|
153
194
|
it "should call the constructor with the content type, file name, and the filename" do
|
|
154
195
|
filename = "file"
|
|
@@ -159,7 +200,7 @@ describe "Koala::UploadableIO" do
|
|
|
159
200
|
end
|
|
160
201
|
|
|
161
202
|
describe "getting a file" do
|
|
162
|
-
it "
|
|
203
|
+
it "returns the File if initialized with a file" do
|
|
163
204
|
f = File.new(BEACH_BALL_PATH)
|
|
164
205
|
Koala::UploadableIO.new(f).to_file.should == f
|
|
165
206
|
end
|
|
@@ -175,19 +216,19 @@ describe "Koala::UploadableIO" do
|
|
|
175
216
|
it "returns true for Rails 3 file uploads" do
|
|
176
217
|
Koala::UploadableIO.binary_content?(rails_3_mocks.last).should be_true
|
|
177
218
|
end
|
|
178
|
-
|
|
219
|
+
|
|
179
220
|
it "returns true for Sinatra file uploads" do
|
|
180
221
|
Koala::UploadableIO.binary_content?(rails_3_mocks.last).should be_true
|
|
181
222
|
end
|
|
182
|
-
|
|
223
|
+
|
|
183
224
|
it "returns true for File objects" do
|
|
184
225
|
Koala::UploadableIO.binary_content?(File.open(BEACH_BALL_PATH)).should be_true
|
|
185
226
|
end
|
|
186
|
-
|
|
227
|
+
|
|
187
228
|
it "returns false for everything else" do
|
|
188
229
|
Koala::UploadableIO.binary_content?(StringIO.new).should be_false
|
|
189
230
|
Koala::UploadableIO.binary_content?(BEACH_BALL_PATH).should be_false
|
|
190
231
|
Koala::UploadableIO.binary_content?(nil).should be_false
|
|
191
232
|
end
|
|
192
233
|
end
|
|
193
|
-
end # describe UploadableIO
|
|
234
|
+
end # describe UploadableIO
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Koala::Utils do
|
|
4
|
+
it "has a deprecate method" do
|
|
5
|
+
Koala::Utils.should respond_to(:deprecate)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
# AFAIK there's no way to test that (Kernel.)warn receives the text
|
|
9
|
+
# Kernel.should_receive(:warn) doesn't seem to work, even though the text gets printed
|
|
10
|
+
end
|
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
1
|
+
# Testing data
|
|
2
|
+
|
|
3
|
+
# IMPORTANT NOTE: live tests will run against a test users automatically
|
|
4
|
+
# If you want to run them against a real user or test users on a different account, you can
|
|
5
|
+
# by enter an OAuth token, code, and session_key (for real users) or changing the app_id and secret (for test users)
|
|
6
|
+
# (note for real users: this will leave some photos and videos posted to your wall, since they can't be deleted through the API)
|
|
7
|
+
|
|
8
|
+
# These values are configured to work with the OAuth Playground app by default
|
|
3
9
|
# Of course, you can change this to work with your own app.
|
|
4
|
-
#
|
|
5
|
-
|
|
6
|
-
# You must supply this value yourself to test the GraphAPI class.
|
|
7
|
-
# Your OAuth token should have publish_stream, read_stream, and user_photos permissions.
|
|
8
|
-
oauth_token:
|
|
10
|
+
# Check out http://oauth.twoalex.com/ to easily generate tokens, cookies, etc.
|
|
9
11
|
|
|
10
|
-
#
|
|
12
|
+
# Your OAuth token should have the read_stream, publish_stream, user_photos, user_videos, and read_insights permissions.
|
|
13
|
+
oauth_token:
|
|
14
|
+
|
|
15
|
+
# for testing the OAuth class
|
|
11
16
|
# baseline app
|
|
12
|
-
oauth_test_data:
|
|
13
|
-
#
|
|
14
|
-
code:
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
multiple_session_keys:
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
|
|
17
|
+
oauth_test_data:
|
|
18
|
+
# the following two values are not needed for most of the test suite, but the relevant tests will not run if they're not present
|
|
19
|
+
code:
|
|
20
|
+
session_key:
|
|
21
|
+
|
|
21
22
|
# These values will work out of the box
|
|
22
23
|
app_id: 119908831367602
|
|
23
24
|
secret: e45e55a333eec232d4206d2703de1307
|
|
@@ -25,15 +26,16 @@ oauth_test_data:
|
|
|
25
26
|
app_access_token: 119908831367602|o3wswWQ88LYjEC9-ukR_gjRIOMw.
|
|
26
27
|
raw_token_string: "access_token=119908831367602|2.6GneoQbnEqtSiPppZzDU4Q__.3600.1273366800-2905623|3OLa3w0x1K4C1S5cOgbs07TytAk.&expires=6621"
|
|
27
28
|
raw_offline_access_token_string: access_token=119908831367602|2.6GneoQbnEqtSiPppZzDU4Q__.3600.1273366800-2905623|3OLa3w0x1K4C1S5cOgbs07TytAk.
|
|
28
|
-
valid_cookies:
|
|
29
|
+
valid_cookies:
|
|
29
30
|
# note: the tests stub the time class so these default cookies are always valid (if you're using the default app)
|
|
30
31
|
# if not you may want to remove the stubbing to test expiration
|
|
31
32
|
fbs_119908831367602: '"access_token=119908831367602|2.LKE7ksSPOx0V_8mHPr2NHQ__.3600.1273363200-2905623|CMpi0AYbn03Oukzv94AUha2qbO4.&expires=1273363200&secret=lT_9zm5r5IbJ6Aa5O54nFw__&session_key=2.LKE7ksSPOx0V_8mHPr2NHQ__.3600.1273363200-2905623&sig=9515e93113921f9476a4efbdd4a3c746&uid=2905623"'
|
|
32
|
-
|
|
33
|
-
fbs_119908831367602: '"access_token=119908831367602|2.xv9mi6QSOpr474s4n2X_pw__.3600.1273287600-2905623|yVt5WH_S6J5p3gFa5_5lBzckhws.&expires=1273287600&secret=V_E79ovQnXqxGctFuC_n5A__&session_key=2.xv9mi6QSOpr474s4n2X_pw__.3600.1273287600-2905623&sig=eeef60838c0c800258d89b7e6ddddddb&uid=2905623"'
|
|
34
|
-
offline_access_cookies:
|
|
33
|
+
offline_access_cookies:
|
|
35
34
|
# note: I've revoked the offline access for security reasons, so you can't make calls against this :)
|
|
36
35
|
fbs_119908831367602: '"access_token=119908831367602|08170230801eb225068e7a70-2905623|Q3LDCYYF8CX9cstxnZLsxiR0nwg.&expires=0&secret=78abaee300b392e275072a9f2727d436&session_key=08170230801eb225068e7a70-2905623&sig=423b8aa4b6fa1f9a571955f8e929d567&uid=2905623"'
|
|
36
|
+
valid_signed_cookies:
|
|
37
|
+
"fbsr_119908831367602": "f1--LHwjHVCxfs97hRHL-4cF-0jNxZRc6MGzo1qHLb0.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImNvZGUiOiIyLkFRQm90a0pBWlhVY1l3RkMuMzYwMC4xMzE0ODEzNjAwLjEtMjkwNTYyM3x4V2xya0d0UmJIZlpIclRnVWwxQmxJcVhRbjQiLCJpc3N1ZWRfYXQiOjEzMTQ4MDY2NTUsInVzZXJfaWQiOiIyOTA1NjIzIn0"
|
|
38
|
+
|
|
37
39
|
|
|
38
40
|
# These values from the OAuth Playground (see above) will work out of the box
|
|
39
41
|
# You can update this to live data if desired
|
|
@@ -44,17 +46,17 @@ oauth_test_data:
|
|
|
44
46
|
algorithm: HMAC-SHA256
|
|
45
47
|
user_id: "2905623"
|
|
46
48
|
oauth_token: 119908831367602|2.zVF_6NrMELHuJa4gIU9tKw__.3600.1301922000-2905623|zgqPsr2BG9LoOK9kekGgRURZx0k
|
|
47
|
-
user:
|
|
49
|
+
user:
|
|
48
50
|
country: de
|
|
49
51
|
locale: de_DE
|
|
50
|
-
age:
|
|
52
|
+
age:
|
|
51
53
|
min: 21
|
|
52
54
|
issued_at: 1301917299
|
|
53
55
|
|
|
54
56
|
subscription_test_data:
|
|
55
57
|
subscription_path: http://oauth.twoalex.com/subscriptions
|
|
56
58
|
verify_token: "myverificationtoken|1f54545d5f722733e17faae15377928f"
|
|
57
|
-
challenge_data:
|
|
59
|
+
challenge_data:
|
|
58
60
|
"hub.challenge": "1290024882"
|
|
59
61
|
"hub.verify_token": "myverificationtoken|1f54545d5f722733e17faae15377928f"
|
|
60
62
|
"hub.mode": "subscribe"
|