Class: OpenstackBridge::Swift
- Inherits:
-
Struct
- Object
- Struct
- OpenstackBridge::Swift
- Defined in:
- lib/openstack_bridge/swift.rb
Instance Attribute Summary collapse
-
#authentication_response ⇒ Object
Returns the value of attribute authentication_response.
-
#container ⇒ Object
Returns the value of attribute container.
-
#host ⇒ Object
Returns the value of attribute host.
-
#password ⇒ Object
Returns the value of attribute password.
-
#tenant ⇒ Object
Returns the value of attribute tenant.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #create(path, content) ⇒ Object
- #delete(path) ⇒ Object
- #end_point ⇒ Object
- #exists?(path) ⇒ Boolean
- #file_path(path) ⇒ Object
-
#initialize ⇒ Swift
constructor
A new instance of Swift.
- #read(path) ⇒ Object
- #request(method, path, params = {}.to_json, httpclient = false) ⇒ Object
- #token ⇒ Object
Constructor Details
#initialize ⇒ Swift
Returns a new instance of Swift.
5 6 7 8 |
# File 'lib/openstack_bridge/swift.rb', line 5 def initialize(*) super self.authentication_response = OpenstackBridge::Authentication.new(host, user, password, tenant).response end |
Instance Attribute Details
#authentication_response ⇒ Object
Returns the value of attribute authentication_response.
3 4 5 |
# File 'lib/openstack_bridge/swift.rb', line 3 def authentication_response @authentication_response end |
#container ⇒ Object
Returns the value of attribute container
2 3 4 |
# File 'lib/openstack_bridge/swift.rb', line 2 def container @container end |
#host ⇒ Object
Returns the value of attribute host
2 3 4 |
# File 'lib/openstack_bridge/swift.rb', line 2 def host @host end |
#password ⇒ Object
Returns the value of attribute password
2 3 4 |
# File 'lib/openstack_bridge/swift.rb', line 2 def password @password end |
#tenant ⇒ Object
Returns the value of attribute tenant
2 3 4 |
# File 'lib/openstack_bridge/swift.rb', line 2 def tenant @tenant end |
#user ⇒ Object
Returns the value of attribute user
2 3 4 |
# File 'lib/openstack_bridge/swift.rb', line 2 def user @user end |
Instance Method Details
#create(path, content) ⇒ Object
34 35 36 |
# File 'lib/openstack_bridge/swift.rb', line 34 def create(path, content) request(:put, file_path(path), content) end |
#delete(path) ⇒ Object
30 31 32 |
# File 'lib/openstack_bridge/swift.rb', line 30 def delete(path) request(:delete, file_path(path)) end |
#end_point ⇒ Object
14 15 16 |
# File 'lib/openstack_bridge/swift.rb', line 14 def end_point self.authentication_response['access']['serviceCatalog'].detect {|s| s['name'] == 'swift'}['endpoints'].first['publicURL'] end |
#exists?(path) ⇒ Boolean
22 23 24 |
# File 'lib/openstack_bridge/swift.rb', line 22 def exists?(path) request(:head, file_path(path)).code == 200 end |
#file_path(path) ⇒ Object
18 19 20 |
# File 'lib/openstack_bridge/swift.rb', line 18 def file_path(path) "#{end_point}/#{container}/#{path}" end |
#read(path) ⇒ Object
26 27 28 |
# File 'lib/openstack_bridge/swift.rb', line 26 def read(path) request(:get, file_path(path)).raw_body end |
#request(method, path, params = {}.to_json, httpclient = false) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/openstack_bridge/swift.rb', line 39 def request(method, path, params={}.to_json, httpclient = false) request = HTTPI::Request.new request.url = path request.body = params request.headers['Content-Type'] = 'application/json' request.headers['X-Auth-Token'] = token HTTPI.send(method, request, (httpclient ? :httpclient : :curb)) end |
#token ⇒ Object
10 11 12 |
# File 'lib/openstack_bridge/swift.rb', line 10 def token self.authentication_response['access']['token']['id'] end |