Class: SwiftClient
- Inherits:
-
Object
show all
- Defined in:
- lib/swift_client.rb,
lib/swift_client/version.rb
Defined Under Namespace
Classes: AuthenticationError, EmptyNameError, OptionError, ResponseError, TempUrlKeyMissing
Constant Summary
collapse
- VERSION =
"0.0.3"
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#delete_container(container) ⇒ Object
-
#delete_object(object, container) ⇒ Object
-
#get_container(container, query = {}) ⇒ Object
-
#get_containers(query = {}) ⇒ Object
-
#get_object(object, container) ⇒ Object
-
#get_objects(container, query = {}) ⇒ Object
-
#head_container(container) ⇒ Object
-
#head_object(object, container) ⇒ Object
-
#initialize(options = {}) ⇒ SwiftClient
constructor
A new instance of SwiftClient.
-
#post_account(headers = {}) ⇒ Object
-
#post_container(container, headers = {}) ⇒ Object
-
#post_object(object, container, headers = {}) ⇒ Object
-
#public_url(object, container) ⇒ Object
-
#put_container(container, headers = {}) ⇒ Object
-
#put_object(object, data_or_io, container, headers = {}) ⇒ Object
-
#temp_url(object, container, opts = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ SwiftClient
Returns a new instance of SwiftClient.
29
30
31
32
33
34
35
36
37
|
# File 'lib/swift_client.rb', line 29
def initialize(options = {})
[:auth_url, :username, :api_key].each do |key|
raise(OptionError, "#{key} is missing") unless options.key?(key)
end
self.options = options
authenticate
end
|
Instance Attribute Details
#auth_token ⇒ Object
Returns the value of attribute auth_token.
27
28
29
|
# File 'lib/swift_client.rb', line 27
def auth_token
@auth_token
end
|
#options ⇒ Object
Returns the value of attribute options.
27
28
29
|
# File 'lib/swift_client.rb', line 27
def options
@options
end
|
#storage_url ⇒ Object
Returns the value of attribute storage_url.
27
28
29
|
# File 'lib/swift_client.rb', line 27
def storage_url
@storage_url
end
|
Instance Method Details
#delete_container(container) ⇒ Object
71
72
73
74
75
|
# File 'lib/swift_client.rb', line 71
def delete_container(container)
raise(EmptyNameError) if container.empty?
request :delete, "/#{container}"
end
|
#delete_object(object, container) ⇒ Object
106
107
108
109
110
|
# File 'lib/swift_client.rb', line 106
def delete_object(object, container)
raise(EmptyNameError) if object.empty? || container.empty?
request :delete, "/#{container}/#{object}"
end
|
#get_container(container, query = {}) ⇒ Object
47
48
49
50
51
|
# File 'lib/swift_client.rb', line 47
def get_container(container, query = {})
raise(EmptyNameError) if container.empty?
request :get, "/#{container}", :query => query
end
|
#get_containers(query = {}) ⇒ Object
43
44
45
|
# File 'lib/swift_client.rb', line 43
def get_containers(query = {})
request :get, "/", :query => query
end
|
#get_object(object, container) ⇒ Object
94
95
96
97
98
|
# File 'lib/swift_client.rb', line 94
def get_object(object, container)
raise(EmptyNameError) if object.empty? || container.empty?
request :get, "/#{container}/#{object}"
end
|
#get_objects(container, query = {}) ⇒ Object
112
113
114
115
116
|
# File 'lib/swift_client.rb', line 112
def get_objects(container, query = {})
raise(EmptyNameError) if container.empty?
request :get, "/#{container}", :query => query
end
|
#head_container(container) ⇒ Object
53
54
55
56
57
|
# File 'lib/swift_client.rb', line 53
def head_container(container)
raise(EmptyNameError) if container.empty?
request :head, "/#{container}"
end
|
#head_object(object, container) ⇒ Object
100
101
102
103
104
|
# File 'lib/swift_client.rb', line 100
def head_object(object, container)
raise(EmptyNameError) if object.empty? || container.empty?
request :head, "/#{container}/#{object}"
end
|
#post_account(headers = {}) ⇒ Object
39
40
41
|
# File 'lib/swift_client.rb', line 39
def post_account( = {})
request :post, "/", :headers =>
end
|
#post_container(container, headers = {}) ⇒ Object
65
66
67
68
69
|
# File 'lib/swift_client.rb', line 65
def post_container(container, = {})
raise(EmptyNameError) if container.empty?
request :post, "/#{container}", :headers =>
end
|
#post_object(object, container, headers = {}) ⇒ Object
88
89
90
91
92
|
# File 'lib/swift_client.rb', line 88
def post_object(object, container, = {})
raise(EmptyNameError) if object.empty? || container.empty?
request :post, "/#{container}/#{object}", :headers =>
end
|
#public_url(object, container) ⇒ Object
118
119
120
121
122
|
# File 'lib/swift_client.rb', line 118
def public_url(object, container)
raise(EmptyNameError) if object.empty? || container.empty?
"#{storage_url}/#{container}/#{object}"
end
|
#put_container(container, headers = {}) ⇒ Object
59
60
61
62
63
|
# File 'lib/swift_client.rb', line 59
def put_container(container, = {})
raise(EmptyNameError) if container.empty?
request :put, "/#{container}", :headers =>
end
|
#put_object(object, data_or_io, container, headers = {}) ⇒ Object
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/swift_client.rb', line 77
def put_object(object, data_or_io, container, = {})
raise(EmptyNameError) if object.empty? || container.empty?
mime_type = MIME::Types.of(object).first
= .dup
["Content-Type"] ||= mime_type.content_type if mime_type
request :put, "/#{container}/#{object}", :body => data_or_io.respond_to?(:read) ? data_or_io.read : data_or_io, :headers =>
end
|
#temp_url(object, container, opts = {}) ⇒ Object
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/swift_client.rb', line 124
def temp_url(object, container, opts = {})
raise(EmptyNameError) if object.empty? || container.empty?
raise(TempUrlKeyMissing) unless options[:temp_url_key]
expires = (Time.now + (options[:expires_in] || 3600).to_i).to_i
path = "/#{container}/#{object}"
signature = OpenSSL::HMAC.hexdigest("sha1", options[:temp_url_key], "GET\n#{expires}\n#{path}")
"#{storage_url}#{path}?temp_url_sig=#{signature}&temp_url_expires=#{expires}"
end
|