GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 71f83d...bc7c18 )
by Juan Jose
06:10
created

Base.optimized_callback_url()   A

Complexity

Conditions 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 3.6875

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 0
loc 12
rs 9.4285
ccs 1
cts 4
cp 0.25
crap 3.6875
1
# codebeat:disable[TOTAL_LOC, TOO_MANY_FUNCTIONS, TOTAL_COMPLEXITY]
2 1
import re
3
4 1
from .constants import (
5
    TRAVEL_MODE,
6
    OPTIMIZE, DEVICE_TYPE,
7
    DISTANCE_UNIT,
8
    ROUTE_PATH_OUTPUT,
9
    TRUCK_HAZARDOUS_GOODS,
10
    FORMAT,
11
)
12 1
from .exceptions import ParamValueException
13
14
15 1
class Base(object):
16
    """
17
    Base Class, with common methods.
18
    """
19
20 1
    def __init__(self, api):
21
        """
22
        Base instance
23
        :param api:
24
        :return:
25
        """
26 1
        self.response = None
27 1
        self.api = api
28 1
        self.data = {'parameters': {},
29
                     'addresses': {},
30
                     }
31 1
        self.params = {'api_key': api.key, }
32
33 1
    @staticmethod
34
    def check_string_type(obj):
35
        """
36
        Check if an object is string type
37
        :param obj:
38
        :return:
39
        """
40 1
        try:
41 1
            return isinstance(obj, basestring)
42 1
        except NameError:
43 1
            return isinstance(obj, str)
44
45 1
    def format(self, set_format):
46
        """
47
        Add format to params.
48
        :param set_format:
49
        :return:
50
        :raise: ParamValueException if set_format is not in FORMAT
51
        """
52
        if set_format in FORMAT.reverse_mapping.keys():
53
            self._copy_param({'format': set_format})
54
        else:
55
            raise ParamValueException('format', 'Must be CSV, SERIALIZED, XML')
56
57 1
    def member_id(self, member_id, target='data'):
58
        """
59
        Set member_id in params or data
60
        :param member_id:
61
        :param target:
62
        :return:
63
        :raise: ParamValueException if member_id is not Integer
64
        """
65
        if isinstance(member_id, int):
66
            getattr(self, '_copy_%s' % target)({'member_id': member_id})
67
        else:
68
            raise ParamValueException('member_id', 'Must be integer')
69
70 1
    def route_id(self, route_id):
71
        """
72
        Set route_id in params or data
73
        :param route_id:
74
        :return:
75
        :raise: ParamValueException if route_id is not String
76
        """
77 1
        if self.check_string_type(route_id):
78 1
            self._copy_param({'route_id': route_id})
79
        else:
80
            raise ParamValueException('route_id', 'Must be String')
81
82 1
    def address_1(self, address_1):
83
        """
84
        Set address_1 in params or data
85
        :param address_1:
86
        :return:
87
        :raise: ParamValueException if address_1 is not String
88
        """
89
        if self.check_string_type(address_1):
90
            self._copy_param({'address_1': address_1})
91
        else:
92
            raise ParamValueException('address_1', 'Must be String')
93
94 1
    def tx_id(self, tx_id):
95
        """
96
        Set tx_id param
97
        :param tx_id:
98
        :return:
99
        """
100
        if self.check_string_type(tx_id):
101
            self._copy_param({'tx_id': tx_id})
102
        else:
103
            raise ParamValueException('tx_id', 'Must be String')
104
105 1
    def vehicle_id(self, vehicle_id):
106
        """
107
        Set vehicle_id param
108
        :param vehicle_id:
109
        :return:
110
        """
111
        if isinstance(vehicle_id, int):
112
            self._copy_data({'vehicle_id': vehicle_id})
113
        else:
114
            raise ParamValueException('vehicle_id', 'Must be integer')
115
116 1
    def course(self, course):
117
        """
118
        Set course param
119
        :param course:
120
        :return:
121
        """
122
        if isinstance(course, int):
123
            self._copy_param({'course': course})
124
        else:
125
            raise ParamValueException('course', 'Must be integer')
