ym4r 0.0.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/README +24 -8
  2. data/lib/ym4r.rb +3 -4
  3. data/lib/ym4r/google_maps.rb +7 -0
  4. data/lib/ym4r/google_maps/api_key.rb +10 -0
  5. data/lib/ym4r/google_maps/config/config.yml +1 -0
  6. data/lib/ym4r/google_maps/control.rb +59 -0
  7. data/lib/ym4r/google_maps/helper.rb +19 -0
  8. data/lib/ym4r/google_maps/map.rb +94 -0
  9. data/lib/ym4r/google_maps/mapping.rb +70 -0
  10. data/lib/ym4r/google_maps/overlay.rb +125 -0
  11. data/lib/ym4r/google_maps/point.rb +34 -0
  12. data/lib/ym4r/yahoo_maps.rb +2 -0
  13. data/lib/ym4r/yahoo_maps/app_id.rb +5 -0
  14. data/lib/ym4r/yahoo_maps/building_block.rb +4 -0
  15. data/lib/ym4r/yahoo_maps/building_block/exception.rb +21 -0
  16. data/lib/ym4r/yahoo_maps/building_block/geocoding.rb +81 -0
  17. data/lib/ym4r/yahoo_maps/building_block/local_search.rb +156 -0
  18. data/lib/ym4r/yahoo_maps/building_block/map_image.rb +75 -0
  19. data/lib/ym4r/yahoo_maps/building_block/traffic.rb +120 -0
  20. data/lib/ym4r/yahoo_maps/flash.rb +7 -0
  21. data/lib/ym4r/yahoo_maps/flash/latlon.rb +18 -0
  22. data/lib/ym4r/yahoo_maps/flash/map.rb +74 -0
  23. data/lib/ym4r/yahoo_maps/flash/mapping.rb +71 -0
  24. data/lib/ym4r/yahoo_maps/flash/marker.rb +43 -0
  25. data/lib/ym4r/yahoo_maps/flash/overlay.rb +44 -0
  26. data/lib/ym4r/yahoo_maps/flash/tool.rb +30 -0
  27. data/lib/ym4r/yahoo_maps/flash/widget.rb +33 -0
  28. data/rakefile.rb +4 -4
  29. data/test/test_geocoding.rb +3 -3
  30. data/test/test_local_search.rb +2 -2
  31. data/test/test_map_image.rb +3 -3
  32. data/test/test_maps.rb +14 -0
  33. data/test/test_traffic.rb +1 -1
  34. metadata +30 -9
  35. data/lib/ym4r/app_id.rb +0 -3
  36. data/lib/ym4r/building_block/geocoding.rb +0 -81
  37. data/lib/ym4r/building_block/local_search.rb +0 -156
  38. data/lib/ym4r/building_block/map_image.rb +0 -76
  39. data/lib/ym4r/building_block/traffic.rb +0 -120
  40. data/lib/ym4r/exception.rb +0 -18
metadata CHANGED
@@ -3,9 +3,9 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: ym4r
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.1
7
- date: 2006-05-25 00:00:00 +05:00
8
- summary: Using the Yahoo Maps API from Ruby
6
+ version: 0.1.2
7
+ date: 2006-06-03 00:00:00 +05:00
8
+ summary: Using Google Maps and Yahoo! Maps from Ruby and Rails
9
9
  require_paths:
10
10
  - lib
11
11
  email: guilhem.vellut+ym4r@gmail.com
@@ -29,14 +29,34 @@ authors:
29
29
  - Guilhem Vellut
30
30
  files:
31
31
  - lib/ym4r.rb
