Class: Fog::Brightbox::Storage::Connection
- Inherits:
-
Core::Connection
- Object
- Core::Connection
- Fog::Brightbox::Storage::Connection
- Defined in:
- lib/fog/brightbox/storage/connection.rb
Instance Method Summary collapse
- #authenticated_headers ⇒ Object
- #connection_options ⇒ Object
- #default_headers ⇒ Object
-
#initialize(config) ⇒ Connection
constructor
A new instance of Connection.
- #management_url ⇒ Object
- #path_in_params(params) ⇒ Object
- #persistent? ⇒ Boolean
- #request(params, parse_json = true) ⇒ Object
- #request_headers(excon_params) ⇒ Object
Constructor Details
#initialize(config) ⇒ Connection
Returns a new instance of Connection.
8 9 10 11 12 13 14 15 16 |
# File 'lib/fog/brightbox/storage/connection.rb', line 8 def initialize(config) @config = config if management_url @connection = super(management_url.to_s, persistent?, ) else raise ManagementUrlUnknown end end |
Instance Method Details
#authenticated_headers ⇒ Object
60 61 62 63 64 |
# File 'lib/fog/brightbox/storage/connection.rb', line 60 def authenticated_headers default_headers.merge( "X-Auth-Token" => @config.latest_access_token ) end |
#connection_options ⇒ Object
77 78 79 |
# File 'lib/fog/brightbox/storage/connection.rb', line 77 def @config. end |
#default_headers ⇒ Object
66 67 68 69 70 71 |
# File 'lib/fog/brightbox/storage/connection.rb', line 66 def default_headers { "Content-Type" => "application/json", "Accept" => "application/json" } end |
#management_url ⇒ Object
40 41 42 |
# File 'lib/fog/brightbox/storage/connection.rb', line 40 def management_url @config.storage_management_url end |
#path_in_params(params) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/fog/brightbox/storage/connection.rb', line 44 def path_in_params(params) if params.respond_to?(:key?) && params.key?(:path) URI.join(@config.storage_management_url.to_s + "/", params[:path]).path else @config.storage_management_url.path end end |
#persistent? ⇒ Boolean
73 74 75 |
# File 'lib/fog/brightbox/storage/connection.rb', line 73 def persistent? @config.connection_persistent? end |
#request(params, parse_json = true) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/fog/brightbox/storage/connection.rb', line 18 def request(params, parse_json = true) begin raise ArgumentError if params.nil? request_params = params.merge( :headers => request_headers(params), :path => path_in_params(params) ) response = @connection.request(request_params) rescue Excon::Errors::Unauthorized => error raise AuthenticationRequired.slurp(error) rescue Excon::Errors::NotFound => error raise Fog::Storage::Brightbox::NotFound.slurp(error) rescue Excon::Errors::HTTPStatusError => error raise error end if !response.body.empty? && parse_json && response.get_header("Content-Type") =~ %r{application/json} response.body = Fog::JSON.decode(response.body) end response end |
#request_headers(excon_params) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/fog/brightbox/storage/connection.rb', line 52 def request_headers(excon_params) if excon_params.respond_to?(:key?) && excon_params.key?(:headers) authenticated_headers.merge(excon_params[:headers]) else authenticated_headers end end |