126
127 1
    def speed(self, speed):
128
        """
129
        Set speed param
130
        :param speed:
131
        :return:
132
        """
133
        if isinstance(speed, int):
134
            self._copy_param({'speed': speed})
135
        else:
136
            raise ParamValueException('speed', 'Must be Float')
137
138 1
    def lat(self, lat):
139
        """
140
        Set lat param
141
        :param lat:
142
        :return:
143
        """
144
        if isinstance(lat, float):
145
            self._copy_param({'lat': lat})
146
        else:
147
            raise ParamValueException('lat', 'Must be Float')
148
149 1
    def lng(self, lng):
150
        """
151
        Set lng param
152
        :param lng:
153
        :return:
154
        """
155
        if isinstance(lng, float):
156
            self._copy_param({'lng': lng})
157
        else:
158
            raise ParamValueException('lng', 'Must be Float')
159
160 1
    def cached_lat(self, lat):
161
        """
162
        Set lat param
163
        :param lat:
164
        :return:
165
        """
166
        if isinstance(lat, float):
167
            self._copy_param({'lat': lat})
168
        else:
169
            raise ParamValueException('lat', 'Must be Float')
170
171 1
    def cached_lng(self, lng):
172
        """
173
        Set lng param
174
        :param lng:
175
        :return:
176
        """
177
        if isinstance(lng, float):
178
            self._copy_param({'lng': lng})
179
        else:
180
            raise ParamValueException('lng', 'Must be Float')
181
182 1
    def altitude(self, altitude):
183
        """
184
        Set altitude param
185
        :param altitude:
186
        :return:
187
        """
188
        if isinstance(altitude, float):
189
            self._copy_param({'altitude': altitude})
190
        else:
191
            raise ParamValueException('altitude', 'Must be Float')
192
193 1
    def device_guid(self, device_guid):
194
        """
195
        Set device_guid param
196
        :param device_guid:
197
        :return:
198
        """
199
        if self.check_string_type(device_guid):
200
            self._copy_param({'device_guid': device_guid})
201
        else:
202
            raise ParamValueException('device_guid', 'Must be String')
203
204 1
    def app_version(self, app_version):
205
        """
206
        Set app_version param
207
        :param app_version:
208
        :return:
209
        """
210
        if self.check_string_type(app_version):
211
            self._copy_param({'app_version': app_version})
212
        else:
213
            raise ParamValueException('app_version', 'Must be String')
214
215 1
    def device_timestamp(self, device_timestamp):
216
        """
217
        Set device_timestamp param. Must be a vale date time
218
        with this format:  YYYY-MM-DD HH:MM:SS
219
        :param device_timestamp:
220
        :return:
221
        """
222 1
        pattern = '^(\d{4})-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01]) ' \
223
                  '([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$'
224 1
        if re.match(pattern, device_timestamp):
225
            self._copy_param({'device_timestamp': device_timestamp})
226
        else:
227 1
            raise ParamValueException('device_timestamp',
228
                                      'Must be YYYY-MM-DD HH:MM:SS format')
229
230 1
    def algorithm_type(self, algorithm_type):
231
        """
232
        Set algorithm_type. Choices are:
233
        TSP, VRP, CVRP_TW_SD
234
        CVRP_TW_MD, TSP_TW,
235
        TSP_TW_CR and BBCVRP
236
        :param: algorithm_type:
237
        :return:
238
        """
239 1
        VALID = [1, 2, 3, 4, 5, 6, 7, 100, 101, ]
240 1
        if algorithm_type in VALID:
241 1
            self._copy_data({'algorithm_type': algorithm_type})
242
        else:
243
            raise ParamValueException('algorithm_type',
244
                                      'Must be ALGORITHM_TYPE: '
245
                                      'TSP(1), VRP(2), CVRP_TW_SD(3), '
246
                                      'CVRP_TW_MD(4), TSP_TW(5), '
247
                                      'TSP_TW_CR(6), BBCVRP(7), '
248
                                      'NO OPTIMIZATION(100) or '
249
                                      'LEGACY_DISTRIBUTED(101)')
