cloudmate 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -46,7 +46,15 @@ Reverse POI Geocoding:
46
46
  Cloudmate.geocode(object_type: 'cafe', around: [51.51558, -0.141449], distance: :closest)
47
47
  ```
48
48
 
49
- ## Contributing
49
+ ### Routing
50
+
51
+ http://developers.cloudmade.com/wiki/routing-http-api/Documentation
52
+
53
+ ```ruby
54
+ Cloudmate.route(points: [[47.25976, 9.58423], [47.26117, 9.59882]], type: :bicycle)
55
+ ```
56
+
57
+ ## Contributing [![Build Status](https://secure.travis-ci.org/brainspec/cloudmate.png?branch=master)](https://next.travis-ci.org/brainspec/cloudmate)
50
58
 
51
59
  1. Fork it
52
60
  2. Create your feature branch (`git checkout -b my-new-feature`)
data/cloudmate.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
10
10
  gem.email = ['team@brainspec.com']
11
11
  gem.description = %q{CloudMade API ruby client library}
12
12
  gem.summary = %q{CloudMade API ruby client library}
13
- gem.homepage = ''
13
+ gem.homepage = 'https://github.com/brainspec/cloudmate'
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
data/examples/route.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'cloudmate'
2
+
3
+ Cloudmate.configure do |config|
4
+ config.api_key = '8ee2a50541944fb9bcedded5165f09d9' # Test API key taken from the official docs
5
+ end
6
+
7
+ p Cloudmate.route(points: [[47.25976, 9.58423], [47.26117, 9.59882]], type: :bicycle)
@@ -30,5 +30,20 @@ module Cloudmate
30
30
 
31
31
  connection.request(:get, url, options)
32
32
  end
33
+
34
+ def route(options)
35
+ points = options.delete(:points)
36
+ route_type = options.delete(:type) { 'car' }
37
+ route_type_modifier = options.delete(:type_modifier)
38
+
39
+ coords = points[1..-2].flatten.join(',')
40
+ coords = [points.first, coords.empty? ? nil : "%5B#{coords}%5D", points.last].compact.flatten.join(',')
41
+
42
+ url = "http://routes.cloudmade.com/#{config.api_key}/api/0.3"
43
+ url = [url, coords, route_type, route_type_modifier].compact.join('/')
44
+ url << '.js'
45
+
46
+ connection.request(:get, url, options)
47
+ end
33
48
  end
34
49
  end
@@ -1,3 +1,3 @@
1
1
  module Cloudmate
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
data/lib/cloudmate.rb CHANGED
@@ -2,13 +2,11 @@ require 'cloudmate/version'
2
2
  require 'cloudmate/client'
3
3
 
4
4
  module Cloudmate
5
- class << self
6
- extend Forwardable
5
+ extend SingleForwardable
7
6
 
8
- def_delegators :client, :configure, :geocode
7
+ def_delegators :client, :configure, :geocode, :route
9
8
 
10
- def client
11
- @client ||= Client.new
12
- end
9
+ def self.client
10
+ @client ||= Client.new
13
11
  end
14
12
  end
@@ -0,0 +1 @@
1
+ {"version":0.3,"status":0,"route_summary":{"total_distance":1603,"total_time":173,"start_point":"Sägerstraße","end_point":"Im Gisinger Feld"},"route_geometry":[[47.25948,9.58395],[47.259239,9.58449],[47.258469,9.58625],[47.25893,9.58668],[47.25885,9.58687],[47.258419,9.58784],[47.258148,9.58849],[47.258991,9.58929],[47.259319,9.58957],[47.259548,9.5898],[47.259708,9.5901],[47.259789,9.59034],[47.259861,9.59071],[47.259918,9.59088],[47.259769,9.59246],[47.259739,9.59299],[47.259701,9.59367],[47.259682,9.59403],[47.259651,9.59418],[47.259571,9.59441],[47.259399,9.59497],[47.259209,9.5956],[47.259178,9.59574],[47.259159,9.59587],[47.259102,9.59682],[47.259102,9.59689],[47.258991,9.59737],[47.25898,9.59743],[47.258862,9.59792],[47.258709,9.59839],[47.25869,9.59847],[47.258808,9.59861],[47.258881,9.59878],[47.25893,9.59878],[47.25922,9.5988],[47.259548,9.59889],[47.25988,9.59897],[47.26001,9.59902],[47.260201,9.59911],[47.260429,9.59921],[47.260761,9.59938],[47.261009,9.59879]],"route_instructions": [["Head southeast on Sägerstraße",207,0,25,"0.2 km","SE",123.3],["Turn left at Austraße",60,2,7,"60 m","NE",32.7,"TL",270.2],["Turn right at Stefan-Allgäuer-Weg",162,3,19,"0.2 km","SE",120.8,"TR",90.3],["Turn left at L60\/Nofler Straße",400,6,21,"0.4 km","NE",32.7,"TL",271.6],["Slight right at Hauptstraße",689,13,83,"0.7 km","E",98.0,"TSLR",27.5],["Turn left at Hauptstraße",32,30,4,"32 m","NE",37.4,"TL",292.1],["Slight left at Runastraße",237,32,28,"0.2 km","N",3.0,"TSLL",315.5],["Turn left at Im Gisinger Feld",53,40,6,"53 m","NW",301.6,"TL",282.3]]}
@@ -0,0 +1 @@
1
+ {"version":0.3,"status":0,"route_summary":{"total_distance":9185,"total_time":655,"start_point":"Generaal Belliardstraat","end_point":"Unbekannte Straße neben Antwerpen","transit_points":[["Sint-Jacobstraat",51.220062,4.409652],["Harmoniestraat",51.200474,4.409129]]},"route_geometry":[[51.225449,4.40728],[51.226879,4.40712],[51.22699,4.40712],[51.227112,4.40707],[51.227032,4.40559],[51.227039,4.40521],[51.22694,4.40522],[51.22681,4.4052],[51.22665,4.40511],[51.226521,4.40506],[51.225601,4.40479],[51.225109,4.40501],[51.225052,4.40481],[51.22506,4.40468],[51.224621,4.40383],[51.224091,4.40318],[51.223721,4.40301],[51.223621,4.40317],[51.22356,4.40321],[51.222599,4.40425],[51.221821,4.40501],[51.22179,4.40502],[51.221439,4.4051],[51.221249,4.40519],[51.221001,4.40681],[51.220959,4.40709],[51.220879,4.40769],[51.220871,4.40779],[51.22073,4.40921],[51.220638,4.40992],[51.220058,4.40965],[51.21965,4.40946],[51.21965,4.40928],[51.219742,4.40814],[51.21981,4.40735],[51.219818,4.40726],[51.219891,4.40628],[51.219971,4.40571],[51.220032,4.40526],[51.219971,4.40526],[51.21944,4.40517],[51.219421,4.40518],[51.21907,4.40514],[51.21899,4.40509],[51.218929,4.40508],[51.21859,4.40503],[51.218491,4.405],[51.218472,4.40501],[51.21838,4.40509],[51.21833,4.40514],[51.218262,4.40525],[51.21817,4.40533],[51.21809,4.40534],[51.2178,4.40533],[51.217522,4.40535],[51.217232,4.4054],[51.216911,4.40545],[51.216702,4.40543],[51.216549,4.4054],[51.216438,4.40534],[51.216381,4.40529],[51.216301,4.40516],[51.216251,4.40497],[51.216171,4.40483],[51.21616,4.40481],[51.216099,4.40478],[51.215961,4.40482],[51.215599,4.40492],[51.215511,4.40499],[51.215389,4.40503],[51.215271,4.40506],[51.21513,4.4051],[51.214062,4.40505],[51.21402,4.40499],[51.213829,4.40498],[51.213612,4.40495],[51.2132,4.40491],[51.21286,4.40512],[51.21244,4.40699],[51.212349,4.40727],[51.212269,4.40744],[51.212132,4.4075],[51.211418,4.40766],[51.211288,4.40768],[51.211121,4.4077],[51.210972,4.40771],[51.210819,4.40773],[51.210709,4.40774],[51.209679,4.40793],[51.209141,4.40825],[51.208691,4.40857],[51.208401,4.40887],[51.20829,4.40894],[51.206951,4.40973],[51.206718,4.4098],[51.20644,4.40989],[51.206181,4.40991],[51.205898,4.40989],[51.20565,4.40998],[51.204319,4.41081],[51.202839,4.4118],[51.20195,4.4124],[51.201691,4.41244],[51.20158,4.4124],[51.200821,4.41199],[51.199749,4.41144],[51.1987,4.4109],[51.19838,4.41075],[51.198151,4.41044],[51.198051,4.41019],[51.197971,4.40963],[51.197811,4.40834],[51.19767,4.40761],[51.19809,4.40749],[51.198669,4.40745],[51.19891,4.40738],[51.199329,4.40718],[51.199459,4.40789],[51.199619,4.40805],[51.199982,4.40845],[51.20047,4.40913],[51.200531,4.40921],[51.20097,4.40976],[51.201439,4.41032],[51.201511,4.41035],[51.20166,4.41035],[51.202122,4.41033],[51.202229,4.41029],[51.202351,4.41021],[51.20245,4.41017],[51.203899,4.40924],[51.204319,4.41081],[51.20435,4.41092],[51.20438,4.41107],[51.205879,4.41016],[51.2062,4.41013],[51.20649,4.41003],[51.206772,4.40988],[51.206951,4.40973],[51.20829,4.40894],[51.208401,4.40887],[51.20871,4.40873],[51.20974,4.40809],[51.210789,4.40786],[51.210911,4.40785],[51.211151,4.40822],[51.211731,4.40897],[51.211899,4.40918],[51.212132,4.40932],[51.213829,4.41157],[51.213871,4.41198],[51.214909,4.41333],[51.21513,4.41326],[51.21563,4.41382],[51.21571,4.41387],[51.215931,4.41403],[51.216049,4.41411],[51.216049,4.41411],[51.217838,4.41526],[51.218029,4.41538],[51.218281,4.41552],[51.218441,4.4156],[51.218689,4.41571],[51.21957,4.41608],[51.219681,4.41612],[51.2197,4.41613],[51.219799,4.41617],[51.220169,4.41631],[51.220619,4.41648],[51.220772,4.41655],[51.220989,4.4166],[51.22179,4.41636],[51.222618,4.41604],[51.224541,4.41526],[51.225929,4.41477],[51.22617,4.41468],[51.226261,4.41466],[51.227451,4.41421],[51.227859,4.41405],[51.229038,4.4136],[51.229252,4.41356],[51.2295,4.41356],[51.22966,4.41354],[51.229752,4.41352],[51.229778,4.41351],[51.229759,4.41369],[51.229771,4.41528],[51.229771,4.41718],[51.22979,4.41841],[51.22979,4.41872],[51.22979,4.41981],[51.22979,4.42001]],"route_instructions": [["Richtung Nord auf Generaal Belliardstraat",185,0,22,"0.1 Meilen","N",355.9],["Bei Oudeleeuwenrui links abbiegen",131,3,8,"430 ft","W",265.3,"TL",272.9],["Links abbiegen",233,5,28,"0.1 Meilen","S",176.4,"TL",265.5],["Bei Huikstraat rechts abbiegen",34,11,4,"112 ft","SW",243.8,"TR",79.2],["Links halten bei Huikstraat",268,13,32,"0.2 Meilen","SW",230.1,"TSLL",334.6],["Bei Sint-Paulusstraat links abbiegen",455,16,27,"0.3 Meilen","SE",135.8,"TL",300.0],["Bei Kipdorp links abbiegen",357,23,43,"0.2 Meilen","E",103.9,"TL",302.0],["Bei Sint-Jacobstraat rechts abbiegen",115,29,14,"377 ft","S",196.1,"TR",94.1],["Bei Lange Nieuwstraat rechts abbiegen",13,31,2,"43 ft","W",273.8,"TR",77.6],["Weiter auf Lange Nieuwstraat",290,32,35,"0.2 Meilen","W",276.7,"C",2.9],["Bei Sint-Katelijnevest links abbiegen",469,38,28,"0.3 Meilen","S",182.4,"TL",262.2],["Bei Lange Gasthuisstraat links abbiegen",325,65,20,"0.2 Meilen","S",167.9,"TL",308.6],["Rechts halten bei Lange Gasthuisstraat",163,72,10,"0.1 Meilen","SW",221.5,"TSLR",10.4],["Links halten bei Sint-Jorispoort",339,77,20,"0.2 Meilen","E",109.7,"TSLL",311.1],["Weiter",1148,83,59,"0.7 Meilen","S",177.3,"C",5.2],["Rechts halten bei N155\/Koningin Elisabethlei",511,102,26,"0.3 Meilen","S",195.2,"TSLR",24.1],["Rechts halten bei N177\/Jan Van Rijswijcklaan",426,107,22,"0.3 Meilen","SW",220.0,"TSLR",23.2],["Bei Lange Lozanastraat rechts abbiegen",328,112,20,"0.2 Meilen","N",350.2,"TR",97.3],["Bei Harmoniestraat rechts abbiegen",619,116,74,"0.4 Meilen","E",73.3,"TR",90.5],["Bei Van Schoonbekestraat rechts abbiegen",158,130,19,"518 ft","NE",67.0,"TR",89.0],["Bei N1\/Mechelsesteenweg links abbiegen",1061,133,55,"0.7 Meilen","N",339.0,"TL",270.9],["Weiter auf N1\/Frankrijklei",573,148,29,"0.4 Meilen","NE",39.7,"C",18.4],["Bei N1\/Frankrijklei links abbiegen",705,151,36,"0.4 Meilen","N",347.8,"TL",308.4],["Weiter auf N1\/Italiëlei",1171,167,60,"0.7 Meilen","N",13.5,"C",359.7],["Weiter auf N1\/Italiëlei",62,180,4,"203 ft","N",360.0,"C",5.8],["Rechts abbiegen",566,184,34,"0.4 Meilen","E",101.3,"TR",107.9]]}
data/test/geocode_test.rb CHANGED
@@ -2,6 +2,8 @@ require 'test_helper'
2
2
 
3
3
  module Cloudmate
4
4
  class GeocodeTest < MiniTest::Unit::TestCase
5
+ include TestHelper
6
+
5
7
  def test_query
6
8
  stub_request(:get, 'http://geocoding.cloudmade.com/TEST_API_KEY/geocoding/v2/find.js?query=133%20Fleet%20street,%20London,%20UK').
7
9
  to_return(status: 200, body: fixture(:geocode_query))
@@ -25,20 +27,5 @@ module Cloudmate
25
27
  result = client.geocode(around: [51.51558, -0.141449])
26
28
  assert_equal 9, result['found']
27
29
  end
28
-
29
- private
30
-
31
- def client
32
- client = Cloudmate::Client.new
33
- client.configure do |config|
34
- config.api_key = 'TEST_API_KEY'
35
- end
36
-
37
- client
38
- end
39
-
40
- def fixture(name)
41
- File.read(File.expand_path("../fixtures/#{name}.json", __FILE__))
42
- end
43
30
  end
44
31
  end
@@ -0,0 +1,31 @@
1
+ require 'test_helper'
2
+
3
+ module Cloudmate
4
+ class RouteTest < MiniTest::Unit::TestCase
5
+ include TestHelper
6
+
7
+ def test_route
8
+ stub_request(:get, 'http://routes.cloudmade.com/TEST_API_KEY/api/0.3/47.25976,9.58423,47.26117,9.59882/car/shortest.js').
9
+ to_return(status: 200, body: fixture(:route))
10
+
11
+ result = client.route(points: [[47.25976, 9.58423], [47.26117, 9.59882]], type: :car, type_modifier: :shortest)
12
+ assert_equal 1603, result['route_summary']['total_distance']
13
+ end
14
+
15
+ def test_route_transit
16
+ stub_request(:get, 'http://routes.cloudmade.com/TEST_API_KEY/api/0.3/51.22545,4.4073,%5B51.22,4.41,51.2,4.41%5D,51.23,4.42/car.js?units=miles').
17
+ to_return(status: 200, body: fixture(:route_transit))
18
+
19
+ result = client.route(points: [[51.22545, 4.40730], [51.22, 4.41], [51.2, 4.41], [51.23, 4.42]], type: :car, units: :miles)
20
+ assert_equal 9185, result['route_summary']['total_distance']
21
+ end
22
+
23
+ def test_route_car_by_default
24
+ stub_request(:get, 'http://routes.cloudmade.com/TEST_API_KEY/api/0.3/47.25976,9.58423,47.26117,9.59882/car.js').
25
+ to_return(status: 200, body: fixture(:route))
26
+
27
+ result = client.route(points: [[47.25976, 9.58423], [47.26117, 9.59882]])
28
+ assert_equal 1603, result['route_summary']['total_distance']
29
+ end
30
+ end
31
+ end
data/test/test_helper.rb CHANGED
@@ -3,3 +3,22 @@ require 'minitest/unit'
3
3
  require 'webmock/minitest'
4
4
 
5
5
  require 'cloudmate'
6
+
7
+ module Cloudmate
8
+ module TestHelper
9
+ private
10
+
11
+ def client
12
+ client = Cloudmate::Client.new
13
+ client.configure do |config|
14
+ config.api_key = 'TEST_API_KEY'
15
+ end
16
+
17
+ client
18
+ end
19
+
20
+ def fixture(name)
21
+ File.read(File.expand_path("../fixtures/#{name}.json", __FILE__))
22
+ end
23
+ end
24
+ end
metadata CHANGED
@@ -1,96 +1,96 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudmate
3
3
  version: !ruby/object:Gem::Version
4
+ version: 0.0.2
4
5
  prerelease:
5
- version: 0.0.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Sergey Nartimov
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-02 00:00:00.000000000 Z
12
+ date: 2012-11-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ~>
18
- - !ruby/object:Gem::Version
19
- version: 0.8.4
20
- none: false
21
15
  type: :runtime
22
16
  version_requirements: !ruby/object:Gem::Requirement
17
+ none: false
23
18
  requirements:
24
19
  - - ~>
25
20
  - !ruby/object:Gem::Version
26
21
  version: 0.8.4
27
- none: false
28
22
  prerelease: false
29
23
  name: faraday
30
- - !ruby/object:Gem::Dependency
31
24
  requirement: !ruby/object:Gem::Requirement
25
+ none: false
32
26
  requirements:
33
27
  - - ~>
34
28
  - !ruby/object:Gem::Version
35
- version: 0.9.0
36
- none: false
29
+ version: 0.8.4
30
+ - !ruby/object:Gem::Dependency
37
31
  type: :runtime
38
32
  version_requirements: !ruby/object:Gem::Requirement
33
+ none: false
39
34
  requirements:
40
35
  - - ~>
41
36
  - !ruby/object:Gem::Version
42
37
  version: 0.9.0
43
- none: false
44
38
  prerelease: false
45
39
  name: faraday_middleware
46
- - !ruby/object:Gem::Dependency
47
40
  requirement: !ruby/object:Gem::Requirement
41
+ none: false
48
42
  requirements:
49
43
  - - ~>
50
44
  - !ruby/object:Gem::Version
51
- version: 0.9.2.2
52
- none: false
45
+ version: 0.9.0
46
+ - !ruby/object:Gem::Dependency
53
47
  type: :development
54
48
  version_requirements: !ruby/object:Gem::Requirement
49
+ none: false
55
50
  requirements:
56
51
  - - ~>
57
52
  - !ruby/object:Gem::Version
58
53
  version: 0.9.2.2
59
- none: false
60
54
  prerelease: false
61
55
  name: rake
62
- - !ruby/object:Gem::Dependency
63
56
  requirement: !ruby/object:Gem::Requirement
57
+ none: false
64
58
  requirements:
65
59
  - - ~>
66
60
  - !ruby/object:Gem::Version
67
- version: '4.1'
68
- none: false
61
+ version: 0.9.2.2
62
+ - !ruby/object:Gem::Dependency
69
63
  type: :development
70
64
  version_requirements: !ruby/object:Gem::Requirement
65
+ none: false
71
66
  requirements:
72
67
  - - ~>
73
68
  - !ruby/object:Gem::Version
74
69
  version: '4.1'
75
- none: false
76
70
  prerelease: false
77
71
  name: minitest
78
- - !ruby/object:Gem::Dependency
79
72
  requirement: !ruby/object:Gem::Requirement
73
+ none: false
80
74
  requirements:
81
75
  - - ~>
82
76
  - !ruby/object:Gem::Version
83
- version: 1.8.11
84
- none: false
77
+ version: '4.1'
78
+ - !ruby/object:Gem::Dependency
85
79
  type: :development
86
80
  version_requirements: !ruby/object:Gem::Requirement
81
+ none: false
87
82
  requirements:
88
83
  - - ~>
89
84
  - !ruby/object:Gem::Version
90
85
  version: 1.8.11
91
- none: false
92
86
  prerelease: false
93
87
  name: webmock
88
+ requirement: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 1.8.11
94
94
  description: CloudMade API ruby client library
95
95
  email:
96
96
  - team@brainspec.com
@@ -106,6 +106,7 @@ files:
106
106
  - Rakefile
107
107
  - cloudmate.gemspec
108
108
  - examples/geocode.rb
109
+ - examples/route.rb
109
110
  - lib/cloudmate.rb
110
111
  - lib/cloudmate/client.rb
111
112
  - lib/cloudmate/configuration.rb
@@ -115,32 +116,35 @@ files:
115
116
  - test/delegation_test.rb
116
117
  - test/fixtures/geocode_around.json
117
118
  - test/fixtures/geocode_query.json
119
+ - test/fixtures/route.json
120
+ - test/fixtures/route_transit.json
118
121
  - test/geocode_test.rb
122
+ - test/route_test.rb
119
123
  - test/test_helper.rb
120
- homepage: ''
124
+ homepage: https://github.com/brainspec/cloudmate
121
125
  licenses: []
122
126
  post_install_message:
123
127
  rdoc_options: []
124
128
  require_paths:
125
129
  - lib
126
130
  required_ruby_version: !ruby/object:Gem::Requirement
131
+ none: false
127
132
  requirements:
128
133
  - - ! '>='
129
134
  - !ruby/object:Gem::Version
130
- hash: -1300770322977338273
131
- version: '0'
132
135
  segments:
133
136
  - 0
134
- none: false
137
+ hash: -29694625687329867
138
+ version: '0'
135
139
  required_rubygems_version: !ruby/object:Gem::Requirement
140
+ none: false
136
141
  requirements:
137
142
  - - ! '>='
138
143
  - !ruby/object:Gem::Version
139
- hash: -1300770322977338273
140
- version: '0'
141
144
  segments:
142
145
  - 0
143
- none: false
146
+ hash: -29694625687329867
147
+ version: '0'
144
148
  requirements: []
145
149
  rubyforge_project:
146
150
  rubygems_version: 1.8.23
@@ -152,5 +156,8 @@ test_files:
152
156
  - test/delegation_test.rb
153
157
  - test/fixtures/geocode_around.json
154
158
  - test/fixtures/geocode_query.json
159
+ - test/fixtures/route.json
160
+ - test/fixtures/route_transit.json
155
161
  - test/geocode_test.rb
162
+ - test/route_test.rb
156
163
  - test/test_helper.rb