yahoo-placemaker 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,56 +1 @@
1
- require "yahoo-placemaker/response"
2
- require "yahoo-placemaker/exception"
3
- require "yahoo-placemaker/version"
4
-
5
- require "json"
6
- require "net/http"
7
-
8
- module Yahoo
9
- module Placemaker
10
-
11
- # Main method for interacting w/ the Yahoo! Placemaker API
12
-
13
- def self.extract (text = '', options = {})
14
-
15
- unless defined?(Yahoo::Placemaker::APP_ID)
16
- raise Yahoo::Placemaker::Exception.new("Invalid APP_ID")
17
- end
18
-
19
- result = nil
20
- host = 'wherein.yahooapis.com'
21
-
22
- # These options need to be explicitly set!
23
- options['documentContent'] = text
24
- options['appid'] = Yahoo::Placemaker::APP_ID
25
- options['outputType'] = 'json'
26
- options['documentType'] = 'text/plain'
27
-
28
- req = ::Net::HTTP::Post.new('/v1/document')
29
- req.body = to_url_params(options)
30
- begin
31
- response = ::Net::HTTP.new(host).start do |http|
32
- http.request(req)
33
- end
34
- json = ::JSON.parse(response.body)
35
-
36
- result = Yahoo::Placemaker::Response.new(json)
37
- rescue Exception => e
38
- # puts e
39
- # Something has gone horribly wrong...
40
- end
41
-
42
- result
43
-
44
- end
45
-
46
- private
47
-
48
- # Takes a hash and turns it into a query string that can be used
49
- # in a URL request
50
-
51
- def self.to_url_params(params)
52
- params.collect{|key, value| "#{key}=#{value}"}.join('&')
53
- end
54
-
55
- end
56
- end
1
+ require 'yahoo/placemaker'
@@ -0,0 +1,56 @@
1
+ require "yahoo/placemaker/response"
2
+ require "yahoo/placemaker/exception"
3
+ require "yahoo/placemaker/version"
4
+
5
+ require "json"
6
+ require "net/http"
7
+
8
+ module Yahoo
9
+ module Placemaker
10
+
11
+ # Main method for interacting w/ the Yahoo! Placemaker API
12
+
13
+ def self.extract (text = '', options = {})
14
+
15
+ unless defined?(Yahoo::Placemaker::APP_ID)
16
+ raise Yahoo::Placemaker::Exception.new("Invalid APP_ID")
17
+ end
18
+
19
+ result = nil
20
+ host = 'wherein.yahooapis.com'
21
+
22
+ # These options need to be explicitly set!
23
+ options['documentContent'] = text
24
+ options['appid'] = Yahoo::Placemaker::APP_ID
25
+ options['outputType'] = 'json'
26
+ options['documentType'] = 'text/plain'
27
+
28
+ req = ::Net::HTTP::Post.new('/v1/document')
29
+ req.body = to_url_params(options)
30
+ begin
31
+ response = ::Net::HTTP.new(host).start do |http|
32
+ http.request(req)
33
+ end
34
+ json = ::JSON.parse(response.body)
35
+
36
+ result = Yahoo::Placemaker::Response.new(json)
37
+ rescue Exception => e
38
+ # puts e
39
+ # Something has gone horribly wrong...
40
+ end
41
+
42
+ result
43
+
44
+ end
45
+
46
+ private
47
+
48
+ # Takes a hash and turns it into a query string that can be used
49
+ # in a URL request
50
+
51
+ def self.to_url_params(params)
52
+ params.collect{|key, value| "#{key}=#{value}"}.join('&')
53
+ end
54
+
55
+ end
56
+ end
@@ -0,0 +1,8 @@
1
+ require 'yahoo/placemaker/scope'
2
+
3
+ module Yahoo
4
+ module Placemaker
5
+ class AdministrativeScope < Yahoo::Placemaker::Scope
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,13 @@
1
+ module Yahoo
2
+ module Placemaker
3
+ class Ancestor
4
+ attr_accessor :woe_id, :type, :name
5
+
6
+ def initialize (json)
7
+ @woe_id = json['woeId']
8
+ @type = json['type']
9
+ @name = json['name']
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,11 +1,13 @@
1
- require 'yahoo-placemaker/geographic_scope'
2
- require 'yahoo-placemaker/local_scope'
3
- require 'yahoo-placemaker/administrative_scope'
4
- require 'yahoo-placemaker/reference'
5
- require 'yahoo-placemaker/extents'
6
- require 'yahoo-placemaker/place'
1
+ require 'yahoo/placemaker/geographic_scope'
2
+ require 'yahoo/placemaker/local_scope'
3
+ require 'yahoo/placemaker/administrative_scope'
4
+ require 'yahoo/placemaker/reference'
5
+ require 'yahoo/placemaker/extents'
6
+ require 'yahoo/placemaker/place'
7
7
 
