simple-mappr 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/lib/simple-mappr.rb +378 -0
- data/lib/simple-mappr/constants.rb +80 -0
- data/lib/simple-mappr/exceptions.rb +3 -0
- data/lib/simple-mappr/transporter.rb +21 -0
- data/lib/simple-mappr/validator.rb +146 -0
- data/lib/simple-mappr/version.rb +7 -0
- metadata +136 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 16967f26e4668195844c0caf0f38ad08aa3684e3
|
4
|
+
data.tar.gz: 274d9f9d3176d9945d8065379cbb8a4ca78c0d12
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4f131d8b9cdd3521b3237a41e14bb970054068d62f9a388cc2dd1e6e183e845c3f4bf7552f0650d849c3a39878c2fb4e4fac0d1e7b5554ae82ec8a807e6d29bb
|
7
|
+
data.tar.gz: 305a60041b79e4269dfd60e69648316cf36c0edfc366dc78180ab0e1a1d00306fbf3bf824ea39847e41561cbd45efbebb3b000f78662317a223d03ab3a9b20af
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2016 David P. Shorthouse
|
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/lib/simple-mappr.rb
ADDED
@@ -0,0 +1,378 @@
|
|
1
|
+
require "simple-mappr/constants"
|
2
|
+
require "simple-mappr/exceptions"
|
3
|
+
require "simple-mappr/transporter"
|
4
|
+
require "simple-mappr/validator"
|
5
|
+
|
6
|
+
class SimpleMappr
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@parameters = {}
|
10
|
+
end
|
11
|
+
|
12
|
+
##
|
13
|
+
# View the built parameters
|
14
|
+
#
|
15
|
+
def params
|
16
|
+
@parameters
|
17
|
+
end
|
18
|
+
|
19
|
+
##
|
20
|
+
# Check if the RESTful API is alive and well
|
21
|
+
#
|
22
|
+
def alive?
|
23
|
+
response = Transporter.ping
|
24
|
+
response[:status] == "ok"
|
25
|
+
end
|
26
|
+
|
27
|
+
##
|
28
|
+
# Send the SimpleMappr object to the RESTful API
|
29
|
+
# and receive a Hash in return containing
|
30
|
+
# a URL to the image and its expected expiry
|
31
|
+
#
|
32
|
+
# == Example Output
|
33
|
+
#
|
34
|
+
# {
|
35
|
+
# imageURL: "http://img.simplemappr.local/579273e6_1dd1_2.png",
|
36
|
+
# expiry: "2016-07-22T21:28:38-04:00"
|
37
|
+
# }
|
38
|
+
#
|
39
|
+
def create
|
40
|
+
Transporter.send_data @parameters
|
41
|
+
end
|
42
|
+
|
43
|
+
##
|
44
|
+
# Set a bounding box in decimal degrees as minx,miny,maxx,maxy
|
45
|
+
#
|
46
|
+
# == Example
|
47
|
+
#
|
48
|
+
# instance.bbox = "-120,45,-100,52"
|
49
|
+
#
|
50
|
+
def bbox=(bbox)
|
51
|
+
Validator.validate_bbox(bbox)
|
52
|
+
@parameters[:bbox] = bbox
|
53
|
+
end
|
54
|
+
|
55
|
+
def bbox
|
56
|
+
@parameters[:bbox] || nil
|
57
|
+
end
|
58
|
+
|
59
|
+
##
|
60
|
+
# Set the colors in rgb corresponding to the points
|
61
|
+
#
|
62
|
+
# == Example
|
63
|
+
#
|
64
|
+
# instance.color = ["255,0,0","0,255,0"]
|
65
|
+
#
|
66
|
+
def color=(color)
|
67
|
+
Validator.validate_colors(color)
|
68
|
+
@parameters[:color] = color
|
69
|
+
end
|
70
|
+
|
71
|
+
def color
|
72
|
+
@parameters[:color] || nil
|
73
|
+
end
|
74
|
+
|
75
|
+
##
|
76
|
+
# Set a file path for a csv or tab-separated text file
|
77
|
+
#
|
78
|
+
# == Example
|
79
|
+
#
|
80
|
+
# instance.file = "/Users/SimpleMappr/demo.txt"
|
81
|
+
#
|
82
|
+
def file_path=(file_path)
|
83
|
+
Validator.validate_type(file_path, 'File')
|
84
|
+
@parameters[:file] = File.new(file_path, "r")
|
85
|
+
end
|
86
|
+
|
87
|
+
def file_path
|
88
|
+
@parameters[:file].path rescue nil
|
89
|
+
end
|
90
|
+
|
91
|
+
##
|
92
|
+
# Turn on or off the graticules (grid)
|
93
|
+
#
|
94
|
+
# == Example
|
95
|
+
#
|
96
|
+
# instance.graticules = true
|
97
|
+
#
|
98
|
+
def graticules=(graticules)
|
99
|
+
Validator.validate_type(graticules, 'Boolean')
|
100
|
+
@parameters[:graticules] = graticules
|
101
|
+
end
|
102
|
+
|
103
|
+
def graticules
|
104
|
+
@parameters[:graticules] || nil
|
105
|
+
end
|
106
|
+
|
107
|
+
##
|
108
|
+
# Specify the height of the image in pixels
|
109
|
+
# Maximum value is 4500
|
110
|
+
#
|
111
|
+
# == Example
|
112
|
+
#
|
113
|
+
# instance.height = 1_000
|
114
|
+
#
|
115
|
+
def height=(height)
|
116
|
+
Validator.validate_dimension(height)
|
117
|
+
@parameters[:height] = height
|
118
|
+
end
|
119
|
+
|
120
|
+
def height
|
121
|
+
@parameters[:height] || nil
|
122
|
+
end
|
123
|
+
|
124
|
+
##
|
125
|
+
# Specify the layers to include in the image
|
126
|
+
# Expressed as a comma-separated String without spaces
|
127
|
+
# See SimpleMappr.layers
|
128
|
+
#
|
129
|
+
# == Example
|
130
|
+
#
|
131
|
+
# instance.layers = 'oceans,lakes,rivers'
|
132
|
+
#
|
133
|
+
def layers=(layers)
|
134
|
+
Validator.validate_layers(layers)
|
135
|
+
@parameters[:layers] = layers
|
136
|
+
end
|
137
|
+
|
138
|
+
def layers
|
139
|
+
@parameters[:layers] || nil
|
140
|
+
end
|
141
|
+
|
142
|
+
##
|
143
|
+
# Specify the legend title(s)
|
144
|
+
# Expressed as an array of Strings corresponding to the points
|
145
|
+
#
|
146
|
+
# == Example
|
147
|
+
#
|
148
|
+
# instance.layers = ['My First Legend','My Second Legend']
|
149
|
+
#
|
150
|
+
def legend=(legend)
|
151
|
+
Validator.validate_type(legend, 'Array')
|
152
|
+
@parameters[:legend] = legend
|
153
|
+
end
|
154
|
+
|
155
|
+
def legend
|
156
|
+
@parameters[:legend] || nil
|
157
|
+
end
|
158
|
+
|
159
|
+
##
|
160
|
+
# Specify the origin of natural longitude
|
161
|
+
#
|
162
|
+
# == Example
|
163
|
+
#
|
164
|
+
# instance.origin = -100
|
165
|
+
#
|
166
|
+
def origin=(origin)
|
167
|
+
Validator.validate_origin(origin)
|
168
|
+
@parameters[:origin] = origin
|
169
|
+
end
|
170
|
+
|
171
|
+
def origin
|
172
|
+
@parameters[:origin] || nil
|
173
|
+
end
|
174
|
+
|
175
|
+
##
|
176
|
+
# Specify the color in rgb for the outline around all points
|
177
|
+
#
|
178
|
+
# == Example
|
179
|
+
#
|
180
|
+
# instance.outlinecolor = "10,10,10"
|
181
|
+
#
|
182
|
+
def outlinecolor=(outlinecolor)
|
183
|
+
Validator.validate_color(outlinecolor)
|
184
|
+
@parameters[:outlinecolor] = outlinecolor
|
185
|
+
end
|
186
|
+
|
187
|
+
def outlinecolor
|
188
|
+
@parameters[:outlinecolor] || nil
|
189
|
+
end
|
190
|
+
|
191
|
+
##
|
192
|
+
# Specify the output file format
|
193
|
+
# Options are svg, png, or jpg
|
194
|
+
#
|
195
|
+
# == Example
|
196
|
+
#
|
197
|
+
# instance.output = "png"
|
198
|
+
#
|
199
|
+
def output=(output)
|
200
|
+
Validator.validate_output(output)
|
201
|
+
@parameters[:output] = output
|
202
|
+
end
|
203
|
+
|
204
|
+
def output
|
205
|
+
@parameters[:output] || nil
|
206
|
+
end
|
207
|
+
|
208
|
+
##
|
209
|
+
# An array of geographic coordinates, each as latitude,longitude
|
210
|
+
# Group coordinates in array elements, each of which can also be
|
211
|
+
# separated by linebreaks, \n
|
212
|
+
#
|
213
|
+
# == Example
|
214
|
+
#
|
215
|
+
# instance.points = ["45,-120\n45.4,-110","52,-120"]
|
216
|
+
#
|
217
|
+
def points=(points)
|
218
|
+
Validator.validate_points(points)
|
219
|
+
@parameters[:points] = points
|
220
|
+
end
|
221
|
+
|
222
|
+
def points
|
223
|
+
@parameters[:points] || nil
|
224
|
+
end
|
225
|
+
|
226
|
+
##
|
227
|
+
# Specify the projection
|
228
|
+
# See simple-mappr/constants.rb
|
229
|
+
#
|
230
|
+
# == Example
|
231
|
+
#
|
232
|
+
# instance.projection = "epsg:4326"
|
233
|
+
#
|
234
|
+
def projection=(projection)
|
235
|
+
Validator.validate_projection(projection)
|
236
|
+
@parameters[:projection] = projection
|
237
|
+
end
|
238
|
+
|
239
|
+
def projection
|
240
|
+
@parameters[:projection] || nil
|
241
|
+
end
|
242
|
+
|
243
|
+
##
|
244
|
+
# Include an embedded scalebar
|
245
|
+
#
|
246
|
+
# == Example
|
247
|
+
#
|
248
|
+
# instance.scalebar = true
|
249
|
+
#
|
250
|
+
def scalebar=(scalebar)
|
251
|
+
Validator.validate_type(scalebar, 'Boolean')
|
252
|
+
@parameters[:scalebar] = scalebar
|
253
|
+
end
|
254
|
+
|
255
|
+
def scalebar
|
256
|
+
@parameters[:scalebar] || nil
|
257
|
+
end
|
258
|
+
|
259
|
+
##
|
260
|
+
# Include shaded regions as a Hash
|
261
|
+
# Specify color, title, and places as keys
|
262
|
+
#
|
263
|
+
# == Example
|
264
|
+
#
|
265
|
+
# instance.shade = { color: "200,200,200", title: "My Regions", places: "Canada,US[WY|WA]"}
|
266
|
+
#
|
267
|
+
def shade=(shade)
|
268
|
+
Validator.validate_shade(shade)
|
269
|
+
@parameters[:shade] = shade
|
270
|
+
end
|
271
|
+
|
272
|
+
def shade
|
273
|
+
@parameters[:shade] || nil
|
274
|
+
end
|
275
|
+
|
276
|
+
##
|
277
|
+
# Describe the shape to use corresponding to the points
|
278
|
+
# See simple-mappr/constants.rb
|
279
|
+
#
|
280
|
+
# == Example
|
281
|
+
#
|
282
|
+
# instance.shape = ['circle','square']
|
283
|
+
#
|
284
|
+
def shape=(shape)
|
285
|
+
Validator.validate_shapes(shape)
|
286
|
+
@parameters[:shape] = shape
|
287
|
+
end
|
288
|
+
|
289
|
+
def shape
|
290
|
+
@parameters[:shape] || nil
|
291
|
+
end
|
292
|
+
|
293
|
+
##
|
294
|
+
# Specify the size of the corresponding points
|
295
|
+
# Options are Integer less than or equal to 14
|
296
|
+
#
|
297
|
+
# == Example
|
298
|
+
#
|
299
|
+
# instance.size = [8,14]
|
300
|
+
#
|
301
|
+
def size=(size)
|
302
|
+
Validator.validate_sizes(size)
|
303
|
+
@parameters[:size] = size
|
304
|
+
end
|
305
|
+
|
306
|
+
def size
|
307
|
+
@parameters[:size] || nil
|
308
|
+
end
|
309
|
+
|
310
|
+
##
|
311
|
+
# Specify the spacing between graticule (grid) lines in degrees
|
312
|
+
# Must be an Integer less than or equal to 10
|
313
|
+
#
|
314
|
+
# == Example
|
315
|
+
#
|
316
|
+
# instance.spacing = 5
|
317
|
+
#
|
318
|
+
def spacing=(spacing)
|
319
|
+
Validator.validate_spacing(spacing)
|
320
|
+
@parameters[:spacing] = spacing
|
321
|
+
end
|
322
|
+
|
323
|
+
def spacing
|
324
|
+
@parameters[:spacing] || nil
|
325
|
+
end
|
326
|
+
|
327
|
+
##
|
328
|
+
# Specify a remote URL
|
329
|
+
# Source must be a csv, a tab-delimited file, or a GeoRSS
|
330
|
+
#
|
331
|
+
# == Example
|
332
|
+
#
|
333
|
+
# instance.url = "http://www.simplemappr.net/public/files/demo.csv"
|
334
|
+
#
|
335
|
+
def url=(url)
|
336
|
+
Validator.validate_url(url)
|
337
|
+
@parameters[:url] = url
|
338
|
+
end
|
339
|
+
|
340
|
+
def url
|
341
|
+
@parameters[:url] || nil
|
342
|
+
end
|
343
|
+
|
344
|
+
##
|
345
|
+
# Specify the width of the output in pixels
|
346
|
+
# Must be less than or eqaual to 4500
|
347
|
+
#
|
348
|
+
# == Example
|
349
|
+
#
|
350
|
+
# instance.width = 1_000
|
351
|
+
#
|
352
|
+
def width=(width)
|
353
|
+
Validator.validate_dimension(width)
|
354
|
+
@parameters[:width] = width
|
355
|
+
end
|
356
|
+
|
357
|
+
def width
|
358
|
+
@parameters[:width] || nil
|
359
|
+
end
|
360
|
+
|
361
|
+
##
|
362
|
+
# Specify a zoom level, centred on the geographic center of all points
|
363
|
+
# Must be less than or eqaual to 10
|
364
|
+
#
|
365
|
+
# == Example
|
366
|
+
#
|
367
|
+
# instance.zoom = 3
|
368
|
+
#
|
369
|
+
def zoom=(zoom)
|
370
|
+
Validator.validate_zoom(zoom)
|
371
|
+
@parameters[:zoom] = zoom
|
372
|
+
end
|
373
|
+
|
374
|
+
def zoom
|
375
|
+
@parameters[:zoom] || nil
|
376
|
+
end
|
377
|
+
|
378
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
class SimpleMappr
|
2
|
+
|
3
|
+
API_URL = "http://www.simplemappr.net/api/"
|
4
|
+
|
5
|
+
PROJECTIONS = [
|
6
|
+
'epsg:4326',
|
7
|
+
'esri:102009',
|
8
|
+
'esri:102015',
|
9
|
+
'esri:102014',
|
10
|
+
'esri:102012',
|
11
|
+
'esri:102024',
|
12
|
+
'epsg:3112',
|
13
|
+
'epsg:102017',
|
14
|
+
'epsg:102019'
|
15
|
+
]
|
16
|
+
|
17
|
+
SHAPES = [
|
18
|
+
'plus',
|
19
|
+
'cross',
|
20
|
+
'asterisk',
|
21
|
+
'circle',
|
22
|
+
'square',
|
23
|
+
'triangle',
|
24
|
+
'inversetriangle',
|
25
|
+
'star',
|
26
|
+
'hexagon',
|
27
|
+
'opencircle',
|
28
|
+
'opensquare',
|
29
|
+
'opentriangle',
|
30
|
+
'inverseopentriangle',
|
31
|
+
'openstar',
|
32
|
+
'openhexagon'
|
33
|
+
]
|
34
|
+
|
35
|
+
LAYERS = [
|
36
|
+
'countries',
|
37
|
+
'countrynames',
|
38
|
+
'relief',
|
39
|
+
'reliefgrey',
|
40
|
+
'stateprovinces',
|
41
|
+
'stateprovnames',
|
42
|
+
'lakes',
|
43
|
+
'lakesOutline',
|
44
|
+
'lakenames',
|
45
|
+
'rivers',
|
46
|
+
'rivernames',
|
47
|
+
'oceans',
|
48
|
+
'marineLabels',
|
49
|
+
'placenames',
|
50
|
+
'physicalLabels',
|
51
|
+
'ecoregions',
|
52
|
+
'ecoregionLabels',
|
53
|
+
'conservation',
|
54
|
+
'hotspotLabels',
|
55
|
+
'blueMarble'
|
56
|
+
]
|
57
|
+
|
58
|
+
OUTPUTS = ['svg', 'png', 'jpg']
|
59
|
+
|
60
|
+
def self.api_url
|
61
|
+
API_URL
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.shapes
|
65
|
+
SHAPES
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.projections
|
69
|
+
PROJECTIONS
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.layers
|
73
|
+
LAYERS
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.outputs
|
77
|
+
OUTPUTS
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "rest_client"
|
2
|
+
require "json"
|
3
|
+
require "simple-mappr/validator"
|
4
|
+
|
5
|
+
class SimpleMappr
|
6
|
+
class Transporter
|
7
|
+
|
8
|
+
def self.send_data params
|
9
|
+
Validator.validate_type(params, 'Hash')
|
10
|
+
params.delete_if{ |k,v| !v }
|
11
|
+
RestClient.post(API_URL, params) do |response, request, result, &block|
|
12
|
+
JSON.parse(response.body, :symbolize_names => true)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.ping
|
17
|
+
send_data({ ping: true })
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
require "uri"
|
2
|
+
|
3
|
+
class SimpleMappr
|
4
|
+
class Validator
|
5
|
+
|
6
|
+
def self.validate_bbox(data)
|
7
|
+
validate_type(data, 'String')
|
8
|
+
coords = data.split(",")
|
9
|
+
if coords.length != 4
|
10
|
+
raise InvalidParameterValue, "bbox must have four parameters in the form -110,45,-100,52"
|
11
|
+
end
|
12
|
+
validate_coordinate(coords[1].to_f, coords[0].to_f)
|
13
|
+
validate_coordinate(coords[3].to_f, coords[2].to_f)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.validate_coordinate(latitude, longitude)
|
17
|
+
if latitude > 90 || latitude < -90 || longitude > 180 || longitude < -180
|
18
|
+
raise InvalidParameterValue, "Coordinate latitude,longitude=#{latitude},#{longitude} is not valid"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.validate_colors(data)
|
23
|
+
validate_type(data, 'Array')
|
24
|
+
data.each { |item| validate_color(item) }
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.validate_color(data)
|
28
|
+
validate_type(data, 'String')
|
29
|
+
rgb = data.split(",")
|
30
|
+
if rgb.length != 3
|
31
|
+
raise InvalidParameterValue, "color must have three parameters in the form 0,0,0"
|
32
|
+
end
|
33
|
+
rgb.each do |item|
|
34
|
+
begin
|
35
|
+
Integer(item || '')
|
36
|
+
rescue ArgumentError
|
37
|
+
raise InvalidParameterValue, "color value must be an integer <= 255"
|
38
|
+
end
|
39
|
+
if item.to_i > 255
|
40
|
+
raise InvalidParameterValue, "color value must be an integer <= 255"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.validate_dimension(data)
|
46
|
+
validate_type(data, 'Integer')
|
47
|
+
if data > 4_500
|
48
|
+
raise InvalidParameterValue, "Accepted integer values are <= 4500"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.validate_points(data)
|
53
|
+
validate_type(data, 'Array')
|
54
|
+
data.each { |item| validate_type(item, 'String') }
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.validate_shapes(data)
|
58
|
+
validate_type(data, 'Array')
|
59
|
+
data.each do |item|
|
60
|
+
if !SHAPES.include?(item)
|
61
|
+
raise InvalidParameterValue, "Values must each be one of #{SHAPES.join(", ")}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.validate_sizes(data)
|
67
|
+
validate_type(data, 'Array')
|
68
|
+
data.each do |item|
|
69
|
+
validate_type(item, 'Integer')
|
70
|
+
if item > 14
|
71
|
+
raise InvalidParameterValue, "Values must each be integers less than 14"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.validate_url(data)
|
77
|
+
validate_type(data, 'String')
|
78
|
+
if data !~ /\A#{URI::regexp(['http', 'https'])}\z/
|
79
|
+
raise InvalidParameterValue, "URL must be in the form http:// or https://"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.validate_zoom(data)
|
84
|
+
validate_type(data, 'Integer')
|
85
|
+
if data > 10
|
86
|
+
raise InvalidParameterValue, "Accepted integer value is <= 10"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.validate_shade(data)
|
91
|
+
validate_type(data, 'Hash')
|
92
|
+
data = data.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
93
|
+
if !(data.keys - [:places, :title, :color]).empty?
|
94
|
+
raise InvalidParameterValue, "Shade must be Hash in the form { places: \"\", title: \"\", color: \"\" }"
|
95
|
+
end
|
96
|
+
if data.key?(:color)
|
97
|
+
validate_color(data[:color])
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.validate_layers(data)
|
102
|
+
validate_type(data, 'String')
|
103
|
+
if !(data.split(",") - LAYERS).empty?
|
104
|
+
raise InvalidParameterValue, "Accepted layers are combinations of #{LAYERS.join(", ")}"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def self.validate_projection(data)
|
109
|
+
if !PROJECTIONS.include?(data)
|
110
|
+
raise InvalidParameterValue, "Accepted projection values are #{PROJECTIONS.join(", ")}"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def self.validate_origin(data)
|
115
|
+
validate_type(data, 'Integer')
|
116
|
+
if data > 180 || data < -180
|
117
|
+
raise InvalidParameterValue, "Accepted integer values are -180 <= x <= 180"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def self.validate_spacing(data)
|
122
|
+
validate_type(data, 'Integer')
|
123
|
+
if data > 10
|
124
|
+
raise InvalidParameterValue, "Accepted integer values are <= 10"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def self.validate_output(data)
|
129
|
+
if !OUTPUTS.include?(data)
|
130
|
+
raise InvalidParameterValue, "Accepted outputs are #{OUTPUTS.join(", ")}"
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def self.validate_type(data, type)
|
135
|
+
case type
|
136
|
+
when 'String', 'Array', 'Integer', 'Hash'
|
137
|
+
raise InvalidParameterValue, "Must be a #{type}" unless data.is_a?(Object.const_get(type))
|
138
|
+
when 'Boolean'
|
139
|
+
raise InvalidParameterValue, "Must be a Boolean" unless [true, false].include?(data)
|
140
|
+
when 'File'
|
141
|
+
raise InvalidParameterValue, "Must be a file path & file must exist" unless File.file?(data)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
end
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple-mappr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David P. Shorthouse
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '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: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '11.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '11.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.4'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.4'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.10'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.10'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: byebug
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '8.2'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '8.2'
|
97
|
+
description: A gem to access the SimpleMappr API
|
98
|
+
email: 'davidpshorthouse@gmail.com '
|
99
|
+
executables: []
|
100
|
+
extensions: []
|
101
|
+
extra_rdoc_files: []
|
102
|
+
files:
|
103
|
+
- MIT-LICENSE
|
104
|
+
- lib/simple-mappr.rb
|
105
|
+
- lib/simple-mappr/constants.rb
|
106
|
+
- lib/simple-mappr/exceptions.rb
|
107
|
+
- lib/simple-mappr/transporter.rb
|
108
|
+
- lib/simple-mappr/validator.rb
|
109
|
+
- lib/simple-mappr/version.rb
|
110
|
+
homepage: https://github.com/dshorthouse/simple-mappr
|
111
|
+
licenses:
|
112
|
+
- MIT
|
113
|
+
metadata: {}
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options:
|
116
|
+
- "--encoding"
|
117
|
+
- UTF-8
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 2.3.0
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
requirements: []
|
131
|
+
rubyforge_project:
|
132
|
+
rubygems_version: 2.5.1
|
133
|
+
signing_key:
|
134
|
+
specification_version: 4
|
135
|
+
summary: A gem to access the SimpleMappr API
|
136
|
+
test_files: []
|