mapbox 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 88274cc718d1e8028bb550e950c3a6c6fff35e1e
4
+ data.tar.gz: a14846005d1d0681c430be5e5a8b715969e658d9
5
+ SHA512:
6
+ metadata.gz: 3b365d9b1d4dbedf7141846811a6ff896cd2591e6cc2c7fa8dbf3699c1549657d91d72c14d6ccd45106c096763722e9ac1eb799b106f6bca0e8c1988d3e2c30b
7
+ data.tar.gz: e20a56ca9bc3aa6620f118a1ad63862e7bf6823c7320ea24553168d20100bb028bf86ebff51f4a5a59e048825ea63808cbc066a1b6da0d356150231793929d68
@@ -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/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mapbox.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'coolline'
8
+ gem 'guard'
9
+ gem 'guard-rspec'
10
+ gem 'guard-bundler'
11
+ gem 'rb-fsevent'
12
+ gem 'terminal-notifier-guard'
13
+ gem 'json'
14
+ gem 'rspec'
15
+ gem 'github-markup'
16
+ end
@@ -0,0 +1,15 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2 do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
7
+ watch(%r{^spec/support/shared_versioning_examples.rb$}) { |m| "spec/" }
8
+ watch('spec/spec_helper.rb') { "spec/" }
9
+ end
10
+
11
+
12
+ guard 'bundler' do
13
+ watch('Gemfile')
14
+ watch(/^.+\.gemspec/)
15
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Mark Madsen
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.
@@ -0,0 +1,76 @@
1
+ # Mapbox
2
+
3
+ Mapbox is awesome. But it doesn't have an official gem. :( So....
4
+
5
+ This the the _**unofficial**_ way to connect to the [Static Map API from MapBox](http://mapbox.com/developers/api/).
6
+
7
+ This gem provides a simple way to create a static map and add markers.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'mapbox'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install mapbox
22
+
23
+ ## Usage
24
+
25
+ ### Quick Start
26
+
27
+ Set your MAP API ID .
28
+ ```
29
+ ENV['MAPBOX_API_ID'] = "examples.map-4l7djmvo"
30
+ ```
31
+
32
+ OR
33
+
34
+ ```
35
+ StaticMap.api_id = "examples.map-4l7djmvo"
36
+ ```
37
+
38
+ Make a map.
39
+
40
+ ```ruby
41
+ # StaticMap.new(lat, lon, zoom, width=640, height=480)
42
+ map = StaticMap.new(38.89,-77.04,13)
43
+ map.width = 400
44
+ map.width = 300
45
+ map.to_s
46
+ # => "api.tiles.mapbox.com/v3/examples.map-4l7djmvo/-77.04,38.89,13/300x480.png"
47
+ ```
48
+
49
+ Add markers.
50
+
51
+ ```ruby
52
+ # MapboxMarker.new(latitude, longitude, size=SMALL_PIN, label=nil, color=nil)
53
+ map << MapboxMarker.new(38.89, -77.04, MapboxMarker::MEDIUM_PIN, "monument")
54
+ map.to_s
55
+ # => "api.tiles.mapbox.com/v3/examples.map-4l7djmvo/pin-m-monument(-77.04,38.89)/-77.04,38.89,13/300x480.png"
56
+ ```
57
+
58
+ ### StaticMap
59
+
60
+ ... docs coming soon ...
61
+
62
+ ### MapboxMarker
63
+
64
+ ... docs coming soon ...
65
+
66
+ ### CustomMarker
67
+
68
+ ... docs coming soon ...
69
+
70
+ ## Contributing
71
+
72
+ 1. Fork it
73
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
74
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
75
+ 4. Push to the branch (`git push origin my-new-feature`)
76
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,10 @@
1
+ require "mapbox/version"
2
+ require "mapbox/mapbox_utils"
3
+ require "mapbox/abstract_marker"
4
+ require "mapbox/mapbox_marker"
5
+ require "mapbox/custom_marker"
6
+ require "mapbox/static_map"
7
+
8
+ module Mapbox
9
+
10
+ end
@@ -0,0 +1,41 @@
1
+ class AbstractMarker
2
+ attr_accessor :latitude, :longitude
3
+
4
+ def initialize(args=nil)
5
+ raise "Cannot directly instantiate a SimpleMarker" if self.class == AbstractMarker
6
+ super
7
+ end
8
+
9
+ def lat
10
+ self.latitude
11
+ end
12
+
13
+ def lon
14
+ self.longitude
15
+ end
16
+
17
+ def lat=(latitude)
18
+ self.latitude = latitude
19
+ end
20
+
21
+ def lon=(longitude)
22
+ self.longitude = longitude
23
+ end
24
+
25
+ # Override the setting methods so that they validate the input and return
26
+ # a meaningful error message
27
+
28
+ def latitude=(latitude)
29
+ @latitude = MapboxUtils.validate_latitude(latitude)
30
+ end
31
+
32
+ def longitude=(longitude)
33
+ @longitude = MapboxUtils.validate_longitude(longitude)
34
+ end
35
+
36
+ def to_s
37
+ "(#{self.lon},#{self.lat})"
38
+ end
39
+
40
+ end
41
+
@@ -0,0 +1,26 @@
1
+ class CustomMarker < AbstractMarker
2
+ attr_accessor :url
3
+
4
+ def initialize(latitude, longitude, url)
5
+ self.latitude = latitude
6
+ self.longitude = longitude
7
+ self.url = url
8
+ end
9
+
10
+ def url=(url)
11
+ @url = CustomMarker.encode_url(url) unless url.nil?
12
+ end
13
+
14
+ def to_s
15
+ "url-#{self.url}(#{self.lon},#{self.lat})"
16
+ end
17
+
18
+ private
19
+
20
+ def self.encode_url(url)
21
+ url.sub!(/^http[s]?\:\/\//, '')
22
+ MapboxUtils.encode_url(url)
23
+ end
24
+
25
+ end
26
+
@@ -0,0 +1,83 @@
1
+ class MapboxMarker < AbstractMarker
2
+ attr_accessor :name, :label, :color
3
+
4
+ SMALL_PIN = "pin-s"
5
+ MEDIUM_PIN = "pin-m"
6
+ LARGE_PIN = "pin-l"
7
+
8
+ def self.size
9
+ {
10
+ :small => SMALL_PIN,
11
+ :medium => MEDIUM_PIN,
12
+ :large => LARGE_PIN
13
+ }
14
+ end
15
+
16
+ def self.maki_icons
17
+ [ "circle-stroked", "circle", "square-stroked", "square", "triangle-stroked", "triangle",
18
+ "star-stroked", "star", "cross", "marker-stroked", "marker", "religious-jewish",
19
+ "religious-christian", "religious-muslim", "cemetery", "place-of-worship", "airport",
20
+ "heliport", "rail", "rail-underground", "rail-above", "bus", "fuel", "parking",
21
+ "parking-garage", "airfield", "roadblock", "ferry", "harbor", "bicycle", "park",
22
+ "park2", "museum", "lodging", "monument", "zoo", "garden", "campsite", "theatre",
23
+ "art-gallery", "pitch", "soccer", "america-football", "tennis", "basketball", "baseball",
24
+ "golf", "swimming", "cricket", "skiing", "school", "college", "library", "post",
25
+ "fire-station", "town-hall", "police", "prison", "embassy", "waste-basket", "toilets",
26
+ "telephone", "emergency-telephone", "disability", "beer", "restaurant", "cafe", "shop",
27
+ "fast-food", "bar", "bank", "grocery", "cinema", "alcohol-shop", "music", "hospital",
28
+ "pharmacy", "danger", "industrial", "warehouse", "commercial", "building", "oil-well",
29
+ "dam", "slaughterhouse", "logging", "water", "wetland" ]
30
+ end
31
+
32
+ def initialize(latitude, longitude, size=SMALL_PIN, label=nil, color=nil)
33
+ self.name = size
34
+ self.latitude = latitude
35
+ self.longitude = longitude
36
+ self.label = label
37
+ self.color = color
38
+ end
39
+
40
+ def size
41
+ self.name
42
+ end
43
+
44
+ def size=(size)
45
+ self.name = size
46
+ end
47
+
48
+ def color=(color)
49
+ @color = MapboxMarker.validate_color(color) unless color.nil?
50
+ end
51
+
52
+ def label=(label)
53
+ @label = MapboxMarker.validate_label(label) unless label.nil?
54
+ end
55
+
56
+ def label_string
57
+ "-#{self.label}" unless self.label.nil? || self.label.strip == ""
58
+ end
59
+
60
+ def color_string
61
+ "+#{self.color}" unless self.color.nil? || self.color.strip == ""
62
+ end
63
+
64
+ def to_s
65
+ "#{self.name}#{self.label_string}#{self.color_string}(#{self.lon},#{self.lat})"
66
+ end
67
+
68
+ private
69
+
70
+ def self.validate_color(color)
71
+ color = color[1..7] if color.start_with?("#")
72
+ raise ArgumentError, "color is not a hex color of the form aabbcc" unless color =~ /^[0-9a-fA-F]{6}$/
73
+ color.downcase
74
+ end
75
+
76
+ def self.validate_label(label)
77
+ label = label.to_s
78
+ raise ArgumentError, "a label is either a single charater 0-9 or a-z OR a maki icon" unless
79
+ label =~ /^[0-9a-zA-Z]{1}$/ || MapboxMarker.maki_icons.include?(label)
80
+ label
81
+ end
82
+ end
83
+
@@ -0,0 +1,36 @@
1
+ require 'cgi'
2
+ class MapboxUtils
3
+
4
+ def self.encode_url(url)
5
+ url.sub!(/^http[s]?\:\/\//, '')
6
+ CGI::escape(url.to_s)
7
+ end
8
+
9
+ def self.validate_latitude(latitude)
10
+ latitude = latitude.to_f
11
+ raise ArgumentError, "latitude needs to be between -85 and 85" unless
12
+ latitude >= -85.0 && latitude <= 85.0
13
+ latitude
14
+ end
15
+
16
+ def self.validate_longitude(longitude)
17
+ longitude = longitude.to_f
18
+ raise ArgumentError, "longitude needs to be between -180 and 180" unless
19
+ longitude >= -180.0 && longitude <= 180.0
20
+ longitude
21
+ end
22
+
23
+ def self.validate_zoom(zoom)
24
+ zoom = zoom.to_i
25
+ raise ArgumentError, "zoom needs to be between 0 and 22" unless
26
+ zoom >= 0 && zoom <= 22
27
+ zoom
28
+ end
29
+
30
+
31
+ def self.validate_api_id(api_id)
32
+ raise ArgumentError, "api_id cannot be nil" if api_id.nil?
33
+ api_id
34
+ end
35
+
36
+ end
@@ -0,0 +1,90 @@
1
+ class StaticMap
2
+
3
+ attr_accessor :latitude, :longitude, :zoom, :width, :height, :api_id, :markers
4
+
5
+ def initialize(latitude, longitude, zoom, width=640, height=480, api_id=nil, markers=nil)
6
+ self.latitude = latitude
7
+ self.longitude = longitude
8
+ self.zoom = zoom
9
+ self.width = width
10
+ self.height = height
11
+ self.api_id = api_id || StaticMap.api_id
12
+ self.markers = markers || []
13
+ end
14
+
15
+ # api.tiles.mapbox.com/v3/examples.map-4l7djmvo/-77.04,38.89,13/400x300.png
16
+ # api.tiles.mapbox.com/v3/examples.map-4l7djmvo/pin-m-monument(-77.04,38.89)/-77.04,38.89,13/400x300.png
17
+ def to_s
18
+ "#{StaticMap.api_path}/#{self.api_id}/#{marker_string}#{lon},#{lat},#{zoom}/#{width}x#{height}.png"
19
+ end
20
+
21
+ def lat
22
+ self.latitude
23
+ end
24
+
25
+ def lon
26
+ self.longitude
27
+ end
28
+
29
+ def lat=(latitude)
30
+ self.latitude = latitude
31
+ end
32
+
33
+ def lon=(longitude)
34
+ self.longitude = longitude
35
+ end
36
+
37
+ def latitude=(latitude)
38
+ @latitude = MapboxUtils.validate_latitude(latitude)
39
+ end
40
+
41
+ def longitude=(longitude)
42
+ @longitude = MapboxUtils.validate_longitude(longitude)
43
+ end
44
+
45
+ def zoom=(zoom)
46
+ @zoom = MapboxUtils.validate_zoom(zoom)
47
+ end
48
+
49
+ def api_id=(api_id)
50
+ @api_id = MapboxUtils.validate_api_id(api_id)
51
+ end
52
+
53
+ def markers
54
+ @markers ||= []
55
+ end
56
+
57
+ def add_marker(marker)
58
+ self.markers << marker
59
+ end
60
+
61
+ def <<(marker)
62
+ self.markers << marker
63
+ end
64
+ # make the string from the markers
65
+
66
+ def marker_string
67
+ markers.each.map{|marker| marker.to_s}.join(",") + "/" unless markers.nil? || markers.length == 0
68
+ end
69
+
70
+ # Allow the user to class level configure the API ID
71
+ # defaults to reading MAPBOX_API_ID so that you can use this
72
+ # in a very simple fashion with services like heroku
73
+
74
+ def self.api_id
75
+ @@api_id ||= ENV["MAPBOX_API_ID"]
76
+ end
77
+
78
+ def self.api_id=(api_id)
79
+ @@api_id = api_id
80
+ end
81
+
82
+ def self.api_path
83
+ @@api_path ||= (ENV["MAPBOX_API_PATH"] || "api.tiles.mapbox.com/v3")
84
+ end
85
+
86
+ def self.api_path=(api_path)
87
+ @@api_path = api_path
88
+ end
89
+
90
+ end
@@ -0,0 +1,3 @@
1
+ module Mapbox
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mapbox/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mapbox"
8
+ spec.version = Mapbox::VERSION
9
+ spec.authors = ["Mark Madsen"]
10
+ spec.email = ["growl@agileanimal.com"]
11
+ spec.description = %q{Ruby Gem for the MapBox Static Image API}
12
+ spec.summary = %q{Ruby Gem for the MapBox Static Image API}
13
+ spec.homepage = "https://github.com/aai/mapbox"
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_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency 'rspec', '~> 2.9'
24
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+ require 'mapbox'
3
+
4
+ #:name-:label+:color(:lon,:lat)
5
+ #pin-s-park+cc4422(-77,38)
6
+
7
+ describe AbstractMarker do
8
+ class Marker < AbstractMarker
9
+ def initialize(latitude, longitude)
10
+ self.latitude = latitude
11
+ self.longitude = longitude
12
+ end
13
+ end
14
+
15
+ context "mixed bag of mapbox options to test validation" do
16
+ subject(:marker){ Marker.new(lat, lon,) }
17
+ let(:lat){ "12.34567" }
18
+ let(:lon){ 123.45678 }
19
+
20
+ its(:lat){ should == 12.34567 }
21
+ its(:lon){ should == 123.45678 }
22
+ its(:to_s){ should == "(123.45678,12.34567)" }
23
+
24
+ it "should throw an exception if the latitude is malformed." do
25
+ expect{ subject.latitude = 1337 }.to raise_error(ArgumentError)
26
+ expect{ subject.latitude = 86 }.to raise_error(ArgumentError)
27
+ expect{ subject.latitude = -85.000001 }.to raise_error(ArgumentError)
28
+ end
29
+
30
+ it "should throw an exception if the longitude is malformed." do
31
+ expect{ subject.longitude = 1337 }.to raise_error(ArgumentError)
32
+ expect{ subject.longitude = -181 }.to raise_error(ArgumentError)
33
+ expect{ subject.longitude = 180.000001 }.to raise_error(ArgumentError)
34
+ end
35
+ end
36
+
37
+ context "AbstractMarker class" do
38
+ subject(:klass) { AbstractMarker }
39
+
40
+ it "define constanst for pin sizes" do
41
+ expect{ subject.new }.to raise_error(RuntimeError)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+ require 'mapbox'
3
+
4
+ #:name-:label+:color(:lon,:lat)
5
+ #pin-s-park+cc4422(-77,38)
6
+
7
+ describe CustomMarker do
8
+ subject(:marker){ CustomMarker.new(lat, lon, url) }
9
+
10
+ let(:lat){ 38 }
11
+ let(:lon){ -77 }
12
+ let(:url){ "http://bit.ly/KahHBj" }
13
+
14
+ # Thes examples come from the MaxBox developer documentation and will be maintained
15
+ # to match the documentation. if matching the docs causes a fail we need to look
16
+ # if the format has changed.
17
+
18
+ context "with external marker image at :url" do
19
+ its(:url){ should == "bit.ly%2FKahHBj" }
20
+ its(:to_s){ should == "url-bit.ly%2FKahHBj(-77.0,38.0)" }
21
+ end
22
+
23
+ # These examples test some edge cases and input variations
24
+
25
+ context "mixed bag of mapbox options to test validation" do
26
+ let(:url){ "m.anml.io/image/1233456" }
27
+
28
+ its(:url){ should == "m.anml.io%2Fimage%2F1233456" }
29
+ its(:to_s){ should == "url-m.anml.io%2Fimage%2F1233456(-77.0,38.0)" }
30
+ end
31
+ end
@@ -0,0 +1,126 @@
1
+ require 'spec_helper'
2
+ require 'mapbox'
3
+
4
+ #:name-:label+:color(:lon,:lat)
5
+ #pin-s-park+cc4422(-77,38)
6
+
7
+ describe MapboxMarker do
8
+ subject(:marker){ MapboxMarker.new(lat, lon, size) }
9
+
10
+ let(:lat){ 38 }
11
+ let(:lon){ -77 }
12
+ let(:size){ MapboxMarker::SMALL_PIN }
13
+ let(:color){ "cc4400" }
14
+ let(:label){ "fire-station" }
15
+
16
+ # Thes examples come from the MaxBox developer documentation and will be maintained
17
+ # to match the documentation. if matching the docs causes a fail we need to look
18
+ # if the format has changed.
19
+
20
+ context "with color as an RGB hex color" do
21
+ subject(:marker){ MapboxMarker.new(lat, lon, size, label, color) }
22
+ let(:label){ "park" }
23
+ let(:color){ "cc4422" }
24
+
25
+ its(:to_s){ should == "pin-s-park+cc4422(-77.0,38.0)" }
26
+ end
27
+
28
+ context "with a pin, small" do
29
+ let(:size){ MapboxMarker::SMALL_PIN }
30
+
31
+ its(:name){ should == "pin-s" }
32
+ its(:to_s){ should == "pin-s(-77.0,38.0)" }
33
+ end
34
+
35
+ context "with a pin, medium" do
36
+ let(:size){ MapboxMarker::MEDIUM_PIN }
37
+
38
+ its(:name){ should == "pin-m" }
39
+ its(:to_s){ should == "pin-m(-77.0,38.0)" }
40
+ end
41
+
42
+ context "with a pin, large" do
43
+ let(:size){ MapboxMarker::LARGE_PIN }
44
+
45
+ its(:name){ should == "pin-l" }
46
+ its(:to_s){ should == "pin-l(-77.0,38.0)" }
47
+ end
48
+
49
+ context "with a label as one of the letters from A through Z" do
50
+ subject(:marker){ MapboxMarker.new(lat, lon, size, label) }
51
+ let(:label){ "a" }
52
+
53
+ its(:label){ should == "a" }
54
+ its(:to_s){ should == "pin-s-a(-77.0,38.0)" }
55
+ end
56
+
57
+ context "with a label as one of the digits from 0 through 9 " do
58
+ subject(:marker){ MapboxMarker.new(lat, lon, size, label) }
59
+ let(:label){ 5 }
60
+
61
+ its(:label){ should == "5" }
62
+ its(:to_s){ should == "pin-s-5(-77.0,38.0)" }
63
+ end
64
+
65
+ context "with a label as a Maki icon id" do
66
+ subject(:marker){ MapboxMarker.new(lat, lon, size, label) }
67
+
68
+ its(:label){ should == "fire-station" }
69
+ its(:to_s){ should == "pin-s-fire-station(-77.0,38.0)" }
70
+ end
71
+
72
+ context "with color as an RGB hex color" do
73
+ subject(:marker){ MapboxMarker.new(lat, lon, size, label, color) }
74
+
75
+ its(:color){ should == "cc4400" }
76
+ its(:to_s){ should == "pin-s-fire-station+cc4400(-77.0,38.0)" }
77
+ end
78
+
79
+ # These examples test some edge cases and input variations
80
+
81
+ context "mixed bag of mapbox options to test validation" do
82
+ subject(:marker){ MapboxMarker.new("12.34567", 123.45678, MapboxMarker.size[:medium], "a", "#9900cc") }
83
+
84
+ its(:name){ should == MapboxMarker::MEDIUM_PIN }
85
+ its(:size){ should == "pin-m" }
86
+ its(:lat){ should == 12.34567 }
87
+ its(:lon){ should == 123.45678 }
88
+ its(:label){ should == "a" }
89
+ its(:color){ should == "9900cc" }
90
+
91
+ its(:to_s){ should == "pin-m-a+9900cc(123.45678,12.34567)" }
92
+
93
+ it "should throw an exception if the color is not correctly formatted." do
94
+ expect{ subject.color = "hahhah" }.to raise_error(ArgumentError)
95
+ end
96
+
97
+ it "should throw an exception if the label is malformed." do
98
+ expect{ subject.label = 10 }.to raise_error(ArgumentError)
99
+ expect{ subject.label = "10" }.to raise_error(ArgumentError)
100
+ expect{ subject.label = "AA" }.to raise_error(ArgumentError)
101
+ expect{ subject.label = "q" }.to_not raise_error(ArgumentError)
102
+ expect{ subject.label = 5 }.to_not raise_error(ArgumentError)
103
+ end
104
+
105
+ it "should throw an exception if the label is not a maki-icon." do
106
+ expect{ subject.label = "wilbert" }.to raise_error(ArgumentError)
107
+ expect{ subject.label = "religious-agnostic" }.to raise_error(ArgumentError)
108
+ expect{ subject.label = "cricket" }.to_not raise_error(ArgumentError)
109
+ end
110
+ end
111
+
112
+ context "MapboxMarker class" do
113
+ subject(:klass) { MapboxMarker }
114
+
115
+ its(:maki_icons){ should include("wetland") }
116
+ its(:maki_icons){ should include("zoo") }
117
+ its(:maki_icons){ should include("circle-stroked") }
118
+ its(:maki_icons){ should_not include("dangerous") }
119
+
120
+ it "define constanst for pin sizes" do
121
+ MapboxMarker::SMALL_PIN.should == "pin-s"
122
+ MapboxMarker::MEDIUM_PIN.should == "pin-m"
123
+ MapboxMarker::LARGE_PIN.should == "pin-l"
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+ require 'mapbox'
3
+
4
+
5
+ # /:map/:lon,:lat,:z/:widthx:height.png
6
+ # api.tiles.mapbox.com/v3/examples.map-4l7djmvo/-77.04,38.89,13/400x300.png
7
+
8
+ # /:map/:markers/:lon,:lat,:z/:widthx:height.png
9
+ # api.tiles.mapbox.com/v3/examples.map-4l7djmvo/pin-m-monument(-77.04,38.89)/-77.04,38.89,13/400x300.png
10
+
11
+ describe StaticMap do
12
+ subject(:map){ StaticMap.new(lat, lon, zoom, width, height, api_id) }
13
+ let(:lat){38.89}
14
+ let(:lon){-77.04}
15
+ let(:zoom){13}
16
+ let(:width){400}
17
+ let(:height){300}
18
+ let(:api_id){"examples.map-4l7djmvo"}
19
+
20
+ context "static image for :map" do
21
+ subject(:map){ StaticMap.new(lat, lon, zoom, width, height, api_id, markers) }
22
+ let(:markers){ [MapboxMarker.new(38.89,-77.04,MapboxMarker::MEDIUM_PIN,"monument")] }
23
+ its(:to_s){should == "api.tiles.mapbox.com/v3/examples.map-4l7djmvo/pin-m-monument(-77.04,38.89)/-77.04,38.89,13/400x300.png" }
24
+ end
25
+
26
+ context "Static image for :map with :markers" do
27
+ its(:to_s){should == "api.tiles.mapbox.com/v3/examples.map-4l7djmvo/-77.04,38.89,13/400x300.png" }
28
+
29
+ it "should add markers to itself" do
30
+ subject << MapboxMarker.new(38.89,-77.04,MapboxMarker::MEDIUM_PIN,"monument")
31
+
32
+ subject.to_s.should ==
33
+ "api.tiles.mapbox.com/v3/examples.map-4l7djmvo/pin-m-monument(-77.04,38.89)/-77.04,38.89,13/400x300.png"
34
+ end
35
+ end
36
+
37
+ context "Testing input validation" do
38
+ it "should throw an exception without an api_id." do
39
+ expect{ subject.api_id = nil }.to raise_error(ArgumentError)
40
+ end
41
+
42
+ it "should throw an exception if the latitude is malformed." do
43
+ expect{ subject.latitude = 1337 }.to raise_error(ArgumentError)
44
+ expect{ subject.latitude = 86 }.to raise_error(ArgumentError)
45
+ expect{ subject.latitude = -85.000001 }.to raise_error(ArgumentError)
46
+ end
47
+
48
+ it "should throw an exception if the longitude is malformed." do
49
+ expect{ subject.longitude = 1337 }.to raise_error(ArgumentError)
50
+ expect{ subject.longitude = -181 }.to raise_error(ArgumentError)
51
+ expect{ subject.longitude = 180.000001 }.to raise_error(ArgumentError)
52
+ end
53
+
54
+ it "should throw an exception if the zoom is malformed." do
55
+ expect{ subject.zoom = -1 }.to raise_error(ArgumentError)
56
+ expect{ subject.zoom = 23 }.to raise_error(ArgumentError)
57
+ expect{ subject.zoom = 22 }.not_to raise_error(ArgumentError)
58
+ expect{ subject.zoom = 0 }.not_to raise_error(ArgumentError)
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'support'))
4
+
5
+ require 'rubygems'
6
+ require 'bundler'
7
+
8
+ Bundler.require :default, :test
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mapbox
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mark Madsen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2.9'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.9'
55
+ description: Ruby Gem for the MapBox Static Image API
56
+ email:
57
+ - growl@agileanimal.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .rspec
64
+ - Gemfile
65
+ - Guardfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - lib/mapbox.rb
70
+ - lib/mapbox/abstract_marker.rb
71
+ - lib/mapbox/custom_marker.rb
72
+ - lib/mapbox/mapbox_marker.rb
73
+ - lib/mapbox/mapbox_utils.rb
74
+ - lib/mapbox/static_map.rb
75
+ - lib/mapbox/version.rb
76
+ - mapbox.gemspec
77
+ - spec/mapbox/abstract_marker_spec.rb
78
+ - spec/mapbox/custom_marker_spec.rb
79
+ - spec/mapbox/mapbox_marker_spec.rb
80
+ - spec/mapbox/static_map_spec.rb
81
+ - spec/spec_helper.rb
82
+ homepage: https://github.com/aai/mapbox
83
+ licenses:
84
+ - MIT
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 2.0.3
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: Ruby Gem for the MapBox Static Image API
106
+ test_files:
107
+ - spec/mapbox/abstract_marker_spec.rb
108
+ - spec/mapbox/custom_marker_spec.rb
109
+ - spec/mapbox/mapbox_marker_spec.rb
110
+ - spec/mapbox/static_map_spec.rb
111
+ - spec/spec_helper.rb
112
+ has_rdoc: