lib/carbon/emission_estimate/response.rb in carbon-0.2.3 vs lib/carbon/emission_estimate/response.rb in carbon-0.2.4
- old
+ new
@@ -24,10 +24,14 @@
raise $!, "Rate limited #{attempts} time(s) in a row"
end
end
raise ::Carbon::RealtimeEstimateFailed unless response.success?
@data = ::ActiveSupport::JSON.decode response.body
+ instantiate_known_response_objects
@number = data['emission'].to_f.freeze
+ end
+ def instantiate_known_response_objects # :nodoc:
+ data['active_subtimeframe'] = ::Timeframe.interval(data['active_subtimeframe']) if data.has_key? 'active_subtimeframe'
end
def load_async_data # :nodoc:
response = perform
raise ::Carbon::QueueingFailed unless response.success?
@data = {}