32
- - lib/ym4r/app_id.rb
33
- - lib/ym4r/exception.rb
34
- - lib/ym4r/building_block/geocoding.rb
35
- - lib/ym4r/building_block/local_search.rb
36
- - lib/ym4r/building_block/map_image.rb
37
- - lib/ym4r/building_block/traffic.rb
32
+ - lib/ym4r/google_maps.rb
33
+ - lib/ym4r/yahoo_maps.rb
34
+ - lib/ym4r/google_maps/api_key.rb
35
+ - lib/ym4r/google_maps/control.rb
36
+ - lib/ym4r/google_maps/helper.rb
37
+ - lib/ym4r/google_maps/map.rb
38
+ - lib/ym4r/google_maps/mapping.rb
39
+ - lib/ym4r/google_maps/overlay.rb
40
+ - lib/ym4r/google_maps/point.rb
41
+ - lib/ym4r/yahoo_maps/app_id.rb
42
+ - lib/ym4r/yahoo_maps/building_block.rb
43
+ - lib/ym4r/yahoo_maps/flash.rb
44
+ - lib/ym4r/yahoo_maps/building_block/exception.rb
45
+ - lib/ym4r/yahoo_maps/building_block/geocoding.rb
46
+ - lib/ym4r/yahoo_maps/building_block/local_search.rb
47
+ - lib/ym4r/yahoo_maps/building_block/map_image.rb
48
+ - lib/ym4r/yahoo_maps/building_block/traffic.rb
49
+ - lib/ym4r/yahoo_maps/flash/latlon.rb
50
+ - lib/ym4r/yahoo_maps/flash/map.rb
51
+ - lib/ym4r/yahoo_maps/flash/mapping.rb
52
+ - lib/ym4r/yahoo_maps/flash/marker.rb
53
+ - lib/ym4r/yahoo_maps/flash/overlay.rb
54
+ - lib/ym4r/yahoo_maps/flash/tool.rb
55
+ - lib/ym4r/yahoo_maps/flash/widget.rb
56
+ - lib/ym4r/google_maps/config/config.yml
38
57
  - test/test_geocoding.rb
39
58
  - test/test_local_search.rb
59
+ - test/test_maps.rb
40
60
  - test/test_map_image.rb
41
61
  - test/test_traffic.rb
42
62
  - README
@@ -45,6 +65,7 @@ files:
45
65
  test_files:
46
66
  - test/test_geocoding.rb
47
67
  - test/test_local_search.rb
68
+ - test/test_maps.rb
48
69
  - test/test_map_image.rb
49
70
  - test/test_traffic.rb
50
71
  rdoc_options:
