yahoo-placemaker 0.0.4 → 0.0.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/README.markdown CHANGED
@@ -10,6 +10,10 @@
10
10
 
11
11
  gem install yahoo-placemaker
12
12
 
13
+ ## Documentation
14
+
15
+ http://rdoc.info/github/kyledecot/yahoo-placemaker/master/frames
16
+
13
17
  ## Usage
14
18
 
15
19
  require 'yahoo-placemaker'
@@ -17,6 +21,7 @@
17
21
  result = Yahoo::Placemaker.extract "Columbus Ohio is my hometown"
18
22
  result.document.geographic_scope.name # Columbus, OH, US
19
23
  result.document.administrative_scope.centroid.latitude # 39.962
24
+ result.document.references.first.text # Columbus Ohio
20
25
 
21
26
  ## Contributing
22
27
 
@@ -1,4 +1,3 @@
1
- require "yahoo-placemaker/version"
2
1
  require "yahoo-placemaker/response"
3
2
  require "yahoo-placemaker/version"
4
3
 
@@ -8,8 +7,10 @@ require "net/http"
8
7
  module Yahoo
9
8
  module Placemaker
10
9
 
11
- def self.extract (text = '', options = {})
10
+ # Main method for interacting w/ the Yahoo! Placemaker API
12
11
 
12
+ def self.extract (text = '', options = {})
13
+ result = nil
13
14
  host = 'wherein.yahooapis.com'
14
15
 
15
16
  # These options need to be explicitly set!
@@ -20,23 +21,29 @@ module Yahoo
20
21
 
21
22
  req = ::Net::HTTP::Post.new('/v1/document')
22
23
  req.body = to_url_params(options)
23
- response = ::Net::HTTP.new(host).start do |http|
24
- http.request(req)
24
+ begin
25
+ response = ::Net::HTTP.new(host).start do |http|
26
+ http.request(req)
27
+ end
28
+ json = ::JSON.parse(response.body)
29
+
30
+ result = Yahoo::Placemaker::Response.new(json)
31
+ rescue Exception => e
32
+ # puts e
33
+ # Something has gone horribly wrong...
25
34
  end
26
- json = ::JSON.parse(response.body)
27
35
 
28
- Yahoo::Placemaker::Response.new(json)
36
+ result
29
37
 
30
38
  end
31
39
 
32
- private
40
+ private
33
41
 
34
- def self.to_url_params(h)
35
- elements = []
36
- h.keys.size.times do |i|
37
- elements << "#{h.keys[i]}=#{h.values[i]}"
38
- end
39
- elements.join('&')
42
+ # Takes a hash and turns it into a query string that can be used
43
+ # in a URL request
44
+
45
+ def self.to_url_params(params)
46
+ params.collect{|key, value| "#{key}=#{value}"}.join('&')
40
47
  end
41
48
 
42
49
  end
@@ -1,14 +1,12 @@
1
1
  require 'yahoo-placemaker/geographic_scope'
2
2
  require 'yahoo-placemaker/local_scope'
3
3
  require 'yahoo-placemaker/administrative_scope'
4
- require 'yahoo-placemaker/reference_list'
5
4
  require 'yahoo-placemaker/reference'
6
5
  require 'yahoo-placemaker/extents'
7
6
  require 'yahoo-placemaker/place'
8
- require 'yahoo-placemaker/places'
9
7
 
10
8
  class Yahoo::Placemaker::Document
11
- attr_accessor :administrative_scope, :geographic_scope, :local_scopes, :reference_list, :extents, :place_details, :places
9
+ attr_accessor :administrative_scope, :geographic_scope, :local_scopes, :references, :extents, :places
12
10
  def initialize(json)
13
11
 
14
12
  if json['administrativeScope']
@@ -23,7 +21,8 @@ class Yahoo::Placemaker::Document
23
21
  @administrative_scope = Yahoo::Placemaker::AdministrativeScope.new(json['administrativeScope'])
24
22
  end
25
23
 
26
- @places = Yahoo::Placemaker::Places.new
24
+ @places = Array.new
25
+
27
26
  # if the placeDetails key exists then that means that we
28
27
  # only have one result so we'll just use it. Otherwise
29
28
  # yahoo has given us back some POORLY formatted data which
@@ -42,8 +41,8 @@ class Yahoo::Placemaker::Document
42
41
  end
43
42
  end
44
43
 
44
+ @local_scopes = Array.new
45
45
  if json['localScopes']