8
- class Yahoo::Placemaker::Document
8
+ module Yahoo
9
+ module Placemaker
10
+ class Document
9
11
  attr_accessor :administrative_scope, :geographic_scope, :local_scopes, :references, :extents, :places
10
12
  def initialize(json)
11
13
 
@@ -69,5 +71,7 @@ class Yahoo::Placemaker::Document
69
71
  end
70
72
  end
71
73
 
74
+ end
75
+ end
72
76
  end
73
77
  end
@@ -0,0 +1,6 @@
1
+ module Yahoo
2
+ module Placemaker
3
+ class Exception < Exception
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,17 @@
1
+ require 'yahoo/placemaker/lat_lng'
2
+
3
+ module Yahoo
4
+ module Placemaker
5
+ class Extents
6
+
7
+ attr_accessor :center, :south_west, :north_east
8
+
9
+ def initialize(json)
10
+ @center = Yahoo::Placemaker::LatLng.new(json['center'])
11
+ @south_west = Yahoo::Placemaker::LatLng.new(json['southWest'])
12
+ @north_east = Yahoo::Placemaker::LatLng.new(json['northEast'])
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,8 @@
1
+ require 'yahoo/placemaker/scope'
2
+
3
+ module Yahoo
4
+ module Placemaker
5
+ class GeographicScope < Yahoo::Placemaker::Scope
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,11 @@
1
+ module Yahoo
2
+ module Placemaker
3
+ class LatLng
4
+ attr_accessor :latitude, :longitude
5
+ def initialize(json)
6
+ @latitude = json['latitude'].to_f
7
+ @longitude = json['longitude'].to_f
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,33 @@
1
+ require 'yahoo/placemaker/scope'
2
+ require 'yahoo/placemaker/ancestor'
3
+
4
+ module Yahoo
5
+ module Placemaker
6
+ class LocalScope < Yahoo::Placemaker::Scope
7
+
8
+ attr_accessor :ancestors, :centroid, :south_west, :north_east
9
+
10
+ def initialize (json)
11
+ super(json)
12
+ @centroid = Yahoo::Placemaker::LatLng.new json['centroid']
13
+ @south_west = Yahoo::Placemaker::LatLng.new json['southWest']
14
+ @north_east = Yahoo::Placemaker::LatLng.new json['northEast']
15
+
16
+ # Yahoo doesn't always return an array of ancestors; ancestors can
17
+ # be an array, a hash, or a string containing "\n"?! We need to
18
+ # account for this and stuff everything into @ancestors...
19
+
20
+ @ancestors = Array.new
21
+ if json['ancestors'].class == Array
22
+ json['ancestors'].each do |ancestor|
23
+ @ancestors << Yahoo::Placemaker::Ancestor.new(ancestor['ancestor'])
24
+ end
25
+ elsif json['ancestors'].class == Hash
26
+ @ancestors << Yahoo::Placemaker::Ancestor.new(json['ancestors']['ancestor'])
27
+ else
28
+ # no ancestors...country?
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,25 @@
1
+ require 'yahoo/placemaker/lat_lng'
2
+
3
+ module Yahoo
4
+ module Placemaker
5
+ class Place
6
+
7
+ attr_accessor :place_id, :match_type, :place_reference_ids, :weight, :confidence
8
+ attr_accessor :centroid, :type, :woe_id, :name
9
+
10
+ def initialize(json)
11
+
12
+ @place_id = json['placeId']
13
+ @centroid = Yahoo::Placemaker::LatLng.new json['place']['centroid']
14
+ @type = json['place']['type']
15
+ @woe_id = json['place']['woeId']
16
+ @name = json['place']['name']
17
+
18
+ @match_type = json['matchType']
19
+ @place_reference_ids = json['placeReferenceIds']
20
+ @weight = json['weight'].to_i
21
+ @confidence = json['confidence'].to_i
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,19 @@
1
+ module Yahoo
2
+ module Placemaker
3
+ class Reference
4
+ attr_accessor :woe_ids, :end, :start, :place_reference_id, :place_ids, :text, :type, :xpath, :is_plaintext_marker
5
+
6
+ def initialize(json)
7
+ @woe_ids = json['woeIds']
8
+ @end = json['end'].to_i
9
+ @start = json['start'].to_i
10
+ @place_reference_id = json['placeReferenceId']
11
+ @place_ids = json['placeIds']
12
+ @text = json['text']
13
+ @type = json['type']
14
+ @xpath = json['xpath']
15
+ @is_plaintext_marker = json['isPlaintextMarker']
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ require 'yahoo/placemaker/document'
2
+
3
+ module Yahoo
4
+ module Placemaker
5
+ class Response
6
+ attr_accessor :document, :version, :processing_time
7
+ def initialize (json)
8
+ @document = Yahoo::Placemaker::Document.new(json['document'])
9
+ @version = json['version']
10
+ @processing_time = json['processingTime']
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ require 'yahoo/placemaker/lat_lng'
2
+
3
+ module Yahoo
4
+ module Placemaker
5
+ class Scope
6
+
7
+ attr_accessor :woe_id, :type, :name, :centroid
8
+
9
+ def initialize(json)
10
+ @centroid = Yahoo::Placemaker::LatLng.new(json['centroid'])
11
+ @woe_id = json['woeId']
12
+ @type = json['type']
13
+ @name = json['name']
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -1,5 +1,5 @@
1
1
  module Yahoo