250
251 1
    def route_name(self, route_name):
252
        """
253
        Set route_name param
254
        :param route_name:
255
        :return:
256
        """
257 1
        if self.check_string_type(route_name):
258 1
            self._copy_data({'route_name': route_name})
259
        else:
260 1
            raise ParamValueException('route_name', 'Must be String')
261
262 1
    def optimization_problem_id(self, optimization_problem_id):
263
        """
264
        Set optimization_problem_id param
265
        :param optimization_problem_id:
266
        :return:
267
        """
268
        if self.check_string_type(optimization_problem_id):
269
            self._copy_param({'optimization_problem_id':
270
                              optimization_problem_id})
271
        else:
272
            raise ParamValueException('optimization_problem_id',
273
                                      'Must be String')
274
275 1
    def optimized_callback_url(self, optimized_callback_url):
276
        """
277
        Set optimized_callback_url param
278
        :param optimized_callback_url:
279
        :return:
280
        """
281
        if self.check_string_type(optimized_callback_url):
282
            self._copy_param({'optimized_callback_url':
283
                                  optimized_callback_url})
284
        else:
285
            raise ParamValueException('optimized_callback_url',
286
                                      'Must be String')
287
288 1
    def remote_ip(self, remote_ip):
289
        """
290
        Set remote_ip param
291
        :param remote_ip:
292
        :return:
293
        """
294
        if isinstance(remote_ip, int):
295
            self._copy_data({'remote_ip': remote_ip})
296
        else:
297
            raise ParamValueException('remote_ip', 'Must be integer')
298
299 1
    def travel_mode(self, travel_mode):
300
        """
301
        Set travel_mode. Options are:
302
        DRIVING, WALKING, TRUCKING
303
        :param travel_mode:
304
        :return:
305
        """
306 1
        if travel_mode in TRAVEL_MODE.reverse_mapping.keys():
307 1
            self._copy_data({'travel_mode': travel_mode})
308
        else:
309
            raise ParamValueException('travel_mode', 'Must be DRIVING, '
310
                                                     'WALKING, TRUCKING')
311
312 1
    def optimize(self, optimize):
313
        """
314
        Set optimize param
315
        :param optimize:
316
        :return:
317
        """
318 1
        if optimize in OPTIMIZE.reverse_mapping.keys():
319 1
            self._copy_data({'optimize': optimize})
320
        else:
321
            raise ParamValueException('optimize', 'Must be DISTANCE, TIME, '
322
                                                  'TIME_WITH_TRAFFIC')
323
324 1
    def distance_unit(self, distance_unit):
325
        """
326
        Set distance_unit param
327
        :param distance_unit:
328
        :return:
329
        """
330 1
        if distance_unit in DISTANCE_UNIT.reverse_mapping.keys():
331 1
            self._copy_data({'distance_unit': distance_unit})
332
        else:
333
            raise ParamValueException('distance_unit', 'Must be MI or KM')
334
335 1
    def device_type(self, device_type, target='data'):
336
        """
337
        Set device_type. Options are: WEB, IPHONE, IPAD, ANDROID_PHONE,
338
        ANDROID_TABLET
339
        :param device_type:
340
        :param target:
341
        :return:
342
        """
343 1
        if device_type in DEVICE_TYPE.reverse_mapping.keys():
344 1
            getattr(self, '_copy_%s' % target)({'device_type': device_type})
345
        else:
346
            raise ParamValueException('device_type', 'Must be WEB, IPHONE, '
347
                                                     'IPAD, ANDROID_PHONE, '
348
                                                     'ANDROID_TABLET')
349
350 1
    def route_path_output(self, route_path_output):
351
        """
352
        Set device_type. Options are: WEB, IPHONE, IPAD, ANDROID_PHONE,
353
        ANDROID_TABLET
354
        :param route_path_output:
355
        :param target:
356
        :return:
357
        """
358
        if route_path_output in ROUTE_PATH_OUTPUT.reverse_mapping.keys():
359
            self._copy_param({'route_path_output': route_path_output})
360
        else:
361
            raise ParamValueException('route_path_output', 'Must be NONE or '
362
                                                           'POINTS')
