Sha256: 69937276b379293d48f9993f07b03c85988d6b88dad9623827a5de5ba6508ea4
Contents?: true
Size: 1.26 KB
Versions: 11
Compression:
Stored size: 1.26 KB
Contents
module Fog module DigitalOcean 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
11 entries across 9 versions & 3 rubygems