mapquest 0.0.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/.gitignore +18 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +43 -0
- data/Rakefile +9 -0
- data/lib/mapquest.rb +34 -0
- data/lib/mapquest/request.rb +16 -0
- data/lib/mapquest/response.rb +28 -0
- data/lib/mapquest/services/core.rb +13 -0
- data/lib/mapquest/services/directions.rb +66 -0
- data/lib/mapquest/services/geocoding.rb +83 -0
- data/lib/mapquest/version.rb +3 -0
- data/mapquest.gemspec +27 -0
- data/test/directions_spec.rb +21 -0
- data/test/fixtures/invalid_key.json +1 -0
- data/test/fixtures/no_data.json +1 -0
- data/test/fixtures/results.json +1 -0
- data/test/geocoding_spec.rb +78 -0
- data/test/spec_helper.rb +13 -0
- metadata +153 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2013 Gordan Grasarevic
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# MapQuest [](https://travis-ci.org/ggordan/mapquest)
|
|
2
|
+
|
|
3
|
+
A gem to communicate with the MapQuest web services.
|
|
4
|
+
|
|
5
|
+
API Key
|
|
6
|
+
----
|
|
7
|
+
To get an API key visit [http://developer.mapquest.com](http://developer.mapquest.com)
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
Add this line to your application's Gemfile:
|
|
12
|
+
|
|
13
|
+
gem 'mapquest'
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install mapquest
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
require 'mapquest'
|
|
26
|
+
|
|
27
|
+
# Instantiate the API using an API key
|
|
28
|
+
mapquest = MapQuest.new API_KEY
|
|
29
|
+
|
|
30
|
+
# Get geolocation data
|
|
31
|
+
data = mapquest.geocoding.decode :location => "London, UK"
|
|
32
|
+
|
|
33
|
+
# Get lat/long coordinates of all the locations found
|
|
34
|
+
data.locations.each { |location| puts location[:latLng] }
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
## Contributing
|
|
38
|
+
|
|
39
|
+
1. Fork it
|
|
40
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
41
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
42
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
43
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/mapquest.rb
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require 'rest-client'
|
|
2
|
+
require 'json'
|
|
3
|
+
require "mapquest/response"
|
|
4
|
+
require "mapquest/request"
|
|
5
|
+
require "mapquest/services/core"
|
|
6
|
+
require "mapquest/services/directions"
|
|
7
|
+
require "mapquest/services/geocoding"
|
|
8
|
+
|
|
9
|
+
class MapQuest
|
|
10
|
+
|
|
11
|
+
attr_accessor :api_key, :response
|
|
12
|
+
class Error < StandardError; end
|
|
13
|
+
|
|
14
|
+
def initialize(key)
|
|
15
|
+
@api_key = key
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def geocoding
|
|
19
|
+
Services::Geocoding.new self
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def directions
|
|
23
|
+
Services::Directions.new self
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def request(method, params, response)
|
|
27
|
+
req = Request.new method
|
|
28
|
+
params.merge! :key => api_key
|
|
29
|
+
params.each { |k,v| params.delete(k) if v.nil? }
|
|
30
|
+
@response = response.new req.send(params)
|
|
31
|
+
return @response
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class MapQuest
|
|
2
|
+
class Request < RestClient::Resource
|
|
3
|
+
|
|
4
|
+
# The base url of the mapquest api
|
|
5
|
+
API_ROOT = 'http://www.mapquestapi.com/%s/v%s/%s'
|
|
6
|
+
|
|
7
|
+
def initialize(method)
|
|
8
|
+
super API_ROOT % [method[:location], method[:version], method[:call]]
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def send(params)
|
|
12
|
+
get :params => params
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
class MapQuest
|
|
2
|
+
class Response
|
|
3
|
+
|
|
4
|
+
attr_reader :response, :valid
|
|
5
|
+
|
|
6
|
+
class InvalidRequest < StandardError; end
|
|
7
|
+
|
|
8
|
+
def initialize(response_string)
|
|
9
|
+
@response = JSON.parse(response_string, :symbolize_names => true)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def info
|
|
13
|
+
response[:info]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def copyright
|
|
17
|
+
info[:copyright]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Returns information about the response.
|
|
21
|
+
# :code is an integer return value. See http://www.mapquestapi.com/geocoding/status_codes.html
|
|
22
|
+
# :messages subfield is an array of error messages which describe the status.
|
|
23
|
+
def status
|
|
24
|
+
return :code => info[:statuscode].to_i, :messages => info[:messages]
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
class MapQuest
|
|
2
|
+
module Services
|
|
3
|
+
class Directions < Core
|
|
4
|
+
|
|
5
|
+
API_LOCATION = :directions
|
|
6
|
+
|
|
7
|
+
def get(params)
|
|
8
|
+
if params.has_key? :from && :to
|
|
9
|
+
api_method = {
|
|
10
|
+
:location => API_LOCATION,
|
|
11
|
+
:version => '1',
|
|
12
|
+
:call => 'route'
|
|
13
|
+
}
|
|
14
|
+
response = mapquest.request api_method, params, Response
|
|
15
|
+
else
|
|
16
|
+
raise Error
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
class Response < MapQuest::Response
|
|
21
|
+
|
|
22
|
+
def valid_request?
|
|
23
|
+
if response[:route].any?
|
|
24
|
+
true
|
|
25
|
+
else
|
|
26
|
+
false
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def route
|
|
31
|
+
response[:route]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Returns the drive time in <b>minutes</b>
|
|
35
|
+
def time
|
|
36
|
+
(route[:time].to_i / 60).ceil
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Returns the calculated distance of the route in <b>miles</b>
|
|
40
|
+
def distance
|
|
41
|
+
route[:distance].to_i
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def locations
|
|
45
|
+
route[:locations]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Returns a hash of the maneuvers in the route
|
|
49
|
+
def maneuvers
|
|
50
|
+
route[:legs].first[:maneuvers]
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Returns only the narratives for the route as a list
|
|
54
|
+
def narrative
|
|
55
|
+
narrative = []
|
|
56
|
+
route[:legs].first[:maneuvers].each do |maneuver|
|
|
57
|
+
narrative.push maneuver[:narrative]
|
|
58
|
+
end
|
|
59
|
+
narrative
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
class MapQuest
|
|
2
|
+
module Services
|
|
3
|
+
class Geocoding < Core
|
|
4
|
+
|
|
5
|
+
API_LOCATION = :geocoding
|
|
6
|
+
|
|
7
|
+
# Returns a response object of the found locations
|
|
8
|
+
# == Required parameters
|
|
9
|
+
# * :location [String] The location for which you wish to get data
|
|
10
|
+
# == Optional parameters
|
|
11
|
+
# * :maxResults [Integer] The number of results to limit the response to. Defaults to -1 (-1 indicates no limit)
|
|
12
|
+
# * :thumbMaps [Boolean] Return a URL to a static map thumbnail image for a location. Defaults to true
|
|
13
|
+
def decode(params = {})
|
|
14
|
+
raise Error unless params.has_key? :location
|
|
15
|
+
|
|
16
|
+
# Remove keys that are not supported
|
|
17
|
+
params.keys.each { |k| params.delete(k) unless [:location,:maxResults,:thumbMaps].include? k }
|
|
18
|
+
api_method = {
|
|
19
|
+
:location => API_LOCATION,
|
|
20
|
+
:version => '1',
|
|
21
|
+
:call => 'address'
|
|
22
|
+
}
|
|
23
|
+
mapquest.request api_method, params, Response
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Returns a response object of the found locations
|
|
27
|
+
# == Required parameters
|
|
28
|
+
# * :location [Array] The lat, and lng to search for
|
|
29
|
+
# == Optional parameters
|
|
30
|
+
# * :maxResults [Integer] The number of results to limit the response to. Defaults to -1 (-1 indicates no limit)
|
|
31
|
+
# * :thumbMaps [Boolean] Return a URL to a static map thumbnail image for a location. Defaults to true
|
|
32
|
+
def reverse(params = {})
|
|
33
|
+
raise Error unless params.has_key?(:location) && params[:location].kind_of?(Array)
|
|
34
|
+
params[:location] = params[:location].join(',')
|
|
35
|
+
api_method = {
|
|
36
|
+
:location => API_LOCATION,
|
|
37
|
+
:version => '1',
|
|
38
|
+
:call => 'reverse'
|
|
39
|
+
}
|
|
40
|
+
mapquest.request api_method, params, Response
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
class Response < MapQuest::Response
|
|
44
|
+
|
|
45
|
+
def initialize(response_string)
|
|
46
|
+
super response_string
|
|
47
|
+
valid_request?
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Check whether the request made to the API call is valid. Raises an error if the response code is 500
|
|
51
|
+
def valid_request?
|
|
52
|
+
# 400 - Error with input
|
|
53
|
+
# 403 - Key related error
|
|
54
|
+
# 500 -Unknown error
|
|
55
|
+
# Check http://www.mapquestapi.com/geocoding/status_codes.html for more details
|
|
56
|
+
invalid_requests = [400, 403, 500]
|
|
57
|
+
if invalid_requests.include? status[:code]
|
|
58
|
+
if status[:code] === 500
|
|
59
|
+
raise InvalidRequest
|
|
60
|
+
end
|
|
61
|
+
@valid = false
|
|
62
|
+
else
|
|
63
|
+
@valid = true
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def locations
|
|
68
|
+
if valid then response[:results].first[:locations] else status end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def providedLocation
|
|
72
|
+
if valid then response[:results].first[:providedLocation] else status end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def options
|
|
76
|
+
if valid then response[:options] else status end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
data/mapquest.gemspec
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'mapquest/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "mapquest"
|
|
8
|
+
spec.version = MapQuest::VERSION
|
|
9
|
+
spec.authors = ["Gordan Grasarevic"]
|
|
10
|
+
spec.email = ["me@ggordan.com"]
|
|
11
|
+
spec.description = "Retrieve data from various MapQuest web services"
|
|
12
|
+
spec.summary = "Retrieve data from various MapQuest web services"
|
|
13
|
+
spec.homepage = ""
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files`.split($/)
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_dependency "json"
|
|
22
|
+
spec.add_dependency "rest-client"
|
|
23
|
+
|
|
24
|
+
spec.add_development_dependency "rspec", "~> 2.8.0"
|
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
|
26
|
+
spec.add_development_dependency "rake"
|
|
27
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
|
+
|
|
3
|
+
describe "MapQuest::Services::Directions" do
|
|
4
|
+
|
|
5
|
+
before :all do
|
|
6
|
+
init
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
describe '.new' do
|
|
10
|
+
it 'should be an instance of' do
|
|
11
|
+
@mapquest.directions.should be_an_instance_of MapQuest::Services::Directions
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
describe '#get' do
|
|
16
|
+
it 'raise an error if :from and :to are missing' do
|
|
17
|
+
expect { @mapquest.directions.get }.to raise_error
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"results":[{"locations":[],"providedLocation":{}}],"options":{"ignoreLatLngInput":false,"maxResults":-1,"thumbMaps":true},"info":{"copyright":{"text":"© 2013 MapQuest, Inc.","imageUrl":"http://api.mqcdn.com/res/mqlogo.gif","imageAltText":"© 2013 MapQuest, Inc."},"statuscode":403,"messages":["This is not a valid key. Please check that you have entered this correctly. If you do not have a key, you can obtain a free key by registering at http://developer.mapquest.com."]}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"results":[{"locations":[{"latLng":{"lng":-99.141968,"lat":39.527596},"adminArea4":"","adminArea5Type":"City","adminArea4Type":"County","adminArea5":"","street":"","adminArea1":"US","adminArea3":"","type":"s","displayLatLng":{"lng":-99.141968,"lat":39.527596},"linkId":0,"postalCode":"","sideOfStreet":"N","dragPoint":false,"adminArea1Type":"Country","geocodeQuality":"COUNTRY","geocodeQualityCode":"A1XAX","mapUrl":"http://www.mapquestapi.com/staticmap/v4/getmap?key=Fmjtd|luub2d6ynu,7a=o5-9u22gr&type=map&size=225,160&pois=purple-1,39.527596,-99.141968,0,0|¢er=39.527596,-99.141968&zoom=2&rand=-1587667519","adminArea3Type":"State"}],"providedLocation":{"location":"adsddhasuidy3289asda"}}],"options":{"ignoreLatLngInput":false,"maxResults":-1,"thumbMaps":true},"info":{"copyright":{"text":"© 2013 MapQuest, Inc.","imageUrl":"http://api.mqcdn.com/res/mqlogo.gif","imageAltText":"© 2013 MapQuest, Inc."},"statuscode":0,"messages":[]}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"results":[{"locations":[{"latLng":{"lng":-0.12766,"lat":51.507276},"adminArea4":"London","adminArea5Type":"City","adminArea4Type":"County","adminArea5":"London","street":"","adminArea1":"GB","adminArea3":"England","type":"s","displayLatLng":{"lng":-0.12766,"lat":51.507276},"linkId":0,"postalCode":"","sideOfStreet":"N","dragPoint":false,"adminArea1Type":"Country","geocodeQuality":"CITY","geocodeQualityCode":"A5XAX","mapUrl":"http://www.mapquestapi.com/staticmap/v4/getmap?key=Fmjtd|luub2d6ynu,7a=o5-9u22gr&type=map&size=225,160&pois=purple-1,51.5072759,-0.1276597,0,0|¢er=51.5072759,-0.1276597&zoom=12&rand=-1536541888","adminArea3Type":"State"},{"latLng":{"lng":-0.08729,"lat":51.514624},"adminArea4":"City of London","adminArea5Type":"City","adminArea4Type":"County","adminArea5":"","street":"","adminArea1":"GB","adminArea3":"England","type":"s","displayLatLng":{"lng":-0.08729,"lat":51.514624},"linkId":0,"postalCode":"","sideOfStreet":"N","dragPoint":false,"adminArea1Type":"Country","geocodeQuality":"COUNTY","geocodeQualityCode":"A4XXX","mapUrl":"http://www.mapquestapi.com/staticmap/v4/getmap?key=Fmjtd|luub2d6ynu,7a=o5-9u22gr&type=map&size=225,160&pois=purple-2,51.5146237,-0.0872901,0,0|¢er=51.5146237,-0.0872901&zoom=9&rand=-1536541888","adminArea3Type":"State"},{"latLng":{"lng":-3.049338,"lat":59.135418},"adminArea4":"Rousay","adminArea5Type":"City","adminArea4Type":"County","adminArea5":"London","street":"","adminArea1":"GB","adminArea3":"Scotland","type":"s","displayLatLng":{"lng":-3.049338,"lat":59.135418},"linkId":0,"postalCode":"","sideOfStreet":"N","dragPoint":false,"adminArea1Type":"Country","geocodeQuality":"CITY","geocodeQualityCode":"A5XAX","mapUrl":"http://www.mapquestapi.com/staticmap/v4/getmap?key=Fmjtd|luub2d6ynu,7a=o5-9u22gr&type=map&size=225,160&pois=purple-3,59.1354177,-3.0493379,0,0|¢er=59.1354177,-3.0493379&zoom=12&rand=-1536541888","adminArea3Type":"State"},{"latLng":{"lng":-0.141158,"lat":51.517561},"adminArea4":"London","adminArea5Type":"City","adminArea4Type":"County","adminArea5":"City of Westminster","street":"Mortimer Street","adminArea1":"GB","adminArea3":"England","type":"s","displayLatLng":{"lng":-0.141158,"lat":51.517561},"linkId":0,"postalCode":"W1B 3DG","sideOfStreet":"N","dragPoint":false,"adminArea1Type":"Country","geocodeQuality":"ADDRESS","geocodeQualityCode":"L1XXX","mapUrl":"http://www.mapquestapi.com/staticmap/v4/getmap?key=Fmjtd|luub2d6ynu,7a=o5-9u22gr&type=map&size=225,160&pois=purple-4,51.5175614698645,-0.141158489226213,0,0|¢er=51.5175614698645,-0.141158489226213&zoom=15&rand=-1536541888","adminArea3Type":"State"},{"latLng":{"lng":-2.978759,"lat":51.350317},"adminArea4":"North Somerset","adminArea5Type":"City","adminArea4Type":"County","adminArea5":"Weston-super-Mare","street":"Waterloo Street","adminArea1":"GB","adminArea3":"England","type":"s","displayLatLng":{"lng":-2.978759,"lat":51.350317},"linkId":0,"postalCode":"","sideOfStreet":"N","dragPoint":false,"adminArea1Type":"Country","geocodeQuality":"ADDRESS","geocodeQualityCode":"L1XXX","mapUrl":"http://www.mapquestapi.com/staticmap/v4/getmap?key=Fmjtd|luub2d6ynu,7a=o5-9u22gr&type=map&size=225,160&pois=purple-5,51.3503173,-2.9787593,0,0|¢er=51.3503173,-2.9787593&zoom=15&rand=-1536541888","adminArea3Type":"State"},{"latLng":{"lng":-0.132185,"lat":51.516195},"adminArea4":"London","adminArea5Type":"City","adminArea4Type":"County","adminArea5":"City of Westminster","street":"47 Oxford Street","adminArea1":"GB","adminArea3":"England","type":"s","displayLatLng":{"lng":-0.132185,"lat":51.516195},"linkId":0,"postalCode":"W1D 2DU","sideOfStreet":"N","dragPoint":false,"adminArea1Type":"Country","geocodeQuality":"ADDRESS","geocodeQualityCode":"L1XXX","mapUrl":"http://www.mapquestapi.com/staticmap/v4/getmap?key=Fmjtd|luub2d6ynu,7a=o5-9u22gr&type=map&size=225,160&pois=purple-6,51.5161952,-0.1321849,0,0|¢er=51.5161952,-0.1321849&zoom=15&rand=-1536541888","adminArea3Type":"State"},{"latLng":{"lng":-0.111696,"lat":51.601489},"adminArea4":"London","adminArea5Type":"City","adminArea4Type":"County","adminArea5":"London Borough of Haringey","street":"Canning Crescent","adminArea1":"GB","adminArea3":"England","type":"s","displayLatLng":{"lng":-0.111696,"lat":51.601489},"linkId":0,"postalCode":"N22 8LE","sideOfStreet":"N","dragPoint":false,"adminArea1Type":"Country","geocodeQuality":"ADDRESS","geocodeQualityCode":"L1XXX","mapUrl":"http://www.mapquestapi.com/staticmap/v4/getmap?key=Fmjtd|luub2d6ynu,7a=o5-9u22gr&type=map&size=225,160&pois=purple-7,51.6014893,-0.1116958,0,0|¢er=51.6014893,-0.1116958&zoom=15&rand=-1536541888","adminArea3Type":"State"}],"providedLocation":{"location":"London, UK"}}],"options":{"ignoreLatLngInput":false,"maxResults":-1,"thumbMaps":true},"info":{"copyright":{"text":"© 2013 MapQuest, Inc.","imageUrl":"http://api.mqcdn.com/res/mqlogo.gif","imageAltText":"© 2013 MapQuest, Inc."},"statuscode":0,"messages":[]}}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
|
+
|
|
3
|
+
describe 'MapQuest::Services::Geocoding' do
|
|
4
|
+
|
|
5
|
+
context 'when valid request' do
|
|
6
|
+
|
|
7
|
+
before :all do
|
|
8
|
+
@mapquest = MapQuest.new 'xxx'
|
|
9
|
+
@response = MapQuest::Services::Geocoding::Response.new fixture 'results'
|
|
10
|
+
@response.valid.should == true
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe '.new' do
|
|
14
|
+
it 'should be an instance of' do
|
|
15
|
+
@mapquest.geocoding.should be_an_instance_of MapQuest::Services::Geocoding
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
describe '#decode' do
|
|
20
|
+
it 'should raise an error' do
|
|
21
|
+
expect { @mapquest.geocoding.decode }.to raise_error
|
|
22
|
+
end
|
|
23
|
+
it 'should be an instance of' do
|
|
24
|
+
@response.should be_an_instance_of MapQuest::Services::Geocoding::Response
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe '#Request' do
|
|
29
|
+
it 'should return 0' do
|
|
30
|
+
@response.status[:code].should == 0
|
|
31
|
+
end
|
|
32
|
+
it 'should be empty' do
|
|
33
|
+
@response.status[:messages].should == []
|
|
34
|
+
end
|
|
35
|
+
it 'should return locations' do
|
|
36
|
+
@response.locations.should_not == {}
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
context 'when invalid request' do
|
|
43
|
+
|
|
44
|
+
before :all do
|
|
45
|
+
@mapquest = MapQuest.new 'xxx'
|
|
46
|
+
@response = @mapquest.geocoding.decode :location => "London, UK"
|
|
47
|
+
@response.valid.should == false
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
describe '.new' do
|
|
51
|
+
it 'should be an instance of' do
|
|
52
|
+
@mapquest.geocoding.should be_an_instance_of MapQuest::Services::Geocoding
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
describe '#decode' do
|
|
57
|
+
it 'should raise an error' do
|
|
58
|
+
expect { @mapquest.geocoding.decode }.to raise_error
|
|
59
|
+
end
|
|
60
|
+
it 'should be an instance of' do
|
|
61
|
+
@response.should be_an_instance_of MapQuest::Services::Geocoding::Response
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
describe '#Request' do
|
|
66
|
+
it 'should not return 0' do
|
|
67
|
+
@response.status[:code].should_not == 0
|
|
68
|
+
end
|
|
69
|
+
it 'should not be empty' do
|
|
70
|
+
@response.status[:messages].should_not == []
|
|
71
|
+
end
|
|
72
|
+
it 'should not return 0' do
|
|
73
|
+
@response.locations[:code].should_not == 0
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
end
|
|
78
|
+
end
|
data/test/spec_helper.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: mapquest
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Gordan Grasarevic
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2013-05-11 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: json
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '0'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ! '>='
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '0'
|
|
30
|
+
- !ruby/object:Gem::Dependency
|
|
31
|
+
name: rest-client
|
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
|
33
|
+
none: false
|
|
34
|
+
requirements:
|
|
35
|
+
- - ! '>='
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
type: :runtime
|
|
39
|
+
prerelease: false
|
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
42
|
+
requirements:
|
|
43
|
+
- - ! '>='
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '0'
|
|
46
|
+
- !ruby/object:Gem::Dependency
|
|
47
|
+
name: rspec
|
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
|
49
|
+
none: false
|
|
50
|
+
requirements:
|
|
51
|
+
- - ~>
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: 2.8.0
|
|
54
|
+
type: :development
|
|
55
|
+
prerelease: false
|
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
+
none: false
|
|
58
|
+
requirements:
|
|
59
|
+
- - ~>
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 2.8.0
|
|
62
|
+
- !ruby/object:Gem::Dependency
|
|
63
|
+
name: bundler
|
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
|
65
|
+
none: false
|
|
66
|
+
requirements:
|
|
67
|
+
- - ~>
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '1.3'
|
|
70
|
+
type: :development
|
|
71
|
+
prerelease: false
|
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
73
|
+
none: false
|
|
74
|
+
requirements:
|
|
75
|
+
- - ~>
|
|
76
|
+
- !ruby/object:Gem::Version
|
|
77
|
+
version: '1.3'
|
|
78
|
+
- !ruby/object:Gem::Dependency
|
|
79
|
+
name: rake
|
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
|
81
|
+
none: false
|
|
82
|
+
requirements:
|
|
83
|
+
- - ! '>='
|
|
84
|
+
- !ruby/object:Gem::Version
|
|
85
|
+
version: '0'
|
|
86
|
+
type: :development
|
|
87
|
+
prerelease: false
|
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
89
|
+
none: false
|
|
90
|
+
requirements:
|
|
91
|
+
- - ! '>='
|
|
92
|
+
- !ruby/object:Gem::Version
|
|
93
|
+
version: '0'
|
|
94
|
+
description: Retrieve data from various MapQuest web services
|
|
95
|
+
email:
|
|
96
|
+
- me@ggordan.com
|
|
97
|
+
executables: []
|
|
98
|
+
extensions: []
|
|
99
|
+
extra_rdoc_files: []
|
|
100
|
+
files:
|
|
101
|
+
- .gitignore
|
|
102
|
+
- .travis.yml
|
|
103
|
+
- Gemfile
|
|
104
|
+
- LICENSE.txt
|
|
105
|
+
- README.md
|
|
106
|
+
- Rakefile
|
|
107
|
+
- lib/mapquest.rb
|
|
108
|
+
- lib/mapquest/request.rb
|
|
109
|
+
- lib/mapquest/response.rb
|
|
110
|
+
- lib/mapquest/services/core.rb
|
|
111
|
+
- lib/mapquest/services/directions.rb
|
|
112
|
+
- lib/mapquest/services/geocoding.rb
|
|
113
|
+
- lib/mapquest/version.rb
|
|
114
|
+
- mapquest.gemspec
|
|
115
|
+
- test/directions_spec.rb
|
|
116
|
+
- test/fixtures/invalid_key.json
|
|
117
|
+
- test/fixtures/no_data.json
|
|
118
|
+
- test/fixtures/results.json
|
|
119
|
+
- test/geocoding_spec.rb
|
|
120
|
+
- test/spec_helper.rb
|
|
121
|
+
homepage: ''
|
|
122
|
+
licenses:
|
|
123
|
+
- MIT
|
|
124
|
+
post_install_message:
|
|
125
|
+
rdoc_options: []
|
|
126
|
+
require_paths:
|
|
127
|
+
- lib
|
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
129
|
+
none: false
|
|
130
|
+
requirements:
|
|
131
|
+
- - ! '>='
|
|
132
|
+
- !ruby/object:Gem::Version
|
|
133
|
+
version: '0'
|
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
|
+
none: false
|
|
136
|
+
requirements:
|
|
137
|
+
- - ! '>='
|
|
138
|
+
- !ruby/object:Gem::Version
|
|
139
|
+
version: '0'
|
|
140
|
+
requirements: []
|
|
141
|
+
rubyforge_project:
|
|
142
|
+
rubygems_version: 1.8.23
|
|
143
|
+
signing_key:
|
|
144
|
+
specification_version: 3
|
|
145
|
+
summary: Retrieve data from various MapQuest web services
|
|
146
|
+
test_files:
|
|
147
|
+
- test/directions_spec.rb
|
|
148
|
+
- test/fixtures/invalid_key.json
|
|
149
|
+
- test/fixtures/no_data.json
|
|
150
|
+
- test/fixtures/results.json
|
|
151
|
+
- test/geocoding_spec.rb
|
|
152
|
+
- test/spec_helper.rb
|
|
153
|
+
has_rdoc:
|