geo_magic 0.2.4 → 0.2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.4
1
+ 0.2.4.1
data/geo_magic.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{geo_magic}
8
- s.version = "0.2.4"
8
+ s.version = "0.2.4.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kristian Mandrup"]
12
- s.date = %q{2011-01-24}
12
+ s.date = %q{2011-01-28}
13
13
  s.description = %q{Get IP and location data using freegeoip.net - can also calculate of distance between map points using haversine supporting multiple distance units}
14
14
  s.email = %q{kmandrup@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -44,6 +44,7 @@ Gem::Specification.new do |s|
44
44
  "lib/geo_magic/util.rb",
45
45
  "lib/rails/config.rb",
46
46
  "spec/fixtures/map_api_keys.yaml",
47
+ "spec/fixtures/streets.de.yml",
47
48
  "spec/geo_magic/calculate_spec.rb",
48
49
  "spec/geo_magic/geocoder_spec.rb",
49
50
  "spec/geo_magic/include_calc_spec.rb",
@@ -52,6 +53,7 @@ Gem::Specification.new do |s|
52
53
  "spec/geo_magic/remote_spec.rb",
53
54
  "spec/geo_magic/select_nearest_spec.rb",
54
55
  "spec/geo_magic/within_rect_spec.rb",
56
+ "spec/helper/streets.rb",
55
57
  "spec/spec_helper.rb"
56
58
  ]
57
59
  s.homepage = %q{http://github.com/kristianmandrup/geo_magic}
@@ -68,6 +70,7 @@ Gem::Specification.new do |s|
68
70
  "spec/geo_magic/remote_spec.rb",
69
71
  "spec/geo_magic/select_nearest_spec.rb",
70
72
  "spec/geo_magic/within_rect_spec.rb",
73
+ "spec/helper/streets.rb",
71
74
  "spec/spec_helper.rb"
72
75
  ]
73
76
 
@@ -12,7 +12,10 @@ module GeoMagic
12
12
  end
13
13
 
14
14
  def geocode location_str
15
- geo_coder.geocode(location_str).extend GeocodeAPI
15
+ result = geo_coder.geocode(CGI.escape(location_str)).extend GeocodeAPI
16
+ # p result.data['Status']
17
+ raise GeoMagic::GeoCodeError if result.data['Status']['code'] != 200
18
+ result
16
19
  end
17
20
 
18
21
  module GeocodeAPI
@@ -6,6 +6,8 @@ require 'geo_magic/geocode/graticule_adapter'
6
6
  require 'geo_magic/geocode/geocode_adapter'
7
7
 
8
8
  module GeoMagic
9
+ class GeoCodeError < StandardError; end;
10
+
9
11
  class << self
10
12
  def geo_coder options = {:type => :geocode, :service => :google}
11
13
  service_name = options[:service_name] || :google
@@ -19,7 +21,7 @@ module GeoMagic
19
21
  clazz.new services, env
20
22
  end
21
23
 
22
- def geocode location_str
24
+ def geocode location_str
23
25
  geo_coder.geocode location_str
24
26
  end
25
27
  end
@@ -0,0 +1,19 @@
1
+ de:
2
+ munich:
3
+ - Rosenheimerstrasse 108
4
+ - Marienplatz 14
5
+ - Karlzplatz 32
6
+ - Maximilianstrasse 7
7
+ - Burkleinstrasse 1
8
+ - Bruderstrasse 15
9
+ - Maxburgstrasse 12
10
+ - Rindermarkt 2
11
+ - Marienstrasse 10
12
+ - Reitmorstrasse 6
13
+ - Pilotystrasse 11
14
+ - Müllerstrasse 43
15
+ - Maxburgstrasse 9
16
+ - Salvatorstrasse 10
17
+ - Odeonsplatz 8
18
+ - Elisenstrasse 7
19
+ - sdgdsgpapdsdgdsg 1
@@ -1,5 +1,6 @@
1
1
  require 'spec_helper'
2
2
  require 'geo_magic'
3
+ require 'helper/streets'
3
4
 
4
5
  describe "GeoMagic Geocoder" do
5
6
  before do
@@ -41,6 +42,35 @@ describe "GeoMagic Geocoder" do
41
42
  end
42
43
 
43
44
 
