barometer 0.6.4 → 0.6.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/README.rdoc +1 -1
  2. data/VERSION.yml +1 -1
  3. data/barometer.gemspec +9 -2
  4. data/bin/barometer +1 -1
  5. data/lib/barometer/data/geo.rb +12 -1
  6. data/lib/barometer/formats/coordinates.rb +1 -1
  7. data/lib/barometer/query.rb +1 -1
  8. data/spec/barometer_spec.rb +13 -6
  9. data/spec/data/distance_spec.rb +1 -1
  10. data/spec/data/geo_spec.rb +1 -1
  11. data/spec/data/local_datetime_spec.rb +1 -1
  12. data/spec/data/local_time_spec.rb +1 -1
  13. data/spec/data/location_spec.rb +1 -1
  14. data/spec/data/pressure_spec.rb +1 -1
  15. data/spec/data/speed_spec.rb +1 -1
  16. data/spec/data/sun_spec.rb +1 -1
  17. data/spec/data/temperature_spec.rb +1 -1
  18. data/spec/data/units_spec.rb +1 -1
  19. data/spec/data/zone_spec.rb +2 -2
  20. data/spec/fixtures/geocode/40_73.json +173 -0
  21. data/spec/fixtures/geocode/90210.json +41 -0
  22. data/spec/fixtures/geocode/T5B4M9.json +35 -0
  23. data/spec/fixtures/geocode/atlanta.json +38 -0
  24. data/spec/fixtures/geocode/calgary_ab.json +38 -0
  25. data/spec/fixtures/geocode/ksfo.json +42 -0
  26. data/spec/fixtures/geocode/newyork_ny.json +38 -0
  27. data/spec/formats/coordinates_spec.rb +31 -31
  28. data/spec/formats/format_spec.rb +1 -1
  29. data/spec/formats/geocode_spec.rb +2 -2
  30. data/spec/formats/icao_spec.rb +1 -1
  31. data/spec/formats/postalcode_spec.rb +1 -1
  32. data/spec/formats/short_zipcode_spec.rb +1 -1
  33. data/spec/formats/weather_id_spec.rb +1 -1
  34. data/spec/formats/zipcode_spec.rb +1 -1
  35. data/spec/measurements/measurement_spec.rb +14 -14
  36. data/spec/measurements/result_array_spec.rb +1 -1
  37. data/spec/measurements/result_spec.rb +1 -1
  38. data/spec/query_spec.rb +3 -3
  39. data/spec/spec_helper.rb +31 -52
  40. data/spec/weather_services/google_spec.rb +4 -4
  41. data/spec/weather_services/services_spec.rb +2 -2
  42. data/spec/weather_services/weather_bug_spec.rb +6 -6
  43. data/spec/weather_services/weather_dot_com_spec.rb +3 -3
  44. data/spec/weather_services/wunderground_spec.rb +5 -5
  45. data/spec/weather_services/yahoo_spec.rb +3 -3
  46. data/spec/weather_spec.rb +15 -15
  47. data/spec/web_services/geocode_spec.rb +1 -1
  48. data/spec/web_services/web_services_spec.rb +1 -1
  49. metadata +9 -2
data/README.rdoc CHANGED
@@ -15,7 +15,7 @@ this.
15
15
 
16
16
  == version
17
17
 
18
- Version 0.6.4 is the current release of this gem.
18
+ Version 0.6.6 is the current release of this gem.
19
19
  The gem is available from github (attack-barometer) or rubyforge (barometer).
20
20
  It is fully functional (for five weather service APIs).
21
21
 
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 6
4
- :patch: 4
4
+ :patch: 6
5
5
  :build:
data/barometer.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{barometer}
8
- s.version = "0.6.4"
8
+ s.version = "0.6.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Mark G"]
12
- s.date = %q{2010-01-29}
12
+ s.date = %q{2010-02-02}
13
13
  s.default_executable = %q{barometer}
14
14
  s.description = %q{A multi API consuming weather forecasting superstar.}
15
15
  s.email = %q{barometer@attackcorp.com}
@@ -103,12 +103,19 @@ Gem::Specification.new do |s|
103
103
  "spec/fixtures/formats/weather_id/from_USGA0028.xml",
104
104
  "spec/fixtures/formats/weather_id/ksfo.xml",
105
105
  "spec/fixtures/formats/weather_id/new_york.xml",
106
+ "spec/fixtures/geocode/40_73.json",
106
107
  "spec/fixtures/geocode/40_73.xml",
108
+ "spec/fixtures/geocode/90210.json",
107
109
  "spec/fixtures/geocode/90210.xml",
