Added docs/tests for Storage's public_url

This commit is contained in:
Matt Darby 2014-10-31 13:37:40 -04:00
parent 0136ab1cb9
commit d59779cf46
4 changed files with 43 additions and 21 deletions

View File

@ -268,6 +268,15 @@ directory.destroy
**Note**: Directory must be empty before it can be deleted.
## Directory URL
To get a directory's URL:
```ruby
directory.public_url
```
## List Files
To list files in a directory:
@ -384,6 +393,14 @@ File.open('germany.jpg', 'w') {|f| f.write(file_object.body) }
**Note**: This method is more memory intensive as the entire object is loaded into memory before saving the file as in the example above.
## File URL
To get a file's URL:
```ruby
file.public_url
```
## Metadata
You can access metadata as an attribute on `Fog::Storage::Rackspace::File`.
@ -439,3 +456,4 @@ file.destroy
## Support and Feedback
Your feedback is appreciated! If you have specific issues with the **fog** SDK, you should file an [issue via Github](https://github.com/fog/fog/issues).

View File

@ -31,13 +31,11 @@ module Fog
def public_url
requires :key
@public_url ||= begin
begin response = service.head_container(key)
# escape the key to cover for special char. in container names
url = service.public_url(key)
rescue Fog::Storage::OpenStack::NotFound => err
nil
end
service.public_url(key)
rescue Fog::Storage::OpenStack::NotFound => err
nil
end
end

View File

@ -3,10 +3,6 @@ module Fog
class OpenStack
class Real
def url
"#{@scheme}://#{@host}:#{@port}#{@path}"
end
# Get public_url for an object
#
# ==== Parameters
@ -14,18 +10,18 @@ module Fog
# * object<~String> - Name of object to look for
#
def public_url(container=nil, object=nil)
public_url = nil
unless container.nil?
if object.nil?
# return container public url
public_url = "#{url}/#{Fog::OpenStack.escape(container)}"
else
# return object public url
public_url = "#{url}/#{Fog::OpenStack.escape(container)}/#{Fog::OpenStack.escape(object)}"
end
end
public_url
return nil if container.nil?
u = "#{url}/#{Fog::OpenStack.escape(container)}"
u << "/#{Fog::OpenStack.escape(object)}" unless object.nil?
u
end
private
def url
"#{@scheme}://#{@host}:#{@port}#{@path}"
end
end
end
end

View File

@ -31,6 +31,16 @@ Shindo.tests('Fog::Storage[:openstack] | object requests', ["openstack"]) do
data == lorem_file.read
end
tests("#public_url('fogobjectests', 'fog_object')").succeeds do
pending if Fog.mocking?
Fog::Storage[:openstack].directories.first.files.first.public_url
end
tests("#public_url('fogobjectests')").succeeds do
pending if Fog.mocking?
Fog::Storage[:openstack].directories.first.public_url
end
tests("#head_object('fogobjectests', 'fog_object')").succeeds do
pending if Fog.mocking?
Fog::Storage[:openstack].head_object('fogobjecttests', 'fog_object')