kieranj-google-local-search 0.1.0 → 0.2.0

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.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :patch: 0
3
3
  :major: 0
4
- :minor: 1
4
+ :minor: 2
@@ -5,16 +5,20 @@ module GoogleLocalSearch
5
5
  class GeoCode
6
6
 
7
7
  GOOGLE_URL = "http://www.google.com/uds/GlocalSearch?"
8
+
9
+ class NoMatchFound < StandardError; end
10
+
11
+ class Location < Struct.new(:lat, :lng); end
8
12
 
9
13
  class << self
10
14
  def locate(address)
11
15
  options = { "rsz" => "small", "v" => "1.0" }
12
16
  options.merge!("q" => CGI.escape(address))
13
-
14
17
  response = Net::HTTP.get_response(URI.parse(GOOGLE_URL + options.map { |k,v| "#{k}=#{v}" }.join("&")))
15
18
  if response.is_a?(Net::HTTPSuccess)
16
19
  result = JSON.parse(response.body)
17
- return result['responseData']['results'][0]['lat'], result['responseData']['results'][0]['lng']
20
+ raise NoMatchFound if result['responseData']['results'].empty?
21
+ location = Location.new(result['responseData']['results'][0]['lat'], result['responseData']['results'][0]['lng'])
18
22
  else
19
23
  response.error!
20
24
  end
@@ -14,12 +14,16 @@ describe "GoogleLocalSearch" do
14
14
  lambda { GoogleLocalSearch::GeoCode.locate.should raise_error(ArgumentError) }
15
15
  end
16
16
 
17
- it "should return lat/lng array" do
18
- GoogleLocalSearch::GeoCode.locate("NW1").should be_instance_of(Array)
17
+ it "should return a Location object" do
18
+ GoogleLocalSearch::GeoCode.locate("NW1").should be_instance_of(GoogleLocalSearch::GeoCode::Location)
19
19
  end
20
20
 
21
- it "should have 2 items in the array" do
22
- GoogleLocalSearch::GeoCode.locate("NW1").length.should == 2
21
+ it "should have a latitude" do
22
+ GoogleLocalSearch::GeoCode.locate("NW1").lat.should_not be_nil
23
+ end
24
+
25
+ it "should have a longitude" do
26
+ GoogleLocalSearch::GeoCode.locate("NW1").lng.should_not be_nil
23
27
  end
24
28
 
25
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kieranj-google-local-search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kieran Johnson