Skip to content

Commit

Permalink
Fixed bug. Removed double json dump
Browse files Browse the repository at this point in the history
  • Loading branch information
r4m-juan committed Mar 16, 2023
1 parent 5d16cad commit 2e396aa
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 56 deletions.
2 changes: 1 addition & 1 deletion VERSION.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# VERSION.py - MAINTAINER's. Don't edit, if you don't know what are you doing
# ==============================================================================

VERSION = (0, 1, 4, 1)
VERSION = (0, 1, 4, 4)
RELEASE_SUFFIX = ''

VERSION_STRING = '.'.join([str(x) for x in VERSION])
Expand Down
5 changes: 1 addition & 4 deletions route4me/activity_feed.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-

import json

from .api_endpoints import ACTIVITY_FEED
from .base import Base
from .exceptions import ParamValueException
Expand Down Expand Up @@ -106,9 +104,8 @@ def log_specific_message(self, **kwargs):
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)
self.params, json=self.json_data)
return self.response.json()
else:
raise ParamValueException('params', 'Params are not complete')
8 changes: 3 additions & 5 deletions route4me/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,9 @@ def update_address(self, data, route_id, route_destination_id):
'route_destination_id': route_destination_id
}
params.update({'api_key': self.api.key})
data = json.dumps(data)
response = self.api._make_request(ADDRESS_HOST,
params,
data,
self.api._request_put)
response = self.api._request_put(ADDRESS_HOST,
params,
json=data)
return response.json()

def delete_address_from_route(self, route_id, route_destination_id):
Expand Down
4 changes: 1 addition & 3 deletions route4me/address_book.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-

import json

from .api_endpoints import ADDRESSBOOK
from .base import Base
from .exceptions import ParamValueException
Expand Down Expand Up @@ -88,7 +86,7 @@ def delete_addressbook_contact(self, **kwargs):
if self.check_required_params(kwargs, ['address_ids', ]):
self.response = self.api._request_delete(ADDRESSBOOK,
self.params,
data=json.dumps(kwargs))
json=kwargs)
return self.response.json()
else:
raise ParamValueException('params', 'Params are not complete')
28 changes: 15 additions & 13 deletions route4me/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def _request_put(self, url, request_params, json=None, data=None):
headers=self.headers,
verify=self.verify_ssl)

def _request_delete(self, url, request_params, data=None):
def _request_delete(self, url, request_params, data=None, json=None):
"""
DELETE request
:param url:
Expand All @@ -149,6 +149,7 @@ def _request_delete(self, url, request_params, data=None):
"""
return requests.request('DELETE', url, params=request_params,
data=data,
json=json,
headers=self.headers,
verify=self.verify_ssl)

Expand Down Expand Up @@ -178,10 +179,9 @@ def re_optimization(self, optimization_id, data={}):
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)
self.response = self._request_put(API_HOST,
self.optimization.get_params(),
json=data)
try:
return self.response.json()
except ValueError:
Expand Down Expand Up @@ -217,10 +217,11 @@ def export_result_to_json(self, file_name):
if self.response:
try:
f = open(file_name, 'w')
f.write(json.dumps(self.response.content,
ensure_ascii=False,
sort_keys=True,
indent=4))
json.dump(self.response.content,
f,
ensure_ascii=False,
sort_keys=True,
indent=4)
f.close()
except Exception:
raise
Expand All @@ -234,10 +235,11 @@ def export_request_to_json(self, file_name):
if self.optimization.data:
try:
f = open(file_name, 'w')
f.write(json.dumps(self.optimization.data,
ensure_ascii=False,
sort_keys=True,
indent=4))
json.dump(self.optimization.data,
f,
ensure_ascii=False,
sort_keys=True,
indent=4)
f.close()
except Exception:
raise
Expand Down
5 changes: 2 additions & 3 deletions route4me/avoidance_zones.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
# codebeat:disable[SIMILARITY, ABC]

import json

from .api_endpoints import AVOIDANCE
from .base import Base
Expand Down Expand Up @@ -60,7 +59,7 @@ def add_avoidance_zone(self, **kwargs):
'territory']):
self.response = self.api._request_post(AVOIDANCE,
self.params,
data=json.dumps(kwargs))
json=kwargs)
return self.response.json()
else:
raise ParamValueException('params', 'Params are not complete')
Expand Down Expand Up @@ -91,7 +90,7 @@ def update_avoidance_zone(self, territory_id, **kwargs):
'territory']):
self.response = self.api._request_put(AVOIDANCE,
self.params,
data=json.dumps(kwargs))
json=kwargs)
return self.response.json()
else:
raise ParamValueException('params', 'Params are not complete')
Expand Down
6 changes: 2 additions & 4 deletions route4me/members.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ def app_purchase_user_license(self, **kwargs):
'token',
'payload',
'format', ]):
data = json.dumps(kwargs, ensure_ascii=False)
response = self.api._request_post(USER_LICENSE_HOST,
self.params,
data=data)
json=kwargs)
try:
return json.loads(response.content)
except ValueError:
Expand All @@ -63,10 +62,9 @@ def verify_device_license(self, **kwargs):
if self.check_required_params(kwargs, ['device_id',
'device_type',
'format', ]):
data = json.dumps(kwargs, ensure_ascii=False)
response = self.api._request_post(VERIFY_DEVICE_LICENSE,
self.params,
data=data)
json=kwargs)
try:
return json.loads(response.content)
except ValueError:
Expand Down
5 changes: 1 addition & 4 deletions route4me/optimization.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-

