[rackspace|storage] added account model

This commit is contained in:
Kyle Rames 2013-02-15 14:26:45 -06:00
parent 374af71c2b
commit 8ce9044be1
4 changed files with 66 additions and 0 deletions

View File

@ -0,0 +1,24 @@
require 'fog/core/model'
module Fog
module Storage
class Rackspace
class Account < Fog::Model
attribute :meta_temp_url_key, :aliases => 'X-Account-Meta-Temp-Url-Key'
attribute :container_count, :aliases => 'X-Account-Container-Count', :type => :integer
attribute :bytes_used, :aliases => 'X-Account-Bytes-Used', :type => :integer
attribute :object_count, :aliases => 'X-Account-Object-Count', :type => :integer
def save
service.post_set_meta_temp_url_key meta_temp_url_key
true
end
def reload
response = service.head_containers
merge_attributes response.headers
end
end
end
end
end

View File

@ -14,6 +14,7 @@ module Fog
collection :directories
model :file
collection :files
model :account
request_path 'fog/rackspace/requests/storage'
request :copy_object
@ -98,6 +99,11 @@ module Fog
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
end
def account
account = Fog::Storage::Rackspace::Account.new(:service => self)
account.reload
end
def reload
@connection.reset
end

View File

@ -0,0 +1,28 @@
Shindo.tests('Fog::Rackspace::Storage | account', ['rackspace']) do
pending if Fog.mocking?
@account = Fog::Storage[:rackspace].account
tests('load') do
headers = @account.service.head_containers.headers
returns(headers['X-Account-Meta-Temp-Url-Key']) { @account.meta_temp_url_key }
returns(headers['X-Account-Container-Count'].to_i) { @account.container_count }
returns(headers['X-Account-Bytes-Used'].to_i) { @account.bytes_used }
returns(headers['X-Account-Object-Count'].to_i) { @account.object_count }
end
tests('reload') do
@account.reload
end
tests('save') do
key = "testing-update-#{Time.now.to_i}"
@account.meta_temp_url_key = "testing-update-#{Time.now.to_i}"
@account.save
headers = @account.service.head_containers.headers
returns(key) { headers['X-Account-Meta-Temp-Url-Key'] }
end
end

View File

@ -0,0 +1,8 @@
Shindo.tests('Fog::Storage::Rackspace', ['rackspace']) do |variable|
pending if Fog.mocking?
tests('account').succeeds do
Fog::Storage[:rackspace].account
end
end