ya_yahoo_geocode 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,19 +1,33 @@
1
1
  module YaYahooGeocode
2
2
 
3
3
  class Client
4
- @@YAHOO_GEOCODE_ENDPOING = 'http://where.yahooapis.com/geocode'
4
+ @@YAHOO_GEOCODE_ENDPOINT = 'http://where.yahooapis.com/geocode'
5
+ @@YAHOO_PLACES_ENDPOINT = 'http://where.yahooapis.com/v1/place'
5
6
 
6
7
  def search_for_place(search_terms)
7
8
  begin
8
- url = @@YAHOO_GEOCODE_ENDPOING + '?q=' + URI::escape(search_terms)
9
- response = do_http_get(url)
10
- response_hash = Nori.parse(response)['ResultSet']
9
+ url = @@YAHOO_GEOCODE_ENDPOINT + '?q=' + URI::escape(search_terms)
10
+ response = do_http_get(url)
11
+ response_hash = Nori.parse(response)['ResultSet']
11
12
  rescue Exception => e
12
13
  raise "Error searching for location: #{search_terms.inspect}. Got error: #{e.message}"
13
14
  end
14
15
  handle_errors(response_hash, search_terms)
15
16
  select_match(response_hash)
16
17
  end
18
+
19
+ def get_place_by_woeid(woeid)
20
+ begin
21
+ url = @@YAHOO_PLACES_ENDPOINT + '/' + woeid.to_s + '?appid=' + 'g9.D9ZTV34Ehp4lJeRQCgIWfBYBQ9NumiUYf76y3LFB3xbI7XU1fDB70uJgsBFkQ'
22
+ response = do_http_get(url)
23
+ response = Nori.parse(response)
24
+ response['place']
25
+ rescue Exception => e
26
+ raise "Error searching for location: #{woeid.inspect}. Got error: #{e.message}"
27
+ end
28
+ end
29
+
30
+
17
31
 
18
32
  private
19
33
  def do_http_get(url)
@@ -1,3 +1,3 @@
1
1
  module YaYahooGeocode
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,24 @@
1
+ require './lib/ya_yahoo_geocode.rb'
2
+
3
+ describe YaYahooGeocode::Client do
4
+ def sample
5
+ <<END
6
+ <?xml version="1.0" encoding="UTF-8"?>
7
+ <place xmlns="http://where.yahooapis.com/v1/schema.rng" xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" yahoo:uri="http://where.yahooapis.com/v1/place/28751381" xml:lang="en-US"><woeid>28751381</woeid><placeTypeName code="22">Suburb</placeTypeName><name>Midtown</name><country type="Country" code="US">United States</country><admin1 type="State" code="US-NY">New York</admin1><admin2 type="County" code="">Manhattan</admin2><admin3></admin3><locality1 type="Town">New York</locality1><locality2 type="Suburb">Midtown</locality2><postal type="Zip Code">10017</postal><centroid><latitude>40.751122</latitude><longitude>-73.977859</longitude></centroid><boundingBox><southWest><latitude>40.734409</latitude><longitude>-73.996986</longitude></southWest><northEast><latitude>40.767841</latitude><longitude>-73.958817</longitude></northEast></boundingBox><areaRank>2</areaRank><popRank>0</popRank></place>
8
+ END
9
+ end
10
+
11
+ describe "#get_place_by_woeid" do
12
+ context "all goes well" do
13
+ before :each do
14
+ @client = YaYahooGeocode::Client.new
15
+ @client.stub!(:do_http_get).and_return(sample)
16
+ end
17
+
18
+ it "should find Midtown by 28751381" do
19
+ place = @client.get_place_by_woeid(28751381)
20
+ place['name'].should == "Midtown"
21
+ end
22
+ end
23
+ end
24
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: ya_yahoo_geocode
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - John Hinnegan
@@ -52,7 +52,8 @@ files:
52
52
  - lib/ya_yahoo_geocode.rb
53
53
  - lib/ya_yahoo_geocode/client.rb
54
54
  - lib/ya_yahoo_geocode/version.rb
55
- - spec/ya_yahoo_geocode/client_spec.rb
55
+ - spec/ya_yahoo_geocode/client__get_place_by_woeid_spec.rb
56
+ - spec/ya_yahoo_geocode/client__search_for_place_spec.rb
56
57
  - ya_yahoo_geocode.gemspec
57
58
  has_rdoc: true
58
59
  homepage: ""
@@ -83,4 +84,5 @@ signing_key:
83
84
  specification_version: 3
84
85
  summary: This is a gem to help make various calls to yahoo's geo-aware api's
85
86
  test_files:
86
- - spec/ya_yahoo_geocode/client_spec.rb
87
+ - spec/ya_yahoo_geocode/client__get_place_by_woeid_spec.rb
88
+ - spec/ya_yahoo_geocode/client__search_for_place_spec.rb