Skip to content

Commit

Permalink
Add support for specifying a CDN CNAME when getting a Rackspace Cloud…
Browse files Browse the repository at this point in the history
… Files directory.
  • Loading branch information
minter committed Jun 16, 2011
1 parent b4b6375 commit 2c85294
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/fog/storage/models/rackspace/directories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ def all
load(data)
end

# Supply the :cdn_cname option to use the Rackspace CDN CNAME functionality on the public_url.
#
# > fog.directories.get('video', :cdn_cname => 'http://cdn.lunenburg.org').files.first.public_url
# => 'http://cdn.lunenburg.org/hayley-dancing.mov'
def get(key, options = {})
data = connection.get_container(key, options)
directory = new(:key => key)
directory = new(:key => key, :cdn_cname => options[:cdn_cname])
for key, value in data.headers
if ['X-Container-Bytes-Used', 'X-Container-Object-Count'].include?(key)
directory.merge_attributes(key => value)
Expand Down
3 changes: 2 additions & 1 deletion lib/fog/storage/models/rackspace/directory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Directory < Fog::Model

attribute :bytes, :aliases => 'X-Container-Bytes-Used'
attribute :count, :aliases => 'X-Container-Object-Count'
attribute :cdn_cname

def destroy
requires :key
Expand Down Expand Up @@ -42,7 +43,7 @@ def public_url
if connection.rackspace_cdn_ssl == true
response.headers['X-CDN-SSL-URI']
else
response.headers['X-CDN-URI']
cdn_cname || response.headers['X-CDN-URI']
end
end
rescue Fog::Service::NotFound
Expand Down

0 comments on commit 2c85294

Please sign in to comment.