cloudmade 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in cloudmade.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # CloudMade
2
+ ---
3
+
4
+ This is a ruby Gem to use the amazing API for [Cloudmade](http://www.cloudmade.com). They bring you cool services powered by [OpenStreetMaps](http://www.openstreetmaps.org). Check out their website.
5
+
6
+ In their developer section I found this ruby gem which wasn't on [rubygems.org](http://www.rubygems.org). So I forked their project from SVN, updated the Gemspec (Nothing has happened with this Gem for over 2 years) and published it here.
7
+
8
+ In the future I will update this Gem to use the version v2 of the API. I just :heart: the service and I'd love to see it being used by more people.
9
+
10
+
11
+ ## Usage
12
+ Add the Gem to your Gemfile:
13
+ gem 'cloudmade', '0.1.2'
14
+
15
+ Run the bundle command to update your Gemspec and you're ready to roll
16
+
17
+ Go to http://cloudmade.com/start sign up and request an API key
18
+
19
+ ## Examples
20
+ ````ruby
21
+ cm = CloudMade::Client.from_parameters('YOUR-API-KEY')
22
+
23
+ # Find a place
24
+ places = cm.geocoding.find('Potsdamer Platz, Berlin, Germany')
25
+ puts "Location of Potsdamer Platz: #{places.results[0].centroid.lat}, #{places.results[0].centroid.lon}"
26
+
27
+ # Find a pub
28
+ pub = cm.geocoding.find_closest('pub', 52.50938, 13.37627)
29
+ puts "Closest Pub: #{pub.properties.name}"
30
+ ```
31
+
32
+ Some other examples can be found in `lib/cloudmade/examples.rb` (*I didn't put that file there, it has been provided*)
33
+
34
+ ## License
35
+ This version is licensed under the LGPL version 3, see `LICENSE` for details (This has also been provided by CloudMade. My new version of the Gem will be MIT)
36
+
37
+ # Original documentation
38
+ At the end I will attach the original documentation. Have fun:
39
+ ---
40
+
41
+ CloudMadeAPI is a Ruby API for CloudMade's online services: Geocoding, Routing and Tiles.
42
+
43
+ API documentation is available http://cloudmade.com/developers/docs/
44
+
45
+ Install
46
+ =======
47
+
48
+ Using easy_install
49
+
50
+ gem install cloudmade
51
+
52
+ Testing
53
+ =======
54
+
55
+ To test the source distribution you will need to run following command:
56
+
57
+ rake test
58
+
59
+ Module Documentation
60
+ ====================
61
+
62
+ To generate module documentation you will need to run the following command:
63
+
64
+ rake rdoc
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake'
4
+ require 'rake/testtask'
5
+
6
+ task :test => [:test_units]
7
+
8
+ desc "Run unit tests"
9
+ Rake::TestTask.new("test_units") { |t|
10
+ t.pattern = 'test/test_*.rb'
11
+ t.verbose = true
12
+ t.warning = true
13
+ }
data/cloudmade.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "cloudmade/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "cloudmade"
7
+ s.version = Cloudmade::VERSION
8
+ s.authors = ["Klaus Zanders", "cloudmade.com"]
9
+ s.email = ["klaus.zanders@gmail.com", "ishubovych@cloudmade.com"]
10
+ s.homepage = "http://developers.cloudmade.com/projects/show/ruby-lib"
11
+ s.summary = 'CloudMade Ruby API'
12
+ s.description = s.summary
13
+
14
+ s.rubyforge_project = "cloudmade"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = Dir.glob('test/test_*.rb')
18
+ s.require_paths = ["lib"]
19
+
20
+ s.has_rdoc = true
21
+ s.extra_rdoc_files = ['README.md', 'LICENSE']
22
+
23
+ # specify any dependencies here; for example:
24
+ s.add_development_dependency "test-unit"
25
+ s.add_development_dependency "rake"
26
+ # s.add_runtime_dependency "rest-client"
27
+ end
data/lib/cloudmade.rb ADDED
@@ -0,0 +1,26 @@
1
+ #
2
+ # Copyright 2009 CloudMade.
3
+ #
4
+ # Licensed under the GNU Lesser General Public License, Version 3.0;
5
+ # You may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.gnu.org/licenses/lgpl-3.0.txt
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'cloudmade/version'
18
+ require 'cloudmade/connection'
19
+ require 'cloudmade/client'
20
+ require 'cloudmade/geometry'
21
+ require 'cloudmade/service'
22
+ require 'cloudmade/tiles'
23
+ require 'cloudmade/geocoding'
24
+ require 'cloudmade/routing'
25
+ require 'cloudmade/locations'
26
+ require 'cloudmade/exceptions'
@@ -0,0 +1,82 @@
1
+ #
2
+ # Copyright 2009 CloudMade.
3
+ #
4
+ # Licensed under the GNU Lesser General Public License, Version 3.0;
5
+ # You may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.gnu.org/licenses/lgpl-3.0.txt
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ module CloudMade
17
+ class Client
18
+ attr_accessor :connection
19
+ attr_accessor :base_url
20
+ attr_writer :port
21
+ attr_accessor :api_key
22
+ #attr_reader :token
23
+
24
+ #:nodoc:
25
+ def url
26
+ return "#{base_url}#{@port != nil ? ':' + port.to_s : ''}"
27
+ end
28
+
29
+ #:nodoc:
30
+ def port
31
+ return 80 if @port == nil
32
+ @port
33
+ end
34
+
35
+ # Tiles service
36
+ def tiles
37
+ @tiles ||= TilesService.new(self.connection, 'tile')
38
+ end
39
+
40
+ # Geocoding service
41
+ def geocoding
42
+ @geocoding ||= GeocodingService.new(self.connection, 'geocoding')
43
+ end
44
+
45
+ # Routing service
46
+ def routing
47
+ @routing ||= RoutingService.new(self.connection, 'routes')
48
+ end
49
+
50
+ # Locations service
51
+ def locations
52
+ @locations ||= LocationsService.new(self.connection, '')
53
+ end
54
+
55
+ class << self
56
+ def from_connection(connection)
57
+ client = Client.new
58
+ client.connection = connection
59
+ return client
60
+ end
61
+
62
+ def from_parameters(api_key, base_url = nil, port = nil)
63
+ client = Client.new
64
+ client.connection = Connection.new(api_key, base_url, port)
65
+ return client
66
+ end
67
+
68
+ # TODO: Create here methods to connect from XML and YAML configuration file
69
+ end
70
+
71
+ protected
72
+ def initialize()
73
+ end
74
+ ### 2. Allow loads configuration from XML, YAML files
75
+ #def initialize(api_key, base_url = 'cloudmade.com', port = nil)
76
+ # @base_url = base_url
77
+ # @port = port
78
+ # @api_key = api_key
79
+ # #@token = token
80
+ #end
81
+ end
82
+ end
@@ -0,0 +1,70 @@
1
+ #
2
+ # Copyright 2009 CloudMade.
3
+ #
4
+ # Licensed under the GNU Lesser General Public License, Version 3.0;
5
+ # You may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.gnu.org/licenses/lgpl-3.0.txt
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ module CloudMade
18
+ # This +Connection+ class provides a connection to CloudMade online services (HTTP API).
19
+ # Normally you don't need to create it directly. Construct a 'Client' from parameters instead.
20
+ #
21
+ # Connection examples:
22
+ #
23
+ # conn = CloudMade::Connection.new('cloudmade.com', 80, 'FAKE_API_KEY')
24
+ # CloudMade.Client.new(conn)
25
+ #
26
+ class Connection
27
+ attr_accessor :base_url
28
+ attr_writer :port
29
+ attr_accessor :api_key
30
+
31
+ # Initializes connection
32
+ # * +base_url+ should not start with 'www'
33
+ # * +port+ integer value of port for CloudMade portal, if nil then default 80 port is used
34
+ # * +api_key+ your API key to connect to CloudMade services
35
+ def initialize(api_key = nil, base_url = 'cloudmade.com', port = nil)
36
+ self.api_key = api_key
37
+ self.base_url = base_url
38
+ self.base_url = 'cloudmade.com' if self.base_url == nil or self.base_url.empty?
39
+ self.port = port
40
+ end
41
+
42
+ # Make a HTTP connection and send a request. Called by the cloudmade 'Client' object internally
43
+ def connect(server_url, request)
44
+ #sputs "#{server_url} #{request}"
45
+ result = nil
46
+ Net::HTTP.start(server_url, self.port) {|http|
47
+ req = Net::HTTP::Get.new("#{request}")
48
+ response = http.request(req)
49
+ case response
50
+ when Net::HTTPSuccess, Net::HTTPRedirection
51
+ result = response.body
52
+ else
53
+ raise HTTPError.new("Couldn't read data. HTTP status: #{response}")
54
+ end
55
+ }
56
+ return result
57
+ end
58
+
59
+ # Convenience method. Return the base URL and port of this Connection
60
+ def url
61
+ return "#{@base_url}#{@port != nil ? ':' + port.to_s : ''}"
62
+ end
63
+
64
+ # Port number of this Connection
65
+ def port
66
+ return 80 if @port == nil
67
+ @port
68
+ end
69
+ end
70
+ end