363
364 1
    def route_time(self, route_time):
365
        """
366
        Set route_time param
367
        :param route_time:
368
        :return:
369
        """
370 1
        if isinstance(route_time, int):
371 1
            self._copy_data({'route_time': route_time})
372
        else:
373
            raise ParamValueException('route_time', 'Must be integer')
374
375 1
    def trailer_weight_t(self, trailer_weight_t):
376
        """
377
        Set trailer_weight_t param
378
        :param trailer_weight_t:
379
        :return:
380
        """
381
        if isinstance(trailer_weight_t, int):
382
            self._copy_data({'trailer_weight_t': trailer_weight_t})
383
        else:
384
            raise ParamValueException('trailer_weight_t',
385
                                      'Must be integer')
386
387 1
    def limited_weight_t(self, limited_weight_t):
388
        """
389
        Set limited_weight_t param
390
        :param limited_weight_t:
391
        :return:
392
        """
393
        if isinstance(limited_weight_t, float) or \
394
           isinstance(limited_weight_t, int):
395
            self._copy_data({'limited_weight_t': limited_weight_t})
396
        else:
397
            raise ParamValueException('limited_weight_t',
398
                                      'Must be integer')
399
400 1
    def weight_per_axle_t(self, weight_per_axle_t):
401
        """
402
        Set weight_per_axle_t param
403
        :param weight_per_axle_t:
404
        :return:
405
        """
406
        if isinstance(weight_per_axle_t, float) or \
407
           isinstance(weight_per_axle_t, int):
408
            self._copy_data({'weight_per_axle_t': weight_per_axle_t})
409
        else:
410
            raise ParamValueException('weight_per_axle_t',
411
                                      'Must be integer')
412
413 1
    def truck_height(self, truck_height):
414
        """
415
        Set truck_height param
416
        :param truck_height:
417
        :return:
418
        """
419
        if isinstance(truck_height, float) or \
420
           isinstance(truck_height, int):
421
            self._copy_data({'truck_height': truck_height})
422
        else:
423
            raise ParamValueException('truck_height', 'Must be integer')
424
425 1
    def truck_width(self, truck_width):
426
        """
427
        Set truck_width param
428
        :param truck_width:
429
        :return:
430
        """
431
        if isinstance(truck_width, float) or \
432
           isinstance(truck_width, int):
433
            self._copy_data({'truck_width': truck_width})
434
        else:
435
            raise ParamValueException('truck_width', 'Must be integer')
436
437 1
    def truck_length(self, truck_length):
438
        """
439
        Set truck_length param
440
        :param truck_length:
441
        :return:
442
        """
443
        if isinstance(truck_length, float) or \
444
           isinstance(truck_length, int):
445
            self._copy_data({'truck_length': truck_length})
446
        else:
447
            raise ParamValueException('truck_length', 'Must be integer')
448
449 1
    def min_tour_size(self, min_tour_size):
450
        """
451
        Set min_tour_size param
452
        :param min_tour_size:
453
        :return:
454
        """
455
        if isinstance(min_tour_size, int):
456
            self._copy_data({'min_tour_size': min_tour_size})
457
        else:
458
            raise ParamValueException('min_tour_size',
459
                                      'Must be integer')
460
461 1
    def route_date(self, route_date):
462
        """
463
        Set route_date param
464
        :param route_date:
465
        :return:
466
        """
467
        if isinstance(route_date, int):
468
            self._copy_data({'route_date': route_date})
469
        else:
470
            raise ParamValueException('route_date', 'Must be integer')
471
472 1
    def route_max_duration(self, route_max_duration):
473
        """
474
        Set route_max_duration param
475
        :param route_max_duration:
476
        :return:
477
        """
478 1
        if isinstance(route_max_duration, int):
479 1
            self._copy_data({'route_max_duration': route_max_duration})
480
        else:
481
            raise ParamValueException('route_max_duration',
482
                                      'Must be integer')
483
484 1
    def vehicle_capacity(self, vehicle_capacity):
485
        """
486
        Set vehicle_capacity param
487
        :param vehicle_capacity:
488
        :return:
489
        """
