@@ -31,7 +31,7 @@ class Atomx(object):
31
31
"""Interface for the api on api.atomx.com.
32
32
33
33
To learn more about the api visit the
34
- `atomx wiki <http ://wiki.atomx.com/doku.php?id= api>`_
34
+ `atomx wiki <https ://wiki.atomx.com/api>`_
35
35
36
36
:param str email: email address of your atomx user
37
37
:param str password: password of your atomx user
@@ -131,11 +131,11 @@ def search(self, query):
131
131
for v in search_result [m ]]
132
132
return search_result
133
133
134
- def report (self , scope = None , groups = None , metrics = None , where = None ,
135
- from_ = None , to = None , timezone = 'UTC' , emails = None , fast = True ):
134
+ def report (self , scope = None , groups = None , metrics = None , where = None , from_ = None , to = None ,
135
+ timezone = 'UTC' , emails = None , fast = True , when = None , interval = None ):
136
136
"""Create a report.
137
137
138
- See the `reporting atomx wiki <http ://wiki.atomx.com/doku.php?id= reporting>`_
138
+ See the `reporting atomx wiki <https ://wiki.atomx.com/reporting>`_
139
139
for details about parameters and available groups, metrics.
140
140
141
141
:param str scope: either 'advertiser', 'publisher' or 'network' to select the type
@@ -157,14 +157,16 @@ def report(self, scope=None, groups=None, metrics=None, where=None,
157
157
:param datetime.datetime to: :class:`datetime.datetime` where the report
158
158
should end (exclusive). (defaults to `datetime.now()` if undefined)
159
159
:param str timezone: Timezone used for all times. (defaults to `UTC`)
160
- For a supported list see http ://wiki.atomx.com/doku.php?id= timezones
160
+ For a supported list see https ://wiki.atomx.com/timezones
161
161
:param emails: One or multiple email addresses that should get
162
162
notified once the report is finished and ready to download.
163
163
:type emails: str or list
164
164
:param bool fast: if `False` the report will always be run against the low level data.
165
165
This is useful for billing reports for example.
166
166
The default is `True` which means it will always try to use aggregate data
167
167
to speed up the query.
168
+ :param str when: When should the scheduled report run. (daily, monthly, monday-sunday)
169
+ :param str interval: Time period included in the scheduled report ('N days' or 'N month')
168
170
:return: A :class:`atomx.models.Report` model
169
171
"""
170
172
report_json = {'timezone' : timezone , 'fast' : fast }
@@ -198,19 +200,26 @@ def report(self, scope=None, groups=None, metrics=None, where=None,
198
200
if where :
199
201
report_json ['where' ] = where
200
202
201
- if from_ is None :
202
- from_ = datetime . now () - timedelta ( days = 7 )
203
- if isinstance ( from_ , datetime ):
204
- report_json ['from ' ] = from_ . strftime ( "%Y-%m-%d %H:00:00" )
203
+ if when and interval :
204
+ is_scheduled_report = True
205
+ report_json [ 'when' ] = when
206
+ report_json ['interval ' ] = interval
205
207
else :
206
- report_json [ 'from' ] = from_
208
+ is_scheduled_report = False
207
209
208
- if to is None :
209
- to = datetime .now ()
210
- if isinstance (to , datetime ):
211
- report_json ['to' ] = to .strftime ("%Y-%m-%d %H:00:00" )
212
- else :
213
- report_json ['to' ] = to
210
+ if from_ is None :
211
+ from_ = datetime .now () - timedelta (days = 7 )
212
+ if isinstance (from_ , datetime ):
213
+ report_json ['from' ] = from_ .strftime ("%Y-%m-%d %H:00:00" )
214
+ else :
215
+ report_json ['from' ] = from_
216
+
217
+ if to is None :
218
+ to = datetime .now ()
219
+ if isinstance (to , datetime ):
220
+ report_json ['to' ] = to .strftime ("%Y-%m-%d %H:00:00" )
221
+ else :
222
+ report_json ['to' ] = to
214
223
215
224
if emails :
216
225
if not isinstance (emails , list ):
@@ -227,6 +236,9 @@ def report(self, scope=None, groups=None, metrics=None, where=None,
227
236
del r_json ['report' ]
228
237
self .last_response = r_json
229
238
239
+ if is_scheduled_report :
240
+ return models .ScheduledReport (self , query = r .json ()['query' ], ** report )
241
+
230
242
return models .Report (self , query = r .json ()['query' ], ** report )
231
243
232
244
def report_status (self , report ):
@@ -324,7 +336,7 @@ def get(self, resource, *args, **kwargs):
324
336
# is equivalent to atomx.get('advertiser/42/profiles')
325
337
326
338
:param kwargs: Any argument is passed as URL parameter to the respective api endpoint.
327
- See `API URL Parameters <http ://wiki.atomx.com/doku.php?id= api#url_parameters>`_
339
+ See `API URL Parameters <https ://wiki.atomx.com/api#url_parameters>`_
328
340
in the wiki.
329
341
330
342
Example:
@@ -354,6 +366,11 @@ def get(self, resource, *args, **kwargs):
354
366
if isinstance (res , list ):
355
367
return [getattr (models , model )(self , ** m ) for m in res ]
356
368
return getattr (models , model )(self , ** res )
369
+ elif model_name == 'reporting' : # special case for `/reports` status
370
+ return {
371
+ 'reports' : [models .Report (self , ** m ) for m in res ['reports' ]],
372
+ 'scheduled' : [models .ScheduledReport (self , ** m ) for m in res ['scheduled' ]]
373
+ }
357
374
return res
358
375
359
376
def post (self , resource , json , ** kwargs ):
0 commit comments