110
+ "spec/fixtures/geocode/T5B4M9.json",
108
111
  "spec/fixtures/geocode/T5B4M9.xml",
112
+ "spec/fixtures/geocode/atlanta.json",
109
113
  "spec/fixtures/geocode/atlanta.xml",
114
+ "spec/fixtures/geocode/calgary_ab.json",
110
115
  "spec/fixtures/geocode/calgary_ab.xml",
116
+ "spec/fixtures/geocode/ksfo.json",
111
117
  "spec/fixtures/geocode/ksfo.xml",
118
+ "spec/fixtures/geocode/newyork_ny.json",
112
119
  "spec/fixtures/geocode/newyork_ny.xml",
113
120
  "spec/fixtures/services/google/calgary_ab.xml",
114
121
  "spec/fixtures/services/weather_bug/90210_current.xml",
data/bin/barometer CHANGED
@@ -66,7 +66,7 @@ require 'yaml'
66
66
 
67
67
  # file where API keys are stored
68
68
  KEY_FILE = File.expand_path(File.join('~', '.barometer'))
69
- BAROMETER_VERSION = '0.6.3'
69
+ BAROMETER_VERSION = '0.6.6'
70
70
 
71
71
  class App
72
72
 
@@ -24,7 +24,7 @@ module Barometer
24
24
 
25
25
  @query = location["name"]
26
26
  placemark = location["Placemark"]
27
- placemark = placemark.first if placemark.is_a?(Array)
27
+ placemark = find_most_accurate(placemark)
28
28
 
29
29
  if placemark && placemark["Point"] && placemark["Point"]["coordinates"]
30
30
  if placemark["Point"]["coordinates"].is_a?(Array)
@@ -62,6 +62,17 @@ module Barometer
62
62
  s.delete("")
63
63
  s.compact.join(', ')
64
64
  end
65
+
66
+ # geocode may return multiple results, use the first one that has the best accuracy
67
+ #
68
+ def find_most_accurate(placemark)
69
+ return placemark unless placemark.is_a?(Array)
70
+ most_accurate = placemark.first
71
+ placemark.each do |p|
72
+ most_accurate = p if p && p["AddressDetails"] && p["AddressDetails"]["Accuracy"] && p["AddressDetails"]["Accuracy"].to_i < most_accurate["AddressDetails"]["Accuracy"].to_i
73
+ end
74
+ most_accurate
75
+ end
65
76
 
66
77
  end
67
78
  end
@@ -10,7 +10,7 @@ module Barometer
10
10
  class Query::Format::Coordinates < Query::Format
11
11
 
12
12
  def self.format; :coordinates; end
13
- def self.regex; /^[-]?[0-9\.]+[,]{1}[-]?[0-9\.]+$/; end
13
+ def self.regex; /^[-]?[0-9\.]+[,]{1}\s?[-]?[0-9\.]+$/; end
14
14
  def self.convertable_formats
15
15
  [:short_zipcode, :zipcode, :postalcode, :weather_id, :coordinates, :icao, :geocode]
16
16
  end
@@ -104,7 +104,7 @@ module Barometer
104
104
  if Barometer.force_geocode && !@geo
105
105
  if converted_query && converted_query.geo
106
106
  @geo = converted_query.geo
107
- else
107
+ elsif converted_query
108
108
  puts "enhance geocode: #{converted_query.q}" if Barometer::debug?
109
109
  geo_query = Query::Format::Coordinates.to(converted_query)
110
110
  @geo = geo_query.geo if (geo_query && geo_query.geo)
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "Barometer" do
4
4
 
@@ -99,23 +99,30 @@ describe "Barometer" do
99
99
  @time = Time.now
