Class: Stacktor::Swift::V1::Client
Instance Method Summary
collapse
#before_request, #execute_request, #initialize, #settings, #url, #url=
Instance Method Details
#create_object(opts) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/stacktor/swift/v1/client.rb', line 36
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
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/stacktor/swift/v1/client.rb', line 67
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
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/stacktor/swift/v1/client.rb', line 23
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
|
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/stacktor/swift/v1/client.rb', line 79
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
97
98
99
|
# File 'lib/stacktor/swift/v1/client.rb', line 97
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
|
#token ⇒ Object
94
95
96
|
# File 'lib/stacktor/swift/v1/client.rb', line 94
def token
@settings[:token]
end
|
#token=(val) ⇒ Object
91
92
93
|
# File 'lib/stacktor/swift/v1/client.rb', line 91
def token=(val)
@settings[:token] = val
end
|