2
2
  module Placemaker
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
4
4
  end
5
5
  end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Yahoo::Placemaker::LatLng do
4
+
5
+ it "returns the latitude" do
6
+ stub = { :latitude => 0.0, :longitude => 0.0 }
7
+ ll = Yahoo::Placemaker::LatLng.new stub
8
+ ll.latitude.should == 0.0
9
+ end
10
+
11
+ it "returns the longitude" do
12
+ stub = { :latitude => 0.0, :longitude => 0.0 }
13
+ ll = Yahoo::Placemaker::LatLng.new stub
14
+ ll.longitude.should == 0.0
15
+ end
16
+ end
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+
3
+ describe Yahoo::Placemaker::Reference do
4
+ it "returns text" do
5
+ end
6
+ end
@@ -43,5 +43,4 @@ describe Yahoo::Placemaker do
43
43
  response.document.geographic_scope.should == nil
44
44
  end
45
45
  end
46
-
47
46
  end
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
- require "yahoo-placemaker/version"
3
+ require "yahoo/placemaker/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.platform = Gem::Platform::RUBY
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.5
4
+ version: 0.0.6
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-26 00:00:00.000000000Z
12
+ date: 2012-02-27 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70294204088140 !ruby/object:Gem::Requirement
16
+ requirement: &70155972433600 !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: *70294204088140
24
+ version_requirements: *70155972433600
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: fakeweb
27
- requirement: &70294204087600 !ruby/object:Gem::Requirement
27
+ requirement: &70155972433000 !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: *70294204087600
35
+ version_requirements: *70155972433000
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: vcr
38
- requirement: &70294204087020 !ruby/object:Gem::Requirement
38
+ requirement: &70155972432000 !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: *70294204087020
46
+ version_requirements: *70155972432000
47
47
  description: Easily interact w/ the Yahoo Placemaker API
