class Fog::DigitalOcean::Service
Public Instance Methods
request(params, parse_json = true)
click to toggle source
# File lib/fog/digitalocean/service.rb, line 5 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 Instance Methods
headers(options={})
click to toggle source
# File lib/fog/digitalocean/service.rb, line 36 def headers(options={}) {'Content-Type' => 'application/json', 'Accept' => 'application/json', }.merge(options[:headers] || {}) end
process_response(response)
click to toggle source
# File lib/fog/digitalocean/service.rb, line 22 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
request_params(params)
click to toggle source
# File lib/fog/digitalocean/service.rb, line 42 def request_params(params) params.merge({ :headers => headers(params), :path => "#{params[:path]}" }) end