Module Ym4r::YahooMaps::BuildingBlock::MapImage
In: lib/ym4r/yahoo_maps/building_block/map_image.rb

Methods

get  

Classes and Modules

Class Ym4r::YahooMaps::BuildingBlock::MapImage::Result

Public Class methods

Send a request to the Map image API. Gets back a url to an image. This image can be downloaded later.

[Source]

    # File lib/ym4r/yahoo_maps/building_block/map_image.rb, line 11
11:         def self.get(param)
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 MissingParameterException.new("Missing location data for the Yahoo! Maps Map Image service")
19:           end
20:           
21:           url = "http://api.local.yahoo.com/MapsService/V1/mapImage?appid=#{Ym4r::YahooMaps::APP_ID}&"
22:           url << "street=#{param[:street]}&" if param.has_key?(:street)
23:           url << "city=#{param[:city]}&" if param.has_key?(:city)
24:           url << "state=#{param[:state]}&" if param.has_key?(:state)
25:           url << "zip=#{param[:zip]}&" if param.has_key?(:zip)
26:           url << "location=#{param[:location]}&" if param.has_key?(:location)
27:           url << "latitude=#{param[:latitude]}&" if param.has_key?(:latitude)
28:           url << "longitude=#{param[:longitude]}&" if param.has_key?(:longitude)
29:           url << "image_type=#{param[:image_type]}&" if param.has_key?(:image_type) #defaults to PNG
30:           url << "image_height=#{param[:image_height]}&" if param.has_key?(:image_height) #defaults to 500
31:           url << "image_width=#{param[:image_width]}&" if param.has_key?(:image_width) #defaults to 620
32:           url << "zoom=#{param[:zoom]}&" if param.has_key?(:zoom) #defaults to 6
33:           url << "radius=#{param[:radius]}&" if param.has_key?(:radius)
34:           url << "output=xml"
35:           
36:           begin
37:             xml = open(URI.encode(url)).read
38:           rescue OpenURI::HTTPError => error
39:             raise BadRequestException.new(error.to_s)
40:           rescue
41:             raise ConnectionException.new("Unable to connect to Yahoo! Maps Map Image service")
42:           end
43:           
44:           doc = REXML::Document.new(xml) 
45:           
46:           if doc.root.name == "Error"
47:             raise RateLimitExceededException.new("Rate limit exceeded for Yahoo! Maps Map Image service")
48:           else
49:             result = doc.root
50:             MapImage::Result.new(result.attributes['warning'],
51:                                  result.text)
52:           end
53:         end

[Validate]