490 1
        if isinstance(vehicle_capacity, int):
491 1
            self._copy_data({'vehicle_capacity': vehicle_capacity})
492
        else:
493
            raise ParamValueException('vehicle_capacity',
494
                                      'Must be integer')
495
496 1
    def parts(self, parts):
497
        """
498
        Set parts param
499
        :param parts:
500
        :return:
501
        """
502
        if isinstance(parts, int):
503
            self._copy_data({'parts': parts})
504
        else:
505
            raise ParamValueException('parts',
506
                                      'Must be integer')
507
508 1
    def limit(self, limit):
509
        """
510
        Set limit param
511
        :param limit:
512
        :return:
513
        """
514
        if isinstance(limit, int):
515
            self._copy_param({'limit': limit})
516
        else:
517
            raise ParamValueException('limit',
518
                                      'Must be integer')
519
520 1
    def offset(self, offset):
521
        """
522
        Set offset param
523
        :param offset:
524
        :return:
525
        """
526
        if isinstance(offset, int):
527
            self._copy_param({'offset': offset})
528
        else:
529
            raise ParamValueException('offset',
530
                                      'Must be integer')
531
532 1
    def vehicle_max_distance_mi(self, vehicle_max_distance_mi):
533
        """
534
        Set vehicle_max_distance_mi
535
        :param vehicle_max_distance_mi:
536
        :return:
537
        """
538 1
        if isinstance(vehicle_max_distance_mi, int):
539 1
            self._copy_data({'vehicle_max_distance_mi':
540
                             vehicle_max_distance_mi})
541
        else:
542
            raise ParamValueException('vehicle_max_distance_mi',
543
                                      'Must be integer')
544
545 1
    def max_tour_size(self, max_tour_size):
546
        """
547
        Set max_tour_size
548
        :param max_tour_size:
549
        :return:
550
        """
551
        if isinstance(max_tour_size, int):
552
            self._copy_data({'max_tour_size':
553
                             max_tour_size})
554
        else:
555
            raise ParamValueException('max_tour_size',
556
                                      'Must be integer')
557
558 1
    def route_email(self, route_email):
559
        """
560
        Set route_email param
561
        :param route_email:
562
        :return:
563
        """
564
        if self.check_string_type(route_email):
565
            self._copy_data({'route_email': route_email})
566
        else:
567
            raise ParamValueException('route_email', 'Must be String')
568
569 1
    def metric(self, metric):
570
        """
571
        Set metric Param. Must be:
572
        ROUTE4ME_METRIC_EUCLIDEA
573
        ROUTE4ME_METRIC_MANHATTA
574
        ROUTE4ME_METRIC_GEODESIC
575
        ROUTE4ME_METRIC_MATRIX
576
        ROUTE4ME_METRIC_EXACT_2D
577
        :param metric:
578
        :return:
579
        """
580
        if 1 <= metric <= 7:
581
            self._copy_data({'metric': metric})
582
        else:
583
            raise ParamValueException('metric',
584
                                      'Must be METRIC: '
585
                                      'ROUTE4ME_METRIC_EUCLIDEAN , '
586
                                      'ROUTE4ME_METRIC_MANHATTAN, '
587
                                      'ROUTE4ME_METRIC_GEODESIC'
588
                                      'ROUTE4ME_METRIC_MATRIX'
589
                                      'ROUTE4ME_METRIC_EXACT_2D')
590
591 1
    def store_route(self, store_route):
592
        """
593
        Set store_route param
594
        :param store_route:
595
        :return:
596
        """
597 1
        if 0 <= store_route <= 1:
598 1
            self._copy_data({'store_route': store_route})
599
        else:
600
            raise ParamValueException('store_route', 'Must be 0 or 1')
601
602 1
    def lock_last(self, lock_last):
603
        """
604
        Set lock_last param
605
        :param lock_last:
606
        :return:
607
        """
608
        if 0 <= lock_last <= 1:
609
            self._copy_data({'lock_last': lock_last})
610
        else:
611
            raise ParamValueException('lock_last', 'Must be 0 or 1')
