cloudmate 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 ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - ruby-head
5
+ - rbx-19mode
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cloudmate.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Sergey Nartimov
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,55 @@
1
+ # Cloudmate
2
+
3
+ CloudMade API ruby client library
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'cloudmate'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install cloudmate
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ Cloudmate.configure do |config|
23
+ config.api_key = 'CLOUDMADE_API_KEY'
24
+ end
25
+ ```
26
+
27
+ ### Geocoding
28
+
29
+ http://developers.cloudmade.com/projects/show/geocoding-http-api
30
+
31
+ Free form address search:
32
+
33
+ ```ruby
34
+ Cloudmate.geocode(query: '133 Fleet street, London, UK')
35
+ ```
36
+
37
+ Structured address search:
38
+
39
+ ```ruby
40
+ Cloudmate.geocode(query: { house: '133', street: 'Fleet street', city: 'London', country: 'UK' })
41
+ ```
42
+
43
+ Reverse POI Geocoding:
44
+
45
+ ```ruby
46
+ Cloudmate.geocode(object_type: 'cafe', around: [51.51558, -0.141449], distance: :closest)
47
+ ```
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rake/testtask'
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ t.pattern = 'test/*_test.rb'
7
+ t.verbose = true
8
+ end
9
+
10
+ task :default => :test
data/cloudmate.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cloudmate/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'cloudmate'
8
+ gem.version = Cloudmate::VERSION
9
+ gem.authors = ['Sergey Nartimov']
10
+ gem.email = ['team@brainspec.com']
11
+ gem.description = %q{CloudMade API ruby client library}
12
+ gem.summary = %q{CloudMade API ruby client library}
13
+ gem.homepage = ''
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ['lib']
19
+
20
+ gem.add_dependency 'faraday', '~> 0.8.4'
21
+ gem.add_dependency 'faraday_middleware', '~> 0.9.0'
22
+ gem.add_development_dependency 'rake', '~> 0.9.2.2'
23
+ gem.add_development_dependency 'minitest', '~> 4.1'
24
+ gem.add_development_dependency 'webmock', '~> 1.8.11'
25
+ end
@@ -0,0 +1,14 @@
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
+ # Free form address search
8
+ p Cloudmate.geocode(query: '133 Fleet street, London, UK')
9
+
10
+ # Structured address search
11
+ p Cloudmate.geocode(query: { house: '133', street: 'Fleet street', city: 'London', country: 'UK' })
12
+
13
+ # Reverse POI Geocoding
14
+ p Cloudmate.geocode(object_type: 'cafe', around: [51.51558, -0.141449], distance: :closest)
data/lib/cloudmate.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'cloudmate/version'
2
+ require 'cloudmate/client'
3
+
4
+ module Cloudmate
5
+ class << self
6
+ extend Forwardable
7
+
8
+ def_delegators :client, :configure, :geocode
9
+
10
+ def client
11
+ @client ||= Client.new
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,34 @@
1
+ require 'cloudmate/configuration'
2
+ require 'cloudmate/connection'
3
+
4
+ module Cloudmate
5
+ class Client
6
+ attr_reader :config
7
+
8
+ def initialize(options={})
9
+ @config = Configuration.new(options)
10
+ end
11
+
12
+ def configure
13
+ yield config
14
+ end
15
+
16
+ def connection
17
+ @connection ||= Connection.new
18
+ end
19
+
20
+ def geocode(options)
21
+ url = "http://geocoding.cloudmade.com/#{config.api_key}/geocoding/v2/find.js"
22
+
23
+ options.each do |name, value|
24
+ if value.respond_to?(:join)
25
+ options[name] = value.join(',')
26
+ elsif value.kind_of?(Hash)
27
+ options[name] = value.map { |k, v| "#{k}:#{v}" }.join(';')
28
+ end
29
+ end
30
+
31
+ connection.request(:get, url, options)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,14 @@
1
+ module Cloudmate
2
+ class Configuration
3
+ attr_accessor :api_key
4
+
5
+ def initialize(options={})
6
+ options.each_pair do |name, value|
7
+ setter = "#{name}="
8
+ if respond_to?(setter)
9
+ public_send(setter, value)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,21 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+
4
+ module Cloudmate
5
+ class Connection
6
+ def initialize
7
+ @faraday = Faraday.new do |faraday|
8
+ faraday.response :json
9
+ faraday.adapter Faraday.default_adapter
10
+ end
11
+ end
12
+
13
+ def request(method, url, options={})
14
+ response = @faraday.public_send(method) do |request|
15
+ request.url(url, options)
16
+ end
17
+
18
+ response.body
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module Cloudmate
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,10 @@
1
+ require 'test_helper'
2
+
3
+ module Cloudmate
4
+ class ConfigurationTest < MiniTest::Unit::TestCase
5
+ def test_options
6
+ config = Configuration.new(api_key: 'TEST_API_KEY')
7
+ assert_equal 'TEST_API_KEY', config.api_key
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ require 'test_helper'
2
+
3
+ module Cloudmate
4
+ class DelegationTest < MiniTest::Unit::TestCase
5
+ def test_delegation
6
+ mock = MiniTest::Mock.new
7
+ mock.expect(:geocode, :result, [{ query: 'Test query' }])
8
+
9
+ Cloudmate.stub(:client, mock) do
10
+ assert_equal :result, Cloudmate.geocode(query: 'Test query')
11
+ end
12
+
13
+ mock.verify
14
+ end
15
+ end
16
+ end
@@ -0,0 +1 @@
1
+ {"found": 9, "bounds": [[51.51509, -0.14172], [51.51609, -0.14099]], "features": [{"id": 21056979,"centroid": {"type":"POINT","coordinates":[51.5152, -0.14145]},"bounds": [[51.51520, -0.14145], [51.51520, -0.14145]],"properties": {"addr:housenumber": "245", "osm_element": "node", "addr:housename": "Oxford Circus House", "synthesized_name": "245", "osm_id": "799284631"},"type": "Feature"},{"id": 15197178,"centroid": {"type":"POINT","coordinates":[51.51514, -0.14131]},"bounds": [[51.51514, -0.14131], [51.51514, -0.14131]],"properties": {"addr:housenumber": "18", "osm_element": "node", "amenity": "pub", "name": "The Argyll Arms", "osm_id": "499350848"},"type": "Feature"},{"id": 13303751,"centroid": {"type":"POINT","coordinates":[51.51551, -0.14099]},"bounds": [[51.51551, -0.14099], [51.51551, -0.14099]],"properties": {"addr:housenumber": "216", "osm_element": "node", "synthesized_name": "216", "osm_id": "383964406"},"type": "Feature"},{"id": 16347698,"centroid": {"type":"POINT","coordinates":[51.51511, -0.14158]},"bounds": [[51.51511, -0.14158], [51.51511, -0.14158]],"properties": {"shop": "clothes", "osm_element": "node", "addr:housenumber": "266 270", "name": "Tezenis", "osm_id": "595299963"},"type": "Feature"},{"id": 22831450,"centroid": {"type":"POINT","coordinates":[51.51609, -0.14145]},"bounds": [[51.51609, -0.14145], [51.51609, -0.14145]],"properties": {"website": "www.melito.co.uk", "addr:housenumber": "12", "amenity": "restaurant", "name": "Melito", "addr:postcode": "W1W 8LR", "telephone": "02076366560", "osm_id": "878030036", "osm_element": "node", "addr:street": "Great Castle Street"},"type": "Feature"},{"id": 21057007,"centroid": {"type":"POINT","coordinates":[51.51509, -0.14127]},"bounds": [[51.51509, -0.14127], [51.51509, -0.14127]],"properties": {"addr:housenumber": "19", "osm_element": "node", "synthesized_name": "19", "osm_id": "799284734"},"type": "Feature"},{"id": 19514929,"centroid": {"type":"POINT","coordinates":[51.51591, -0.14103]},"bounds": [[51.51591, -0.14103], [51.51591, -0.14103]],"properties": {"addr:housenumber": "1", "addr:city": "London", "osm_id": "691084128", "osm_element": "node", "addr:country": "GB", "synthesized_name": "1", "addr:street": "Great Portland Street"},"type": "Feature"},{"id": 22831453,"centroid": {"type":"POINT","coordinates":[51.51604, -0.14172]},"bounds": [[51.51604, -0.14172], [51.51604, -0.14172]],"properties": {"addr:housenumber": "15", "cuisine": "indian", "amenity": "restaurant", "name": "Kerala", "telephone": "02075802125", "osm_id": "878030042", "osm_element": "node"},"type": "Feature"},{"id": 21056974,"centroid": {"type":"POINT","coordinates":[51.51519, -0.14106]},"bounds": [[51.51519, -0.14106], [51.51519, -0.14106]],"properties": {"addr:housenumber": "237/9", "osm_element": "node", "addr:housename": "Western House", "synthesized_name": "237/9", "osm_id": "799284615"},"type": "Feature"}], "type": "FeatureCollection", "crs": {"type": "EPSG", "properties": {"code": 4326, "coordinate_order": [0, 1]}}}
@@ -0,0 +1 @@
1
+ {"found": 2, "bounds": [[51.51426, -0.10719], [51.51516, -0.10617]], "features": [{"id": 35770399,"centroid": {"type":"POINT","coordinates":[51.51433, -0.10656]},"bounds": [[51.51426, -0.10696], [51.51443, -0.10617]],"properties": {"building": "yes", "addr:housenumber": "133", "name": "Daniel House", "addr:postcode": "EC4A 2BB", "osm_id": "39275971", "osm_element": "way", "addr:street": "Fleet Street"},"type": "Feature"},{"id": 35770391,"centroid": {"type":"POINT","coordinates":[51.51455, -0.10666]},"bounds": [[51.51443, -0.10719], [51.51516, -0.10617]],"properties": {"building": "yes", "addr:housenumber": "133", "name": "Peterborough Court", "addr:postcode": "EC4A 2BB", "osm_id": "39275958", "osm_element": "way", "addr:street": "Fleet Street"},"type": "Feature"}], "type": "FeatureCollection", "crs": {"type": "EPSG", "properties": {"code": 4326, "coordinate_order": [0, 1]}}}
@@ -0,0 +1,44 @@
1
+ require 'test_helper'
2
+
3
+ module Cloudmate
4
+ class GeocodeTest < MiniTest::Unit::TestCase
5
+ def test_query
6
+ stub_request(:get, 'http://geocoding.cloudmade.com/TEST_API_KEY/geocoding/v2/find.js?query=133%20Fleet%20street,%20London,%20UK').
7
+ to_return(status: 200, body: fixture(:geocode_query))
8
+
9
+ result = client.geocode(query: '133 Fleet street, London, UK')
10
+ assert_equal 2, result['found']
11
+ end
12
+
13
+ def test_query_structured
14
+ stub_request(:get, 'http://geocoding.cloudmade.com/TEST_API_KEY/geocoding/v2/find.js?query=house:133;street:Fleet+street;city:London;country:UK').
15
+ to_return(status: 200, body: fixture(:geocode_query))
16
+
17
+ result = client.geocode(query: { house: '133', street: 'Fleet street', city: 'London', country: 'UK' })
18
+ assert_equal 2, result['found']
19
+ end
20
+
21
+ def test_around
22
+ stub_request(:get, 'http://geocoding.cloudmade.com/TEST_API_KEY/geocoding/v2/find.js?around=51.51558,-0.141449').
23
+ to_return(status: 200, body: fixture(:geocode_around))
24
+
25
+ result = client.geocode(around: [51.51558, -0.141449])
26
+ assert_equal 9, result['found']
27
+ 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
+ end
44
+ end
@@ -0,0 +1,5 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/unit'
3
+ require 'webmock/minitest'
4
+
5
+ require 'cloudmate'
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cloudmate
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Sergey Nartimov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-02 00:00:00.000000000 Z
13
+ dependencies:
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
+ type: :runtime
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.4
27
+ none: false
28
+ prerelease: false
29
+ name: faraday
30
+ - !ruby/object:Gem::Dependency
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: 0.9.0
36
+ none: false
37
+ type: :runtime
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ version: 0.9.0
43
+ none: false
44
+ prerelease: false
45
+ name: faraday_middleware
46
+ - !ruby/object:Gem::Dependency
47
+ requirement: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ~>
50
+ - !ruby/object:Gem::Version
51
+ version: 0.9.2.2
52
+ none: false
53
+ type: :development
54
+ version_requirements: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ version: 0.9.2.2
59
+ none: false
60
+ prerelease: false
61
+ name: rake
62
+ - !ruby/object:Gem::Dependency
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: '4.1'
68
+ none: false
69
+ type: :development
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ version: '4.1'
75
+ none: false
76
+ prerelease: false
77
+ name: minitest
78
+ - !ruby/object:Gem::Dependency
79
+ requirement: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ~>
82
+ - !ruby/object:Gem::Version
83
+ version: 1.8.11
84
+ none: false
85
+ type: :development
86
+ version_requirements: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ version: 1.8.11
91
+ none: false
92
+ prerelease: false
93
+ name: webmock
94
+ description: CloudMade API ruby client library
95
+ email:
96
+ - team@brainspec.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
+ - cloudmate.gemspec
108
+ - examples/geocode.rb
109
+ - lib/cloudmate.rb
110
+ - lib/cloudmate/client.rb
111
+ - lib/cloudmate/configuration.rb
112
+ - lib/cloudmate/connection.rb
113
+ - lib/cloudmate/version.rb
114
+ - test/configuration_test.rb
115
+ - test/delegation_test.rb
116
+ - test/fixtures/geocode_around.json
117
+ - test/fixtures/geocode_query.json
118
+ - test/geocode_test.rb
119
+ - test/test_helper.rb
120
+ homepage: ''
121
+ licenses: []
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ! '>='
129
+ - !ruby/object:Gem::Version
130
+ hash: -1300770322977338273
131
+ version: '0'
132
+ segments:
133
+ - 0
134
+ none: false
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ! '>='
138
+ - !ruby/object:Gem::Version
139
+ hash: -1300770322977338273
140
+ version: '0'
141
+ segments:
142
+ - 0
143
+ none: false
144
+ requirements: []
145
+ rubyforge_project:
146
+ rubygems_version: 1.8.23
147
+ signing_key:
148
+ specification_version: 3
149
+ summary: CloudMade API ruby client library
150
+ test_files:
151
+ - test/configuration_test.rb
152
+ - test/delegation_test.rb
153
+ - test/fixtures/geocode_around.json
154
+ - test/fixtures/geocode_query.json
155
+ - test/geocode_test.rb
156
+ - test/test_helper.rb