100
100
  FakeWeb.register_uri(:get,
101
101
  "http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=#{CGI.escape(query_term)}",
102
- :string => File.read(File.join(File.dirname(__FILE__),
102
+ :body => File.read(File.join(File.dirname(__FILE__),
103
103
  'fixtures/services/wunderground',
104
104
  'current_calgary_ab.xml')
105
105
  )
106
106
  )
107
107
  FakeWeb.register_uri(:get,
108
108
  "http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=#{CGI.escape(query_term)}",
109
- :string => File.read(File.join(File.dirname(__FILE__),
109
+ :body => File.read(File.join(File.dirname(__FILE__),
110
110
  'fixtures/services/wunderground',
111
111
  'forecast_calgary_ab.xml')
112
112
  )
113
113
  )
114
+ # FakeWeb.register_uri(:get,
115
+ # "http://maps.google.com/maps/geo?gl=&key=#{@key}&q=Calgary%2CAB&sensor=false&output=xml",
116
+ # :body => File.read(File.join(File.dirname(__FILE__),
117
+ # 'fixtures/geocode',
118
+ # 'calgary_ab.xml')
119
+ # )
120
+ # )
114
121
  FakeWeb.register_uri(:get,
115
- "http://maps.google.com:80/maps/geo?gl=&q=Calgary%2CAB&output=xml&key=#{@key}",
116
- :string => File.read(File.join(File.dirname(__FILE__),
122
+ "http://maps.google.com/maps/geo?gl=&key=#{@key}&q=Calgary%2CAB&sensor=false&output=json",
123
+ :body => File.read(File.join(File.dirname(__FILE__),
117
124
  'fixtures/geocode',
118
- 'calgary_ab.xml')
125
+ 'calgary_ab.json')
119
126
  )
120
127
  )
121
128
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe "Data::Distance" do
4
4
 
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe "Data::Geo" do
4
4
 
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe "Data::LocalDateTime" do
4
4
 
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe "Data::LocalTime" do
4
4
 
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe "Location" do
4
4
 
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe "Pressure" do
4
4
 
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe "Speed" do
4
4
 
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe "Data::Sun" do
4
4
 
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe "Data::Temperature" do
4
4
 
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe "Units" do
4
4
 
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe "Data::Zone" do
4
4
 
@@ -65,7 +65,7 @@ describe "Data::Zone" do
65
65
  zone.code.should be_nil
66
66
 
67
67
  zone = Data::Zone.new(@timezone)
68
- zone.code.should == "CEST"
68
+ zone.code.should == "CET"
69
69
  end
70
70
 
71
71
  it "responds to dst?" do
@@ -0,0 +1,173 @@
1
+ {
2
+ "name": "40.756054,-73.986951",
3
+ "Status": {
4
+ "code": 200,
5
+ "request": "geocode"
6
+ },
7
+ "Placemark": [ {
8
+ "id": "p1",
9
+ "address": "Times Sq - 42nd St Station, New York, NY 10036, USA",
10
+ "AddressDetails": {
11
+ "Accuracy" : 9,
12
+ "AddressLine" : [ "Times Sq - 42nd St Station" ]
13
+ },
14
+ "ExtendedData": {
15
+ "LatLonBox": {
16
+ "north": 40.7591946,
17
+ "south": 40.7528994,
18
+ "east": -73.9838014,
19
+ "west": -73.9900966
20
+ }
21
+ },
22
+ "Point": {
23
+ "coordinates": [ -73.9869490, 40.7560470, 0 ]
24
+ }
25
+ }, {
26
+ "id": "p2",
27
+ "address": "600-614 7th Ave, New York, NY 10036, USA",
28
+ "AddressDetails": {
29
+ "Accuracy" : 8,
30
+ "Country" : {
31
+ "AdministrativeArea" : {
32
+ "AdministrativeAreaName" : "NY",
33
+ "SubAdministrativeArea" : {
34
+ "Locality" : {
35
+ "DependentLocality" : {
36
+ "DependentLocalityName" : "Manhattan",
37
+ "PostalCode" : {
38
+ "PostalCodeNumber" : "10036"
39
+ },
40
+ "Thoroughfare" : {
41
+ "ThoroughfareName" : "600-614 7th Ave"
42
+ }
43
+ },
44
+ "LocalityName" : "New York"
45
+ },
46
+ "SubAdministrativeAreaName" : "New York"
47
+ }
48
+ },
49
+ "CountryName" : "USA",
50
+ "CountryNameCode" : "US"
51
+ }
52
+ },
53
+ "ExtendedData": {
54
+ "LatLonBox": {
55
+ "north": 40.7595131,
56
+ "south": 40.7532178,
57
+ "east": -73.9835667,
58
+ "west": -73.9898620
59
+ }
60
+ },
61
+ "Point": {
62
+ "coordinates": [ -73.9869562, 40.7560561, 0 ]
63
+ }
64
+ }, {
65
+ "id": "p3",
66
+ "address": "Times Square-42nd Street, New York, NY 10036, USA",
67
+ "AddressDetails": {
68
+ "Accuracy" : 9,
69
+ "AddressLine" : [ "Times Square-42nd Street" ]
70
+ },
71
+ "ExtendedData": {
72
+ "LatLonBox": {
73
+ "north": 40.7591476,
74
+ "south": 40.7528524,
75
+ "east": -73.9838524,
76
+ "west": -73.9901476
77
+ }
78
+ },
79
+ "Point": {
80
+ "coordinates": [ -73.9870000, 40.7560000, 0 ]
81
+ }
82
+ }, {
83
+ "id": "p4",
84
+ "address": "W 42 ST at 7 AV, New York, NY 10036, USA",
85
+ "AddressDetails": {
86
+ "Accuracy" : 9,
87
+ "AddressLine" : [ "W 42 ST at 7 AV" ]
88
+ },
89
+ "ExtendedData": {
90
+ "LatLonBox": {
91
+ "north": 40.7591446,
92
+ "south": 40.7528494,
93
+ "east": -73.9839964,
94
+ "west": -73.9902916
95
+ }
96
+ },
97
+ "Point": {
98
+ "coordinates": [ -73.9871440, 40.7559970, 0 ]
99
+ }
100
+ }, {
101
+ "id": "p5",
102
+ "address": "W 42 ST at 7 AV, New York, NY 10036, USA",
103
+ "AddressDetails": {
104
+ "Accuracy" : 9,
105
+ "AddressLine" : [ "W 42 ST at 7 AV" ]
106
+ },
107
+ "ExtendedData": {
108
+ "LatLonBox": {
109
+ "north": 40.7594606,
110
+ "south": 40.7531654,
111
+ "east": -73.9842484,
112
+ "west": -73.9905436
113
+ }
114
+ },
115
+ "Point": {
116
+ "coordinates": [ -73.9873960, 40.7563130, 0 ]
117
+ }
118
+ }, {
119
+ "id": "p6",
120
+ "address": "W 42 ST at BROADWAY, New York, NY 10036, USA",
121
+ "AddressDetails": {
122
+ "Accuracy" : 9,
123
+ "AddressLine" : [ "W 42 ST at BROADWAY" ]
124
+ },
125
+ "ExtendedData": {
126
+ "LatLonBox": {
127
+ "north": 40.7588236,
128
+ "south": 40.7525284,
129
+ "east": -73.9831654,
130
+ "west": -73.9894606
131
+ }
132
+ },
133
+ "Point": {
134
+ "coordinates": [ -73.9863130, 40.7556760, 0 ]
135
+ }
136
+ }, {
137
+ "id": "p7",
138
+ "address": "7 AV at W 41 ST, New York, NY 10036, USA",
139
+ "AddressDetails": {
140
+ "Accuracy" : 9,
141
+ "AddressLine" : [ "7 AV at W 41 ST" ]
142
+ },
143
+ "ExtendedData": {
144
+ "LatLonBox": {
145
+ "north": 40.7586296,
146
+ "south": 40.7523344,
147
+ "east": -73.9843024,
148
+ "west": -73.9905976
149
+ }
150
+ },
151
+ "Point": {
152
+ "coordinates": [ -73.9874500, 40.7554820, 0 ]
153
+ }
154
+ }, {
155
+ "id": "p8",
156
+ "address": "7 AV at W 45 ST, New York, NY 10036, USA",
157
+ "AddressDetails": {
158
+ "Accuracy" : 9,
159
+ "AddressLine" : [ "7 AV at W 45 ST" ]
160
+ },
161
+ "ExtendedData": {
162
+ "LatLonBox": {
163
+ "north": 40.7610286,
164
+ "south": 40.7547334,
165
+ "east": -73.9825394,
166
+ "west": -73.9888346
167
+ }
168
+ },
169
+ "Point": {
170
+ "coordinates": [ -73.9856870, 40.7578810, 0 ]
171
+ }
172
+ } ]
173
+ }
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "90210",
3
+ "Status": {
4
+ "code": 200,
5
+ "request": "geocode"
6
+ },
7
+ "Placemark": [ {
8
+ "id": "p1",
9
+ "address": "Beverly Hills, CA 90210, USA",
10
+ "AddressDetails": {
11
+ "Accuracy" : 5,
12
+ "Country" : {
13
+ "AdministrativeArea" : {
14
+ "AdministrativeAreaName" : "CA",
15
+ "SubAdministrativeArea" : {
16
+ "Locality" : {
17
+ "LocalityName" : "Beverly Hills",
18
+ "PostalCode" : {
19
+ "PostalCodeNumber" : "90210"
20
+ }
21
+ },
22
+ "SubAdministrativeAreaName" : "Los Angeles"
23
+ }
24
+ },
25
+ "CountryName" : "USA",
26
+ "CountryNameCode" : "US"
27
+ }
28
+ },
29
+ "ExtendedData": {
30
+ "LatLonBox": {
31
+ "north": 34.1320070,
32
+ "south": 34.0644090,
33
+ "east": -118.3809750,
34
+ "west": -118.4467140
35
+ }
36
+ },
37
+ "Point": {
38
+ "coordinates": [ -118.4104684, 34.1030032, 0 ]
39
+ }
40
+ } ]
41
+ }