cloudfiles 1.4.8 → 1.4.9
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/Rakefile +7 -1
- data/VERSION +1 -1
- data/cloudfiles.gemspec +5 -2
- data/lib/cloudfiles/authentication.rb +16 -11
- data/lib/cloudfiles/connection.rb +10 -3
- data/lib/cloudfiles/container.rb +8 -6
- data/test/cloudfiles_authentication_test.rb +7 -7
- data/test/cloudfiles_connection_test.rb +32 -8
- data/test/cloudfiles_container_test.rb +84 -11
- metadata +20 -4
data/Rakefile
CHANGED
@@ -10,6 +10,7 @@ begin
|
|
10
10
|
gemspec.homepage = "http://www.rackspacecloud.com/cloud_hosting_products/files"
|
11
11
|
gemspec.authors = ["H. Wade Minter", "Rackspace Hosting"]
|
12
12
|
gemspec.add_dependency('mime-types', '>= 1.16')
|
13
|
+
gemspec.add_development_dependency "mocha", "~> 0.9.8"
|
13
14
|
end
|
14
15
|
Jeweler::GemcutterTasks.new
|
15
16
|
rescue LoadError
|
@@ -31,4 +32,9 @@ namespace :test do
|
|
31
32
|
|
32
33
|
end
|
33
34
|
|
34
|
-
|
35
|
+
require 'rake/testtask'
|
36
|
+
Rake::TestTask.new(:test) do |test|
|
37
|
+
test.libs << 'lib' << 'test'
|
38
|
+
test.pattern = 'test/**/*_test.rb'
|
39
|
+
test.verbose = true
|
40
|
+
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.4.
|
1
|
+
1.4.9
|
data/cloudfiles.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{cloudfiles}
|
8
|
-
s.version = "1.4.
|
8
|
+
s.version = "1.4.9"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["H. Wade Minter", "Rackspace Hosting"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-10-19}
|
13
13
|
s.description = %q{A Ruby version of the Rackspace Cloud Files API.}
|
14
14
|
s.email = %q{minter@lunenburg.org}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -57,11 +57,14 @@ Gem::Specification.new do |s|
|
|
57
57
|
|
58
58
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
59
59
|
s.add_runtime_dependency(%q<mime-types>, [">= 1.16"])
|
60
|
+
s.add_development_dependency(%q<mocha>, ["~> 0.9.8"])
|
60
61
|
else
|
61
62
|
s.add_dependency(%q<mime-types>, [">= 1.16"])
|
63
|
+
s.add_dependency(%q<mocha>, ["~> 0.9.8"])
|
62
64
|
end
|
63
65
|
else
|
64
66
|
s.add_dependency(%q<mime-types>, [">= 1.16"])
|
67
|
+
s.add_dependency(%q<mocha>, ["~> 0.9.8"])
|
65
68
|
end
|
66
69
|
end
|
67
70
|
|
@@ -10,11 +10,12 @@ module CloudFiles
|
|
10
10
|
#
|
11
11
|
# Should probably never be called directly.
|
12
12
|
def initialize(connection)
|
13
|
-
|
13
|
+
parsed_authurl = URI.parse(connection.authurl)
|
14
|
+
path = parsed_authurl.path
|
14
15
|
hdrhash = { "X-Auth-User" => connection.authuser, "X-Auth-Key" => connection.authkey }
|
15
16
|
begin
|
16
|
-
server
|
17
|
-
server.use_ssl
|
17
|
+
server = get_server(connection, parsed_authurl)
|
18
|
+
server.use_ssl = true
|
18
19
|
server.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
19
20
|
server.start
|
20
21
|
rescue
|
@@ -22,16 +23,16 @@ module CloudFiles
|
|
22
23
|
end
|
23
24
|
response = server.get(path,hdrhash)
|
24
25
|
if (response.code == "204")
|
25
|
-
connection.cdnmgmthost
|
26
|
-
connection.cdnmgmtpath
|
27
|
-
connection.cdnmgmtport
|
26
|
+
connection.cdnmgmthost = URI.parse(response["x-cdn-management-url"]).host
|
27
|
+
connection.cdnmgmtpath = URI.parse(response["x-cdn-management-url"]).path
|
28
|
+
connection.cdnmgmtport = URI.parse(response["x-cdn-management-url"]).port
|
28
29
|
connection.cdnmgmtscheme = URI.parse(response["x-cdn-management-url"]).scheme
|
29
|
-
connection.storagehost
|
30
|
-
connection.storagepath
|
31
|
-
connection.storageport
|
30
|
+
connection.storagehost = set_snet(connection,URI.parse(response["x-storage-url"]).host)
|
31
|
+
connection.storagepath = URI.parse(response["x-storage-url"]).path
|
32
|
+
connection.storageport = URI.parse(response["x-storage-url"]).port
|
32
33
|
connection.storagescheme = URI.parse(response["x-storage-url"]).scheme
|
33
|
-
connection.authtoken
|
34
|
-
connection.authok
|
34
|
+
connection.authtoken = response["x-auth-token"]
|
35
|
+
connection.authok = true
|
35
36
|
else
|
36
37
|
connection.authtoken = false
|
37
38
|
raise AuthenticationException, "Authentication failed"
|
@@ -41,6 +42,10 @@ module CloudFiles
|
|
41
42
|
|
42
43
|
private
|
43
44
|
|
45
|
+
def get_server(connection, parsed_authurl)
|
46
|
+
Net::HTTP::Proxy(connection.proxy_host, connection.proxy_port).new(parsed_authurl.host,parsed_authurl.port)
|
47
|
+
end
|
48
|
+
|
44
49
|
def set_snet(connection,hostname)
|
45
50
|
if connection.snet?
|
46
51
|
"snet-#{hostname}"
|
@@ -11,6 +11,9 @@ module CloudFiles
|
|
11
11
|
|
12
12
|
# Authentication username provided when the CloudFiles class was instantiated
|
13
13
|
attr_reader :authuser
|
14
|
+
|
15
|
+
# API host to authenticate to
|
16
|
+
attr_reader :authurl
|
14
17
|
|
15
18
|
# Hostname of the CDN management server
|
16
19
|
attr_accessor :cdnmgmthost
|
@@ -61,12 +64,15 @@ module CloudFiles
|
|
61
64
|
# This is useful if you are using the library on a Rackspace-hosted system, as it provides faster speeds, keeps traffic off of
|
62
65
|
# the public network, and the bandwidth is not billed.
|
63
66
|
#
|
67
|
+
# If you need to connect to a Cloud Files installation that is NOT the standard Rackspace one, set the :authurl option to the URL
|
68
|
+
# of your authentication endpoint. The default is https://auth.api.rackspacecloud.com/v1.0
|
69
|
+
#
|
64
70
|
# This will likely be the base class for most operations.
|
65
71
|
#
|
66
72
|
# With gem 1.4.8, the connection style has changed. It is now a hash of arguments. Note that the proxy options are currently only
|
67
73
|
# supported in the new style.
|
68
74
|
#
|
69
|
-
# cf = CloudFiles::Connection.new(:username => "MY_USERNAME", :api_key => "MY_API_KEY", :retry_auth => true, :snet => false, :proxy_host => "localhost", :proxy_port => "1234")
|
75
|
+
# cf = CloudFiles::Connection.new(:username => "MY_USERNAME", :api_key => "MY_API_KEY", :authurl => "https://auth.api.rackspacecloud.com/v1.0", :retry_auth => true, :snet => false, :proxy_host => "localhost", :proxy_port => "1234")
|
70
76
|
#
|
71
77
|
# The old style (positional arguments) is deprecated and will be removed at some point in the future.
|
72
78
|
#
|
@@ -76,6 +82,7 @@ module CloudFiles
|
|
76
82
|
options = args[0]
|
77
83
|
@authuser = options[:username] ||( raise AuthenticationException, "Must supply a :username")
|
78
84
|
@authkey = options[:api_key] || (raise AuthenticationException, "Must supply an :api_key")
|
85
|
+
@authurl = options[:authurl] || "https://auth.api.rackspacecloud.com/v1.0"
|
79
86
|
@retry_auth = options[:retry_auth] || true
|
80
87
|
@snet = ENV['RACKSPACE_SERVICENET'] || options[:snet]
|
81
88
|
@proxy_host = options[:proxy_host]
|
@@ -145,7 +152,7 @@ module CloudFiles
|
|
145
152
|
def containers(limit=0,marker="")
|
146
153
|
paramarr = []
|
147
154
|
paramarr << ["limit=#{URI.encode(limit.to_s).gsub(/&/,'%26')}"] if limit.to_i > 0
|
148
|
-
paramarr << ["
|
155
|
+
paramarr << ["marker=#{URI.encode(marker.to_s).gsub(/&/,'%26')}"] unless marker.to_s.empty?
|
149
156
|
paramstr = (paramarr.size > 0)? paramarr.join("&") : "" ;
|
150
157
|
response = cfreq("GET",@storagehost,"#{@storagepath}?#{paramstr}",@storageport,@storagescheme)
|
151
158
|
return [] if (response.code == "204")
|
@@ -167,7 +174,7 @@ module CloudFiles
|
|
167
174
|
def containers_detail(limit=0,marker="")
|
168
175
|
paramarr = []
|
169
176
|
paramarr << ["limit=#{URI.encode(limit.to_s).gsub(/&/,'%26')}"] if limit.to_i > 0
|
170
|
-
paramarr << ["
|
177
|
+
paramarr << ["marker=#{URI.encode(marker.to_s).gsub(/&/,'%26')}"] unless marker.to_s.empty?
|
171
178
|
paramstr = (paramarr.size > 0)? paramarr.join("&") : "" ;
|
172
179
|
response = cfreq("GET",@storagehost,"#{@storagepath}?format=xml&#{paramstr}",@storageport,@storagescheme)
|
173
180
|
return {} if (response.code == "204")
|
data/lib/cloudfiles/container.rb
CHANGED
@@ -118,11 +118,11 @@ module CloudFiles
|
|
118
118
|
|
119
119
|
# Gathers a list of all available objects in the current container and returns an array of object names.
|
120
120
|
# container = cf.container("My Container")
|
121
|
-
# container.objects #=> [ "
|
121
|
+
# container.objects #=> [ "cat", "dog", "donkey", "monkeydir", "monkeydir/capuchin"]
|
122
122
|
# Pass a limit argument to limit the list to a number of objects:
|
123
|
-
# container.objects(:limit => 1) #=> [ "
|
124
|
-
# Pass an
|
125
|
-
# container.objects(:limit => 1, :
|
123
|
+
# container.objects(:limit => 1) #=> [ "cat" ]
|
124
|
+
# Pass an marker with or without a limit to start the list at a certain object:
|
125
|
+
# container.objects(:limit => 1, :marker => 'dog') #=> [ "donkey" ]
|
126
126
|
# Pass a prefix to search for objects that start with a certain string:
|
127
127
|
# container.objects(:prefix => "do") #=> [ "dog", "donkey" ]
|
128
128
|
# Only search within a certain pseudo-filesystem path:
|
@@ -132,9 +132,10 @@ module CloudFiles
|
|
132
132
|
# Returns an empty array if no object exist in the container. Throws an InvalidResponseException
|
133
133
|
# if the request fails.
|
134
134
|
def objects(params = {})
|
135
|
+
params[:marker] ||= params[:offset]
|
135
136
|
paramarr = []
|
136
137
|
paramarr << ["limit=#{URI.encode(params[:limit].to_s).gsub(/&/,'%26')}"] if params[:limit]
|
137
|
-
paramarr << ["
|
138
|
+
paramarr << ["marker=#{URI.encode(params[:marker].to_s).gsub(/&/,'%26')}"] if params[:marker]
|
138
139
|
paramarr << ["prefix=#{URI.encode(params[:prefix]).gsub(/&/,'%26')}"] if params[:prefix]
|
139
140
|
paramarr << ["path=#{URI.encode(params[:path]).gsub(/&/,'%26')}"] if params[:path]
|
140
141
|
paramstr = (paramarr.size > 0)? paramarr.join("&") : "" ;
|
@@ -162,10 +163,11 @@ module CloudFiles
|
|
162
163
|
# :bytes=>"22"}
|
163
164
|
# }
|
164
165
|
def objects_detail(params = {})
|
166
|
+
params[:marker] ||= params[:offset]
|
165
167
|
paramarr = []
|
166
168
|
paramarr << ["format=xml"]
|
167
169
|
paramarr << ["limit=#{URI.encode(params[:limit].to_s).gsub(/&/,'%26')}"] if params[:limit]
|
168
|
-
paramarr << ["
|
170
|
+
paramarr << ["marker=#{URI.encode(params[:marker].to_s).gsub(/&/,'%26')}"] if params[:marker]
|
169
171
|
paramarr << ["prefix=#{URI.encode(params[:prefix]).gsub(/&/,'%26')}"] if params[:prefix]
|
170
172
|
paramarr << ["path=#{URI.encode(params[:path]).gsub(/&/,'%26')}"] if params[:path]
|
171
173
|
paramstr = (paramarr.size > 0)? paramarr.join("&") : "" ;
|
@@ -8,8 +8,8 @@ class CloudfilesAuthenticationTest < Test::Unit::TestCase
|
|
8
8
|
response.stubs(:code).returns('204')
|
9
9
|
server = mock(:use_ssl= => true, :verify_mode= => true, :start => true, :finish => true)
|
10
10
|
server.stubs(:get).returns(response)
|
11
|
-
|
12
|
-
@connection = stub(:authuser => 'dummy_user', :authkey => 'dummy_key', :cdnmgmthost= => true, :cdnmgmtpath= => true, :cdnmgmtport= => true, :cdnmgmtscheme= => true, :storagehost= => true, :storagepath= => true, :storageport= => true, :storagescheme= => true, :authtoken= => true, :authok= => true, :snet? => false)
|
11
|
+
CloudFiles::Authentication.any_instance.stubs(:get_server).returns(server)
|
12
|
+
@connection = stub(:authuser => 'dummy_user', :authkey => 'dummy_key', :cdnmgmthost= => true, :cdnmgmtpath= => true, :cdnmgmtport= => true, :cdnmgmtscheme= => true, :storagehost= => true, :storagepath= => true, :storageport= => true, :storagescheme= => true, :authtoken= => true, :authok= => true, :snet? => false, :authurl => 'https://auth.api.rackspacecloud.com/v1.0')
|
13
13
|
result = CloudFiles::Authentication.new(@connection)
|
14
14
|
assert_equal result.class, CloudFiles::Authentication
|
15
15
|
end
|
@@ -19,8 +19,8 @@ class CloudfilesAuthenticationTest < Test::Unit::TestCase
|
|
19
19
|
response.stubs(:code).returns('204')
|
20
20
|
server = mock(:use_ssl= => true, :verify_mode= => true, :start => true, :finish => true)
|
21
21
|
server.stubs(:get).returns(response)
|
22
|
-
|
23
|
-
@connection = stub(:authuser => 'dummy_user', :authkey => 'dummy_key', :cdnmgmthost= => true, :cdnmgmtpath= => true, :cdnmgmtport= => true, :cdnmgmtscheme= => true, :storagehost= => true, :storagepath= => true, :storageport= => true, :storagescheme= => true, :authtoken= => true, :authok= => true, :snet? => true)
|
22
|
+
CloudFiles::Authentication.any_instance.stubs(:get_server).returns(server)
|
23
|
+
@connection = stub(:authuser => 'dummy_user', :authkey => 'dummy_key', :cdnmgmthost= => true, :cdnmgmtpath= => true, :cdnmgmtport= => true, :cdnmgmtscheme= => true, :storagehost= => true, :storagepath= => true, :storageport= => true, :storagescheme= => true, :authtoken= => true, :authok= => true, :snet? => true, :authurl => 'https://auth.api.rackspacecloud.com/v1.0')
|
24
24
|
result = CloudFiles::Authentication.new(@connection)
|
25
25
|
assert_equal result.class, CloudFiles::Authentication
|
26
26
|
end
|
@@ -30,8 +30,8 @@ class CloudfilesAuthenticationTest < Test::Unit::TestCase
|
|
30
30
|
response.stubs(:code).returns('499')
|
31
31
|
server = mock(:use_ssl= => true, :verify_mode= => true, :start => true)
|
32
32
|
server.stubs(:get).returns(response)
|
33
|
-
|
34
|
-
@connection = stub(:authuser => 'bad_user', :authkey => 'bad_key', :authok= => true, :authtoken= => true)
|
33
|
+
CloudFiles::Authentication.any_instance.stubs(:get_server).returns(server)
|
34
|
+
@connection = stub(:authuser => 'bad_user', :authkey => 'bad_key', :authok= => true, :authtoken= => true, :authurl => 'https://auth.api.rackspacecloud.com/v1.0')
|
35
35
|
assert_raises(AuthenticationException) do
|
36
36
|
result = CloudFiles::Authentication.new(@connection)
|
37
37
|
end
|
@@ -39,7 +39,7 @@ class CloudfilesAuthenticationTest < Test::Unit::TestCase
|
|
39
39
|
|
40
40
|
def test_bad_hostname
|
41
41
|
Net::HTTP.stubs(:new).raises(ConnectionException)
|
42
|
-
@connection = stub(:authuser => 'bad_user', :authkey => 'bad_key', :authok= => true, :authtoken= => true)
|
42
|
+
@connection = stub(:authuser => 'bad_user', :authkey => 'bad_key', :authok= => true, :authtoken= => true, :authurl => 'https://auth.api.rackspacecloud.com/v1.0')
|
43
43
|
assert_raises(ConnectionException) do
|
44
44
|
result = CloudFiles::Authentication.new(@connection)
|
45
45
|
end
|
@@ -232,6 +232,22 @@ class CloudfilesConnectionTest < Test::Unit::TestCase
|
|
232
232
|
assert_equal containers.first, 'foo'
|
233
233
|
end
|
234
234
|
|
235
|
+
def test_containers_with_limit
|
236
|
+
build_net_http_object_with_cfreq_expectations({:body => "foo", :code => '200'},
|
237
|
+
{:path => includes('limit=1')})
|
238
|
+
containers = @connection.containers(1)
|
239
|
+
assert_equal containers.size, 1
|
240
|
+
assert_equal containers.first, 'foo'
|
241
|
+
end
|
242
|
+
|
243
|
+
def test_containers_with_marker
|
244
|
+
build_net_http_object_with_cfreq_expectations({:body => "boo", :code => '200'},
|
245
|
+
{:path => includes('marker=baz')})
|
246
|
+
containers = @connection.containers(0, 'baz')
|
247
|
+
assert_equal containers.size, 1
|
248
|
+
assert_equal containers.first, 'boo'
|
249
|
+
end
|
250
|
+
|
235
251
|
def test_no_containers_yet
|
236
252
|
build_net_http_object
|
237
253
|
containers = @connection.containers
|
@@ -270,17 +286,25 @@ class CloudfilesConnectionTest < Test::Unit::TestCase
|
|
270
286
|
|
271
287
|
private
|
272
288
|
|
273
|
-
def build_net_http_object(args={:code => '204' })
|
289
|
+
def build_net_http_object(args={:code => '204' }, cfreq_expectations={})
|
274
290
|
args[:response] = {} unless args[:response]
|
275
291
|
response = {'x-cdn-management-url' => 'http://cdn.example.com/path', 'x-storage-url' => 'http://cdn.example.com/storage', 'authtoken' => 'dummy_token'}.merge(args[:response])
|
276
292
|
response.stubs(:code).returns(args[:code])
|
277
293
|
response.stubs(:body).returns args[:body] || nil
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
294
|
+
|
295
|
+
if !cfreq_expectations.empty?
|
296
|
+
parameter_expectations = [anything(), anything(), anything(), anything(), anything(), anything(), anything(), anything()]
|
297
|
+
parameter_expectations[0] = cfreq_expectations[:method] if cfreq_expectations[:method]
|
298
|
+
parameter_expectations[2] = cfreq_expectations[:path] if cfreq_expectations[:path]
|
299
|
+
|
300
|
+
@connection.expects(:cfreq).with(*parameter_expectations).returns(response)
|
301
|
+
else
|
302
|
+
@connection.stubs(:cfreq).returns(response)
|
303
|
+
end
|
304
|
+
|
305
|
+
end
|
306
|
+
|
307
|
+
def build_net_http_object_with_cfreq_expectations(args={:code => '204' }, cfreq_expectations={})
|
308
|
+
build_net_http_object(args, cfreq_expectations)
|
284
309
|
end
|
285
|
-
|
286
310
|
end
|
@@ -149,19 +149,78 @@ class CloudfilesContainerTest < Test::Unit::TestCase
|
|
149
149
|
assert_equal objects.first, 'foo'
|
150
150
|
end
|
151
151
|
|
152
|
-
def
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
152
|
+
def test_fetch_objects_with_limit
|
153
|
+
build_net_http_object_with_cfreq_expectations({:code => '200', :body => "foo"},
|
154
|
+
{:path => includes("limit=1")})
|
155
|
+
objects = @container.objects(:limit => 1)
|
156
|
+
assert_equal objects.class, Array
|
157
|
+
assert_equal objects.size, 1
|
158
|
+
assert_equal objects.first, 'foo'
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_fetch_objects_with_marker
|
162
|
+
build_net_http_object_with_cfreq_expectations({:code => '200', :body => "bar"},
|
163
|
+
{:path => includes("marker=foo")})
|
164
|
+
objects = @container.objects(:marker => 'foo')
|
165
|
+
assert_equal objects.class, Array
|
166
|
+
assert_equal objects.size, 1
|
167
|
+
assert_equal objects.first, 'bar'
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_fetch_objects_with_deprecated_offset_param
|
171
|
+
build_net_http_object_with_cfreq_expectations({:code => '200', :body => "bar"},
|
172
|
+
{:path => includes("marker=foo")})
|
173
|
+
objects = @container.objects(:offset => 'foo')
|
174
|
+
assert_equal objects.class, Array
|
175
|
+
assert_equal objects.size, 1
|
176
|
+
assert_equal objects.first, 'bar'
|
177
|
+
end
|
178
|
+
|
179
|
+
def object_detail_body(skip_kisscam=false)
|
180
|
+
lines = ['<?xml version="1.0" encoding="UTF-8"?>',
|
181
|
+
'<container name="video">']
|
182
|
+
unless skip_kisscam
|
183
|
+
lines << '<object><name>kisscam.mov</name><hash>96efd5a0d78b74cfe2a911c479b98ddd</hash><bytes>9196332</bytes><content_type>video/quicktime</content_type><last_modified>2008-12-18T10:34:43.867648</last_modified></object>
|
184
|
+
>'
|
185
|
+
end
|
186
|
+
lines << '<object><name>penaltybox.mov</name><hash>d2a4c0c24d8a7b4e935bee23080e0685</hash><bytes>24944966</bytes><content_type>video/quicktime</content_type><last_modified>2008-12-18T10:35:19.273927</last_modified></object>'
|
187
|
+
lines << '</container>'
|
188
|
+
|
189
|
+
lines.join("\n\n")
|
190
|
+
end
|
191
|
+
|
192
|
+
def test_fetch_objects_detail
|
193
|
+
build_net_http_object(:code => '200', :body => object_detail_body)
|
160
194
|
details = @container.objects_detail
|
161
195
|
assert_equal details.size, 2
|
162
196
|
assert_equal details['kisscam.mov'][:bytes], '9196332'
|
163
197
|
end
|
164
198
|
|
199
|
+
def test_fetch_objects_details_with_limit
|
200
|
+
build_net_http_object_with_cfreq_expectations({:code => '200', :body => object_detail_body},
|
201
|
+
{:path => includes("limit=2")})
|
202
|
+
details = @container.objects_detail(:limit => 2)
|
203
|
+
assert_equal details.size, 2
|
204
|
+
assert_equal details['kisscam.mov'][:bytes], '9196332'
|
205
|
+
end
|
206
|
+
|
207
|
+
def test_fetch_objects_detail_with_marker
|
208
|
+
build_net_http_object_with_cfreq_expectations({:code => '200', :body => object_detail_body(true)},
|
209
|
+
{:path => includes("marker=kisscam.mov")})
|
210
|
+
details = @container.objects_detail(:marker => 'kisscam.mov')
|
211
|
+
assert_equal details.size, 1
|
212
|
+
assert_equal details['penaltybox.mov'][:bytes], '24944966'
|
213
|
+
end
|
214
|
+
|
215
|
+
def test_fetch_objects_detail_with_deprecated_offset_param
|
216
|
+
build_net_http_object_with_cfreq_expectations({:code => '200', :body => object_detail_body(true)},
|
217
|
+
{:path => includes("marker=kisscam.mov")})
|
218
|
+
details = @container.objects_detail(:offset => 'kisscam.mov')
|
219
|
+
assert_equal details.size, 1
|
220
|
+
assert_equal details['penaltybox.mov'][:bytes], '24944966'
|
221
|
+
end
|
222
|
+
|
223
|
+
|
165
224
|
def test_fetch_object_detail_empty
|
166
225
|
build_net_http_object
|
167
226
|
details = @container.objects_detail
|
@@ -182,17 +241,31 @@ class CloudfilesContainerTest < Test::Unit::TestCase
|
|
182
241
|
|
183
242
|
private
|
184
243
|
|
185
|
-
def build_net_http_object(args={:code => '204' })
|
244
|
+
def build_net_http_object(args={:code => '204' }, cfreq_expectations={})
|
186
245
|
CloudFiles::Container.any_instance.stubs(:populate).returns(true)
|
187
246
|
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https')
|
188
247
|
args[:response] = {} unless args[:response]
|
189
248
|
response = {'x-cdn-management-url' => 'http://cdn.example.com/path', 'x-storage-url' => 'http://cdn.example.com/storage', 'authtoken' => 'dummy_token', 'last-modified' => Time.now.to_s}.merge(args[:response])
|
190
249
|
response.stubs(:code).returns(args[:code])
|
191
250
|
response.stubs(:body).returns args[:body] || nil
|
192
|
-
|
251
|
+
|
252
|
+
if !cfreq_expectations.empty?
|
253
|
+
#cfreq(method,server,path,port,scheme,headers = {},data = nil,attempts = 0,&block)
|
254
|
+
|
255
|
+
parameter_expectations = [anything(), anything(), anything(), anything(), anything(), anything(), anything(), anything()]
|
256
|
+
parameter_expectations[0] = cfreq_expectations[:method] if cfreq_expectations[:method]
|
257
|
+
parameter_expectations[2] = cfreq_expectations[:path] if cfreq_expectations[:path]
|
258
|
+
|
259
|
+
connection.expects(:cfreq).with(*parameter_expectations).returns(response)
|
260
|
+
else
|
261
|
+
connection.stubs(:cfreq => response)
|
262
|
+
end
|
263
|
+
|
193
264
|
@container = CloudFiles::Container.new(connection, 'test_container')
|
194
265
|
@container.stubs(:connection).returns(connection)
|
195
266
|
end
|
196
267
|
|
197
|
-
|
268
|
+
def build_net_http_object_with_cfreq_expectations(args={:code => '204'}, cfreq_expectations={})
|
269
|
+
build_net_http_object(args, cfreq_expectations)
|
270
|
+
end
|
198
271
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudfiles
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 1.4.
|
9
|
+
- 9
|
10
|
+
version: 1.4.9
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- H. Wade Minter
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-
|
19
|
+
date: 2010-10-19 00:00:00 -04:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -34,6 +34,22 @@ dependencies:
|
|
34
34
|
version: "1.16"
|
35
35
|
type: :runtime
|
36
36
|
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: mocha
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 43
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
- 9
|
49
|
+
- 8
|
50
|
+
version: 0.9.8
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
37
53
|
description: A Ruby version of the Rackspace Cloud Files API.
|
38
54
|
email: minter@lunenburg.org
|
39
55
|
executables: []
|