612
613 1
    def disable_optimization(self, disable_optimization):
614
        """
615
        Set disable_optimization param
616
        :param disable_optimization:
617
        :return:
618
        """
619
        if 0 <= disable_optimization <= 1:
620
            self._copy_data({'disable_optimization': disable_optimization})
621
        else:
622
            raise ParamValueException('disable_optimization', 'Must be 0 or 1')
623
624 1
    def shared_publicly(self, shared_publicly):
625
        """
626
        Set shared_publicly param
627
        :param shared_publicly:
628
        :return:
629
        """
630
        if 0 <= shared_publicly <= 1:
631
            self._copy_data({'shared_publicly': shared_publicly})
632
        else:
633
            raise ParamValueException('shared_publicly', 'Must be 0 or 1')
634
635 1
    def reoptimize(self, reoptimize):
636
        """
637
        Set reoptimize param
638
        :param reoptimize:
639
        :return:
640
        """
641
        if 0 <= reoptimize <= 1:
642
            self._copy_param({'reoptimize': reoptimize})
643
        else:
644
            raise ParamValueException('reoptimize', 'Must be 0 or 1')
645
646 1
    def share_route(self, share_route):
647
        """
648
        Set share_route param
649
        :param share_route:
650
        :return:
651
        """
652 1
        if 0 <= share_route <= 1:
653 1
            self._copy_data({'share_route': share_route})
654
        else:
655
            raise ParamValueException('share_route', 'Must be 0 or 1')
656
657 1
    def rt(self, rt):
658
        """
659
        Set rt param.
660
        :param rt:
661
        :return:
662
        """
663
        if 0 <= rt <= 1:
664
            self._copy_data({'rt': rt})
665
        else:
666
            raise ParamValueException('rt', 'Must be 0 or 1')
667
668 1
    def has_trailer(self, has_trailer):
669
        """
670
        Set has_trailer param.
671
        :param has_trailer:
672
        :return:
673
        """
674
        if 0 <= has_trailer <= 1:
675
            self._copy_data({'has_trailer': has_trailer})
676
        else:
677
            raise ParamValueException('has_trailer', 'Must be 0 or 1')
678
679 1
    def optimization_quality(self, optimization_quality):
680
        """
681
        Set optimization_quality param.
682
        :param optimization_quality:
683
        :return:
684
        """
685
        if 1 <= optimization_quality <= 3:
686
            self._copy_data({'optimization_quality': optimization_quality})
687
        else:
688
            raise ParamValueException('optimization_quality',
689
                                      'Must be between 1 to 3')
690
691 1
    def directions(self, directions):
692
        """
693
        Set directions param.
694
        :param directions:
695
        :return:
696
        """
697
        if 0 <= directions <= 1:
698
            self._copy_param({'directions': directions})
699
        else:
700
            raise ParamValueException('directions', 'Must be 0 or 1')
701
702 1
    def device_tracking_history(self, device_tracking_history):
703
        """
704
        Set device_tracking_history param.
705
        :param device_tracking_history:
706
        :return:
707
        """
708
        if 0 <= device_tracking_history <= 1:
709
            self._copy_param({
710
                'device_tracking_history': device_tracking_history
711
            })
712
        else:
713
            raise ParamValueException('device_tracking_history',
714
                                      'Must be 0 or 1')
715
716 1
    def uturn(self, uturn_type):
717
        """
718
        Set uturn_type. Choices are:
719
        UTURN_DEPART_SHORTEST or
720
        UTURN_DEPART_TO_RIGHT
721
        :param: uturn_type:
722
        :return:
723
        """
724
        if 1 <= uturn_type <= 2:
725
            self._copy_data({'uturn': uturn_type})
726
        else:
727
            raise ParamValueException('uturn',
728
                                      'Must be : '
729
                                      'UTURN_DEPART_SHORTEST or '
730
                                      'UTURN_DEPART_TO_RIGHT')
731
732 1
    def leftturn(self, left_turn_type):
733
        """
734
        Set leftturn. Choices are:
735
        LEFTTURN_ALLOW or
736
        LEFTTURN_FORBID or
737
        LEFTTURN_MULTIAPPROACH
738
        :param: leftturn:
739
        :return:
740
        """