48
48
  email:
49
49
  - kyle.decot@me.com
@@ -58,20 +58,23 @@ files:
58
58
  - README.markdown
59
59
  - Rakefile
60
60
  - lib/yahoo-placemaker.rb
61
- - lib/yahoo-placemaker/administrative_scope.rb
62
- - lib/yahoo-placemaker/ancestor.rb
63
- - lib/yahoo-placemaker/config.rb
64
- - lib/yahoo-placemaker/document.rb
65
- - lib/yahoo-placemaker/exception.rb
66
- - lib/yahoo-placemaker/extents.rb
67
- - lib/yahoo-placemaker/geographic_scope.rb
68
- - lib/yahoo-placemaker/lat_lng.rb
69
- - lib/yahoo-placemaker/local_scope.rb
70
- - lib/yahoo-placemaker/place.rb
71
- - lib/yahoo-placemaker/reference.rb
72
- - lib/yahoo-placemaker/response.rb
73
- - lib/yahoo-placemaker/scope.rb
74
- - lib/yahoo-placemaker/version.rb
61
+ - lib/yahoo/placemaker.rb
62
+ - lib/yahoo/placemaker/administrative_scope.rb
63
+ - lib/yahoo/placemaker/ancestor.rb
64
+ - lib/yahoo/placemaker/config.rb
65
+ - lib/yahoo/placemaker/document.rb
66
+ - lib/yahoo/placemaker/exception.rb
67
+ - lib/yahoo/placemaker/extents.rb
68
+ - lib/yahoo/placemaker/geographic_scope.rb
69
+ - lib/yahoo/placemaker/lat_lng.rb
70
+ - lib/yahoo/placemaker/local_scope.rb
71
+ - lib/yahoo/placemaker/place.rb
72
+ - lib/yahoo/placemaker/reference.rb
73
+ - lib/yahoo/placemaker/response.rb
74
+ - lib/yahoo/placemaker/scope.rb
75
+ - lib/yahoo/placemaker/version.rb
76
+ - spec/lat_lng_spec.rb
77
+ - spec/reference_spec.rb
75
78
  - spec/spec_helper.rb
76
79
  - spec/yahoo_placemaker_spec.rb
77
80
  - yahoo-placemaker.gemspec
@@ -100,5 +103,7 @@ signing_key:
100
103
  specification_version: 3
101
104
  summary: Easily interact w/ the Yahoo Placemaker API
102
105
  test_files:
106
+ - spec/lat_lng_spec.rb
107
+ - spec/reference_spec.rb
103
108
  - spec/spec_helper.rb
104
109
  - spec/yahoo_placemaker_spec.rb
