barometer 0.7.3 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. data/.gitignore +1 -0
  2. data/.travis.yml +7 -0
  3. data/LICENSE +1 -1
  4. data/{README.rdoc → README.md} +124 -110
  5. data/Rakefile +1 -21
  6. data/TODO +8 -9
  7. data/barometer.gemspec +20 -19
  8. data/bin/barometer +36 -83
  9. data/lib/barometer.rb +13 -11
  10. data/lib/barometer/base.rb +10 -10
  11. data/lib/barometer/data.rb +1 -1
  12. data/lib/barometer/data/distance.rb +25 -25
  13. data/lib/barometer/data/geo.rb +9 -9
  14. data/lib/barometer/data/local_datetime.rb +24 -20
  15. data/lib/barometer/data/local_time.rb +13 -13
  16. data/lib/barometer/data/location.rb +6 -6
  17. data/lib/barometer/data/pressure.rb +24 -24
  18. data/lib/barometer/data/speed.rb +28 -28
  19. data/lib/barometer/data/sun.rb +7 -7
  20. data/lib/barometer/data/temperature.rb +29 -29
  21. data/lib/barometer/data/units.rb +9 -9
  22. data/lib/barometer/data/zone.rb +19 -19
  23. data/lib/barometer/formats.rb +1 -1
  24. data/lib/barometer/formats/coordinates.rb +7 -7
  25. data/lib/barometer/formats/format.rb +6 -6
  26. data/lib/barometer/formats/geocode.rb +5 -5
  27. data/lib/barometer/formats/icao.rb +6 -6
  28. data/lib/barometer/formats/postalcode.rb +3 -3
  29. data/lib/barometer/formats/short_zipcode.rb +2 -2
  30. data/lib/barometer/formats/weather_id.rb +10 -10
  31. data/lib/barometer/formats/woe_id.rb +20 -20
  32. data/lib/barometer/formats/zipcode.rb +3 -3
  33. data/lib/barometer/key_file_parser.rb +20 -0
  34. data/lib/barometer/measurements/measurement.rb +32 -32
  35. data/lib/barometer/measurements/result.rb +39 -39
  36. data/lib/barometer/measurements/result_array.rb +12 -12
  37. data/lib/barometer/query.rb +15 -15
  38. data/lib/barometer/services.rb +3 -3
  39. data/lib/barometer/translations/icao_country_codes.yml +20 -20
  40. data/lib/barometer/translations/weather_country_codes.yml +1 -1
  41. data/lib/barometer/translations/zone_codes.yml +2 -2
  42. data/lib/barometer/version.rb +3 -0
  43. data/lib/barometer/weather.rb +27 -27
  44. data/lib/barometer/weather_services/noaa.rb +314 -3
  45. data/lib/barometer/weather_services/service.rb +32 -30
  46. data/lib/barometer/weather_services/weather_bug.rb +35 -33
  47. data/lib/barometer/weather_services/wunderground.rb +31 -29
  48. data/lib/barometer/weather_services/yahoo.rb +36 -35
  49. data/lib/barometer/web_services/geocode.rb +5 -7
  50. data/lib/barometer/web_services/noaa_station_id.rb +53 -0
  51. data/lib/barometer/web_services/placemaker.rb +11 -13
  52. data/lib/barometer/web_services/timezone.rb +5 -7
  53. data/lib/barometer/web_services/weather_id.rb +4 -6
  54. data/lib/barometer/web_services/web_service.rb +4 -4
  55. data/spec/barometer_spec.rb +25 -27
  56. data/spec/cassettes/Barometer.json +1 -0
  57. data/spec/cassettes/Query.json +1 -0
  58. data/spec/cassettes/Query_Format_Coordinates.json +1 -0
  59. data/spec/cassettes/Query_Format_Geocode.json +1 -0
  60. data/spec/cassettes/Query_Format_WeatherID.json +1 -0
  61. data/spec/cassettes/Query_Format_WoeID.json +1 -0
  62. data/spec/cassettes/WeatherService.json +1 -0
  63. data/spec/cassettes/WeatherService_Noaa.json +1 -0
  64. data/spec/cassettes/WeatherService_WeatherBug.json +1 -0
  65. data/spec/cassettes/WeatherService_Wunderground.json +1 -0
  66. data/spec/cassettes/WeatherService_Yahoo.json +1 -0
  67. data/spec/cassettes/WebService_Geocode.json +1 -0
  68. data/spec/cassettes/WebService_NoaaStation.json +1 -0
  69. data/spec/data/distance_spec.rb +60 -60
  70. data/spec/data/geo_spec.rb +23 -23
  71. data/spec/data/local_datetime_spec.rb +44 -44
  72. data/spec/data/local_time_spec.rb +47 -47
  73. data/spec/data/location_spec.rb +16 -16
  74. data/spec/data/pressure_spec.rb +61 -61
  75. data/spec/data/speed_spec.rb +69 -69
  76. data/spec/data/sun_spec.rb +25 -25
  77. data/spec/data/temperature_spec.rb +68 -68
  78. data/spec/data/units_spec.rb +21 -21
  79. data/spec/data/zone_spec.rb +35 -35
  80. data/spec/formats/coordinates_spec.rb +27 -27
  81. data/spec/formats/format_spec.rb +17 -25
  82. data/spec/formats/geocode_spec.rb +23 -31
  83. data/spec/formats/icao_spec.rb +26 -32
  84. data/spec/formats/postalcode_spec.rb +22 -28
  85. data/spec/formats/short_zipcode_spec.rb +20 -26
  86. data/spec/formats/weather_id_spec.rb +57 -67
  87. data/spec/formats/woe_id_spec.rb +59 -59
  88. data/spec/formats/zipcode_spec.rb +39 -47
  89. data/spec/key_file_parser_spec.rb +28 -0
  90. data/spec/measurements/measurement_spec.rb +79 -133
  91. data/spec/measurements/result_array_spec.rb +23 -38
  92. data/spec/measurements/result_spec.rb +100 -128
  93. data/spec/query_spec.rb +83 -100
  94. data/spec/spec_helper.rb +24 -6
  95. data/spec/weather_services/noaa_spec.rb +179 -0
  96. data/spec/weather_services/services_spec.rb +28 -36
  97. data/spec/weather_services/weather_bug_spec.rb +57 -77
  98. data/spec/weather_services/wunderground_spec.rb +36 -65
  99. data/spec/weather_services/yahoo_spec.rb +38 -60
  100. data/spec/weather_spec.rb +79 -79
  101. data/spec/web_services/geocode_spec.rb +7 -11
  102. data/spec/web_services/noaa_station_id_spec.rb +33 -0
  103. data/spec/web_services/placemaker_spec.rb +7 -12
  104. data/spec/web_services/web_services_spec.rb +3 -9
  105. metadata +214 -163
  106. data/VERSION.yml +0 -5
  107. data/lib/barometer/weather_services/google.rb +0 -142
  108. data/lib/barometer/weather_services/weather_dot_com.rb +0 -279
  109. data/spec/fakeweb_helper.rb +0 -179
  110. data/spec/fixtures/formats/weather_id/90210.xml +0 -7
  111. data/spec/fixtures/formats/weather_id/from_USGA0028.xml +0 -3
  112. data/spec/fixtures/formats/weather_id/ksfo.xml +0 -1
  113. data/spec/fixtures/formats/weather_id/manhattan.xml +0 -7
  114. data/spec/fixtures/formats/weather_id/new_york.xml +0 -1
  115. data/spec/fixtures/formats/weather_id/the_hills.xml +0 -1
  116. data/spec/fixtures/geocode/40_73_v3.json +0 -497
  117. data/spec/fixtures/geocode/90210_v3.json +0 -63
  118. data/spec/fixtures/geocode/T5B4M9_v3.json +0 -68
  119. data/spec/fixtures/geocode/atlanta_v3.json +0 -58
  120. data/spec/fixtures/geocode/calgary_ab_v3.json +0 -58
  121. data/spec/fixtures/geocode/ksfo_v3.json +0 -73
  122. data/spec/fixtures/geocode/newyork_ny_v3.json +0 -58
  123. data/spec/fixtures/services/google/calgary_ab.xml +0 -1
  124. data/spec/fixtures/services/placemaker/T5B4M9.xml +0 -65
  125. data/spec/fixtures/services/placemaker/atlanta.xml +0 -65
  126. data/spec/fixtures/services/placemaker/coords.xml +0 -65
  127. data/spec/fixtures/services/placemaker/ksfo.xml +0 -65
  128. data/spec/fixtures/services/placemaker/new_york.xml +0 -65
  129. data/spec/fixtures/services/placemaker/the_hills.xml +0 -65
  130. data/spec/fixtures/services/placemaker/w615702.xml +0 -47
  131. data/spec/fixtures/services/weather_bug/90210_current.xml +0 -93
  132. data/spec/fixtures/services/weather_bug/90210_forecast.xml +0 -76
  133. data/spec/fixtures/services/weather_dot_com/90210.xml +0 -1
  134. data/spec/fixtures/services/wunderground/current_calgary_ab.xml +0 -9
  135. data/spec/fixtures/services/wunderground/forecast_calgary_ab.xml +0 -13
  136. data/spec/fixtures/services/yahoo/90210.xml +0 -3
  137. data/spec/weather_services/google_spec.rb +0 -181
  138. data/spec/weather_services/weather_dot_com_spec.rb +0 -224
