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.5"
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_account ⇒ Object
-
#head_container(container) ⇒ Object
-
#head_containers ⇒ 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
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
79
80
81
82
83
|
# File 'lib/swift_client.rb', line 79
def delete_container(container)
raise(EmptyNameError) if container.empty?
request :delete, "/#{container}"
end
|
#delete_object(object, container) ⇒ Object
114
115
116
117
118
|
# File 'lib/swift_client.rb', line 114
def delete_object(object, container)
raise(EmptyNameError) if object.empty? || container.empty?
request :delete, "/#{container}/#{object}"
end
|
#get_container(container, query = {}) ⇒ Object
55
56
57
58
59
|
# File 'lib/swift_client.rb', line 55
def get_container(container, query = {})
raise(EmptyNameError) if container.empty?
request :get, "/#{container}", :query => query
end
|
#get_containers(query = {}) ⇒ Object
51
52
53
|
# File 'lib/swift_client.rb', line 51
def get_containers(query = {})
request :get, "/", :query => query
end
|
#get_object(object, container) ⇒ Object
102
103
104
105
106
|
# File 'lib/swift_client.rb', line 102
def get_object(object, container)
raise(EmptyNameError) if object.empty? || container.empty?
request :get, "/#{container}/#{object}"
end
|
#get_objects(container, query = {}) ⇒ Object
120
121
122
123
124
|
# File 'lib/swift_client.rb', line 120
def get_objects(container, query = {})
raise(EmptyNameError) if container.empty?
request :get, "/#{container}", :query => query
end
|
#head_account ⇒ Object
39
40
41
|
# File 'lib/swift_client.rb', line 39
def head_account
request :head, "/"
end
|
#head_container(container) ⇒ Object
61
62
63
64
65
|
# File 'lib/swift_client.rb', line 61
def head_container(container)
raise(EmptyNameError) if container.empty?
request :head, "/#{container}"
end
|
#head_containers ⇒ Object
47
48
49
|
# File 'lib/swift_client.rb', line 47
def head_containers
request :head, "/"
end
|
#head_object(object, container) ⇒ Object
108
109
110
111
112
|
# File 'lib/swift_client.rb', line 108
def head_object(object, container)
raise(EmptyNameError) if object.empty? || container.empty?
request :head, "/#{container}/#{object}"
end
|
#post_account(headers = {}) ⇒ Object
43
44
45
|
# File 'lib/swift_client.rb', line 43
def post_account( = {})
request :post, "/", :headers =>
end
|
#post_container(container, headers = {}) ⇒ Object
73
74
75
76
77
|
# File 'lib/swift_client.rb', line 73
def post_container(container, = {})
raise(EmptyNameError) if container.empty?
request :post, "/#{container}", :headers =>
end
|
#post_object(object, container, headers = {}) ⇒ Object
96
97
98
99
100
|
# File 'lib/swift_client.rb', line 96
def post_object(object, container, = {})
raise(EmptyNameError) if object.empty? || container.empty?
request :post, "/#{container}/#{object}", :headers =>
end
|
#public_url(object, container) ⇒ Object
126
127
128
129
130
|
# File 'lib/swift_client.rb', line 126
def public_url(object, container)
raise(EmptyNameError) if object.empty? || container.empty?
"#{storage_url}/#{container}/#{object}"
end
|
#put_container(container, headers = {}) ⇒ Object
67
68
69
70
71
|
# File 'lib/swift_client.rb', line 67
def put_container(container, = {})
raise(EmptyNameError) if container.empty?
request :put, "/#{container}", :headers =>
end
|
#put_object(object, data_or_io, container, headers = {}) ⇒ Object
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/swift_client.rb', line 85
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
132
133
134
135
136
137
138
139
140
141
142
|
# File 'lib/swift_client.rb', line 132
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 = URI.parse("#{storage_url}/#{container}/#{object}").path
signature = OpenSSL::HMAC.hexdigest("sha1", options[:temp_url_key], "GET\n#{expires}\n#{path}")
"#{storage_url}/#{container}/#{object}?temp_url_sig=#{signature}&temp_url_expires=#{expires}"
end
|