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.
5 6 7 8 9 10 11 12 13 |
# File 'lib/fog/brightbox/storage/connection.rb', line 5 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
57 58 59 60 61 |
# File 'lib/fog/brightbox/storage/connection.rb', line 57 def authenticated_headers default_headers.merge( "X-Auth-Token" => @config.latest_access_token ) end |
#connection_options ⇒ Object
74 75 76 |
# File 'lib/fog/brightbox/storage/connection.rb', line 74 def @config. end |
#default_headers ⇒ Object
63 64 65 66 67 68 |
# File 'lib/fog/brightbox/storage/connection.rb', line 63 def default_headers { "Content-Type" => "application/json", "Accept" => "application/json" } end |
#management_url ⇒ Object
37 38 39 |
# File 'lib/fog/brightbox/storage/connection.rb', line 37 def management_url @config.storage_management_url end |
#path_in_params(params) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/fog/brightbox/storage/connection.rb', line 41 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
70 71 72 |
# File 'lib/fog/brightbox/storage/connection.rb', line 70 def persistent? @config.connection_persistent? end |
#request(params, parse_json = true) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/fog/brightbox/storage/connection.rb', line 15 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::Brightbox::Storage::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
49 50 51 52 53 54 55 |
# File 'lib/fog/brightbox/storage/connection.rb', line 49 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 |