data/VERSION.yml DELETED
@@ -1,5 +0,0 @@
1
- ---
2
- :major: 0
3
- :minor: 7
4
- :patch: 3
5
- :build:
@@ -1,142 +0,0 @@
1
- module Barometer
2
- #
3
- # = Google Weather
4
- # www.google.com
5
- # NOTE: Google does not have an official API
6
- #
7
- # - key required: NO
8
- # - registration required: NO
9
- # - supported countries: ALL
10
- #
11
- # === performs geo coding
12
- # - city: YES (except postalcode query)
13
- # - coordinates: NO
14
- #
15
- # === time info
16
- # - sun rise/set: NO
17
- # - provides timezone: NO
18
- # - requires TZInfo: NO
19
- #
20
- # == resources
21
- # - API: http://unknown
22
- #
23
- # === Possible queries:
24
- # - http://google.com/ig/api?weather=perth
25
- #
26
- # where query can be:
27
- # - zipcode (US or Canadian)
28
- # - city state; city, state
29
- # - city
30
- # - state
31
- # - country
32
- #
33
- # = Google terms of use
34
- # This is an unoffical API. There are no terms of use.
35
- #
36
- class WeatherService::Google < WeatherService
37
-
38
- #########################################################################
39
- # PRIVATE
40
- # If class methods could be private, the remaining methods would be.
41
- #
42
-
43
- def self._source_name; :google; end
44
- def self._accepted_formats; [:zipcode, :postalcode, :geocode]; end
45
-
46
- def self._wet_icon_codes
47
- %w(rain chance_of_rain chance_of_storm thunderstorm mist)
48
- end
49
- def self._sunny_icon_codes
50
- %w(sunny mostly_sunny partly_cloudy)
51
- end
52
-
53
- def self._build_current(data, metric=true)
54
- raise ArgumentError unless data.is_a?(Hash)
55
- current = Measurement::Result.new
56
-
57
- if data['current_conditions']
58
- data = data['current_conditions']
59
- if data['icon']
60
- icon_match = data['icon']['data'].match(/.*\/([A-Za-z_]*)\.png/)
61
- current.icon = icon_match[1] if icon_match
62
- end
63
- current.condition = data['condition']['data'] if data['condition']
64
-
65
- humidity_match = data['humidity']['data'].match(/[\d]+/)
66
- current.humidity = humidity_match[0].to_i if humidity_match
67
-
68
- current.temperature = Data::Temperature.new(metric)
69
- current.temperature << [data['temp_c']['data'], data['temp_f']['data']]
70
-
71
- current.wind = Data::Speed.new(metric)
72
- begin
73
- current.wind << data['wind_condition']['data'].match(/[\d]+/)[0]
74
- current.wind.direction = data['wind_condition']['data'].match(/Wind:.*?([\w]+).*?at/)[1]
75
- rescue
76
- end
77
- end
78
- current
79
- end
80
-
81
- def self._build_forecast(data, metric=true)
82
- raise ArgumentError unless data.is_a?(Hash)
83
-
84
- forecasts = Measurement::ResultArray.new
85
- return forecasts unless data && data['forecast_information'] &&
86
- data['forecast_information']['forecast_date']
87
- start_date = Date.parse(data['forecast_information']['forecast_date']['data'])
88
- data = data['forecast_conditions'] if data['forecast_conditions']
89
-
90
- # go through each forecast and create an instance
91
- d = 0
92
- data.each do |forecast|
93
- forecast_measurement = Measurement::Result.new
94
- if forecast['icon']
95
- icon_match = forecast['icon']['data'].match(/.*\/([A-Za-z_]*)\.png/)
96
- forecast_measurement.icon = icon_match[1] if icon_match
97
- end
98
- forecast_measurement.condition = forecast['condition']['data'] if forecast['condition']
99
-
100
- if (start_date + d).strftime("%a").downcase == forecast['day_of_week']['data'].downcase
101
- forecast_measurement.date = start_date + d
102
- end
103
-
104
- forecast_measurement.high = Data::Temperature.new(metric)
105
- forecast_measurement.high << forecast['high']['data']
106
- forecast_measurement.low = Data::Temperature.new(metric)
107
- forecast_measurement.low << forecast['low']['data']
108
-
109
- forecasts << forecast_measurement
110
- d += 1
111
- end
112
- forecasts
113
- end
114
-
115
- def self._build_location(result=nil, geo=nil)
116
- raise ArgumentError unless (geo.nil? || geo.is_a?(Data::Geo))
117
- location = Data::Location.new
118
- if geo
119
- location.city = geo.locality
120
- location.state_code = geo.region
121
- location.country = geo.country
122
- location.country_code = geo.country_code
123
- location.latitude = geo.latitude
124
- location.longitude = geo.longitude
125
- end
126
- location
127
- end
128
-
129
- # use HTTParty to get the current weather
130
- def self._fetch(query, metric=true)
131
- return unless query
132
- puts "fetch google: #{query.q}" if Barometer::debug?
133
- self.get(
134
- "http://www.google.com/ig/api",
135
- :query => {:weather => query.q, :hl => (metric ? "en-GB" : "en-US")},
136
- :format => :xml,
137
- :timeout => Barometer.timeout
138
- )['xml_api_reply']['weather']
139
- end
140
-
141
- end
142
- end
@@ -1,279 +0,0 @@
1
- module Barometer
2
- #
3
- # = Weather.com
4
- # www.weather.com
5
- #
6
- # - usage restrictions: YES ... many !!!
7
- # - key required: YES (partnerid & licensekey)
8
- # - registration required: YES
9
- # - supported countries: US (by zipcode), International (by Weather Location ID)
10
- #
11
- # === performs geo coding
12
- # - city: PARTIAL (just a name)
13
- # - coordinates: YES
14
- #
15
- # === time info
16
- # - sun rise/set: YES
17
- # - provides timezone: NO, but provides a utc offset
18
- # - requires TZInfo: NO
19
- #
20
- # == resources
21
- # - API: ?
22
- #
23
- # === Possible queries:
24
- # - http://xoap.weather.com/weather/local/30339?cc=*&dayf=5&link=xoap&prod=xoap&par=[PartnerID]&key=[LicenseKey]
25
- #
26
- # where query can be:
27
- # - zipcode (US) [5 digits only]
28
- # - Weather Location ID (International)
29
- #
30
- # = Weather.com terms of use
31
- # There are many conditions when using weather.com. Please read the EULA you
32
- # received when you registered for your API keys. In a nutshell (but not limited
33
- # to), do the following:
34
- # - display the weather.com links (all 5)
35
- # - respect the data refresh rates
36
- # - do not alter/delete content
37
- # - display when weather was last updated
38
- # - do not display data in combination with other 3rd party data (except NOAA or GOV)
39
- # - do not reproduce, rent, lease, lend, distribute or re-market data
40
- # - do not resell
41
- # - do not use in combination with a service that charges a fee
42
- # - do not use in a mobile application
43
- # - use the images properly
44
- # - do not display weather for more then 3 locations at a time
45
- # - do not allow the data to be scraped (via robots, spiders, web crawlers, etc)
46
- # - do not use the latitude and longitude information
47
- #
48
- # == notes
49
- # - the Weather Location ID is a propreitary number (shared with yahoo.com)
50
- #
51
- # == TODO
52
- # - improve "forecasted_wet_by_icon?" to determine if day or night and use right code
53
- # - improve "forecasted_sunny_by_icon?" to determine if day or night and use right code
54
- # - improve "forcasted_wet_by_humidity?" to use forecasted values
55
- # - improve "forcasted_windy?" to use forecasted values
56
- # - collect moon and uv information
57
- #
58
- class WeatherService::WeatherDotCom < WeatherService
59
-
60
- @@partner_key = nil
61
- @@license_key = nil
62
-
63
- def self.keys=(keys)
64
- raise ArgumentError unless keys.is_a?(Hash)
65
- keys.each do |key, value|
66
- @@partner_key = value.to_s if key.to_s.downcase == "partner"
67
- @@license_key = value.to_s if key.to_s.downcase == "license"
68
- end
69
- end
70
-
71
- #########################################################################
72
- # PRIVATE
73
- # If class methods could be private, the remaining methods would be.
74
- #
75
-
76
- def self._source_name; :weather_dot_com; end
77
- def self._accepted_formats; [:short_zipcode, :weather_id]; end
78
-
79
- def self._has_keys?; !@@partner_key.nil? && !@@license_key.nil?; end
80
- def self._requires_keys?; true; end
81
-
82
- def self._wet_icon_codes
83
- codes = (0..18).to_a + [35] + (37..43).to_a + (45..47).to_a
84
- codes.collect {|c| c.to_s}
85
- end
86
- def self._sunny_icon_codes
87
- codes = [19, 22, 28, 30, 32, 34, 36]
88
- codes.collect {|c| c.to_s}
89
- end
90
-
91
- # first try to match the zone code, otherwise use the zone offset
92
- #
93
- def self._build_timezone(data)
94
- if data
95
- if data['cc'] && data['cc']['lsup'] &&
96
- (zone_match = data['cc']['lsup'].match(/ ([A-Z]{1,4})$/))
97
- Data::Zone.new(zone_match[1])
98
- elsif data['loc'] && data['loc']['zone']
99
- Data::Zone.new(data['loc']['zone'].to_f)
100
- end
101
- end
102
- end
103
-
104
- def self._parse_local_time(data)
105
- (data && data['loc']) ? Data::LocalTime.parse(data['loc']['tm']) : nil
106
- end
107
-
108
- def self._build_links(data)
109
- links = {}
110
- if data && data['lnks'] && data['lnks']['link']
111
- data['lnks']['link'].each do |link_hash|
112
- links[link_hash['t']] = link_hash['l']
113
- end
114
- end
115
- links
116
- end
117
-
118
- def self._build_current(data, metric=true)
119
- raise ArgumentError unless data.is_a?(Hash)
120
- current = Measurement::Result.new
121
- if data
122
- if data['cc']
123
- current.updated_at = Data::LocalDateTime.parse(data['cc']['lsup'])
124
- current.icon = data['cc']['icon']
125
- current.condition = data['cc']['t']
126
- current.humidity = data['cc']['hmid'].to_i
127
- current.temperature = Data::Temperature.new(metric)
128
- current.temperature << data['cc']['tmp']
129
- current.dew_point = Data::Temperature.new(metric)
130
- current.dew_point << data['cc']['dewp']
131
- current.wind_chill = Data::Temperature.new(metric)
132
- current.wind_chill << data['cc']['flik']
133
- current.visibility = Data::Distance.new(metric)
134
- current.visibility << data['cc']['vis']
135
- if data['cc']['wind']
136
- current.wind = Data::Speed.new(metric)
137
- current.wind << data['cc']['wind']['s']
138
- current.wind.degrees = data['cc']['wind']['d'].to_f
139
- current.wind.direction = data['cc']['wind']['t']
140
- end
141
- if data['cc']['bar']
142
- current.pressure = Data::Pressure.new(metric)
143
- current.pressure << data['cc']['bar']['r']
144
- end
145
- end
146
- end
147
- current
148
- end
149
-
150
- def self._build_forecast(data, metric=true)
151
- raise ArgumentError unless data.is_a?(Hash)
152
- forecasts = Measurement::ResultArray.new
153
-
154
- if data && data['dayf'] && data['dayf']['day']
155
- local_date = data['dayf']['lsup']
156
- data['dayf']['day'].each do |forecast|
157
- day_measurement = Measurement::Result.new
158
- night_measurement = Measurement::Result.new
159
-
160
- # as stated by weather.com "day = 7am-7pm"
161
- # and "night = 7pm-7am"
162
- date = Date.parse(forecast['dt'])
163
- date_string = date.strftime("%b %d")
164
- day_measurement.valid_start_date = Data::LocalDateTime.new(date.year,date.month,date.day,7,0,0)
165
- day_measurement.valid_end_date = Data::LocalDateTime.new(date.year,date.month,date.day,18,59,59)
166
- night_measurement.valid_start_date = Data::LocalDateTime.new(date.year,date.month,date.day,19,0,0)
167
- night_measurement.valid_end_date = Data::LocalDateTime.new(date.year,date.month,date.day+1,6,59,59)
168
-
169
- high = Data::Temperature.new(metric)
170
- high << forecast['hi']
171
- low = Data::Temperature.new(metric)
172
- low << forecast['low']
173
- day_measurement.high = high
174
- day_measurement.low = low
175
- night_measurement.high = high
176
- night_measurement.low = low
177
-
178
- # build sun
179
- rise_local_time = Data::LocalTime.parse(forecast['sunr'])
180
- set_local_time = Data::LocalTime.parse(forecast['suns'])
181
- sun = Data::Sun.new(rise_local_time, set_local_time)
182
- day_measurement.sun = sun
183
- night_measurement.sun = sun
184
-
185
- if forecast['part']
186
- forecast['part'].each do |part|
187
- if part['p'] == 'd'
188
- # add this to the day
189
- day_measurement.description = "#{date_string} - Day"
190
- day_measurement.condition = part['t']
191
- day_measurement.icon = part['icon']
192
- day_measurement.pop = part['ppcp'].to_i
193
- day_measurement.humidity = part['hmid'].to_i
194
-
195
- if part['wind']
196
- day_measurement.wind = Data::Speed.new(metric)
197
- day_measurement.wind << part['wind']['s']
198
- day_measurement.wind.degrees = part['wind']['d'].to_i
199
- day_measurement.wind.direction = part['wind']['t']
200
- end
201
-
202
- elsif part['p'] == 'n'
203
- # add this to the night
204
- night_measurement.description = "#{date_string} - Night"
205
- night_measurement.condition = part['t']
206
- night_measurement.icon = part['icon']
207
- night_measurement.pop = part['ppcp'].to_i
208
- night_measurement.humidity = part['hmid'].to_i
209
-
210
- if part['wind']
211
- night_measurement.wind = Data::Speed.new(metric)
212
- night_measurement.wind << part['wind']['s']
213
- night_measurement.wind.degrees = part['wind']['d'].to_i
214
- night_measurement.wind.direction = part['wind']['t']
215
- end
216
-
217
- end
218
- end
219
- end
220
- forecasts << day_measurement
221
- forecasts << night_measurement
222
- end
223
- end
224
- forecasts
225
- end
226
-
227
- def self._build_location(data, geo=nil)
228
- raise ArgumentError unless data.is_a?(Hash)
229
- raise ArgumentError unless (geo.nil? || geo.is_a?(Data::Geo))
230
- location = Data::Location.new
231
- # use the geocoded data if available, otherwise get data from result
232
- if geo
233
- location.city = geo.locality
234
- location.state_code = geo.region
235
- location.country = geo.country
236
- location.country_code = geo.country_code
237
- location.latitude = geo.latitude
238
- location.longitude = geo.longitude
239
- else
240
- if data && data['loc']
241
- location.name = data['loc']['dnam']
242
- location.latitude = data['loc']['lat']
243
- location.longitude = data['loc']['lon']
244
- end
245
- end
246
- location
247
- end
248
-
249
- def self._build_sun(data)
250
- raise ArgumentError unless data.is_a?(Hash)
251
- sun = nil
252
- if data
253
- if data['loc']
254
- rise_local_time = Data::LocalTime.parse(data['loc']['sunr'])
255
- set_local_time = Data::LocalTime.parse(data['loc']['suns'])
256
- end
257
- sun = Data::Sun.new(rise_local_time, set_local_time)
258
- end
259
- sun || Data::Sun.new
260
- end
261
-
262
- # use HTTParty to get the current weather
263
- #
264
- def self._fetch(query, metric=true)
265
- return unless query
266
- puts "fetch weather.com: #{query.q}" if Barometer::debug?
267
- self.get(
268
- "http://xoap.weather.com/weather/local/#{query.q}",
269
- :query => { :par => @@partner_key, :key => @@license_key,
270
- :prod => "xoap", :link => "xoap", :cc => "*",
271
- :dayf => "5", :unit => (metric ? 'm' : 's')
272
- },
273
- :format => :xml,
274
- :timeout => Barometer.timeout
275
- )['weather']
276
- end
277
-
278
- end
279
- end
@@ -1,179 +0,0 @@
1
- require 'fakeweb'
2
- FakeWeb.allow_net_connect = false
3
-
4
- #
5
- # Set random test keys
6
- #
7
- WEATHER_PARTNER_KEY = "1234"
8
- WEATHER_LICENSE_KEY = "12345"
9
- WEATHERBUG_CODE = "A9999"
10
- YAHOO_KEY = "YAHOO"
11
-
12
- #
13
- # for geocoding
14
- #
15
- geo_url_v3 = "http://maps.googleapis.com/maps/api/geocode/json?"
16
-
17
- # http://maps.googleapis.com/maps/api/geocode/json?region=US&sensor=false&address=90210
18
- FakeWeb.register_uri(:get,
19
- "#{geo_url_v3}region=US&sensor=false&address=90210",
20
- :body => File.read(File.dirname(__FILE__) + '/fixtures/geocode/90210_v3.json')
21
- )
22
- # http://maps.googleapis.com/maps/api/geocode/json?region=&sensor=false&latlng=40.756054%2C-73.986951
23
- FakeWeb.register_uri(:get,
24
- "#{geo_url_v3}region=&sensor=false&latlng=40.756054%2C-73.986951",
25
- :body => File.read(File.dirname(__FILE__) + '/fixtures/geocode/40_73_v3.json')
26
- )
27
- # http://maps.googleapis.com/maps/api/geocode/json?region=&sensor=false&address=New%20York%2C%20NY
28
- FakeWeb.register_uri(:get,
29
- "#{geo_url_v3}region=&sensor=false&address=New%20York%2C%20NY",
30
- :body => File.read(File.dirname(__FILE__) + '/fixtures/geocode/newyork_ny_v3.json')
31
- )
32
- # http://maps.googleapis.com/maps/api/geocode/json?region=CA&sensor=false&address=T5B%204M9
33
- FakeWeb.register_uri(:get,
34
- "#{geo_url_v3}region=CA&sensor=false&address=T5B%204M9",
35
- :body => File.read(File.dirname(__FILE__) + '/fixtures/geocode/T5B4M9_v3.json')
36
- )
37
- # http://maps.googleapis.com/maps/api/geocode/json?region=US&sensor=false&address=KSFO
38
- FakeWeb.register_uri(:get,
39
- "#{geo_url_v3}region=US&sensor=false&address=KSFO",
40
- :body => File.read(File.dirname(__FILE__) + '/fixtures/geocode/ksfo_v3.json')
41
- )
42
- # http://maps.googleapis.com/maps/api/geocode/json?region=&sensor=false&address=Atlanta%2C%20GA%2C%20US
43
- FakeWeb.register_uri(:get,
44
- "#{geo_url_v3}region=&sensor=false&address=Atlanta%2C%20GA%2C%20US",
45
- :body => File.read(File.dirname(__FILE__) + '/fixtures/geocode/atlanta_v3.json')
46
- )
47
- # http://maps.googleapis.com/maps/api/geocode/json?region=&sensor=false&address=Calgary%2CAB
48
- FakeWeb.register_uri(:get,
49
- "#{geo_url_v3}region=&sensor=false&address=Calgary%2CAB",
50
- :body => File.read(File.dirname(__FILE__) + '/fixtures/geocode/calgary_ab_v3.json')
51
- )
52
- #
53
- # for weather.com searches
54
- #
55
- # http://xoap.weather.com:80/search/search?where=Beverly%20Hills%2C%20CA%2C%20USA
56
- FakeWeb.register_uri(:get,
57
- "http://xoap.weather.com:80/search/search?where=Beverly%20Hills%2C%20CA%2C%20United%20States",
58
- :body => File.read(File.dirname(__FILE__) + '/fixtures/formats/weather_id/the_hills.xml')
59
- )
60
- # http://xoap.weather.com:80/search/search?where=New%20York%2C%20NY
61
- FakeWeb.register_uri(:get,
62
- "http://xoap.weather.com:80/search/search?where=New%20York%2C%20NY",
63
- :body => File.read(File.dirname(__FILE__) + '/fixtures/formats/weather_id/new_york.xml')
64
- )
65
- # http://xoap.weather.com:80/search/search?where=Manhattan%2C%20NY%2C%20USA
66
- FakeWeb.register_uri(:get,
67
- "http://xoap.weather.com:80/search/search?where=Manhattan%2C%20NY%2C%20United%20States",
68
- :body => File.read(File.dirname(__FILE__) + '/fixtures/formats/weather_id/manhattan.xml')
69
- )
70
- # http://xoap.weather.com:80/search/search?where=New%20York%2C%20NY%2C%20USA
71
- FakeWeb.register_uri(:get,
72
- "http://xoap.weather.com:80/search/search?where=New%20York%2C%20NY%2C%20United%20States",
73
- :body => File.read(File.dirname(__FILE__) + '/fixtures/formats/weather_id/new_york.xml')
74
- )
75
- # http://xoap.weather.com:80/search/search?where=90210
76
- FakeWeb.register_uri(:get,
77
- "http://xoap.weather.com:80/search/search?where=90210",
78
- :body => File.read(File.dirname(__FILE__) + '/fixtures/formats/weather_id/90210.xml')
79
- )
80
- # http://xoap.weather.com:80/search/search?where=San%20Francisco%2C%20CA%2C%20USA
81
- FakeWeb.register_uri(:get,
82
- "http://xoap.weather.com:80/search/search?where=San%20Francisco%2C%20CA%2C%20United%20States",
83
- :body => File.read(File.dirname(__FILE__) + '/fixtures/formats/weather_id/ksfo.xml')
84
- )
85
- #
86
- # for yahoo.com searches
87
- #
88
- # http://weather.yahooapis.com:80/forecastrss?p=USGA0028
89
- FakeWeb.register_uri(:get,
90
- "http://weather.yahooapis.com:80/forecastrss?p=USGA0028",
91
- :body => File.read(File.dirname(__FILE__) + '/fixtures/formats/weather_id/from_USGA0028.xml')
92
- )
93
- #
94
- # for Google weather
95
- #
96
- # http://www.google.com/ig/api?weather=Calgary%2CAB&hl=en-GB
97
- FakeWeb.register_uri(:get,
98
- "http://www.google.com/ig/api?weather=#{CGI.escape('Calgary,AB')}&hl=en-GB",
99
- :body => File.read(File.dirname(__FILE__) + '/fixtures/services/google/calgary_ab.xml')
100
- )
101
- #
102
- # for WeatherBug weather
103
- #
104
- # http://CODE.api.wxbug.net/getLiveWeatherRSS.aspx?ACode=CODE&OutputType=1&UnitType=1&zipCode=90210
105
- bug_url_current = "http://#{WEATHERBUG_CODE}.api.wxbug.net:80/getLiveWeatherRSS.aspx?"
106
- FakeWeb.register_uri(:get,
107
- "#{bug_url_current}ACode=#{WEATHERBUG_CODE}&OutputType=1&UnitType=1&zipCode=90210",
108
- :body => File.read(File.dirname(__FILE__) + '/fixtures/services/weather_bug/90210_current.xml')
109
- )
110
- # http://CODE.api.wxbug.net/getForecastRSS.aspx?ACode=CODE&OutputType=1&UnitType=1&zipCode=90210
111
- bug_url_future = "http://#{WEATHERBUG_CODE}.api.wxbug.net:80/getForecastRSS.aspx?"
112
- FakeWeb.register_uri(:get,
113
- "#{bug_url_future}ACode=#{WEATHERBUG_CODE}&OutputType=1&UnitType=1&zipCode=90210",
114
- :body => File.read(File.dirname(__FILE__) + '/fixtures/services/weather_bug/90210_forecast.xml')
115
- )
116
- #
117
- # for weather.com weather
118
- #
119
- # http://xoap.weather.com:80/weather/local/90210?dayf=5&unit=m&link=xoap&par=PKEY&prod=xoap&key=LKEY&cc=*
120
- weather_com_url = "http://xoap.weather.com:80/weather/local/"
121
- FakeWeb.register_uri(:get,
122
- "#{weather_com_url}90210?dayf=5&unit=m&link=xoap&par=#{WEATHER_PARTNER_KEY}&prod=xoap&key=#{WEATHER_LICENSE_KEY}&cc=*",
123
- :body => File.read(File.dirname(__FILE__) + '/fixtures/services/weather_dot_com/90210.xml')
124
- )
125
- #
126
- # for yahoo weather
127
- #
128
- # http://weather.yahooapis.com:80/forecastrss?u=c&p=90210
129
- FakeWeb.register_uri(:get,
130
- "http://weather.yahooapis.com:80/forecastrss?u=c&p=90210",
131
- :body => File.read(File.dirname(__FILE__) + '/fixtures/services/yahoo/90210.xml')
132
- )
133
-
134
- #
135
- # For wunderground weather
136
- #
137
- # http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=51.045%2C-114.0572222
138
- FakeWeb.register_uri(:get,
139
- "http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=51.04499999999999%2C-114.0572222",
140
- :body => File.read(File.dirname(__FILE__) + '/fixtures/services/wunderground/current_calgary_ab.xml')
141
- )
142
- # http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=51.045%2C-114.0572222
143
- FakeWeb.register_uri(:get,
144
- "http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=51.04499999999999%2C-114.0572222",
145
- :body => File.read(File.dirname(__FILE__) + '/fixtures/services/wunderground/forecast_calgary_ab.xml')
146
- )
147
- FakeWeb.register_uri(:get,
148
- "http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=#{CGI.escape('Calgary,AB')}",
149
- :body => File.read(File.dirname(__FILE__) + '/fixtures/services/wunderground/current_calgary_ab.xml')
150
- )
151
- FakeWeb.register_uri(:get,
152
- "http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=#{CGI.escape('Calgary,AB')}",
153
- :body => File.read(File.dirname(__FILE__) + '/fixtures/services/wunderground/forecast_calgary_ab.xml')
154
- )
155
-
156
- #
157
- # For Placemaker
158
- #
159
- # curl -d "documentType=text%2Fhtml&outputType=xml&documentContent=<html><body><div class=\"geo\"><span class=\"latitude\">40.756054</span><span class=\"longitude\">-73.986951</span></div></body></html>" http://wherein.yahooapis.com/v1/document
160
- # curl -d "documentType=text%2Fhtml&outputType=xml&documentContent=Chicago" http://wherein.yahooapis.com/v1/document
161
- #
162
- FakeWeb.register_uri(:post,
163
- "http://wherein.yahooapis.com/v1/document",
164
- [
165
- {:body => File.read(File.dirname(__FILE__) + '/fixtures/services/placemaker/the_hills.xml')},
166
- {:body => File.read(File.dirname(__FILE__) + '/fixtures/services/placemaker/the_hills.xml')},
167
- {:body => File.read(File.dirname(__FILE__) + '/fixtures/services/placemaker/the_hills.xml')},
168
- {:body => File.read(File.dirname(__FILE__) + '/fixtures/services/placemaker/T5B4M9.xml')},
169
- {:body => File.read(File.dirname(__FILE__) + '/fixtures/services/placemaker/coords.xml')},
170
- {:body => File.read(File.dirname(__FILE__) + '/fixtures/services/placemaker/new_york.xml')},
171
- {:body => File.read(File.dirname(__FILE__) + '/fixtures/services/placemaker/atlanta.xml')},
172
- {:body => File.read(File.dirname(__FILE__) + '/fixtures/services/placemaker/ksfo.xml')}
173
- ]
174
- )
175
-
176
- FakeWeb.register_uri(:get,
177
- "http://weather.yahooapis.com/forecastrss?w=615702",
178
- :body => File.read(File.dirname(__FILE__) + '/fixtures/services/placemaker/w615702.xml')
179
- )