Skip to content

Commit d5394fe

Browse files
committed
Ad-hoc json - method updated to support conditions and custom_fields
1 parent 1e63525 commit d5394fe

File tree

4 files changed

+22
-17
lines changed

4 files changed

+22
-17
lines changed

ravenpackapi/core.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
from ravenpackapi.models.reference import RpEntityReference, EntityTypeReference
1212
from ravenpackapi.models.results import Results
1313
from ravenpackapi.util import to_curl
14-
from ravenpackapi.utils.constants import JSON_AVAILABLE_FIELDS, ENTITY_TYPES
14+
from ravenpackapi.utils.constants import ENTITY_TYPES
15+
from ravenpackapi.utils.date_formats import as_datetime_str
1516

1617
_VALID_METHODS = ('get', 'post', 'put', 'delete')
17-
VERSION = '1.0.30'
18+
VERSION = '1.0.31'
1819

1920
logger = logging.getLogger("ravenpack.core")
2021

@@ -105,24 +106,35 @@ def get_dataset(self, dataset_id):
105106
def json(self,
106107
start_date,
107108
end_date,
108-
fields,
109+
fields=None,
109110
filters=None,
110111
time_zone=None,
111112
frequency='granular',
112113
having=None,
114+
custom_fields=None,
115+
conditions=None,
113116
product='rpa',
114117
product_version='1.0',
115118
):
116119
# let's build the body, with all the defined fields
117-
body = {}
118-
for k in JSON_AVAILABLE_FIELDS:
119-
if locals().get(k) is not None:
120-
body[k] = locals().get(k)
120+
body = {"start_date": as_datetime_str(start_date),
121+
"end_date": as_datetime_str(end_date),
122+
"time_zone": time_zone}
123+
body.update(dict(
124+
frequency=frequency,
125+
fields=fields,
126+
custom_fields=custom_fields,
127+
filters=filters,
128+
conditions=conditions,
129+
having=having,
130+
product=product,
131+
product_version=product_version,
132+
))
121133

122134
response = self.request(
123135
endpoint="/json",
124136
method='post',
125-
data=body,
137+
data={k: v for k, v in body.items() if v is not None}, # remove null values
126138
)
127139
data = response.json()
128140
return Results(data['records'],

ravenpackapi/models/dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def save(self):
166166
)
167167
}
168168

169-
if 'frequency' in data and not 'fields' in data:
169+
if 'frequency' in data and 'fields' not in data:
170170
# fields can be null, we specify it only when frequency is also given
171171
data['fields'] = self.fields
172172

ravenpackapi/utils/constants.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,2 @@
1-
JSON_AVAILABLE_FIELDS = {
2-
'start_date', 'end_date', 'time_zone',
3-
'frequency', 'fields',
4-
'having', 'filters',
5-
'product', 'product_version',
6-
}
7-
81
ENTITY_TYPES = {None, "CMDT", "COMP", "CURR", "NATL", "ORGA",
92
"ORGT", "PEOP", "PLCE", "PROD", "TEAM", "POSI", "SRCE"}

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from setuptools import setup, find_packages
22

3-
VERSION = '1.0.30'
3+
VERSION = '1.0.31'
44

55
with open('README.rst') as readme_file:
66
readme = readme_file.read()

0 commit comments

Comments
 (0)