data/lib/ym4r/app_id.rb DELETED
@@ -1,3 +0,0 @@
1
- module Ym4r
2
- APP_ID = "YahooMaps4Ruby"
3
- end
@@ -1,81 +0,0 @@
1
- require 'ym4r/app_id'
2
- require 'ym4r/exception'
3
- require 'open-uri'
4
- require 'rexml/document'
5
-
6
- module Ym4r
7
- module BuildingBlock
8
- module Geocoding
9
- #Sends a request to the Yahoo! Maps geocoding service and returns the result in an easy to use Ruby object, hiding the creation of the query string and the XML parsing of the answer.
10
- def self.get(param)
11
- unless param.has_key?(:street) or
12
- param.has_key?(:city) or
13
- param.has_key?(:state) or
14
- param.has_key?(:zip) or
15
- param.has_key?(:location)
16
- raise Ym4r::MissingParameterException.new("Missing location data for the Yahoo! Maps Geocoding service")
17
- end
18
-
19
- url = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=#{Ym4r::APP_ID}&"
20
- url << "street=#{param[:street]}&" if param.has_key?(:street)
21
- url << "city=#{param[:city]}&" if param.has_key?(:city)
22
- url << "state=#{param[:state]}&" if param.has_key?(:state)
23
- url << "zip=#{param[:zip]}&" if param.has_key?(:zip)
24
- url << "location=#{param[:location]}&" if param.has_key?(:location)
25
- url << "output=xml"
26
-
27
- begin
28
- xml = open(URI.encode(url)).read
29
- rescue OpenURI::HTTPError => error
30
- raise Ym4r::BadRequestException.new(error.to_s)
31
- rescue
32
- raise Ym4r::ConnectionException.new("Unable to connect to Yahoo! Maps Geocoding service")
33
- end
34
-
35
- doc = REXML::Document.new(xml)
36
-
37
- if doc.root.name == "Error"
38
- raise Ym4r::RateLimitExceededException.new("Rate limit exceeded for Yahoo! Maps Geocoding service")
39
- else
40
- results = []
41
- doc.elements.each("//Result") do |result|
42
- data = result.elements
43
- results << Geocoding::Result.new(result.attributes['precision'],
44
- result.attributes['warning'],
45
- data['Latitude'].text.to_f,
46
- data['Longitude'].text.to_f,
47
- data['Address'].text,
48
- data['City'].text,
49
- data['State'].text,
50
- data['Zip'].text,
51
- data['Country'].text)
52
- end
53
- results
54
- end
55
- end
56
-
57
- #Contains a result match from the Yahoo! Maps geocoding service.
58
- class Result < Struct.new(:precision,:warning,:latitude,:longitude,:address,:city,:state,:zip,:country)
59
-
60
- #Convenience method for the lazy.
61
- def latlon
62
- [latitude,longitude]
63
- end
64
-
65
- #Convenience method for the lazy.
66
- def lonlat
67
- [longitude,latitude]
68
- end
69
-
70
- #Indicates if the location passed in the request could be exactly identified.
71
- def exact_match?
72
- warning.nil?
73
- end
74
-
75
- end
76
-
77
- end #Geocoding
78
-
79
- end #BuildingBlock
80
-
81
- end #Ym4r
@@ -1,156 +0,0 @@
1
- require 'ym4r/app_id'
2
- require 'ym4r/exception'
3
- require 'open-uri'
4
- require 'rexml/document'
5
-
6
- module Ym4r
7
- module BuildingBlock
8
- module LocalSearch
9
- #Send a request to the local search REST API V3.
10
- def self.get(param)
11
-
12
- unless param.has_key?(:street) or
13
- param.has_key?(:city) or
14
- param.has_key?(:state) or
15
- param.has_key?(:zip) or
16
- param.has_key?(:location) or
17
- (param.has_key?(:longitude) and param.has_key?(:latitude))
18
- raise Ym4r::MissingParameterException.new("Missing location data for the Yahoo! Maps Local Search service")
19
- end
20
-
21
- unless param.has_key?(:query) or
22
- param.has_key?(:listing_id)
23
- raise Ym4r::MissingParameterException.new("Missing query data for the Yahoo! Maps Local Search service")
24
- end
25
-
26
- url = "http://api.local.yahoo.com/LocalSearchService/V3/localSearch?appid=#{Ym4r::APP_ID}&"
27
- url << "query=#{param[:query]}&" if param.has_key?(:query)
28
- url << "listing_id=#{param[:query]}&" if param.has_key?(:listing_id)
29
- url << "results=#{param[:results]}&" if param.has_key?(:results)
30
- url << "start=#{param[:start]}&" if param.has_key?(:start)
31
- url << "sort=#{param[:sort]}&" if param.has_key?(:sort)
32
- url << "radius=#{param[:radius]}&" if param.has_key?(:radius)
33
- url << "street=#{param[:street]}&" if param.has_key?(:street)
34
- url << "city=#{param[:city]}&" if param.has_key?(:city)
35
- url << "state=#{param[:state]}&" if param.has_key?(:state)
36
- url << "zip=#{param[:zip]}&" if param.has_key?(:zip)
37
- url << "location=#{param[:location]}&" if param.has_key?(:location)
38
- url << "latitude=#{param[:latitude]}&" if param.has_key?(:latitude)
39
- url << "longitude=#{param[:longitude]}&" if param.has_key?(:longitude)
40
- url << "category=#{param[:category]}&" if param.has_key?(:category)
41
- url << "omit_category=#{param[:omit_category]}&" if param.has_key?(:omit_category)
42
- url << "minimum_rating=#{param[:minimum_rating]}&" if param.has_key?(:minimum_rating)
43
- url << "output=json"
44
-
45
- begin
46
- json = open(URI.encode(url)).read
47
- rescue OpenURI::HTTPError => error
48
- raise Ym4r::BadRequestException.new(error.to_s)
49
- rescue
50
- raise Ym4r::ConnectionException.new("Unable to connect to Yahoo! Maps REST service")
51
- end
52
-
53
- #see http://rubyforge.org/snippet/detail.php?type=snippet&id=29. Safe?
54
- json_obj = eval(json.gsub(/(["'])\s*:\s*(['"0-9tfn\[{])/){"#{$1}=>#{$2}"})
55
-
56
- if json_obj.has_key?("Error")
57
- raise Ym4r::RateLimitExceededException.new("Rate limit exceeded for Yahoo! Maps Traffic REST service")
58
- else
59
- json_result_set = json_obj['ResultSet']
60
-
61
- result_set = LocalSearch::ResultSet.new(json_result_set['ResultSetMapUrl'],
62
- json_result_set['totalResultsAvailable'].to_i,
63
- json_result_set['totalResultsReturned'].to_i,
64
- json_result_set['firstResultPosition'].to_i)
65
-
66
- unless json_result_set['Result'].nil?
67
- json_results = [json_result_set['Result']].flatten #uniform processing in case there is only one result
68
-
69
- json_results.each do |json_result|
70
-
71
- #get the rating
72
- json_rating = json_result['Rating']
73
- rating = LocalSearch::Rating.new(json_rating['AverageRating'].to_f, #when NaN, converted to 0 but can be tested (since TotalRating is 0 in this case) with is_rated? on the rating object
74
- json_rating['TotalRatings'].to_i,
75
- json_rating['TotalReviews'].to_i,
76
- Time.at(json_rating['LastReviewDate'].to_i),
77
- json_rating['LastReviewIntro'])
78
-
79
- #get the categories
80
- categories = []
81
- unless json_result['Categories']['Category'].nil? #no category present in the result
82
- json_categories = [json_result['Categories']['Category']].flatten #uniform processing in case there is only one category
83
- json_categories.each do |json_category|
84
- categories << LocalSearch::Category.new(json_category['id'].to_i,
85
- json_category['content'])
86
- end
87
- end
88
-
89
- result_set << LocalSearch::Result.new(json_result['id'].to_i,
90
- json_result['Title'],
91
- json_result['Address'],
92
- json_result['City'],
93
- json_result['State'],
94
- json_result['Phone'],
95
- json_result['Latitude'].to_f,
96
- json_result['Longitude'].to_f,
97
- rating,
98
- json_result['Distance'].to_f,
99
- json_result['Url'],
100
- json_result['ClickUrl'],
101
- json_result['MapUrl'],
102
- json_result['BusinessUrl'],
103
- json_result['BusinessClickUrl'],
104
- categories)
105
-
106
- end
107
- end #unless json_result_set['Result'].nil?
108
-
109
- result_set
110
-
111
- end
112
- end
113
-
114
- #Contains a list of results from the Yahoo! Maps Local Search REST service V3
115
- class ResultSet < Array
116
- attr_accessor :map_url, :total_results_available, :total_results_returned, :first_result_position
117
-
118
- def initialize(map_url,total_results_available, total_results_returned, first_result_position)
119
- super(0)
120
- @map_url = map_url
121
- @total_results_available = total_results_available
122
- @total_results_returned = total_results_returned
123
- @first_result_position = first_result_position
124
- end
125
-
126
- end
127
-
128
- #Contains a result from the Yahoo! Maps Local Search REST service V3.
129
- class Result < Struct.new(:id,:title,:address,:city,:state,:phone,:latitude,:longitude,:rating,:distance,:url,:click_url,:map_url,:business_url,:business_click_url,:categories)
130
-
131
- #convenience method for the lazy
132
- def lonlat
133
- [longitude,latitude]
134
- end
135
-
136
- #convenience method for the lazy
137
- def latlon
138
- [latitude,longitude]
139
- end
140
-
141
- end
142
-
143
- class Category < Struct.new(:id,:name)
144
- end
145
-
146
- class Rating < Struct.new(:average_rating,:total_ratings,:total_reviews,:last_review_date,:last_review_intro)
147
- def is_rated?
148
- total_ratings != 0
149
- end
150
- end
151
-
152
- end #LocalSearch
153
-
154
- end #BuildingBlock
155
-
156
- end #Ym4r
@@ -1,76 +0,0 @@
1
- require 'ym4r/app_id'
2
- require 'ym4r/exception'
3
- require 'open-uri'
4
- require 'rexml/document'
5
-
6
- module Ym4r
7
- module BuildingBlock
8
- module MapImage
9
- #Send a request to the Map image API. Gets back a url to an image. This image can be downloaded later.
10
- def self.get(param)
11
- unless param.has_key?(:street) or
12
- param.has_key?(:city) or
13
- param.has_key?(:state) or
14
- param.has_key?(:zip) or
15
- param.has_key?(:location) or
16
- (param.has_key?(:longitude) and param.has_key?(:latitude))
17
- raise Ym4r::MissingParameterException.new("Missing location data for the Yahoo! Maps Map Image service")
18
- end
19
-
20
- url = "http://api.local.yahoo.com/MapsService/V1/mapImage?appid=#{Ym4r::APP_ID}&"
21
- url << "street=#{param[:street]}&" if param.has_key?(:street)
22
- url << "city=#{param[:city]}&" if param.has_key?(:city)
23
- url << "state=#{param[:state]}&" if param.has_key?(:state)
24
- url << "zip=#{param[:zip]}&" if param.has_key?(:zip)
25
- url << "location=#{param[:location]}&" if param.has_key?(:location)
26
- url << "latitude=#{param[:latitude]}&" if param.has_key?(:latitude)
27
- url << "longitude=#{param[:longitude]}&" if param.has_key?(:longitude)
28
- url << "image_type=#{param[:image_type]}&" if param.has_key?(:image_type) #defaults to PNG
29
- url << "image_height=#{param[:image_height]}&" if param.has_key?(:image_height) #defaults to 500
30
- url << "image_width=#{param[:image_width]}&" if param.has_key?(:image_width) #defaults to 620
31
- url << "zoom=#{param[:zoom]}&" if param.has_key?(:zoom) #defaults to 6
32
- url << "radius=#{param[:radius]}&" if param.has_key?(:radius)
33
- url << "output=xml"
34
-
35
- begin
36
- xml = open(URI.encode(url)).read
37
- rescue OpenURI::HTTPError => error
38
- raise Ym4r::BadRequestException.new(error.to_s)
39
- rescue
40
- raise Ym4r::ConnectionException.new("Unable to connect to Yahoo! Maps Map Image service")
41
- end
42
-
43
- doc = REXML::Document.new(xml)
44
-
45
- if doc.root.name == "Error"
46
- raise Ym4r::RateLimitExceededException.new("Rate limit exceeded for Yahoo! Maps Map Image service")
47
- else
48
- result = doc.root
49
- MapImage::Result.new(result.attributes['warning'],
50
- result.text)
51
- end
52
- end
53
-
54
- #Contains a result match from the Yahoo! Maps Map Image service.
55
- class Result < Struct.new(:warning,:url)
56
-
57
- #Downloads the image to +file+.
58
- def download_to(file)
59
- data = open(url).read
60
- open(file,"wb") do |f|
61
- f.write data
62
- end
63
- end
64
-
65
- #Indicates if the location passed in the request could be exactly identified.
66
- def exact_match?
67
- warning.nil?
68
- end
69
-
70
- end
71
-
72
- end #MapImage
73
-
74
- end #BuildingBlock
75
-
76
- end #Ym4r
@@ -1,120 +0,0 @@
1
- require 'ym4r/app_id'
2
- require 'ym4r/exception'
3
- require 'open-uri'
4
- require 'rexml/document'
5
-
6
- module Ym4r
7
- module BuildingBlock
8
- module Traffic
9
- #Send a request to the traffic REST API.
10
- def self.get(param)
11
- unless param.has_key?(:street) or
12
- param.has_key?(:city) or
13
- param.has_key?(:state) or
14
- param.has_key?(:zip) or
15
- param.has_key?(:location) or
16
- (param.has_key?(:longitude) and param.has_key?(:latitude))
17
- raise Ym4r::MissingParameterException.new("Missing location data for the Yahoo! Maps Traffic service")
18
- end
19
-
20
- url = "http://api.local.yahoo.com/MapsService/V1/trafficData?appid=#{Ym4r::APP_ID}&"
21
- url << "street=#{param[:street]}&" if param.has_key?(:street)
22
- url << "city=#{param[:city]}&" if param.has_key?(:city)
23
- url << "state=#{param[:state]}&" if param.has_key?(:state)
24
- url << "zip=#{param[:zip]}&" if param.has_key?(:zip)
25
- url << "location=#{param[:location]}&" if param.has_key?(:location)
26
- url << "latitude=#{param[:latitude]}&" if param.has_key?(:latitude)
27
- url << "longitude=#{param[:longitude]}&" if param.has_key?(:longitude)
28
- url << "image_type=#{param[:image_type]}&" if param.has_key?(:image_type) #defaults to PNG
29
- url << "image_height=#{param[:image_height]}&" if param.has_key?(:image_height) #defaults to 500
30
- url << "image_width=#{param[:image_width]}&" if param.has_key?(:image_width) #defaults to 620
31
- url << "zoom=#{param[:zoom]}&" if param.has_key?(:zoom) #defaults to 6
32
- url << "radius=#{param[:radius]}&" if param.has_key?(:radius)
33
- url << "include_map=#{param[:include_map]?1:0}&" if param.has_key?(:include_map)
34
- url << "severity=#{param[:severity]}&" if param.has_key?(:severity)
35
- url << "output=xml"
36
-
37
- begin
38
- xml = open(URI.encode(url)).read
39
- rescue OpenURI::HTTPError => error
40
- raise Ym4r::BadRequestException.new(error.to_s)
41
- rescue
42
- raise Ym4r::ConnectionException.new("Unable to connect to Yahoo! Maps Traffic REST service")
43
- end
44
-
45
- doc = REXML::Document.new(xml)
46
-
47
- if doc.root.name == "Error"
48
- raise Ym4r::RateLimitExceededException.new("Rate limit exceeded for Yahoo! Maps Traffic REST service")
49
- else
50
- results = Traffic::ResultSet.new(Time.at(doc.root.elements['LastUpdateDate'].text.to_i),doc.root.elements['Warning'].nil? ? nil : doc.root.elements['Warning'].text)
51
-
52
- doc.root.elements.each('//Result') do |result|
53
- data = result.elements
54
- results << Traffic::Result.new(result.attributes['type'],
55
- data['Title'].text,
56
- data['Description'].text,
57
- data['Latitude'].text.to_f,
58
- data['Longitude'].text.to_f,
59
- data['Direction'].text,
60
- data['Severity'].text.to_i,
61
- Time.at(data['ReportDate'].text.to_i),
62
- Time.at(data['UpdateDate'].text.to_i),
63
- Time.at(data['EndDate'].text.to_i),
64
- data['ImageUrl'].nil? ? nil : data['ImageUrl'].text)
65
- end
66
- results
67
-
68
- end
69
- end
70
-
71
- #Contains a list of results from the Yahoo! Maps Traffic REST API
72
- class ResultSet < Array
73
- attr_accessor :last_update_date,:warning
74
-
75
- def initialize(last_update_date,warning)
76
- super(0)
77
- @last_update_date = last_update_date
78
- @warning = warning
79
- end
80
-
81
- #Indicates if the location passed in the request could be exactly identified.
82
- def exact_match?
83
- warning.nil?
84
- end
85
- end
86
-
87
- #Contains a result from the Yahoo! Maps Traffic REST service.
88
- class Result < Struct.new(:type,:title,:description,:latitude,:longitude,:direction,:severity,:report_date,:update_date,:end_date,:image_url)
89
-
90
- #Downloads the image (if there is one) to +file+.
91
- def download_to(file)
92
- if has_image?
93
- data = open(image_url).read
94
- open(file,"wb") do |f|
95
- f.write data
96
- end
97
- end
98
- end
99
-
100
- def has_image?
101
- ! image_url.nil?
102
- end
103
-
104
- #Convenience method for the lazy.
105
- def lonlat
106
- [longitude,latitude]
107
- end
108
-
109
- #Convenience method for the lazy.
110
- def latlon
111
- [latitude,longitude]
112
- end
113
-
114
- end
115
-
116
- end #Traffic
117
-
118
- end #BuildingBlock
119
-
120
- end #Ym4r