yahoo-placemaker 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gemtest ADDED
File without changes
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  *.gem
2
2
  .DS_Store
3
3
  .bundle
4
+ spec/fixtures/*
4
5
  Gemfile.lock
5
6
  pkg/*
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
1
  source "http://rubygems.org"
2
-
3
- # Specify your gem's dependencies in yahoo-placemaker.gemspec
4
2
  gemspec
3
+
4
+ gem 'rake', '>= 0.8.7'
5
+ gem 'json'
data/README.markdown CHANGED
@@ -2,13 +2,22 @@
2
2
 
3
3
  `yahoo-placemaker` is a rubygem that allows for easy interaction w/ the [Yahoo Placemaker](http://developer.yahoo.com/geo/placemaker) API.
4
4
 
5
+ ## Build Status
5
6
 
6
- ## Examples
7
+ ![Build Status](https://secure.travis-ci.org/kyledecot/yahoo-placemaker.png)
8
+
9
+ ## Installation
10
+
11
+ gem install yahoo-placemaker
12
+
13
+ ## Usage
7
14
 
8
15
  require 'yahoo-placemaker'
9
- Yahoo::Placemaker.APP_ID = 'xxxx'
10
- place = Yahoo::Placemaker.extact "Columbus Ohio is my hometown"
16
+ Yahoo::Placemaker::APP_ID = 'xxxx'
17
+ result = Yahoo::Placemaker.extract "Columbus Ohio is my hometown"
18
+ result.document.geographic_scope.name # Columbus, OH, US
19
+ result.document.administrative_scope.centroid.latitude # 39.962
11
20
 
12
21
  ## Contributing
13
22
 
14
- I am by not means a Ruby guru so if you have seen something that I have done incorrectly or that could be improved please feel free to contribute some code!h
23
+ I am by not means a Ruby guru so if you have seen something that I have done incorrectly or that could be improved please feel free to contribute some code.
data/Rakefile CHANGED
@@ -1 +1,7 @@
1
- require "bundler/gem_tasks"
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
@@ -0,0 +1,4 @@
1
+ require 'yahoo-placemaker/scope'
2
+
3
+ class Yahoo::Placemaker::AdministrativeScope < Yahoo::Placemaker::Scope
4
+ end
@@ -0,0 +1,11 @@
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
@@ -0,0 +1,4 @@
1
+ require 'yahoo-placemaker/lat_lng'
2
+
3
+ class Yahoo::Placemaker::Centroid < Yahoo::Placemaker::LatLng
4
+ end
@@ -0,0 +1,67 @@
1
+ require 'yahoo-placemaker/geographic_scope'
2
+ require 'yahoo-placemaker/local_scope'
3
+ require 'yahoo-placemaker/administrative_scope'
4
+ require 'yahoo-placemaker/reference_list'
5
+ require 'yahoo-placemaker/reference'
6
+ require 'yahoo-placemaker/extents'
7
+ require 'yahoo-placemaker/place'
8
+ require 'yahoo-placemaker/places'
9
+
10
+ class Yahoo::Placemaker::Document
11
+ attr_accessor :administrative_scope, :geographic_scope, :local_scopes, :reference_list, :extents, :place_details, :places
12
+ def initialize(json)
13
+
14
+ if json['administrativeScope']
15
+ @administrative_scope = json['administrativeScope']
16
+ end
17
+
18
+ if json['geographicScope']
19
+ @geographic_scope = Yahoo::Placemaker::GeographicScope.new(json['geographicScope'])
20
+ end
21
+
22
+ if json['administrativeScope']
23
+ @administrative_scope = Yahoo::Placemaker::AdministrativeScope.new(json['administrativeScope'])
24
+ end
25
+
26
+ @places = Yahoo::Placemaker::Places.new
27
+ # if the placeDetails key exists then that means that we
28
+ # only have one result so we'll just use it. Otherwise
29
+ # yahoo has given us back some POORLY formatted data which
30
+ # is in numeric keys so we'll search for them and pull them out
31
+
32
+ if json.has_key? 'placeDetails'
33
+ @places << Yahoo::Placemaker::Place.new(json['placeDetails'])
34
+ else
35
+ (json.map{ |k,v| k =~ /^[\d]+$/ ? v : nil }).compact.each do |place|
36
+ @places << Yahoo::Placemaker::Place.new(place['placeDetails'])
37
+ end
38
+ end
39
+
40
+ if json['localScopes']
41
+ @local_scopes = Array.new
42
+ if json['localScopes'].class == Array
43
+ json['localScopes'].each do |ls|
44
+ @local_scopes << Yahoo::Placemaker::LocalScope.new(ls['localScope'])
45
+ end
46
+ else
47
+ @local_scopes << Yahoo::Placemaker::LocalScope.new(json['localScopes']['localScope'])
48
+ end
49
+ end
50
+
51
+ if json['extents']
52
+ @extents = Yahoo::Placemaker::Extents.new(json['extents'])
53
+ end
54
+
55
+ @reference_list = Yahoo::Placemaker::ReferenceList.new
56
+ if json['referenceList']
57
+ if json['referenceList'].class == Array
58
+ json['referenceList'].each do |reference|
59
+ @reference_list << Yahoo::Placemaker::Reference.new(reference)
60
+ end
61
+ else
62
+ @reference_list << Yahoo::Placemaker::Reference.new(json['referenceList'])
63
+ end
64
+ end
65
+
66
+ end
67
+ end
@@ -0,0 +1,13 @@
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
@@ -0,0 +1,11 @@
1
+ require 'yahoo-placemaker/scope'
2
+ require 'yahoo-placemaker/centroid'
3
+
4
+ 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
+ end
@@ -0,0 +1,7 @@
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
@@ -0,0 +1,23 @@
1
+ require 'yahoo-placemaker/scope'
2
+ require 'yahoo-placemaker/ancestor'
3
+ require 'yahoo-placemaker/centroid'
4
+
5
+ class Yahoo::Placemaker::LocalScope < Yahoo::Placemaker::Scope
6
+
7
+ attr_accessor :ancestors, :centroid, :south_west, :north_east
8
+
9
+ def initialize (json)
10
+ super(json)
11
+ @centroid = Yahoo::Placemaker::Centroid.new json['centroid']
12
+ @south_west = Yahoo::Placemaker::LatLng.new json['southWest']
13
+ @north_east = Yahoo::Placemaker::LatLng.new json['northEast']
14
+ @ancestors = Array.new
15
+ if json['ancestors'].class == Array
16
+ json['ancestors'].each do |ancestor|
17
+ @ancestors << Yahoo::Placemaker::Ancestor.new(ancestor['ancestor'])
18
+ end
19
+ else
20
+ @ancestors << Yahoo::Placemaker::Ancestor.new(json['ancestors']['ancestor'])
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,2 @@
1
+ class Yahoo::Placemaker::LocalScopes < Array
2
+ end
@@ -0,0 +1,21 @@
1
+ require 'yahoo-placemaker/centroid'
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::Centroid.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
@@ -0,0 +1,2 @@
1
+ class Yahoo::Placemaker::Places < Array
2
+ end
@@ -0,0 +1,16 @@
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']
7
+ @start = json['start']
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
@@ -0,0 +1,3 @@
1
+ require 'yahoo-placemaker/reference'
2
+ class Yahoo::Placemaker::ReferenceList < Array
3
+ end
@@ -0,0 +1,10 @@
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
@@ -0,0 +1,13 @@
1
+ require 'yahoo-placemaker/centroid'
2
+
3
+ class Yahoo::Placemaker::Scope
4
+ attr_accessor :woe_id, :type, :name, :centroid
5
+
6
+ def initialize(json)
7
+ @centroid = Yahoo::Placemaker::Centroid.new json['centroid']
8
+ @woe_id = json['woeId']
9
+ @type = json['type']
10
+ @name = json['name']
11
+ end
12
+
13
+ end
@@ -1,5 +1,5 @@
1
1
  module Yahoo
2
2
  module Placemaker
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -1,6 +1,8 @@
1
1
  require "yahoo-placemaker/version"
2
+ require "yahoo-placemaker/response"
3
+ require "yahoo-placemaker/version"
4
+
2
5
  require "json"
3
- require "ostruct"
4
6
  require "net/http"
5
7
 
6
8
  module Yahoo
@@ -22,7 +24,9 @@ module Yahoo
22
24
  http.request(req)
23
25
  end
24
26
  json = ::JSON.parse(response.body)
25
- OpenStruct.new(json)
27
+
28
+ Yahoo::Placemaker::Response.new(json)
29
+
26
30
  end
27
31
 
28
32
  private
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'vcr'
4
+ require 'fakeweb'
5
+ require 'yahoo-placemaker'
6
+
7
+ Yahoo::Placemaker::APP_ID = 'xxx'
8
+
9
+ VCR.config do |c|
10
+ c.cassette_library_dir = 'spec/fixtures'
11
+ c.stub_with :fakeweb
12
+ end
13
+
14
+ RSpec.configure do |config|
15
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Yahoo::Placemaker do
4
+
5
+ it "determines we're talking about Columbus, Ohio" do
6
+ VCR.use_cassette('columbus ohio') do
7
+ response = Yahoo::Placemaker.extract "columbus ohio"
8
+ response.document.administrative_scope.name.should == "Columbus, OH, US"
9
+ end
10
+ end
11
+
12
+ it "returns an administrative scope of 'United States' when given a string of text w/ two US locations" do
13
+ VCR.use_cassette('columbus ohio miami florida') do
14
+ response = Yahoo::Placemaker.extract "columbus ohio miami florida"
15
+ response.document.administrative_scope.name.should == "United States"
16
+ end
17
+ end
18
+
19
+ it "contains only one item in reference_list when given 'Atlanta Georgia'" do
20
+ VCR.use_cassette('atlanta_georgia') do
21
+ response = Yahoo::Placemaker.extract "Atlanta Georgia"
22
+ response.document.reference_list.size.should == 1
23
+ end
24
+ end
25
+
26
+ end
@@ -3,6 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
  require "yahoo-placemaker/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
+ s.platform = Gem::Platform::RUBY
6
7
  s.name = "yahoo-placemaker"
7
8
  s.version = Yahoo::Placemaker::VERSION
8
9
  s.authors = ["Kyle Decot"]
@@ -18,7 +19,8 @@ Gem::Specification.new do |s|
18
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
20
  s.require_paths = ["lib"]
20
21
 
21
- # specify any dependencies here; for example:
22
- # s.add_development_dependency "rspec"
23
- # s.add_runtime_dependency "rest-client"
24
- end
22
+ s.add_development_dependency "rspec"
23
+ s.add_development_dependency "fakeweb"
24
+ s.add_development_dependency "vcr"
25
+
26
+ end
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.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,41 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-20 00:00:00.000000000Z
13
- dependencies: []
12
+ date: 2012-02-25 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70211849137140 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70211849137140
25
+ - !ruby/object:Gem::Dependency
26
+ name: fakeweb
27
+ requirement: &70211849136500 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70211849136500
36
+ - !ruby/object:Gem::Dependency
37
+ name: vcr
38
+ requirement: &70211849135540 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70211849135540
14
47
  description: Easily interact w/ the Yahoo Placemaker API
15
48
  email:
16
49
  - kyle.decot@me.com
@@ -18,13 +51,32 @@ executables: []
18
51
  extensions: []
19
52
  extra_rdoc_files: []
20
53
  files:
54
+ - .gemtest
21
55
  - .gitignore
56
+ - .rspec
22
57
  - Gemfile
23
58
  - README.markdown
24
59
  - Rakefile
25
60
  - lib/yahoo-placemaker.rb
61
+ - lib/yahoo-placemaker/administrative_scope.rb
62
+ - lib/yahoo-placemaker/ancestor.rb
63
+ - lib/yahoo-placemaker/centroid.rb
26
64
  - lib/yahoo-placemaker/config.rb
65
+ - lib/yahoo-placemaker/document.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/local_scopes.rb
71
+ - lib/yahoo-placemaker/place.rb
72
+ - lib/yahoo-placemaker/places.rb
73
+ - lib/yahoo-placemaker/reference.rb
74
+ - lib/yahoo-placemaker/reference_list.rb
75
+ - lib/yahoo-placemaker/response.rb
76
+ - lib/yahoo-placemaker/scope.rb
27
77
  - lib/yahoo-placemaker/version.rb
78
+ - spec/spec_helper.rb
79
+ - spec/yahoo_placemaker_spec.rb
28
80
  - yahoo-placemaker.gemspec
29
81
  homepage: ''
30
82
  licenses: []
@@ -50,4 +102,6 @@ rubygems_version: 1.8.10
50
102
  signing_key:
51
103
  specification_version: 3
52
104
  summary: Easily interact w/ the Yahoo Placemaker API
53
- test_files: []
105
+ test_files:
106
+ - spec/spec_helper.rb
107
+ - spec/yahoo_placemaker_spec.rb