741
        if 1 <= left_turn_type <= 3:
742
            self._copy_data({'leftturn': left_turn_type})
743
        else:
744
            raise ParamValueException('leftturn',
745
                                      'Must be : '
746
                                      'LEFTTURN_ALLOW or '
747
                                      'LEFTTURN_FORBID or '
748
                                      'LEFTTURN_MULTIAPPROACH')
749
750 1
    def dm(self, dm):
751
        """
752
        Set dm. Choices are:
753
        R4M_PROPRIETARY_ROUTING or
754
        R4M_TRAFFIC_ENGINE or
755
        TRUCKING
756
        :param: dm:
757
        :return:
758
        """
759
        if dm in [1, 3, 6]:
760
            self._copy_data({'dm': dm})
761
        else:
762
            raise ParamValueException(
763
                'dm',
764
                'Must be : '
765
                'R4M_PROPRIETARY_ROUTING or '
766
                'R4M_TRAFFIC_ENGINE or '
767
                'TRUCKING'
768
            )
769
770 1
    def dirm(self, dirm):
771
        """
772
        Set dirm. Choices are:
773
        R4M_PROPRIETARY_INTERNAL_NAVIGATION_SYSTEM or
774
        TRUCKING
775
        :param: dirm:
776
        :return:
777
        """
778
        if dirm in [1, 3]:
779
            self._copy_data({'dirm': dirm})
780
        else:
781
            raise ParamValueException(
782
                'dirm',
783
                'Must be : '
784
                'R4M_PROPRIETARY_INTERNAL_NAVIGATION_SYSTEM or'
785
                'TRUCKING'
786
            )
787
788 1
    def _copy_data(self, params):
789
        """
790
        Copy params to data
791
        :param params:
792
        :return:
793
        """
794 1
        self.data['parameters'].update(params)
795
796 1
    def _copy_param(self, params):
797
        """
798
        Copy params to params
799
        :param params:
800
        :return:
801
        """
802 1
        self.params.update(params)
803
804 1
    def get_params(self):
805
        """
806
        Get params
807
        :return:  params
808
        """
809 1
        return self.params
810
811 1
    def required_params(self, requirements=[]):
812
        """
813
        Check if required params are set
814
        :param requirements:
815
        :return:
816
        """
817
        return set(requirements).issubset(set(self.params.keys()))
818
819 1
    @staticmethod
820 1
    def check_required_params(params, requirements=[]):
821
        """
822
        Check if required params are set
823
        :param requirements:
824
        :return:
825
        """
826 1
        return set(requirements).issubset(set(params.keys()))
827
828 1
    def validate_params(self, **kwargs):
829
        """
830
        Validate params
831
        :param kwargs:
832
        :return:
833
        """
834 1
        for k, v in kwargs.items():
835 1
            try:
836 1
                self.__getattribute__(k)(v)
837 1
            except ParamValueException as e:
838
                raise e
839 1
            except AttributeError as e:
840 1
                raise ParamValueException(k, 'Not supported')
841 1
        return True
842
843 1
    def add(self, params={}, data={}):
844
        """
845
        Add params and data
846
        :param params:
847
        :param data:
848
        :return:
849
        """
850 1
        self.validate_params(**params)
851 1
        self.validate_params(**data)
852 1
        self.data.update(data)
853 1
        self.params.update(params)
854
855 1
    def truck_hazardous_goods(self, hazardous_goods):
856
        """
857
        Set truck_hazardous_goods param
858
        :param truck_hazardous_goods:
859
        :return:
860
        """
861
        if hazardous_goods in TRUCK_HAZARDOUS_GOODS.reverse_mapping.keys():
862
            self._copy_data({'truck_hazardous_goods': hazardous_goods})
863
        else:
864
            raise ParamValueException('truck_hazardous_goods',
865
                                      'Must be MI or KM')
866
867
# codebeat:enable[TOTAL_LOC, TOO_MANY_FUNCTIONS, TOTAL_COMPLEXITY]
868