import json

from .api_endpoints import ADDRESS_HOST, API_HOST
from .base import Base
from .exceptions import ParamValueException
Expand Down Expand Up @@ -83,10 +81,9 @@ def delete_optimization(self, **kwargs):
"""
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)
json=kwargs)
response = self.response.json()
return response
else:
Expand Down
7 changes: 3 additions & 4 deletions route4me/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ def create_order(self, **kwargs):
:return: API response content
"""
if self.check_required_params(kwargs, self.REQUIRED_FIELDS):
data = json.dumps(kwargs, ensure_ascii=False)
response = self.api._request_post(ORDERS_HOST,
self.params,
data=data)
json=kwargs)
try:
return response.json()
except ValueError:
Expand Down Expand Up @@ -66,7 +65,7 @@ def update_order(self, **kwargs):
if self.check_required_params(kwargs, self.REQUIRED_FIELDS):
response = self.api._request_put(ORDERS_HOST,
self.params,
data=json.dumps(kwargs))
json=kwargs)
try:
return json.loads(response.content)
except ValueError:
Expand All @@ -83,7 +82,7 @@ def delete_order(self, **kwargs):
if self.check_required_params(kwargs, ['order_ids', ]):
response = self.api._request_delete(ORDERS_HOST,
self.params,
data=json.dumps(kwargs))
jsom=kwargs)
try:
return json.loads(response.content)
except ValueError:
Expand Down
13 changes: 4 additions & 9 deletions route4me/route.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

# codebeat:disable[TOO_MANY_FUNCTIONS]

import json

from .api_endpoints import ROUTE_HOST, EXPORTER
from .api_endpoints import ADDRESS_HOST, GET_ACTIVITIES_HOST, DUPLICATE_ROUTE, SHARE_ROUTE_HOST
Expand Down Expand Up @@ -177,10 +176,9 @@ def insert_address_into_route_optimal_position(self, **kwargs):
'optimal_position']):
params = {'api_key': self.params['api_key'],
'route_id': kwargs.pop('route_id')}
data = json.dumps(kwargs, ensure_ascii=False)
response = self.api._request_put(ROUTE_HOST,
params,
data=data)
json=kwargs)
return response.json()
else:
raise ParamValueException('params', 'Params are not complete')
Expand Down Expand Up @@ -254,9 +252,8 @@ def resequence_route(self, **kwargs):
'route_id': kwargs.pop('route_id'),
'route_destination_id': kwargs.pop('route_destination_id'),
}
data = json.dumps(kwargs, ensure_ascii=False)
response = self.api._request_put(ROUTE_HOST,
params, data=data)
params, json=kwargs)
return response.json()

else:
Expand Down Expand Up @@ -289,10 +286,9 @@ def merge_routes(self, **kwargs):
AttributeError if there is an error deleting a route
"""
if self.check_required_params(kwargs, ['route_ids']):
data = json.dumps(kwargs, ensure_ascii=False)
response = self.api._request_post(MERGE_ROUTES_HOST,
self.params,
data=data)
json=kwargs)
return response.json()

else:
Expand Down Expand Up @@ -330,9 +326,8 @@ def update_route_destination_custom_data(self, **kwargs):
'route_id': kwargs.pop('route_id'),
'route_destination_id': kwargs.pop('route_destination_id'),
}
data = json.dumps(kwargs, ensure_ascii=False)
response = self.api._request_put(ADDRESS_HOST,
params, data=data)
params, json=kwargs)
return response.json()

else:
Expand Down
8 changes: 3 additions & 5 deletions route4me/territory.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
# codebeat:disable[SIMILARITY, BLOCK_NESTING]

import json

from .api_endpoints import TERRITORY_HOST
from .base import Base
from .exceptions import ParamValueException
Expand Down Expand Up @@ -60,7 +58,7 @@ def add_territory(self, **kwargs):
'territory']):
self.response = self.api._request_post(TERRITORY_HOST,
self.params,
data=json.dumps(kwargs))
json=kwargs)
return self.response.json()
else:
raise ParamValueException('params', 'Params are not complete')
Expand All @@ -74,7 +72,7 @@ def delete_territory(self, **kwargs):
kwargs.update({'api_key': self.params['api_key'], })
if self.check_required_params(kwargs, ['territory_id']):
self.response = self.api._request_delete(TERRITORY_HOST,
kwargs)
json=kwargs)
return self.response.json()
else:
raise ParamValueException('params', 'Params are not complete')
Expand All @@ -91,7 +89,7 @@ def update_territory(self, territory_id, **kwargs):
'territory']):
self.response = self.api._request_put(TERRITORY_HOST,
self.params,
data=json.dumps(kwargs))
json=kwargs)
return self.response.json()
else:
raise ParamValueException('params', 'Params are not complete')
Expand Down
2 changes: 1 addition & 1 deletion route4me/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# VERSION.py - MAINTAINER's. Don't edit, if you don't know what are you doing
# ==============================================================================

VERSION = (0, 1, 4, 3)
VERSION = (0, 1, 4, 4)
RELEASE_SUFFIX = ''

VERSION_STRING = '.'.join([str(x) for x in VERSION])
Expand Down

0 comments on commit 2e396aa

Please sign in to comment.