46
- @local_scopes = Array.new
47
46
  if json['localScopes'].class == Array
48
47
  json['localScopes'].each do |ls|
49
48
  @local_scopes << Yahoo::Placemaker::LocalScope.new(ls['localScope'])
@@ -57,14 +56,16 @@ class Yahoo::Placemaker::Document
57
56
  @extents = Yahoo::Placemaker::Extents.new(json['extents'])
58
57
  end
59
58
 
60
- @reference_list = Yahoo::Placemaker::ReferenceList.new
59
+ # referenceList -> references
60
+
61
+ @references = Array.new
61
62
  if json['referenceList']
62
63
  if json['referenceList'].class == Array
63
64
  json['referenceList'].each do |reference|
64
- @reference_list << Yahoo::Placemaker::Reference.new(reference)
65
+ @references << Yahoo::Placemaker::Reference.new(reference)
65
66
  end
66
67
  else
67
- @reference_list << Yahoo::Placemaker::Reference.new(json['referenceList'])
68
+ @references << Yahoo::Placemaker::Reference.new(json['referenceList']['reference'])
68
69
  end
69
70
  end
70
71
 
@@ -1,11 +1,4 @@
1
1
  require 'yahoo-placemaker/scope'
2
- require 'yahoo-placemaker/centroid'
3
2
 
4
3
  class Yahoo::Placemaker::GeographicScope < Yahoo::Placemaker::Scope
5
- def initialize (json)
6
- @woe_id = json['woeId']
7
- @type = json['type']
8
- @name = json['name']
9
- @centroid = Yahoo::Placemaker::Centroid.new(json['centroid'])
10
- end
11
4
  end
@@ -1,6 +1,5 @@
1
1
  require 'yahoo-placemaker/scope'
2
2
  require 'yahoo-placemaker/ancestor'
3
- require 'yahoo-placemaker/centroid'
4
3
 
5
4
  class Yahoo::Placemaker::LocalScope < Yahoo::Placemaker::Scope
6
5
 
@@ -8,7 +7,7 @@ class Yahoo::Placemaker::LocalScope < Yahoo::Placemaker::Scope
8
7
 
9
8
  def initialize (json)
10
9
  super(json)
11
- @centroid = Yahoo::Placemaker::Centroid.new json['centroid']
10
+ @centroid = Yahoo::Placemaker::LatLng.new json['centroid']
12
11
  @south_west = Yahoo::Placemaker::LatLng.new json['southWest']
13
12
  @north_east = Yahoo::Placemaker::LatLng.new json['northEast']
14
13
  @ancestors = Array.new
@@ -16,8 +15,10 @@ class Yahoo::Placemaker::LocalScope < Yahoo::Placemaker::Scope
16
15
  json['ancestors'].each do |ancestor|
17
16
  @ancestors << Yahoo::Placemaker::Ancestor.new(ancestor['ancestor'])
18
17
  end
19
- else
18
+ elsif json['ancestors'].class == Hash
20
19
  @ancestors << Yahoo::Placemaker::Ancestor.new(json['ancestors']['ancestor'])
20
+ else
21
+ # no ancestors...country?
21
22
  end
22
23
  end
23
24
  end
@@ -1,4 +1,4 @@
1
- require 'yahoo-placemaker/centroid'
1
+ require 'yahoo-placemaker/lat_lng'
2
2
 
3
3
  class Yahoo::Placemaker::Place
4
4
 
@@ -8,7 +8,7 @@ class Yahoo::Placemaker::Place
8
8
  def initialize(json)
9
9
 
10
10
  @place_id = json['placeId']
11
- @centroid = Yahoo::Placemaker::Centroid.new json['place']['centroid']
11
+ @centroid = Yahoo::Placemaker::LatLng.new json['place']['centroid']
12
12
  @type = json['place']['type']
13
13
  @woe_id = json['place']['woeId']
14
14
  @name = json['place']['name']
@@ -3,8 +3,8 @@ class Yahoo::Placemaker::Reference
3
3
 
4
4
  def initialize(json)
5
5
  @woe_ids = json['woeIds']
6
- @end = json['end']
7
- @start = json['start']
6
+ @end = json['end'].to_i
7
+ @start = json['start'].to_i
8
8
  @place_reference_id = json['placeReferenceId']
9
9
  @place_ids = json['placeIds']
10
10
  @text = json['text']
