Module: WeatherBug

Defined in:
lib/weatherbug.rb,
lib/weatherbug/station.rb,
lib/weatherbug/version.rb,
lib/weatherbug/forecast.rb,
lib/weatherbug/hash_methods.rb,
lib/weatherbug/station_hint.rb,
lib/weatherbug/live_observation.rb,
lib/weatherbug/transformable_data.rb

Defined Under Namespace

Classes: Forecast, HashMethods, LiveObservation, Station, StationHint, TransformableData

Constant Summary collapse

API_URL =
'datafeed.weatherbug.com'
VERSION =
[0, 0, 8]

Class Method Summary collapse

Class Method Details

.closest_station(lookup_options) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/weatherbug.rb', line 35

def self.closest_station(lookup_options)
  HashMethods.valid_keys(lookup_options, [:zip_code, :city_code, :postal_code, :include_pws])
  HashMethods.valid_one_only(lookup_options, [:zip_code, :city_code])
  HashMethods.valid_one_only(lookup_options, [:postal_code, :city_code])
  HashMethods.valid_needs(lookup_options, :zip_code, :postal_code) if lookup_options.has_key?(:postal_code)
  params = HashMethods.convert_symbols(lookup_options)
  params['ListType'] = '1'
  lookup_options[:include_pws] = '1' if lookup_options.has_key?(:include_pws)
  response = make_request('StationList', params)

  WeatherBug::Station.from_document response.xpath('/aws:weather/aws:station').first 
end

.forecast(options) ⇒ Object



86
87
88
# File 'lib/weatherbug.rb', line 86

def self.forecast(options)
  self.retrieve_forecast(7, options)
end

.get_station(station_id) ⇒ Object



48
49
50
51
52
53
# File 'lib/weatherbug.rb', line 48

def self.get_station(station_id)
  params = {'StationId' => station_id}
  response = make_request('StationInfo', params)

  WeatherBug::Station.from_document response.xpath('/aws:weather/aws:station').first
end

.live_observation(station, unit_type = :f) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/weatherbug.rb', line 55

def self.live_observation(station, unit_type = :f)
  station_id = station.is_a?(WeatherBug::Station) ? station.station_id : station
  params = {'StationId' => station_id}
  params['UnitType'] = '1' if unit_type == :c
  params['ShowIcon'] = '1'
  response = make_request('LiveObservations', params)

  live_observation = WeatherBug::LiveObservation.from_document response.xpath('/aws:weather/aws:ob').first
  live_observation.send(:station_reference=, station) if station.is_a?(WeatherBug::Station)
  live_observation
end

.nearby_stations(lookup_options) ⇒ Object

Get the 25 closest stations, or less in less dense areas



24
25
26
27
28
29
30
31
32
33
# File 'lib/weatherbug.rb', line 24

def self.nearby_stations(lookup_options)
  HashMethods.valid_keys(lookup_options, [:zip_code, :city_code, :postal_code, :include_pws])
  HashMethods.valid_one_only(lookup_options, [:zip_code, :city_code])
  HashMethods.valid_one_only(lookup_options, [:postal_code, :city_code])
  HashMethods.valid_needs(lookup_options, :zip_code, :postal_code) if lookup_options.has_key?(:postal_code)
  lookup_options[:include_pws] = '1' if lookup_options.has_key?(:include_pws)
  response = make_request('StationList', HashMethods.convert_symbols(lookup_options))

  response.xpath('/aws:weather/aws:station').map { |station| WeatherBug::Station.from_document(station) }
end

.partner_id=(partner_id) ⇒ Object

Set your application’s partner ID



19
20
21
# File 'lib/weatherbug.rb', line 19

def self.partner_id=(partner_id)
  @partner_id = partner_id
end

.stations_in_box(top_right_lat, top_right_lng, bot_left_lat, bot_left_lng) ⇒ Object

Get the list of stations in a bounding box Does not return full stations



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/weatherbug.rb', line 69

def self.stations_in_box(top_right_lat, top_right_lng, bot_left_lat, bot_left_lng)
  params = {
    'LatitudeTopRight' => top_right_lat,
    'LongitudeTopRight' => top_right_lng,
    'LatitudeBottomLeft' => bot_left_lat,
    'LongitudeBottomLeft' => bot_left_lng
  }
  response = make_request('StationListByLatLng', params)
  
  station_data = response.xpath('/aws:weather/aws:stations/aws:station')
  return nil unless station_data 

  station_data.map do |sdata|
    WeatherBug::StationHint.from_document(sdata)
  end
end

.versionObject



5
6
7
# File 'lib/weatherbug/version.rb', line 5

def self.version
  VERSION.join('.')
end