mapbox-ruby 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.
- checksums.yaml +7 -0
- data/LICENSE.md +20 -0
- data/README.md +11 -0
- data/lib/mapbox.rb +27 -0
- data/lib/mapbox/base.rb +54 -0
- data/lib/mapbox/html.rb +15 -0
- data/lib/mapbox/image.rb +32 -0
- data/lib/mapbox/overlay.rb +6 -0
- data/lib/mapbox/overlay/base.rb +24 -0
- data/lib/mapbox/overlay/geo_json.rb +10 -0
- data/lib/mapbox/overlay/marker.rb +39 -0
- data/lib/mapbox/overlay/path.rb +23 -0
- data/lib/mapbox/version.rb +4 -0
- data/mapbox-ruby.gemspec +22 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0c7807e0ca8cf7a93fb7634fda78abc976a0ca87
|
4
|
+
data.tar.gz: 08c8717286a70002bf0a114757aadb9d68627fa0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ef0613b12a03c63246755374e029762af15c3c5ee18fe3399fa33643f23ffc9ef732bad5f5119bbe1daba667bc6f50a9b054a5b3169ba45a327ad41a48604a50
|
7
|
+
data.tar.gz: e77011ebcb71b3ad5e15772aaf136d26efff7a15f2651708e1d004877ebfb0dea25f630354c9a519f37fd1240043955070650e1dc27dccdda170b49df76bcb74
|
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2015 Claudio Fiorini
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
[](https://travis-ci.org/cfiorini/mapbox-ruby)
|
2
|
+
[](https://codeclimate.com/github/cfiorini/mapbox-ruby)
|
3
|
+
|
4
|
+
A Ruby interface to the [Mapbox](https://www.mapbox.com) API.
|
5
|
+
|
6
|
+
### This gem is under development, use with precautions
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
gem install mapbox-ruby
|
10
|
+
|
11
|
+
|
data/lib/mapbox.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'mapbox/overlay'
|
2
|
+
require 'mapbox/html'
|
3
|
+
require 'mapbox/image'
|
4
|
+
require 'mapbox/version'
|
5
|
+
|
6
|
+
# Gem
|
7
|
+
module Mapbox
|
8
|
+
class Error < ::StandardError; end
|
9
|
+
|
10
|
+
API_VERSION = 'v4'
|
11
|
+
API_URL = 'http://api.tiles.mapbox.com'
|
12
|
+
|
13
|
+
ID_STREETS = 'mapbox.streets'
|
14
|
+
ID_LIGHT = 'mapbox.light'
|
15
|
+
ID_DARK = 'mapbox.dark'
|
16
|
+
ID_SATELLITE = 'mapbox.satellite'
|
17
|
+
ID_STREETS_SATELLITE = 'mapbox.streets-satellites'
|
18
|
+
ID_WHEATPASTE = 'mapbox.wheatpaste'
|
19
|
+
ID_STREETS_BASIC = 'mapbox.streets-basic'
|
20
|
+
ID_COMIC = 'mapbox.comic'
|
21
|
+
ID_OUTDOORS = 'mapbox.outdoors'
|
22
|
+
ID_RUN_BIKE_HIKE = 'mapbox.run-bike-hike'
|
23
|
+
ID_PENCIL = 'mapbox.pencil'
|
24
|
+
ID_PIRATES = 'mapbox.pirates'
|
25
|
+
ID_EMERALD = 'mapbox.emerald'
|
26
|
+
ID_HIGH_CONTRAST = 'mapbox.high-contrast'
|
27
|
+
end
|
data/lib/mapbox/base.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'excon'
|
2
|
+
require 'forwardable'
|
3
|
+
|
4
|
+
module Mapbox
|
5
|
+
# Base class
|
6
|
+
class Base
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
attr_accessor :access_token, :access_token_secret
|
10
|
+
attr_accessor :mapid, :map_option, :map_type, :overlays
|
11
|
+
attr_accessor :z, :x, :y
|
12
|
+
attr_accessor :lat, :lon, :zoom
|
13
|
+
|
14
|
+
def_delegator :connection, :get, :get
|
15
|
+
|
16
|
+
def initialize(opts = {})
|
17
|
+
opts.each do |key, value|
|
18
|
+
instance_variable_set("@#{key}", value)
|
19
|
+
end
|
20
|
+
@overlays ||= []
|
21
|
+
|
22
|
+
yield(self) if block_given?
|
23
|
+
end
|
24
|
+
|
25
|
+
def parameters_check
|
26
|
+
fail ArgumentError, ':access_token' if @access_token.nil?
|
27
|
+
fail ArgumentError, ':mapid' if @mapid.nil?
|
28
|
+
end
|
29
|
+
|
30
|
+
def base_url
|
31
|
+
tmp_overlays = @overlays.join(',') if @overlays.size > 0
|
32
|
+
tmp_overlays ||= nil
|
33
|
+
|
34
|
+
[API_URL, API_VERSION, @mapid, tmp_overlays,
|
35
|
+
@llz, @z, @x, @y, @map_option, @wh]
|
36
|
+
.compact
|
37
|
+
.join('/') + ".#{@map_type}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def connection
|
41
|
+
Excon.new(base_url, query: { access_token: @access_token })
|
42
|
+
end
|
43
|
+
|
44
|
+
# latitude longitude zoom
|
45
|
+
def llz
|
46
|
+
[@lat, @lon, @zoom].join(',')
|
47
|
+
end
|
48
|
+
|
49
|
+
# width and height
|
50
|
+
def wh
|
51
|
+
[@width, @height].join('x')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/mapbox/html.rb
ADDED
data/lib/mapbox/image.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
require 'mapbox/base'
|
3
|
+
|
4
|
+
module Mapbox
|
5
|
+
# Image class
|
6
|
+
class Image < Mapbox::Base
|
7
|
+
def initialize(opts = {})
|
8
|
+
super(opts)
|
9
|
+
@map_type ||= 'png'
|
10
|
+
|
11
|
+
@llz = llz
|
12
|
+
@wh = wh
|
13
|
+
parameters_check
|
14
|
+
end
|
15
|
+
|
16
|
+
def parameters_check
|
17
|
+
super
|
18
|
+
fail ArgumentError,
|
19
|
+
':lon must be between -180 to 180' unless (-180..180).to_a.include?(@lon)
|
20
|
+
fail ArgumentError,
|
21
|
+
':lat must be between -85 to 85' unless (-85..85).to_a.include?(@lat)
|
22
|
+
fail ArgumentError,
|
23
|
+
':zoom must be between 0 to 15' unless (0..15).to_a.include?(@zoom)
|
24
|
+
end
|
25
|
+
|
26
|
+
def response
|
27
|
+
::Tempfile.open("foo.#{@map_type}") do |r|
|
28
|
+
r.write get.data[:body]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Mapbox
|
2
|
+
module Overlay
|
3
|
+
# Overlay base class
|
4
|
+
class Base
|
5
|
+
def self.add(opts = {})
|
6
|
+
a = new(opts)
|
7
|
+
a.generate_overlay
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(opts = {})
|
11
|
+
opts.each do |key, value|
|
12
|
+
instance_variable_set("@#{key}", value)
|
13
|
+
end
|
14
|
+
arguments_check
|
15
|
+
end
|
16
|
+
|
17
|
+
def arguments_check; end
|
18
|
+
|
19
|
+
def generate_overlay
|
20
|
+
fail Exception 'You cannot call generate_overlay from Base class'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Mapbox
|
2
|
+
module Overlay
|
3
|
+
# Marker class
|
4
|
+
class Marker < Base
|
5
|
+
MAKI = %w(
|
6
|
+
a-z 0-9 airfield airport alcohol-shop america-football art-gallery
|
7
|
+
bakery bank bar baseball basketball beer bicycle building bus cafe
|
8
|
+
camera campsite car cemetery chemist cinema circle-stroked circle
|
9
|
+
city clothing-store college commercial cricket cross dam danger
|
10
|
+
dentist disability dog-park embassy emergency-telephone entrance
|
11
|
+
farm fast-food ferry fire-station fuel garden gift golf grocery
|
12
|
+
hairdresser harbor heart heliport hospital ice-cream industrial
|
13
|
+
land-use laundry library lighthouse lodging logging london-underground
|
14
|
+
marker-stroked marker minefield mobilephone monument museum music
|
15
|
+
oil-well park2 park parking-garage parking pharmacy pitch place-of-worship
|
16
|
+
playground police polling-place post prison rail-above rail-light rail-metro
|
17
|
+
rail-underground rail religious-christian religious-jewish religious-muslim
|
18
|
+
restaurant roadblock rocket school scooter shop skiing slaughterhouse
|
19
|
+
soccer square-stroked square star-stroked star suitcase swimming
|
20
|
+
telephone tennis theatre toilets town-hall town triangle-stroked
|
21
|
+
triangle village warehouse waste-basket water wetland zoo
|
22
|
+
)
|
23
|
+
|
24
|
+
def arguments_check
|
25
|
+
return if @label.nil?
|
26
|
+
fail ArgumentError, ":label not found: #{@label}" if MAKI.include?(@label) == false
|
27
|
+
end
|
28
|
+
|
29
|
+
def generate_overlay
|
30
|
+
oly = []
|
31
|
+
oly << "pin-#{@size}"
|
32
|
+
oly << "-#{@label}" unless @label.nil?
|
33
|
+
oly << "+#{@color}" unless @color.nil?
|
34
|
+
oly << "(#{@lat},#{@lon})"
|
35
|
+
oly.join
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Mapbox
|
2
|
+
module Overlay
|
3
|
+
# Path class
|
4
|
+
class Path < Base
|
5
|
+
def arguments_check
|
6
|
+
fail ArgumentError, ':polyline not found' if @polyline.nil?
|
7
|
+
end
|
8
|
+
|
9
|
+
def generate_overlay
|
10
|
+
oly = []
|
11
|
+
oly << 'path'
|
12
|
+
oly << "-#{@size}" unless @size.nil?
|
13
|
+
oly << "+#{@strokecolor}" unless @strokecolor.nil?
|
14
|
+
oly << "-#{@strokeopacity}" unless @strokeopacity.nil?
|
15
|
+
oly << "+#{@fillcolor}" unless @fillcolor.nil?
|
16
|
+
oly << "-#{@fillopacity}" unless @fillopacity.nil?
|
17
|
+
|
18
|
+
oly << "(#{@polyline})"
|
19
|
+
oly.join
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/mapbox-ruby.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'mapbox/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.add_dependency 'excon', '~> 0.45.3'
|
7
|
+
spec.add_dependency 'polylines', '~> 0.2.0'
|
8
|
+
spec.add_development_dependency 'bundler', '~> 1.0'
|
9
|
+
spec.add_development_dependency 'pry'
|
10
|
+
spec.authors = ['Claudio Fiorini']
|
11
|
+
spec.description = 'A Ruby interface to the Mapbox API.'
|
12
|
+
spec.email = %w(claudio.fiorini@gmail.com)
|
13
|
+
spec.files = %w(LICENSE.md README.md mapbox-ruby.gemspec) + Dir['lib/**/*.rb']
|
14
|
+
spec.homepage = 'https://github.com/cfiorini/mapbox-ruby'
|
15
|
+
spec.licenses = %w(MIT)
|
16
|
+
spec.name = 'mapbox-ruby'
|
17
|
+
spec.require_paths = %w(lib)
|
18
|
+
spec.required_ruby_version = '>= 2.1.0'
|
19
|
+
spec.required_rubygems_version = '>= 1.3.5'
|
20
|
+
spec.summary = spec.description
|
21
|
+
spec.version = Mapbox::VERSION
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mapbox-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Claudio Fiorini
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: excon
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.45.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.45.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: polylines
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.2.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.2.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: A Ruby interface to the Mapbox API.
|
70
|
+
email:
|
71
|
+
- claudio.fiorini@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- LICENSE.md
|
77
|
+
- README.md
|
78
|
+
- lib/mapbox.rb
|
79
|
+
- lib/mapbox/base.rb
|
80
|
+
- lib/mapbox/html.rb
|
81
|
+
- lib/mapbox/image.rb
|
82
|
+
- lib/mapbox/overlay.rb
|
83
|
+
- lib/mapbox/overlay/base.rb
|
84
|
+
- lib/mapbox/overlay/geo_json.rb
|
85
|
+
- lib/mapbox/overlay/marker.rb
|
86
|
+
- lib/mapbox/overlay/path.rb
|
87
|
+
- lib/mapbox/version.rb
|
88
|
+
- mapbox-ruby.gemspec
|
89
|
+
homepage: https://github.com/cfiorini/mapbox-ruby
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 2.1.0
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: 1.3.5
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.4.5
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: A Ruby interface to the Mapbox API.
|
113
|
+
test_files: []
|