Skip to content

Commit 0e19bc6

Browse files
committed
add new features to response
1 parent dc953d7 commit 0e19bc6

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/quickbase_json/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from quickbase_json.helpers import FileUpload
66
from quickbase_json.qb_insert_update_response import QBInsertResponse
7-
from quickbase_json.qb_response import QBResponse
7+
from quickbase_json.qb_response import QBResponse, QBQueryResponse
88

99

1010
class QuickbaseJSONClient:
@@ -53,7 +53,7 @@ def query_records(self, table: str, select: list, where: str, **kwargs):
5353
print(f'QJAC : query_records : response.json() ---> \n{r.json()}')
5454

5555
# create response object
56-
res = QBResponse('records')
56+
res = QBQueryResponse(res=r)
5757

5858
# update response object with JSON data from request
5959
res.update(r.json())

src/quickbase_json/qb_response.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,30 @@ def wrapper(self, *args, **kwargs):
2424

2525

2626
class QBResponse(dict):
27+
def __init__(self, requests_response):
28+
super().__init__()
29+
self.ok = requests_response.ok
30+
self.status_code = requests_response.status_code
31+
self.text = requests_response.text
32+
2733

28-
def __init__(self, response_type, **kwargs):
29-
self.response_type = response_type
34+
class QBQueryResponse(QBResponse):
35+
36+
def __init__(self, res, **kwargs):
37+
self.response_type = 'records'
3038
self.operations = []
3139
# potential to load sample data for testing
3240
if kwargs.get('sample_data'):
3341
self.update(kwargs.get('sample_data'))
34-
super().__init__()
42+
super().__init__(requests_response=res)
3543

3644
def info(self, prt=True):
3745
"""
3846
Prints information about the response.
3947
:prt: Set to False to only grab the return as a string.
4048
"""
4149
if self.response_type == 'records':
42-
info = []
43-
info.append(f'{Bcolors.OKBLUE}Sample Data:\n')
50+
info = [f'{Bcolors.OKBLUE}Sample Data:\n']
4451
try:
4552
info.append('\t' + str(self.get('data')[0]) + '\n\n')
4653
except KeyError as e:
@@ -266,7 +273,7 @@ def c_currency(currency_format):
266273
else:
267274
for d in self.get('data'):
268275
fmt = currency_format + "{:,.2f}".format(d.get(fid).get('value'))
269-
d.update({fid: {'value': fmt}})
276+
d.update({fid: {'value': fmt}})
270277

271278
if field_type == 'datetime':
272279
c_datetime()

0 commit comments

Comments
 (0)