Class: Duststorm::WeatherApi::Base

Inherits:
Object
  • Object
show all
Includes:
Utils::ResponseMapper
Defined in:
lib/duststorm/weather_apis/base.rb

Direct Known Subclasses

ForecastIo, Wunderground

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::ResponseMapper

#high_temperature_key, #low_temperature_key, #mapped_response_body, #precipitation_key, #summary_key, #sunrise_key, #sunset_key, #temperature_key, #time_key, #wind_speed_key

Constructor Details

#initialize(lat, lng, options = {}) ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
# File 'lib/duststorm/weather_apis/base.rb', line 8

def initialize(lat, lng, options={})
  @lat = lat
  @lng = lng
  @options = options
end

Instance Attribute Details

#latObject (readonly)

Returns the value of attribute lat.



6
7
8
# File 'lib/duststorm/weather_apis/base.rb', line 6

def lat
  @lat
end

#lngObject (readonly)

Returns the value of attribute lng.



6
7
8
# File 'lib/duststorm/weather_apis/base.rb', line 6

def lng
  @lng
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/duststorm/weather_apis/base.rb', line 6

def options
  @options
end

Instance Method Details

#connObject



24
25
26
# File 'lib/duststorm/weather_apis/base.rb', line 24

def conn
  Faraday.new
end

#executeObject



14
15
16
17
18
# File 'lib/duststorm/weather_apis/base.rb', line 14

def execute
  if response.success?
    mapped_response_body
  end
end

#forecast_urlObject



28
29
30
# File 'lib/duststorm/weather_apis/base.rb', line 28

def forecast_url
  root_url + forecast_path
end

#responseObject



20
21
22
# File 'lib/duststorm/weather_apis/base.rb', line 20

def response
  @response ||= conn.get(forecast_url, options)
end