Sha256: 16f4c350b198643fec43bb76b7865a2ce2271207acfff717331fc5f1f93b2346
Contents?: true
Size: 1.27 KB
Versions: 4
Compression:
Stored size: 1.27 KB
Contents
module Fog module Gridscale class Service def request(params, parse_json = true) first_attempt = true begin response = @connection.request(request_params(params)) rescue Excon::Errors::Unauthorized => error raise error unless first_attempt first_attempt = false authenticate retry end process_response(response) if parse_json response end private def process_response(response) if response && response.body && response.body.is_a?(String) && !response.body.strip.empty? begin response.body = Fog::JSON.decode(response.body) rescue Fog::JSON::DecodeError => e Fog::Logger.warning("Error Parsing response json - #{e}") response.body = {} end end end def headers(options={}) {'Content-Type' => 'application/json', 'Accept' => 'application/json', }.merge(options[:headers] || {}) end def request_params(params) params.merge({ :headers => headers(params), :path => "#{params[:path]}" }) end end end end
Version data entries
4 entries across 4 versions & 1 rubygems