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.1.3"
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#delete_container(container_name) ⇒ Object
-
#delete_object(object_name, container_name) ⇒ Object
-
#get_container(container_name, query = {}) ⇒ Object
-
#get_containers(query = {}) ⇒ Object
-
#get_object(object_name, container_name) ⇒ Object
-
#get_objects(container_name, query = {}) ⇒ Object
-
#head_account ⇒ Object
-
#head_container(container_name) ⇒ Object
-
#head_containers ⇒ Object
-
#head_object(object_name, container_name) ⇒ Object
-
#initialize(options = {}) ⇒ SwiftClient
constructor
A new instance of SwiftClient.
-
#paginate_container(container_name, query = {}, &block) ⇒ Object
-
#paginate_containers(query = {}, &block) ⇒ Object
-
#paginate_objects(container_name, query = {}, &block) ⇒ Object
-
#post_account(headers = {}) ⇒ Object
-
#post_container(container_name, headers = {}) ⇒ Object
-
#post_object(object_name, container_name, headers = {}) ⇒ Object
-
#public_url(object_name, container_name) ⇒ Object
-
#put_container(container_name, headers = {}) ⇒ Object
-
#put_object(object_name, data_or_io, container_name, headers = {}) ⇒ Object
-
#temp_url(object_name, container_name, opts = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ SwiftClient
Returns a new instance of SwiftClient.
30
31
32
33
34
35
36
|
# File 'lib/swift_client.rb', line 30
def initialize(options = {})
raise(OptionError, "Setting expires_in connection wide is deprecated") if options[:expires_in]
self.options = options
authenticate
end
|
Instance Attribute Details
#auth_token ⇒ Object
Returns the value of attribute auth_token.
28
29
30
|
# File 'lib/swift_client.rb', line 28
def auth_token
@auth_token
end
|
#options ⇒ Object
Returns the value of attribute options.
28
29
30
|
# File 'lib/swift_client.rb', line 28
def options
@options
end
|
#storage_url ⇒ Object
Returns the value of attribute storage_url.
28
29
30
|
# File 'lib/swift_client.rb', line 28
def storage_url
@storage_url
end
|
Instance Method Details
#delete_container(container_name) ⇒ Object
86
87
88
89
90
|
# File 'lib/swift_client.rb', line 86
def delete_container(container_name)
raise(EmptyNameError) if container_name.empty?
request :delete, "/#{container_name}"
end
|
#delete_object(object_name, container_name) ⇒ Object
127
128
129
130
131
|
# File 'lib/swift_client.rb', line 127
def delete_object(object_name, container_name)
raise(EmptyNameError) if object_name.empty? || container_name.empty?
request :delete, "/#{container_name}/#{object_name}"
end
|
#get_container(container_name, query = {}) ⇒ Object
58
59
60
61
62
|
# File 'lib/swift_client.rb', line 58
def get_container(container_name, query = {})
raise(EmptyNameError) if container_name.empty?
request :get, "/#{container_name}", :query => query
end
|
#get_containers(query = {}) ⇒ Object
50
51
52
|
# File 'lib/swift_client.rb', line 50
def get_containers(query = {})
request :get, "/", :query => query
end
|
#get_object(object_name, container_name) ⇒ Object
115
116
117
118
119
|
# File 'lib/swift_client.rb', line 115
def get_object(object_name, container_name)
raise(EmptyNameError) if object_name.empty? || container_name.empty?
request :get, "/#{container_name}/#{object_name}"
end
|
#get_objects(container_name, query = {}) ⇒ Object
133
134
135
136
137
|
# File 'lib/swift_client.rb', line 133
def get_objects(container_name, query = {})
raise(EmptyNameError) if container_name.empty?
request :get, "/#{container_name}", :query => query
end
|
#head_account ⇒ Object
38
39
40
|
# File 'lib/swift_client.rb', line 38
def head_account
request :head, "/"
end
|
#head_container(container_name) ⇒ Object
68
69
70
71
72
|
# File 'lib/swift_client.rb', line 68
def head_container(container_name)
raise(EmptyNameError) if container_name.empty?
request :head, "/#{container_name}"
end
|
#head_containers ⇒ Object
46
47
48
|
# File 'lib/swift_client.rb', line 46
def head_containers
request :head, "/"
end
|
#head_object(object_name, container_name) ⇒ Object
121
122
123
124
125
|
# File 'lib/swift_client.rb', line 121
def head_object(object_name, container_name)
raise(EmptyNameError) if object_name.empty? || container_name.empty?
request :head, "/#{container_name}/#{object_name}"
end
|
#paginate_container(container_name, query = {}, &block) ⇒ Object
64
65
66
|
# File 'lib/swift_client.rb', line 64
def paginate_container(container_name, query = {}, &block)
paginate :get_container, container_name, query, &block
end
|
#paginate_containers(query = {}, &block) ⇒ Object
54
55
56
|
# File 'lib/swift_client.rb', line 54
def paginate_containers(query = {}, &block)
paginate :get_containers, query, &block
end
|
#paginate_objects(container_name, query = {}, &block) ⇒ Object
139
140
141
|
# File 'lib/swift_client.rb', line 139
def paginate_objects(container_name, query = {}, &block)
paginate :get_objects, container_name, query, &block
end
|
#post_account(headers = {}) ⇒ Object
42
43
44
|
# File 'lib/swift_client.rb', line 42
def post_account( = {})
request :post, "/", :headers =>
end
|
#post_container(container_name, headers = {}) ⇒ Object
80
81
82
83
84
|
# File 'lib/swift_client.rb', line 80
def post_container(container_name, = {})
raise(EmptyNameError) if container_name.empty?
request :post, "/#{container_name}", :headers =>
end
|
#post_object(object_name, container_name, headers = {}) ⇒ Object
109
110
111
112
113
|
# File 'lib/swift_client.rb', line 109
def post_object(object_name, container_name, = {})
raise(EmptyNameError) if object_name.empty? || container_name.empty?
request :post, "/#{container_name}/#{object_name}", :headers =>
end
|
#public_url(object_name, container_name) ⇒ Object
143
144
145
146
147
|
# File 'lib/swift_client.rb', line 143
def public_url(object_name, container_name)
raise(EmptyNameError) if object_name.empty? || container_name.empty?
"#{storage_url}/#{container_name}/#{object_name}"
end
|
#put_container(container_name, headers = {}) ⇒ Object
74
75
76
77
78
|
# File 'lib/swift_client.rb', line 74
def put_container(container_name, = {})
raise(EmptyNameError) if container_name.empty?
request :put, "/#{container_name}", :headers =>
end
|
#put_object(object_name, data_or_io, container_name, headers = {}) ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/swift_client.rb', line 92
def put_object(object_name, data_or_io, container_name, = {})
raise(EmptyNameError) if object_name.empty? || container_name.empty?
mime_type = MIME::Types.of(object_name).first
= ( || {}).dup
unless (, "Content-Type")
["Content-Type"] = mime_type.content_type if mime_type
["Content-Type"] ||= "application/octet-stream"
end
["Transfer-Encoding"] = "chunked"
request :put, "/#{container_name}/#{object_name}", :body_stream => data_or_io.respond_to?(:read) ? data_or_io : StringIO.new(data_or_io), :headers =>
end
|
#temp_url(object_name, container_name, opts = {}) ⇒ Object
149
150
151
152
153
154
155
156
157
158
159
|
# File 'lib/swift_client.rb', line 149
def temp_url(object_name, container_name, opts = {})
raise(EmptyNameError) if object_name.empty? || container_name.empty?
raise(TempUrlKeyMissing) unless options[:temp_url_key]
expires = (Time.now + (opts[:expires_in] || 3600).to_i).to_i
path = URI.parse("#{storage_url}/#{container_name}/#{object_name}").path
signature = OpenSSL::HMAC.hexdigest("sha1", options[:temp_url_key], "GET\n#{expires}\n#{path}")
"#{storage_url}/#{container_name}/#{object_name}?temp_url_sig=#{signature}&temp_url_expires=#{expires}"
end
|