diff --git a/lib/fog/rackspace/block_storage.rb b/lib/fog/rackspace/block_storage.rb index f88b0e5b7..2d894735f 100644 --- a/lib/fog/rackspace/block_storage.rb +++ b/lib/fog/rackspace/block_storage.rb @@ -87,8 +87,8 @@ module Fog @connection = Fog::Connection.new(endpoint_uri.to_s, @persistent, @connection_options) end - def request(params, parse_json = true, &block) - super(params, parse_json, &block) + def request(params, parse_json = true) + super rescue Excon::Errors::NotFound => error raise NotFound.slurp(error, self) rescue Excon::Errors::BadRequest => error diff --git a/lib/fog/rackspace/cdn.rb b/lib/fog/rackspace/cdn.rb index ebc00d324..3fb2e3fc7 100644 --- a/lib/fog/rackspace/cdn.rb +++ b/lib/fog/rackspace/cdn.rb @@ -13,13 +13,13 @@ module Fog request :post_container request :put_container request :delete_object - - + + module Base - URI_HEADERS = { + URI_HEADERS = { "X-Cdn-Ios-Uri" => :ios_uri, "X-Cdn-Uri" => :uri, - "X-Cdn-Streaming-Uri" => :streaming_uri, + "X-Cdn-Streaming-Uri" => :streaming_uri, "X-Cdn-Ssl-Uri" => :ssl_uri }.freeze @@ -53,7 +53,7 @@ module Fog return {} unless publish urls_from_headers(response.headers) end - + # Returns hash of urls for container # @param [Fog::Storage::Rackspace::Directory] container to retrieve urls for # @return [Hash] hash containing urls for published container @@ -62,7 +62,7 @@ module Fog # @raise [Fog::Storage::Rackspace::ServiceError] # @note If unable to find container or container is not published this method will return an empty hash. def urls(container) - begin + begin response = head_container(container.key) return {} unless response.headers['X-Cdn-Enabled'] == 'True' urls_from_headers response.headers @@ -70,17 +70,17 @@ module Fog {} end end - + private - + def urls_from_headers(headers) h = {} URI_HEADERS.keys.each do | header | - key = URI_HEADERS[header] + key = URI_HEADERS[header] h[key] = headers[header] end h - end + end end class Mock < Fog::Rackspace::Service @@ -103,16 +103,16 @@ module Fog def data self.class.data[@rackspace_username] end - + def purge(object) - return true if object.is_a? Fog::Storage::Rackspace::File - raise Fog::Errors::NotImplemented.new("#{object.class} does not support CDN purging") if object + return true if object.is_a? Fog::Storage::Rackspace::File + raise Fog::Errors::NotImplemented.new("#{object.class} does not support CDN purging") if object end def reset_data self.class.data.delete(@rackspace_username) end - + end class Real < Fog::Rackspace::Service @@ -122,7 +122,7 @@ module Fog # api_key and username missing from instance variable sets @rackspace_api_key = options[:rackspace_api_key] @rackspace_username = options[:rackspace_username] - + @connection_options = options[:connection_options] || {} @rackspace_auth_url = options[:rackspace_auth_url] @rackspace_cdn_url = options[:rackspace_cdn_url] @@ -147,7 +147,7 @@ module Fog def reload @cdn_connection.reset end - + # Purges File # @param [Fog::Storage::Rackspace::File] file to be purged from the CDN # @raise [Fog::Errors::NotImplemented] returned when non file parameters are specified @@ -155,13 +155,13 @@ module Fog unless file.is_a? Fog::Storage::Rackspace::File raise Fog::Errors::NotImplemented.new("#{object.class} does not support CDN purging") if object end - + delete_object file.directory.key, file.key true - end + end - def request(params, parse_json = true, &block) - super(params, parse_json, &block) + def request(params, parse_json = true) + super rescue Excon::Errors::NotFound => error raise Fog::Storage::Rackspace::NotFound.slurp(error, self) rescue Excon::Errors::BadRequest => error @@ -171,9 +171,9 @@ module Fog rescue Excon::Errors::HTTPStatusError => error raise Fog::Storage::Rackspace::ServiceError.slurp(error, self) end - - private - + + private + def authenticate_v1(options) credentials = Fog::Rackspace.authenticate(options, @connection_options) endpoint_uri credentials['X-CDN-Management-Url'] diff --git a/lib/fog/rackspace/compute.rb b/lib/fog/rackspace/compute.rb index b8ee75c5b..a79922e2b 100644 --- a/lib/fog/rackspace/compute.rb +++ b/lib/fog/rackspace/compute.rb @@ -205,8 +205,8 @@ module Fog @connection.reset end - def request(params, parse_json = true, &block) - super(params, parse_json, &block) + def request(params, parse_json = true) + super rescue Excon::Errors::NotFound => error raise NotFound.slurp(error, self) rescue Excon::Errors::BadRequest => error diff --git a/lib/fog/rackspace/compute_v2.rb b/lib/fog/rackspace/compute_v2.rb index 0f540fbe5..dd60cd5d4 100644 --- a/lib/fog/rackspace/compute_v2.rb +++ b/lib/fog/rackspace/compute_v2.rb @@ -148,8 +148,8 @@ module Fog @connection = Fog::Connection.new(endpoint_uri.to_s, @persistent, @connection_options) end - def request(params, parse_json = true, &block) - super(params, parse_json, &block) + def request(params, parse_json = true) + super rescue Excon::Errors::NotFound => error raise NotFound.slurp(error, self) rescue Excon::Errors::BadRequest => error diff --git a/lib/fog/rackspace/databases.rb b/lib/fog/rackspace/databases.rb index d4bd9c911..4a5321426 100644 --- a/lib/fog/rackspace/databases.rb +++ b/lib/fog/rackspace/databases.rb @@ -85,8 +85,8 @@ module Fog @connection = Fog::Connection.new(endpoint_uri.to_s, @persistent, @connection_options) end - def request(params, parse_json = true, &block) - super(params, parse_json, &block) + def request(params, parse_json = true) + super rescue Excon::Errors::NotFound => error raise NotFound.slurp(error, self) rescue Excon::Errors::BadRequest => error diff --git a/lib/fog/rackspace/dns.rb b/lib/fog/rackspace/dns.rb index 08021c2d2..ad55f4a32 100644 --- a/lib/fog/rackspace/dns.rb +++ b/lib/fog/rackspace/dns.rb @@ -111,22 +111,20 @@ module Fog private - def request(params, parse_json = true, &block) - begin - super(params, parse_json, &block) - rescue Excon::Errors::NotFound => error - raise NotFound.slurp(error, self) - rescue Excon::Errors::BadRequest => error - raise BadRequest.slurp(error, self) - rescue Excon::Errors::InternalServerError => error - raise InternalServerError.slurp(error, self) - rescue Excon::Errors::ServiceUnavailable => error - raise ServiceUnavailable.slurp(error, self) - rescue Excon::Errors::Conflict => error - raise Conflict.slurp(error, self) - rescue Excon::Errors::HTTPStatusError => error - raise ServiceError.slurp(error, self) - end + def request(params, parse_json = true) + super + rescue Excon::Errors::NotFound => error + raise NotFound.slurp(error, self) + rescue Excon::Errors::BadRequest => error + raise BadRequest.slurp(error, self) + rescue Excon::Errors::InternalServerError => error + raise InternalServerError.slurp(error, self) + rescue Excon::Errors::ServiceUnavailable => error + raise ServiceUnavailable.slurp(error, self) + rescue Excon::Errors::Conflict => error + raise Conflict.slurp(error, self) + rescue Excon::Errors::HTTPStatusError => error + raise ServiceError.slurp(error, self) end def array_to_query_string(arr) diff --git a/lib/fog/rackspace/load_balancers.rb b/lib/fog/rackspace/load_balancers.rb index fe8adb96d..311f24406 100644 --- a/lib/fog/rackspace/load_balancers.rb +++ b/lib/fog/rackspace/load_balancers.rb @@ -120,8 +120,8 @@ module Fog @connection = Fog::Connection.new(endpoint_uri.to_s, @persistent, @connection_options) end - def request(params, parse_json = true, &block) - super(params, parse_json, &block) + def request(params, parse_json = true) + super rescue Excon::Errors::NotFound => error raise NotFound.slurp(error, self) rescue Excon::Errors::BadRequest => error diff --git a/lib/fog/rackspace/monitoring.rb b/lib/fog/rackspace/monitoring.rb index b3053bc00..33d22d030 100644 --- a/lib/fog/rackspace/monitoring.rb +++ b/lib/fog/rackspace/monitoring.rb @@ -129,20 +129,20 @@ module Fog private - def request(params, parse_json = true, &block) - super(params, parse_json, &block) - rescue Excon::Errors::BadRequest => error - raise BadRequest.slurp(error, self) - rescue Excon::Errors::Conflict => error - raise Conflict.slurp(error, self) - rescue Excon::Errors::NotFound => error - raise NotFound.slurp(error, self) - rescue Excon::Errors::ServiceUnavailable => error - raise ServiceUnavailable.slurp(error, self) - rescue Excon::Errors::InternalServerError => error - raise InternalServerError.slurp(error, self) - rescue Excon::Errors::HTTPStatusError => error - raise ServiceError.slurp(error, self) + def request(params, parse_json = true) + super + rescue Excon::Errors::BadRequest => error + raise BadRequest.slurp(error, self) + rescue Excon::Errors::Conflict => error + raise Conflict.slurp(error, self) + rescue Excon::Errors::NotFound => error + raise NotFound.slurp(error, self) + rescue Excon::Errors::ServiceUnavailable => error + raise ServiceUnavailable.slurp(error, self) + rescue Excon::Errors::InternalServerError => error + raise InternalServerError.slurp(error, self) + rescue Excon::Errors::HTTPStatusError => error + raise ServiceError.slurp(error, self) end def authenticate diff --git a/lib/fog/rackspace/requests/storage/get_object.rb b/lib/fog/rackspace/requests/storage/get_object.rb index 374080138..232d011e9 100644 --- a/lib/fog/rackspace/requests/storage/get_object.rb +++ b/lib/fog/rackspace/requests/storage/get_object.rb @@ -13,19 +13,17 @@ module Fog # @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500 # @raise [Fog::Storage::Rackspace::ServiceError] def get_object(container, object, &block) - params = {} - - if block_given? - params[:response_block] = Proc.new - end - - request(params.merge!({ + params = { :expects => 200, :method => 'GET', :path => "#{Fog::Rackspace.escape(container)}/#{Fog::Rackspace.escape(object)}" - }), - false, - &block) + } + + if block_given? + params[:response_block] = block + end + + request(params, false) end end diff --git a/lib/fog/rackspace/service.rb b/lib/fog/rackspace/service.rb index c7817a69a..919899e61 100644 --- a/lib/fog/rackspace/service.rb +++ b/lib/fog/rackspace/service.rb @@ -30,17 +30,17 @@ module Fog self.send authentication_method, options end - def request_without_retry(params, parse_json = true, &block) - response = @connection.request(request_params(params), &block) + def request_without_retry(params, parse_json = true) + response = @connection.request(request_params(params)) process_response(response) if parse_json response end - def request(params, parse_json = true, &block) + def request(params, parse_json = true) first_attempt = true begin - response = @connection.request(request_params(params), &block) + response = @connection.request(request_params(params)) rescue Excon::Errors::Unauthorized => error raise error unless first_attempt first_attempt = false @@ -70,8 +70,7 @@ module Fog end def headers(options={}) - h = { - 'Content-Type' => 'application/json', + { 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'X-Auth-Token' => auth_token }.merge(options[:headers] || {}) @@ -89,7 +88,7 @@ module Fog if v2_authentication? :authenticate_v2 else - Fog::Logger.deprecation "Authentication using a v1.0/v1.1 endpoint is deprecated. Please specify a v2.0 endpoint using :rackpace_auth_url.\ + Fog::Logger.deprecation "Authentication using a v1.0/v1.1 endpoint is deprecated. Please specify a v2.0 endpoint using :rackpace_auth_url.\ For a list of v2.0 endpoints refer to http://docs.rackspace.com/auth/api/v2.0/auth-client-devguide/content/Endpoints-d1e180.html" :authenticate_v1 end diff --git a/lib/fog/rackspace/storage.rb b/lib/fog/rackspace/storage.rb index 0c7db1d78..273fd3097 100644 --- a/lib/fog/rackspace/storage.rb +++ b/lib/fog/rackspace/storage.rb @@ -145,8 +145,8 @@ module Fog @connection.reset end - def request(params, parse_json = true, &block) - super(params, parse_json, &block) + def request(params, parse_json = true) + super rescue Excon::Errors::NotFound => error raise NotFound.slurp(error, self) rescue Excon::Errors::BadRequest => error