@@ -1,4 +0,0 @@
1
- require 'yahoo-placemaker/scope'
2
-
3
- class Yahoo::Placemaker::AdministrativeScope < Yahoo::Placemaker::Scope
4
- end
@@ -1,11 +0,0 @@
1
- class Yahoo::Placemaker::Ancestor
2
-
3
- attr_accessor :woe_id, :type, :name
4
-
5
- def initialize (json)
6
- @woe_id = json['woeId']
7
- @type = json['type']
8
- @name = json['name']
9
- end
10
-
11
- end
@@ -1,2 +0,0 @@
1
- class Yahoo::Placemaker::Exception < Exception
2
- end
@@ -1,13 +0,0 @@
1
- require 'yahoo-placemaker/lat_lng'
2
-
3
- class Yahoo::Placemaker::Extents
4
-
5
- attr_accessor :center, :south_west, :north_east
6
-
7
- def initialize(json)
8
- @center = Yahoo::Placemaker::LatLng.new(json['center'])
9
- @south_west = Yahoo::Placemaker::LatLng.new(json['southWest'])
10
- @north_east = Yahoo::Placemaker::LatLng.new(json['northEast'])
11
- end
12
-
13
- end
@@ -1,4 +0,0 @@
1
- require 'yahoo-placemaker/scope'
2
-
3
- class Yahoo::Placemaker::GeographicScope < Yahoo::Placemaker::Scope
4
- end
@@ -1,7 +0,0 @@
1
- class Yahoo::Placemaker::LatLng
2
- attr_accessor :latitude, :longitude
3
- def initialize(json)
4
- @latitude = json['latitude'].to_f
5
- @longitude = json['longitude'].to_f
6
- end
7
- end
@@ -1,24 +0,0 @@
1
- require 'yahoo-placemaker/scope'
2
- require 'yahoo-placemaker/ancestor'
3
-
4
- class Yahoo::Placemaker::LocalScope < Yahoo::Placemaker::Scope
5
-
6
- attr_accessor :ancestors, :centroid, :south_west, :north_east
7
-
8
- def initialize (json)
9
- super(json)
10
- @centroid = Yahoo::Placemaker::LatLng.new json['centroid']
11
- @south_west = Yahoo::Placemaker::LatLng.new json['southWest']
12
- @north_east = Yahoo::Placemaker::LatLng.new json['northEast']
13
- @ancestors = Array.new
14
- if json['ancestors'].class == Array
15
- json['ancestors'].each do |ancestor|
16
- @ancestors << Yahoo::Placemaker::Ancestor.new(ancestor['ancestor'])
17
- end
18
- elsif json['ancestors'].class == Hash
19
- @ancestors << Yahoo::Placemaker::Ancestor.new(json['ancestors']['ancestor'])
20
- else
21
- # no ancestors...country?
22
- end
23
- end
24
- end
@@ -1,21 +0,0 @@
1
- require 'yahoo-placemaker/lat_lng'
2
-
3
- class Yahoo::Placemaker::Place
4
-
5
- attr_accessor :place_id, :match_type, :place_reference_ids, :weight, :confidence
6
- attr_accessor :centroid, :type, :woe_id, :name
7
-
8
- def initialize(json)
9
-
10
- @place_id = json['placeId']
11
- @centroid = Yahoo::Placemaker::LatLng.new json['place']['centroid']
12
- @type = json['place']['type']
13
- @woe_id = json['place']['woeId']
14
- @name = json['place']['name']
15
-
16
- @match_type = json['matchType']
17
- @place_reference_ids = json['placeReferenceIds']
18
- @weight = json['weight'].to_i
19
- @confidence = json['confidence'].to_i
20
- end
21
- end
@@ -1,16 +0,0 @@
1
- class Yahoo::Placemaker::Reference
2
- attr_accessor :woe_ids, :end, :start, :place_reference_id, :place_ids, :text, :type, :xpath, :is_plaintext_marker
3
-
4
- def initialize(json)
5
- @woe_ids = json['woeIds']
6
- @end = json['end'].to_i
7
- @start = json['start'].to_i
8
- @place_reference_id = json['placeReferenceId']
9
- @place_ids = json['placeIds']
10
- @text = json['text']
11
- @type = json['type']
12
- @xpath = json['xpath']
13
- @is_plaintext_marker = json['isPlaintextMarker']
14
- end
15
-
16
- end
@@ -1,10 +0,0 @@
1
- require 'yahoo-placemaker/document'
2
-
3
- class Yahoo::Placemaker::Response
4
- attr_accessor :document, :version, :processing_time
5
- def initialize (json)
6
- @document = Yahoo::Placemaker::Document.new(json['document'])
7
- @version = json['version']
8
- @processing_time = json['processingTime']
9
- end
10
- end
@@ -1,13 +0,0 @@
1
- require 'yahoo-placemaker/lat_lng'
2
-
3
- class Yahoo::Placemaker::Scope
4
- attr_accessor :woe_id, :type, :name, :centroid
5
-
6
- def initialize(json)
7
- @centroid = Yahoo::Placemaker::LatLng.new(json['centroid'])
8
- @woe_id = json['woeId']
9
- @type = json['type']
10
- @name = json['name']
11
- end
12
-
13
- end