45
+ context 'Streets from munich' do
46
+ before do
47
+ @geocoder = GeoMagic.geo_coder
48
+ @geocoder.configure File.expand_path('../fixtures/map_api_keys.yaml', File.dirname(__FILE__)), :development
49
+
50
+ @streets = Streets.load :munich
51
+ end
52
+
53
+ it "should not fail" do
54
+ begin
55
+ inst = @geocoder.instance
56
+
57
+ @streets.each do |street|
58
+ adr = "#{street}"
59
+ @adr = adr
60
+ p adr
61
+ @location = inst.geocode adr
62
+ # p "status: #{@location.data["Status"]}"
63
+ @location.city.should_not be_nil
64
+ # p "city: #{@location.city}"
65
+ end
66
+ rescue GeoMagic::GeoCodeError
67
+ p "OH NO! #{@adr}"
68
+ rescue Exception => e
69
+ p e
70
+ end
71
+ end
72
+ end
73
+
44
74
  # Geocoder with Rails 3
45
75
 
46
76
  # Expects map api keys (fx for google maps) to be defined in ROOT/config/map_api_keys.yml
@@ -0,0 +1,26 @@
1
+ module Streets
2
+ def self.load city
3
+ country_code = country_code_of(city)
4
+ city = city.to_s
5
+
6
+ @streets ||= {}
7
+ filename = File.join(SPEC_DIR, "fixtures/streets.#{country_code}.yml") # File.expand_path("./../fixtures/streets.#{country_code}.yml", __FILE__)
8
+ @streets[city] ||= begin
9
+ yml = YAML.load_file(filename)
10
+ yml[country_code.to_s][city.to_s]
11
+ rescue
12
+ puts "No key found for city: #{city} in #{filename}"
13
+ []
14
+ end
15
+ end
16
+
17
+ # Move away!
18
+ def self.country_code_of city = :munich
19
+ COUNTRY_CODES[city.to_s.downcase.to_sym]
20
+ end
21
+
22
+ COUNTRY_CODES = {
23
+ :munich => :de,
24
+ :vancouver => :ca
25
+ }
26
+ end
data/spec/spec_helper.rb CHANGED
@@ -7,6 +7,8 @@ require 'geo_magic'
7
7
  # in ./support/ and its subdirectories.
8
8
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
9
 
10
+ SPEC_DIR = File.dirname(__FILE__)
11
+
10
12
  RSpec.configure do |config|
11
13
 
12
14
  end
metadata CHANGED
@@ -6,7 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 0
7
7
  - 2
8
8
  - 4
9
- version: 0.2.4
9
+ - 1
10
+ version: 0.2.4.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Kristian Mandrup
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2011-01-24 00:00:00 +01:00
18
+ date: 2011-01-28 00:00:00 +01:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
@@ -172,6 +173,7 @@ files:
172
173
  - lib/geo_magic/util.rb
173
174
  - lib/rails/config.rb
174
175
  - spec/fixtures/map_api_keys.yaml
176
+ - spec/fixtures/streets.de.yml
175
177
  - spec/geo_magic/calculate_spec.rb
176
178
  - spec/geo_magic/geocoder_spec.rb
177
179
  - spec/geo_magic/include_calc_spec.rb
@@ -180,6 +182,7 @@ files:
180
182
  - spec/geo_magic/remote_spec.rb
181
183
  - spec/geo_magic/select_nearest_spec.rb
182
184
  - spec/geo_magic/within_rect_spec.rb
185
+ - spec/helper/streets.rb
183
186
  - spec/spec_helper.rb
184
187
  has_rdoc: true
185
188
  homepage: http://github.com/kristianmandrup/geo_magic
@@ -195,7 +198,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
195
198
  requirements:
196
199
  - - ">="
197
200
  - !ruby/object:Gem::Version
198
- hash: 1749247139327050469
201
+ hash: 3722236331284659990
199
202
  segments:
200
203
  - 0
201
204
  version: "0"
@@ -223,4 +226,5 @@ test_files:
223
226
  - spec/geo_magic/remote_spec.rb
224
227
  - spec/geo_magic/select_nearest_spec.rb
225
228
  - spec/geo_magic/within_rect_spec.rb
229
+ - spec/helper/streets.rb
226
230
  - spec/spec_helper.rb