Ejemplo n.º 1
0
 def get_address(self, route_id, route_destination_id):
     params = {
         'route_id': route_id,
         'route_destination_id': route_destination_id
     }
     response = self.api.request_address(params)
     return json2obj(response.content)
Ejemplo n.º 2
0
 def update_address(self, data, route_id, route_destination_id):
     params = {
         'route_id': route_id,
         'route_destination_id': route_destination_id
     }
     params.update({'api_key': self.key})
     data = json.dumps(data)
     response = self.api._make_request(ADDRESS_HOST, params, data,
                                       self.api._request_put)
     return json2obj(response.content)
Ejemplo n.º 3
0
    def delete_address_from_route(self, route_id, route_destination_id):
        params = {
            'route_id': route_id,
            'route_destination_id': route_destination_id
        }
        params.update({'api_key': self.key})
        response = self.api._make_request(ADDRESS_HOST, params, None,
                                          self.api._request_delete)

        return json2obj(response.content)
Ejemplo n.º 4
0
 def delete_addressbook_contact(self, **kwargs):
     """
     Delete a contact from AddressBook using DELETE request
     :return: API response
     :raise: ParamValueException if required params are not present.
     """
     if self.check_required_params(kwargs, ['address_ids', ]):
         self.response = self.api._request_delete(ADDRESSBOOK,
                                                  self.params,
                                                  data=json.dumps(kwargs))
         response = json2obj(self.response.content)
         return response
     else:
         raise ParamValueException('params', 'Params are not complete')
Ejemplo n.º 5
0
 def get_avoidance_zones(self):
     """
     Get avoidance zones using GET request
     :return: API response
     :raise: ParamValueException if required params are not present.
     """
     if self.check_required_params(self.params, [
             'api_key',
     ]):
         self.response = self.api._request_get(AVOIDANCE, self.params)
         response = json2obj(self.response.content)
         return response
     else:
         raise ParamValueException('params', 'Params are not complete')
Ejemplo n.º 6
0
 def get_territories(self):
     """
     Get territories using GET request
     :return: API response
     :raise: ParamValueException if required params are not present.
     """
     if self.check_required_params(self.params, [
             'api_key',
     ]):
         self.response = self.api._request_get(TERRITORY_HOST, self.params)
         response = json2obj(self.response.content)
         return response
     else:
         raise ParamValueException('params', 'Params are not complete')
Ejemplo n.º 7
0
 def get_activities_feed_by_type(self, **kwargs):
     """
     Get Activity Feed by Type using GET request
     :return: API response
     :raise: ParamValueException if required params are not present.
     """
     kwargs.update({'api_key': self.params['api_key'], })
     if self.check_required_params(kwargs, ['api_key', 'activity_type']):
         self.response = self.api._request_get(ACTIVITY_FEED,
                                               kwargs)
         response = json2obj(self.response.content)
         return response
     else:
         raise ParamValueException('params', 'Params are not complete')
Ejemplo n.º 8
0
 def add_avoidance_zone(self, **kwargs):
     """
     Add avoidance zone using POST request
     :return: API response
     :raise: ParamValueException if required params are not present.
     """
     if self.check_required_params(
             kwargs, ['territory_name', 'territory_color', 'territory']):
         self.response = self.api._request_post(AVOIDANCE,
                                                self.params,
                                                data=json.dumps(kwargs))
         response = json2obj(self.response.content)
         return response
     else:
         raise ParamValueException('params', 'Params are not complete')
Ejemplo n.º 9
0
 def get_territory(self, **kwargs):
     """
     Get Territory using GET request
     :return: API response
     :raise: ParamValueException if required params are not present.
     """
     kwargs.update({
         'api_key': self.params['api_key'],
     })
     if self.check_required_params(kwargs, ['api_key', 'territory_id']):
         self.response = self.api._request_get(TERRITORY_HOST, kwargs)
         response = json2obj(self.response.content)
         return response
     else:
         raise ParamValueException('params', 'Params are not complete')
Ejemplo n.º 10
0
    def get_optimization(self, **kwargs):
        """
        Get optimization using GET request
        :return: API response
        :raise: ParamValueException if required params are not present.

        """
        kwargs.update({'api_key': self.params['api_key'], })
        if self.check_required_params(kwargs, ['optimization_problem_id', ]):
            self.response = self.api._request_get(API_HOST,
                                                  kwargs)
            response = json2obj(self.response.content)
            return response
        else:
            raise ParamValueException('params', 'Params are not complete')
Ejemplo n.º 11
0
 def delete_avoidance_zone(self, **kwargs):
     """
     Delete avoidance zone using DELETE request
     :return: API response
     :raise: ParamValueException if required params are not present.
     """
     kwargs.update({
         'api_key': self.params['api_key'],
     })
     if self.check_required_params(kwargs, ['territory_id']):
         self.response = self.api._request_delete(AVOIDANCE, kwargs)
         response = json2obj(self.response.content)
         return response
     else:
         raise ParamValueException('params', 'Params are not complete')
