google-geocoder 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -8,3 +8,7 @@
8
8
  == Version 0.0.2
9
9
 
10
10
  * Small bug fixes.
11
+
12
+ == Version 0.0.3
13
+
14
+ * Small bug fixes.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
data/bin/geo CHANGED
@@ -31,9 +31,12 @@ class Geo
31
31
  puts "Version: #{File.open(File::dirname(__FILE__) + "/../VERSION").readlines().first}"
32
32
  when /(.*)/ then
33
33
  begin
34
- @geocoder.query(query)
34
+ result = @geocoder.query(query)
35
+
36
+ puts "No results." if result.size == 0
35
37
  rescue Exception => e
36
- puts "Error: " + e.message
38
+ p e.class.name
39
+ puts "Error: " + e.message unless e.message.empty?
37
40
  end
38
41
  end
39
42
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{google-geocoder}
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alexander Shvets"]
@@ -45,33 +45,37 @@ module Google
45
45
  response = call_service(request)
46
46
 
47
47
  raise(GeocoderServerIsDown) if response.empty?
48
-
49
- raise(InvalidResponse, response['results']) if response['status'] != "OK" # success
50
48
 
51
- root = response["results"][0]
52
- address_components = root["address_components"]
53
- geometry = root["geometry"]
54
-
55
- country = address_component(address_components, "country")
56
- locality = address_component(address_components, "locality")
57
- administrative_area_l1 = address_component(address_components, "administrative_area_level_1")
58
- administrative_area_l2 = address_component(address_components, "administrative_area_level_2")
59
-
60
- latitude = geometry["location"]["lat"]
61
- longitude = geometry["location"]["lng"]
62
-
63
- puts "Country: #{country['long_name']} (#{country['short_name']})"
64
- puts "Locality: #{locality['long_name']} (#{locality['short_name']})"
65
- puts "Administrative Area (level 1): #{administrative_area_l1['long_name']} (#{administrative_area_l1['short_name']})"
66
- puts "Administrative Area (level 2): #{administrative_area_l2['long_name']} (#{administrative_area_l2['short_name']})" unless administrative_area_l2.nil?
67
-
68
- puts "Latitude: #{latitude}"
69
- puts "Longitude: #{longitude}"
70
-
71
- [latitude, longitude]
49
+ if response['status'] == "ZERO_RESULTS"
50
+ []
51
+ else
52
+ raise(InvalidResponse, response['results']) if response['status'] != "OK" # success
53
+
54
+ root = response["results"][0]
55
+ address_components = root["address_components"]
56
+ geometry = root["geometry"]
57
+
58
+ country = address_component(address_components, "country")
59
+ locality = address_component(address_components, "locality")
60
+ administrative_area_l1 = address_component(address_components, "administrative_area_level_1")
61
+ administrative_area_l2 = address_component(address_components, "administrative_area_level_2")
62
+
63
+ latitude = geometry["location"]["lat"]
64
+ longitude = geometry["location"]["lng"]
65
+
66
+ puts "Country: #{country['long_name']} (#{country['short_name']})"
67
+ puts "Locality: #{locality['long_name']} (#{locality['short_name']})"
68
+ puts "Administrative Area (level 1): #{administrative_area_l1['long_name']} (#{administrative_area_l1['short_name']})"
69
+ puts "Administrative Area (level 2): #{administrative_area_l2['long_name']} (#{administrative_area_l2['short_name']})" unless administrative_area_l2.nil?
70
+
71
+ puts "Latitude: #{latitude}"
72
+ puts "Longitude: #{longitude}"
73
+
74
+ [latitude, longitude]
75
+ end
72
76
  rescue OpenURI::HTTPError
73
77
  raise(GeocoderServerIsDown)
74
- end
78
+ end
75
79
  end
76
80
 
77
81
  private
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-geocoder
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alexander Shvets