Skip to content

Commit

Permalink
Removed simplejson dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
laf-rge committed Jun 1, 2024
1 parent 9de4c9e commit 3dcc614
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 289 deletions.
1 change: 0 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ pytest-cov = "*"
urllib3 = ">=2.1.0"
intuit-oauth = "==1.2.5"
requests = ">=2.31.0"
simplejson = ">=3.19.1"
requests_oauthlib = ">=1.3.1"
457 changes: 181 additions & 276 deletions Pipfile.lock

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions quickbooks/client.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import http.client as httplib
import textwrap
import simplejson as json
import json
import base64
import hashlib
import hmac
import decimal

from . import exceptions
from requests_oauthlib import OAuth2Session

to_bytes = lambda value, *args, **kwargs: bytes(value, "utf-8", *args, **kwargs)
def to_bytes(value, *args, **kwargs):
return bytes(value, "utf-8", *args, **kwargs)


class Environments(object):
Expand Down Expand Up @@ -206,7 +208,7 @@ def make_request(self, request_type, url, request_body=None, content_type='appli
"Application authentication failed", error_code=req.status_code, detail=req.text)

try:
result = json.loads(req.text, use_decimal=True)
result = json.loads(req.text, parse_float=decimal.Decimal)
except:
raise exceptions.QuickbooksException("Error reading json response: {0}".format(req.text), 10000)

Expand Down
18 changes: 12 additions & 6 deletions quickbooks/mixins.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import decimal
import json
from urllib.parse import quote

import simplejson as json

from .utils import build_where_clause, build_choose_clause
from .client import QuickBooks
from .exceptions import QuickbooksException
from .utils import build_choose_clause, build_where_clause

class DecimalEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, decimal.Decimal):
return str(obj)
return super(DecimalEncoder, self).default(obj)

class ToJsonMixin(object):
def to_json(self):
return json.dumps(self, default=self.json_filter(), sort_keys=True, indent=4, use_decimal=True)
return json.dumps(self, cls=DecimalEncoder, default=self.json_filter(), sort_keys=True, indent=4)

def json_filter(self):
"""
Expand Down Expand Up @@ -176,7 +182,7 @@ def void(self, qb=None):

data = self.get_void_data()
params = self.get_void_params()
results = qb.post(url, json.dumps(data, use_decimal=True), params=params)
results = qb.post(url, json.dumps(data, cls=DecimalEncoder), params=params)

return results

Expand Down Expand Up @@ -230,7 +236,7 @@ def delete(self, qb=None, request_id=None):
'Id': self.Id,
'SyncToken': self.SyncToken,
}
return qb.delete_object(self.qbo_object_name, json.dumps(data, use_decimal=True), request_id=request_id)
return qb.delete_object(self.qbo_object_name, json.dumps(data, cls=DecimalEncoder), request_id=request_id)


class DeleteNoIdMixin(object):
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
intuit-oauth==1.2.4
requests_oauthlib>=1.3.1
requests>=2.31.0
simplejson>=3.19.1
requests>=2.31.0
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def read(*parts):
'intuit-oauth==1.2.5',
'requests_oauthlib>=1.3.1',
'requests>=2.31.0',
'simplejson>=3.19.1',
'python-dateutil',
],

Expand Down

0 comments on commit 3dcc614

Please sign in to comment.