Class: Everlog::Inf::Api::Wunderground

Inherits:
Everlog::Inf::Api show all
Defined in:
lib/everlog/inf/api/wunderground.rb

Defined Under Namespace

Classes: InfrastructureWeatherError

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Wunderground

Returns a new instance of Wunderground.



5
6
7
8
# File 'lib/everlog/inf/api/wunderground.rb', line 5

def initialize config
  super(config)
  @cache = Inf::Cache::File::Wunderground.new
end

Instance Method Details

#clientObject



10
11
12
# File 'lib/everlog/inf/api/wunderground.rb', line 10

def client
  @client ||= ::Wunderground.new(@config.access_token, throws_exceptions: true)
end

#yesterday(place) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/everlog/inf/api/wunderground.rb', line 14

def yesterday place
  @cache.delete((Date.today - 2).to_s)
  response = @cache.create((Date.today - 1).to_s, { place: place, client: client}) do |args|
    args[:client].yesterday_for(args[:place]).to_json
  end
  JSON.parse(response)['history']
rescue => e
  raise InfrastructureWeatherError, "yesterday error / #{e.message}"
end