Class: Stacktor::Swift::V1::Client
Instance Method Summary
collapse
#before_request, #execute_request, #initialize, #settings, #url, #url=
Instance Method Details
#create_object(opts) ⇒ Hash
Stores object in Swift container
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/stacktor/swift/v1/client.rb', line 65
def create_object(opts)
ctn = opts[:container_name]
obn = opts[:object_name]
if opts[:content].is_a?(String)
body = StringIO.new(opts[:content])
else
body = opts[:content]
end
= {}
if opts[:content_type].nil?
['X-Detect-Content-Type'] = 'true'
else
['Content-Type'] = opts[:content_type]
end
if !opts[:metadata].nil?
opts[:metadata].each do |k,v|
["X-Object-Meta-#{k}"] = v
end
end
resp = self.execute_request(
path: "/#{ctn}/#{obn}",
method: "PUT",
headers: ,
data: body
)
parse_object(resp, {'name' => obn, 'container_name' => ctn})
resp[:object].reload if resp[:object]
return resp
end
|
#delete_object(opts) ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/stacktor/swift/v1/client.rb', line 96
def delete_object(opts)
ctn = opts[:container_name]
obn = opts[:object_name]
resp = self.execute_request(
path: "/#{ctn}/#{obn}",
method: "DELETE"
)
parse_object(resp, {'name' => obn, 'container_name' => ctn})
return resp
end
|
#get_object_content(opts, &resp_fn) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/stacktor/swift/v1/client.rb', line 40
def get_object_content(opts, &resp_fn)
ctn = opts[:container_name]
obn = opts[:object_name]
resp = self.execute_request(
path: "/#{ctn}/#{obn}",
method: "GET",
response_handler: resp_fn
)
parse_object(resp, {'name' => obn, 'container_name' => ctn})
return resp
end
|
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/stacktor/swift/v1/client.rb', line 108
def get_object_metadata(opts)
ctn = opts[:container_name]
obn = opts[:object_name]
resp = self.execute_request(
path: "/#{ctn}/#{obn}",
method: "HEAD"
)
parse_object(resp, {'name' => obn, 'container_name' => ctn})
return resp
end
|
#has_valid_token? ⇒ Boolean
128
129
130
|
# File 'lib/stacktor/swift/v1/client.rb', line 128
def has_valid_token?
@settings[:token] && @settings[:token].valid?
end
|
#list_containers(opts = {}) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/stacktor/swift/v1/client.rb', line 9
def list_containers(opts={})
path = "/"
opts[:format] = 'json'
resp = self.execute_request(
path: path,
method: "GET",
data: opts
)
parse_containers(resp)
return resp
end
|
#list_objects(opts) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/stacktor/swift/v1/client.rb', line 21
def list_objects(opts)
ctn = opts[:container_name]
data = {}
data[:limit] = opts[:limit] || 1000
data[:marker] = opts[:marker] if opts[:marker]
data[:end_marker] = opts[:end_marker] if opts[:end_marker]
data[:format] = 'json'
data[:delimiter] = opts[:delimiter] if opts[:delimiter]
data[:path] = opts[:path] if opts[:path]
result = self.execute_request(
path: "/#{ctn}",
method: "GET",
data: data
)
parse_objects(result, {'container_name' => ctn})
return result
end
|
#token ⇒ Object
125
126
127
|
# File 'lib/stacktor/swift/v1/client.rb', line 125
def token
@settings[:token]
end
|
#token=(val) ⇒ Object
122
123
124
|
# File 'lib/stacktor/swift/v1/client.rb', line 122
def token=(val)
@settings[:token] = val
end
|