graticule 0.1.2 → 0.1.3
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/CHANGELOG.txt +4 -2
- data/README.txt +5 -1
- data/bin/geocode +2 -16
- data/lib/graticule/cli.rb +8 -7
- data/lib/graticule/geocoders/google.rb +9 -6
- data/lib/graticule/version.rb +1 -1
- data/test/fixtures/responses/google/success.xml +2 -2
- metadata +3 -3
data/CHANGELOG.txt
CHANGED
data/README.txt
CHANGED
@@ -22,4 +22,8 @@ Graticule includes a command line interface (CLI).
|
|
22
22
|
|
23
23
|
$ geocode -s yahoo -a yahookey Washington, DC
|
24
24
|
Washington, DC US
|
25
|
-
latitude: 38.895222, longitude: -77.036758
|
25
|
+
latitude: 38.895222, longitude: -77.036758
|
26
|
+
|
27
|
+
= Source
|
28
|
+
|
29
|
+
The source code for Graticule is available at http://source.collectiveidea.com/public/geocode/trunk
|
data/bin/geocode
CHANGED
@@ -1,19 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
3
|
-
# This file was generated by RubyGems.
|
4
|
-
#
|
5
|
-
# The application 'geocode' is installed as part of a gem, and
|
6
|
-
# this file is here to facilitate running it.
|
7
|
-
#
|
8
2
|
|
9
|
-
require '
|
10
|
-
version = "> 0"
|
11
|
-
if ARGV.size > 0 && ARGV[0][0]==95 && ARGV[0][-1]==95
|
12
|
-
if Gem::Version.correct?(ARGV[0][1..-2])
|
13
|
-
version = ARGV[0][1..-2]
|
14
|
-
ARGV.shift
|
15
|
-
end
|
16
|
-
end
|
17
|
-
require_gem 'graticule', version
|
3
|
+
require 'graticule'
|
18
4
|
|
19
|
-
Graticule::Cli.start
|
5
|
+
Graticule::Cli.start ARGV
|
data/lib/graticule/cli.rb
CHANGED
@@ -19,10 +19,10 @@ module Graticule
|
|
19
19
|
# -h, --help Help
|
20
20
|
class Cli
|
21
21
|
|
22
|
-
def self.start
|
22
|
+
def self.start(args)
|
23
23
|
options = { :service => :yahoo, :api_key => 'YahooDemo' }
|
24
24
|
|
25
|
-
|
25
|
+
OptionParser.new do |opts|
|
26
26
|
opts.banner = "Usage: geocode [options] location"
|
27
27
|
opts.separator ""
|
28
28
|
opts.separator "Options: "
|
@@ -37,8 +37,10 @@ module Graticule
|
|
37
37
|
puts opts
|
38
38
|
exit
|
39
39
|
end
|
40
|
-
end.parse!
|
40
|
+
end.parse! args
|
41
41
|
|
42
|
+
options[:location] = args.join(" ")
|
43
|
+
|
42
44
|
result = Graticule.service(options[:service]).new(options[:api_key]).locate(options[:location])
|
43
45
|
location = (result.is_a?(Array) ? result.first : result)
|
44
46
|
if location
|
@@ -46,12 +48,11 @@ module Graticule
|
|
46
48
|
else
|
47
49
|
puts "Location not found"
|
48
50
|
end
|
49
|
-
rescue OptionParser::InvalidArgument => error
|
50
|
-
$stderr.puts error.message
|
51
|
-
rescue OptionParser::InvalidOption => error
|
52
|
-
$stderr.puts error.message
|
53
51
|
rescue Graticule::CredentialsError
|
54
52
|
$stderr.puts "Invalid API key. Pass your #{options[:service]} API key using the -a option. "
|
53
|
+
rescue OptionParser::InvalidArgument, OptionParser::InvalidOption,
|
54
|
+
Graticule::Error => error
|
55
|
+
$stderr.puts error.message
|
55
56
|
end
|
56
57
|
|
57
58
|
|
@@ -45,16 +45,19 @@ module Graticule
|
|
45
45
|
|
46
46
|
# Extracts a Location from +xml+.
|
47
47
|
def parse_response(xml) #:nodoc:
|
48
|
+
address = REXML::XPath.first(xml, '//xal:AddressDetails', 'xal' => "urn:oasis:names:tc:ciq:xsdschema:xAL:2.0")
|
49
|
+
|
48
50
|
longitude, latitude, = xml.elements['/kml/Response/Placemark/Point/coordinates'].text.split(',').map { |v| v.to_f }
|
51
|
+
|
49
52
|
Location.new \
|
50
|
-
:street =>
|
51
|
-
:city =>
|
52
|
-
:state =>
|
53
|
-
:zip =>
|
54
|
-
:country =>
|
53
|
+
:street => address.elements['Country/AdministrativeArea/SubAdministrativeArea/Locality/Thoroughfare/ThoroughfareName/text()'].value,
|
54
|
+
:city => address.elements['Country/AdministrativeArea/SubAdministrativeArea/Locality/LocalityName/text()'].value,
|
55
|
+
:state => address.elements['Country/AdministrativeArea/AdministrativeAreaName/text()'].value,
|
56
|
+
:zip => address.elements['Country/AdministrativeArea/SubAdministrativeArea/Locality/PostalCode/PostalCodeNumber/text()'].value,
|
57
|
+
:country => address.elements['Country/CountryNameCode/text()'].value,
|
55
58
|
:latitude => latitude,
|
56
59
|
:longitude => longitude,
|
57
|
-
:precision => PRECISION[
|
60
|
+
:precision => PRECISION[address.attribute('Accuracy').value.to_i] || :unknown
|
58
61
|
end
|
59
62
|
|
60
63
|
# Extracts and raises an error from +xml+, if any.
|
data/lib/graticule/version.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
<kml>
|
1
|
+
<kml xmlns="http://earth.google.com/kml/2.0">
|
2
2
|
<Response>
|
3
3
|
<name>1600 amphitheatre mtn view ca</name>
|
4
4
|
<Status>
|
@@ -9,7 +9,7 @@
|
|
9
9
|
<address>
|
10
10
|
1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA
|
11
11
|
</address>
|
12
|
-
<AddressDetails Accuracy="8">
|
12
|
+
<AddressDetails xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0" Accuracy="8">
|
13
13
|
<Country>
|
14
14
|
<CountryNameCode>US</CountryNameCode>
|
15
15
|
<AdministrativeArea>
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: graticule
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.1.
|
7
|
-
date: 2007-02-
|
6
|
+
version: 0.1.3
|
7
|
+
date: 2007-02-14 00:00:00 -05:00
|
8
8
|
summary: API for using all the popular geocoding services.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -109,5 +109,5 @@ dependencies:
|
|
109
109
|
requirements:
|
110
110
|
- - ">="
|
111
111
|
- !ruby/object:Gem::Version
|
112
|
-
version: 1.
|
112
|
+
version: 1.2.0
|
113
113
|
version:
|