@@ -1,10 +1,10 @@
1
- require 'yahoo-placemaker/centroid'
1
+ require 'yahoo-placemaker/lat_lng'
2
2
 
3
3
  class Yahoo::Placemaker::Scope
4
4
  attr_accessor :woe_id, :type, :name, :centroid
5
5
 
6
6
  def initialize(json)
7
- @centroid = Yahoo::Placemaker::Centroid.new json['centroid']
7
+ @centroid = Yahoo::Placemaker::LatLng.new(json['centroid'])
8
8
  @woe_id = json['woeId']
9
9
  @type = json['type']
10
10
  @name = json['name']
@@ -1,5 +1,5 @@
1
1
  module Yahoo
2
2
  module Placemaker
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.4.1"
4
4
  end
5
5
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Yahoo::Placemaker do
4
4
 
5
5
  it "determines we're talking about Columbus, Ohio" do
6
- VCR.use_cassette('columbus ohio') do
6
+ VCR.use_cassette('columbus ohio') do
7
7
  response = Yahoo::Placemaker.extract "columbus ohio"
8
8
  response.document.administrative_scope.name.should == "Columbus, OH, US"
9
9
  end
@@ -19,7 +19,14 @@ describe Yahoo::Placemaker do
19
19
  it "contains only one item in reference_list when given 'Atlanta Georgia'" do
20
20
  VCR.use_cassette('atlanta_georgia') do
21
21
  response = Yahoo::Placemaker.extract "Atlanta Georgia"
22
- response.document.reference_list.size.should == 1
22
+ response.document.references.size.should == 1
23
+ end
24
+ end
25
+
26
+ it "doesn't return any ancestors for 'France'" do
27
+ VCR.use_cassette('france') do
28
+ response = Yahoo::Placemaker.extract "France"
29
+ response.document.local_scopes.first.ancestors.should == Array.new
23
30
  end
24
31
  end
25
32
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yahoo-placemaker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-25 00:00:00.000000000Z
12
+ date: 2012-02-26 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70185541547500 !ruby/object:Gem::Requirement
16
+ requirement: &70231339663460 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70185541547500
24
+ version_requirements: *70231339663460
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: fakeweb
27
- requirement: &70185541545820 !ruby/object:Gem::Requirement
27
+ requirement: &70231339662920 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70185541545820
35
+ version_requirements: *70231339662920
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: vcr
38
- requirement: &70185541543640 !ruby/object:Gem::Requirement
38
+ requirement: &70231339662340 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70185541543640
46
+ version_requirements: *70231339662340
47
47
  description: Easily interact w/ the Yahoo Placemaker API
48
48
  email:
49
49
  - kyle.decot@me.com
@@ -60,18 +60,14 @@ files:
60
60
  - lib/yahoo-placemaker.rb
61
61
  - lib/yahoo-placemaker/administrative_scope.rb
62
62
  - lib/yahoo-placemaker/ancestor.rb
63
- - lib/yahoo-placemaker/centroid.rb
64
63
  - lib/yahoo-placemaker/config.rb
65
64
  - lib/yahoo-placemaker/document.rb
66
65
  - lib/yahoo-placemaker/extents.rb
67
66
  - lib/yahoo-placemaker/geographic_scope.rb
68
67
  - lib/yahoo-placemaker/lat_lng.rb
69
68
  - lib/yahoo-placemaker/local_scope.rb
70
- - lib/yahoo-placemaker/local_scopes.rb
71
69
  - lib/yahoo-placemaker/place.rb
72
- - lib/yahoo-placemaker/places.rb
73
70
  - lib/yahoo-placemaker/reference.rb
74
- - lib/yahoo-placemaker/reference_list.rb
75
71
  - lib/yahoo-placemaker/response.rb
76
72
  - lib/yahoo-placemaker/scope.rb
77
73
  - lib/yahoo-placemaker/version.rb
@@ -1,4 +0,0 @@
1
- require 'yahoo-placemaker/lat_lng'
2
-
3
- class Yahoo::Placemaker::Centroid < Yahoo::Placemaker::LatLng
4
- end
@@ -1,2 +0,0 @@
1
- class Yahoo::Placemaker::LocalScopes < Array
2
- end
@@ -1,2 +0,0 @@
1
- class Yahoo::Placemaker::Places < Array
2
- end
@@ -1,3 +0,0 @@
1
- require 'yahoo-placemaker/reference'
2
- class Yahoo::Placemaker::ReferenceList < Array
3
- end