Module: WeatherBug
- Defined in:
- lib/weatherbug.rb,
lib/weatherbug/link.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, Link, LiveObservation, Station, StationHint, TransformableData
Constant Summary collapse
- API_URL =
'datafeed.weatherbug.com'
- Error =
Class.new(RuntimeError)
- NoSuchStation =
Class.new(Error)
- VERSION =
[0, 0, 10]
Class Method Summary collapse
- .closest_station(lookup_options) ⇒ Object
- .forecast(options) ⇒ Object
-
.get_links(link_names = [], lookup_options = {}) ⇒ Object
Get links for a certain zip code or postal code.
- .get_station(station_id) ⇒ Object
- .live_observation(station, unit_type = :f) ⇒ Object
-
.nearby_stations(lookup_options) ⇒ Object
Get the 25 closest stations, or less in less dense areas.
-
.partner_id=(partner_id) ⇒ Object
Set your application’s partner ID.
-
.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.
- .version ⇒ Object
Class Method Details
.closest_station(lookup_options) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/weatherbug.rb', line 39 def self.closest_station() HashMethods.valid_keys(, [:zip_code, :city_code, :postal_code, :include_pws]) HashMethods.valid_one_only(, [:zip_code, :city_code]) HashMethods.valid_one_only(, [:postal_code, :city_code]) HashMethods.valid_needs(, :zip_code, :postal_code) if .has_key?(:postal_code) params = HashMethods.convert_symbols() params['ListType'] = '1' [:include_pws] = '1' if .has_key?(:include_pws) response = make_request('StationList', params) WeatherBug::Station.from_document response.xpath('/aws:weather/aws:station').first end |
.forecast(options) ⇒ Object
104 105 106 |
# File 'lib/weatherbug.rb', line 104 def self.forecast() self.retrieve_forecast(7, ) end |
.get_links(link_names = [], lookup_options = {}) ⇒ Object
Get links for a certain zip code or postal code
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/weatherbug.rb', line 60 def self.get_links(link_names = [], = {}) HashMethods.valid_keys(, [:zip_code, :postal_code]) HashMethods.valid_one_only(, [:zip_code, :postal_code]) HashMethods.valid_needs(, :zip_code, :postal_code) if .has_key?(:postal_code) params = HashMethods.convert_symbols() params['LinkName'] = link_names.is_a?(Array) ? link_names.join(',') : link_names response = make_request('GetLink', params) response.xpath('/aws:weather/aws:Links/aws:Link').map do |link_data| WeatherBug::Link.from_document link_data end end |
.get_station(station_id) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/weatherbug.rb', line 52 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
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/weatherbug.rb', line 73 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
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/weatherbug.rb', line 28 def self.nearby_stations() HashMethods.valid_keys(, [:zip_code, :city_code, :postal_code, :include_pws]) HashMethods.valid_one_only(, [:zip_code, :city_code]) HashMethods.valid_one_only(, [:postal_code, :city_code]) HashMethods.valid_needs(, :zip_code, :postal_code) if .has_key?(:postal_code) [:include_pws] = '1' if .has_key?(:include_pws) response = make_request('StationList', HashMethods.convert_symbols()) 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
23 24 25 |
# File 'lib/weatherbug.rb', line 23 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
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/weatherbug.rb', line 87 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 |
.version ⇒ Object
5 6 7 |
# File 'lib/weatherbug/version.rb', line 5 def self.version VERSION.join('.') end |