Ejemplo n.º 12
0
 def get_activity_feed_route_owner_changed(self, **kwargs):
     """
     Get Activity Feed Route Owner Changed using GET request
     :return: API response
     :raise: ParamValueException if required params are not present.
     """
     kwargs.update({'api_key': self.params['api_key'],
                    'activity_type': 'route-owner-changed', })
     if self.check_required_params(kwargs, ['api_key', 'route_id']):
         self.response = self.api._request_get(ACTIVITY_FEED,
                                               kwargs)
         response = json2obj(self.response.content)
         return response
     else:
         raise ParamValueException('params', 'Params are not complete')
Ejemplo n.º 13
0
    def delete_address_from_optimization(self, **kwargs):
        """
        Delete Address from an optimization using DELETE request
        :return: API response
        :raise: ParamValueException if required params are not present.

        """
        kwargs.update({'api_key': self.params['api_key'], })
        if self.check_required_params(kwargs, ['optimization_problem_id',
                                               'route_destination_id']):
            self.response = self.api._request_delete(ADDRESS_HOST,
                                                     kwargs)
            response = json2obj(self.response.content)
            return response
        else:
            raise ParamValueException('params', 'Params are not complete')
Ejemplo n.º 14
0
 def update_avoidance_zone(self, territory_id, **kwargs):
     """
     Delete avoidance zone using DELETE request
     :return: API response
     :raise: ParamValueException if required params are not present.
     """
     self.params.update({'territory_id': territory_id})
     if self.check_required_params(
             kwargs, ['territory_name', 'territory_color', 'territory']):
         self.response = self.api._request_put(AVOIDANCE,
                                               self.params,
                                               data=json.dumps(kwargs))
         response = json2obj(self.response.content)
         return response
     else:
         raise ParamValueException('params', 'Params are not complete')
Ejemplo n.º 15
0
    def get_activities(self, **kwargs):
        """
        Get routes activities using GET request
        :return: API response
        :raise: ParamValueException if required params are not present.

        """
        kwargs.update({'api_key': self.params['api_key'], })
        if self.check_required_params(kwargs, ['route_id',
                                               'limit',
                                               'offset', ]):
            self.response = self.api._request_get(GET_ACTIVITIES_HOST,
                                                  kwargs)
            response = json2obj(self.response.content)
            return response
        else:
            raise ParamValueException('params', 'Params are not complete')
Ejemplo n.º 16
0
    def delete_optimization(self, **kwargs):
        """
        Delete optimization using DELETE request
        :return: API response
        :raise: ParamValueException if required params are not present.

        """
        self.json_data = kwargs
        if self.check_required_params(kwargs, ['optimization_problem_ids', ]):
            data = json.dumps(self.json_data, ensure_ascii=False)
            self.response = self.api._request_delete(API_HOST,
                                                     self.params,
                                                     data=data)
            response = json2obj(self.response.content)
            return response
        else:
            raise ParamValueException('params', 'Params are not complete')
Ejemplo n.º 17
0
 def re_optimization(self, optimization_id, data={}):
     """
     Execute reoptimization
     :param optimization_id:
     :return: response as a object
     """
     self.optimization.optimization_problem_id(optimization_id)
     self.optimization.reoptimize(1)
     data = {'parameters': data}
     self.response = self._make_request(API_HOST,
                                        self.optimization.get_params(),
                                        json.dumps(data), self._request_put)
     try:
         response = json2obj(self.response.content)
         return response
     except ValueError:
         raise
     except Exception:
         raise
Ejemplo n.º 18
0
    def log_specific_message(self, **kwargs):
        """
        Activity Feed Log an Specific Message using POST request
        :return: API response
        :raise: ParamValueException if required params are not present.
        """
        self.json_data = kwargs
        kwargs.update({'api_key': self.params['api_key'],
                       'activity_type': 'user_message', })
        if self.check_required_params(self.json_data, ['api_key',
                                                       'activity_message',
                                                       'route_id']):
            data = json.dumps(self.json_data, ensure_ascii=False)
            self.response = self.api._request_post(ACTIVITY_FEED,
                                                   self.params, data=data)
            response = json2obj(self.response.content)
            return response

        else:
            raise ParamValueException('params', 'Params are not complete')
Ejemplo n.º 19
0
    def add_address_notes(self, note, **kwargs):
        """
        Add Address  Note using POST request
        :return: API response
        :raise: ParamValueException if required params are not present.
        """
        if self.check_required_params(kwargs, ['address_id', 'route_id']):
            data = {
                'strUpdateType': kwargs.pop('activity_type'),
                'strNoteContents': note
            }
            kwargs.update({
                'api_key': self.params['api_key'],
            })
            self.response = self.api._request_post(ADD_ROUTE_NOTES_HOST,
                                                   kwargs, data)
            response = json2obj(self.response.content)
            return response

        else:
            raise ParamValueException('params', 'Params are not complete')
Ejemplo n.º 20
0
 def test_json2obj(self):
     json_data = json.dumps({'variable1': 'test_value'})
     json_obj = json2obj(json_data)
     self.assertTrue(hasattr(json_obj, 'variable1'))
Ejemplo n.º 21
0
 def test_json2obj(self):
     json_data = json.dumps({'variable1': 'test_value'})
     json_obj = json2obj(json_data)
     self.assertTrue(hasattr(json_obj, 'variable1'))