Class: Fog::Rackspace::Files
- Inherits:
-
Object
- Object
- Fog::Rackspace::Files
- Defined in:
- lib/fog/rackspace/files.rb,
lib/fog/rackspace/requests/files/get_containers.rb,
lib/fog/rackspace/requests/files/head_containers.rb
Class Method Summary collapse
Instance Method Summary collapse
- #cdn_request(params) ⇒ Object
-
#get_containers(options = {}) ⇒ Object
List existing storage containers.
-
#head_containers ⇒ Object
List number of containers and total bytes stored.
-
#initialize(options = {}) ⇒ Files
constructor
A new instance of Files.
- #storage_request(params) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Files
Returns a new instance of Files.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/fog/rackspace/files.rb', line 9 def initialize(={}) credentials = Fog::Rackspace.authenticate() @auth_token = credentials['X-Auth-Token'] cdn_uri = URI.parse(credentials['X-CDN-Management-Url']) @cdn_host = cdn_uri.host @cdn_path = cdn_uri.path @cdn_port = cdn_uri.port @cdn_scheme = cdn_uri.scheme storage_uri = URI.parse(credentials['X-Storage-Url']) @storage_host = storage_uri.host @storage_path = storage_uri.path @storage_port = storage_uri.port @storage_scheme = storage_uri.scheme @connection = Fog::Connection.new("#{@storage_scheme}://#{@storage_host}:#{@storage_port}") end |
Class Method Details
.reload ⇒ Object
5 6 7 |
# File 'lib/fog/rackspace/files.rb', line 5 def self.reload load "fog/rackspace/requests/files/get_containers.rb" end |
Instance Method Details
#cdn_request(params) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/fog/rackspace/files.rb', line 25 def cdn_request(params) response = @connection.request({ :body => params[:body], :expects => params[:expects], :headers => { 'X-Auth-Token' => @auth_token }, :host => @cdn_host, :method => params[:method], :path => "#{@cdn_path}/#{params[:path]}" }) unless response.status == 204 response.body = JSON.parse(response.body) end response end |
#get_containers(options = {}) ⇒ Object
List existing storage containers
Parameters
-
options<~Hash>:
-
‘limit’<~Integer> - Upper limit to number of results returned
-
‘marker’<~String> - Only return objects with name greater than this value
-
Returns
-
response<~Fog::AWS::Response>:
-
body<~Array>:
-
container<~Hash>:
-
‘bytes’<~Integer>: - Number of bytes used by container
-
‘count’<~Integer>: - Number of items in container
-
‘name’<~String>: - Name of container
-
-
-
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fog/rackspace/requests/files/get_containers.rb', line 21 def get_containers( = {}) = { 'format' => 'json' }.merge!() query = [] for key, value in query << "#{key}=#{CGI.escape(value)}" end response = storage_request( :expects => [200, 204], :method => 'GET', :path => '', :query => query.join('&') ) if response.status == 204 response.body = [] end response end |
#head_containers ⇒ Object
List number of containers and total bytes stored
Returns
-
response<~Fog::AWS::Response>:
-
headers<~Hash>:
-
‘X-Account-Container-Count’<~String> - Count of containers
-
‘X-Account-Bytes-Used’<~String> - Bytes used
-
-
14 15 16 17 18 19 20 21 22 |
# File 'lib/fog/rackspace/requests/files/head_containers.rb', line 14 def head_containers response = storage_request( :expects => 204, :method => 'HEAD', :path => '', :query => 'format=json' ) response end |
#storage_request(params) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/fog/rackspace/files.rb', line 42 def storage_request(params) response = @connection.request({ :body => params[:body], :expects => params[:expects], :headers => { 'X-Auth-Token' => @auth_token }, :host => @storage_host, :method => params[:method], :path => "#{@storage_path}/#{params[:path]}" }) unless response.status == 204 response.body = JSON.parse(response.body) end response end |