cartographie 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +37 -0
- data/Rakefile +9 -0
- data/cartographie.gemspec +21 -0
- data/lib/cartographie.rb +28 -0
- data/lib/cartographie/map.rb +92 -0
- data/lib/cartographie/version.rb +3 -0
- data/spec/cartographie/map_spec.rb +67 -0
- data/spec/cartographie_spec.rb +15 -0
- data/spec/spec_helper.rb +5 -0
- metadata +95 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use @$(basename `pwd`) --create
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Matthew Conway
|
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,37 @@
|
|
1
|
+
# Cartographie
|
2
|
+
|
3
|
+
Cartographie is a wrapper for Google's Static Maps API
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'cartographie'
|
10
|
+
|
11
|
+
Or install it yourself as:
|
12
|
+
|
13
|
+
$ gem install cartographie
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
require 'cartographie'
|
19
|
+
Cartographie.map('San Francisco, CA')
|
20
|
+
Cartographie.map('New York, NY', width: 200, height: 200, zoom: 10)
|
21
|
+
```
|
22
|
+
|
23
|
+
**Defaults**
|
24
|
+
|
25
|
+
- width: 300
|
26
|
+
- height: 300
|
27
|
+
- zoom: 15
|
28
|
+
- format: 'png'
|
29
|
+
- sensor: false
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
1. Fork it
|
34
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
35
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
36
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
37
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/cartographie/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Matthew Conway"]
|
6
|
+
gem.email = ["mattonrails@shortmail.com"]
|
7
|
+
gem.description = %q{Beautiful map generation}
|
8
|
+
gem.summary = %q{Wrapper for Google's Static Maps API}
|
9
|
+
gem.homepage = "http://mattonrails.github.com/cartographie/"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "cartographie"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Cartographie::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency("addressable")
|
19
|
+
gem.add_development_dependency("rake")
|
20
|
+
gem.add_development_dependency("rspec", "~>2.11")
|
21
|
+
end
|
data/lib/cartographie.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require "cartographie/version"
|
2
|
+
|
3
|
+
# Cartographie is the root module for all of Cartographie's components
|
4
|
+
module Cartographie
|
5
|
+
|
6
|
+
autoload :Map, 'cartographie/map'
|
7
|
+
|
8
|
+
# Public: Create a new Map instance.
|
9
|
+
#
|
10
|
+
# location - The String for the map's location (default: 'Paris, France').
|
11
|
+
# options - The Hash options used to configure the map (default: {}):
|
12
|
+
# :width - The Integer width of the map (optional).
|
13
|
+
# :height - The Integer height of the map (optional).
|
14
|
+
# :zoom - The Integer zoom level (optional).
|
15
|
+
# :file_format - The String file format for the image (optional).
|
16
|
+
# :sensor - The Boolean indicating GPS usage (optional).
|
17
|
+
#
|
18
|
+
# Examples
|
19
|
+
#
|
20
|
+
# Cartographie.map('Tokyo, Japan')
|
21
|
+
# Cartographie.map('San Francisco, CA', zoom: 10)
|
22
|
+
#
|
23
|
+
# Returns an instance of Cartographie::Map
|
24
|
+
def self.map(location = 'Paris, France', options={})
|
25
|
+
Map.new(location, options)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'addressable/uri'
|
2
|
+
|
3
|
+
module Cartographie
|
4
|
+
# Map represents a map, and contains the details regarding a
|
5
|
+
# map's dimensions, zoom level, the image file format, and whether a GPS
|
6
|
+
# sensor was used in determining the map's location.
|
7
|
+
class Map
|
8
|
+
|
9
|
+
# Public: Gets/Sets the String location of the map.
|
10
|
+
attr_accessor :location
|
11
|
+
# Public: Gets/Sets the Hash options for the map.
|
12
|
+
attr_accessor :options
|
13
|
+
|
14
|
+
API_ENDPOINT = 'http://maps.googleapis.com/maps/api/staticmap'
|
15
|
+
DEFAULT_WIDTH = 300
|
16
|
+
DEFAULT_HEIGHT = 300
|
17
|
+
DEFAULT_ZOOM = 15
|
18
|
+
DEFAULT_FILE_FORMAT = 'png'
|
19
|
+
DEFAULT_SENSOR = false
|
20
|
+
|
21
|
+
# Public: Initialize a Map
|
22
|
+
#
|
23
|
+
# location - The String for the map's location (default: 'Paris, France').
|
24
|
+
# options - The Hash options used to configure the map (default: {}):
|
25
|
+
# :width - The Integer width of the map (optional).
|
26
|
+
# :height - The Integer height of the map (optional).
|
27
|
+
# :zoom - The Integer zoom level (optional).
|
28
|
+
# :file_format - The String file format for the image (optional).
|
29
|
+
# :sensor - The Boolean indicating GPS usage (optional).
|
30
|
+
#
|
31
|
+
# Examples
|
32
|
+
#
|
33
|
+
# Cartographie::Map.new('San Francisco, CA', zoom: 10)
|
34
|
+
def initialize(location='Paris, France', options={})
|
35
|
+
self.location = location
|
36
|
+
self.options = options
|
37
|
+
end
|
38
|
+
|
39
|
+
# Public: Build a Google Static Maps image URI
|
40
|
+
#
|
41
|
+
# Returns the String URI pointing an image of the map
|
42
|
+
def uri
|
43
|
+
params = {
|
44
|
+
center: location,
|
45
|
+
size: size,
|
46
|
+
zoom: zoom,
|
47
|
+
format: file_format,
|
48
|
+
sensor: sensor.to_s
|
49
|
+
}
|
50
|
+
Addressable::URI.parse(api_endpoint).tap do |uri|
|
51
|
+
uri.query_values = params
|
52
|
+
end.to_s
|
53
|
+
end
|
54
|
+
alias to_s uri
|
55
|
+
|
56
|
+
# Returns the Integer width passed in options, or default
|
57
|
+
def width
|
58
|
+
options[:width] || DEFAULT_WIDTH
|
59
|
+
end
|
60
|
+
|
61
|
+
# Returns the Integer height passed in options, or default
|
62
|
+
def height
|
63
|
+
options[:height] || DEFAULT_HEIGHT
|
64
|
+
end
|
65
|
+
|
66
|
+
# Returns the Integer zoom level passed in options, or default
|
67
|
+
def zoom
|
68
|
+
options[:zoom] || DEFAULT_ZOOM
|
69
|
+
end
|
70
|
+
|
71
|
+
# Returns the String file format passed in options, or default
|
72
|
+
def file_format
|
73
|
+
options[:file_format] || DEFAULT_FILE_FORMAT
|
74
|
+
end
|
75
|
+
|
76
|
+
# Returns the Boolean indicating sensor usage passed in options, or default
|
77
|
+
def sensor
|
78
|
+
options[:sensor] || DEFAULT_SENSOR
|
79
|
+
end
|
80
|
+
|
81
|
+
# Returns a string combining width and height into dimensions
|
82
|
+
def size
|
83
|
+
"#{width}x#{height}"
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def api_endpoint
|
89
|
+
API_ENDPOINT
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'cartographie/map'
|
3
|
+
|
4
|
+
describe Cartographie::Map do
|
5
|
+
|
6
|
+
subject { described_class.new }
|
7
|
+
|
8
|
+
describe 'defaults' do
|
9
|
+
its(:location) { should eq('Paris, France') }
|
10
|
+
its(:width) { should eq(300) }
|
11
|
+
its(:height) { should eq(300) }
|
12
|
+
its(:size) { should eq('300x300') }
|
13
|
+
its(:zoom) { should eq(15) }
|
14
|
+
its(:file_format) { should eq('png') }
|
15
|
+
its(:sensor) { should be_false }
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'with options' do
|
19
|
+
let(:options) do
|
20
|
+
{ width: 75, height: 75, zoom: 10, file_format: 'jpg', sensor: true }
|
21
|
+
end
|
22
|
+
subject { described_class.new 'New York, NY', options }
|
23
|
+
|
24
|
+
its(:location) { should eq('New York, NY') }
|
25
|
+
its(:width) { should eq(75) }
|
26
|
+
its(:height) { should eq(75) }
|
27
|
+
its(:size) { should eq('75x75') }
|
28
|
+
its(:zoom) { should eq(10) }
|
29
|
+
its(:file_format) { should eq('jpg') }
|
30
|
+
its(:sensor) { should be_true }
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#uri' do
|
34
|
+
let(:map) { described_class.new 'Tokyo' }
|
35
|
+
|
36
|
+
subject { map.uri }
|
37
|
+
|
38
|
+
it "should match the instance's string representation" do
|
39
|
+
subject.should eq(map.to_s)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'returns a Google Static Maps URI' do
|
43
|
+
subject.should include('http://maps.googleapis.com/maps/api/staticmap')
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'contains the map location' do
|
47
|
+
subject.should include(map.location)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'contains the map size, like 640x640' do
|
51
|
+
subject.should include(map.size)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'contains the map zoom level' do
|
55
|
+
subject.should include(map.zoom.to_s)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'contains the map file format' do
|
59
|
+
subject.should include(map.file_format)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'contains the map sensor indication' do
|
63
|
+
subject.should include(map.sensor.to_s)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cartographie
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Matthew Conway
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: addressable
|
16
|
+
requirement: &70348616677260 !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: *70348616677260
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rake
|
27
|
+
requirement: &70348616676800 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70348616676800
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
requirement: &70348616676220 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '2.11'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70348616676220
|
47
|
+
description: Beautiful map generation
|
48
|
+
email:
|
49
|
+
- mattonrails@shortmail.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- .rspec
|
56
|
+
- .rvmrc
|
57
|
+
- Gemfile
|
58
|
+
- LICENSE
|
59
|
+
- README.md
|
60
|
+
- Rakefile
|
61
|
+
- cartographie.gemspec
|
62
|
+
- lib/cartographie.rb
|
63
|
+
- lib/cartographie/map.rb
|
64
|
+
- lib/cartographie/version.rb
|
65
|
+
- spec/cartographie/map_spec.rb
|
66
|
+
- spec/cartographie_spec.rb
|
67
|
+
- spec/spec_helper.rb
|
68
|
+
homepage: http://mattonrails.github.com/cartographie/
|
69
|
+
licenses: []
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 1.8.16
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: Wrapper for Google's Static Maps API
|
92
|
+
test_files:
|
93
|
+
- spec/cartographie/map_spec.rb
|
94
|
+
- spec/cartographie_spec.rb
|
95
|
+
- spec/spec_helper.rb
|