lib/carbon/emission_estimate/response.rb in carbon-1.0.4 vs lib/carbon/emission_estimate/response.rb in carbon-1.1.0

- old
+ new

@@ -1,8 +1,8 @@ module Carbon class EmissionEstimate - class Response + class Response #:nodoc:all attr_reader :parent attr_reader :data attr_reader :raw_request attr_reader :raw_response @@ -13,11 +13,11 @@ def load_data send "load_#{parent.mode}_data" end private - def load_realtime_data # :nodoc: + def load_realtime_data attempts = 0 response = nil begin response = perform raise ::Carbon::RateLimited if response.status_code == 403 and response.body =~ /Rate Limit/i #TODO: Should we expect an HTTP 402: payment required, instead? @@ -32,17 +32,17 @@ end raise ::Carbon::RealtimeEstimateFailed unless response.success? #TODO: should we expect 300s as well as 200s? Also, we may want to include response code and body in our exception. @data = ::Carbon::EmissionEstimate.parse response.body end - def load_async_data # :nodoc: + def load_async_data response = perform raise ::Carbon::QueueingFailed unless response.success? #TODO: should we expect 300s as well as 200s? Also, we may want to include response code and body in our exception. @data = {} end - def perform # :nodoc: + def perform response = nil if parent.timeout Timeout.timeout(parent.timeout) do response = perform_request end @@ -50,10 +50,10 @@ response = perform_request end response end - def perform_request # :nodoc: + def perform_request @raw_request = ::REST::Request.new :post, ::URI.parse(parent.request.url), parent.request.body, {'Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8'} @raw_response = raw_request.perform end end end