@@ -31,7 +31,7 @@ class Atomx(object):
3131 """Interface for the api on api.atomx.com.
3232
3333 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>`_
3535
3636 :param str email: email address of your atomx user
3737 :param str password: password of your atomx user
@@ -131,11 +131,11 @@ def search(self, query):
131131 for v in search_result [m ]]
132132 return search_result
133133
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 ):
136136 """Create a report.
137137
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>`_
139139 for details about parameters and available groups, metrics.
140140
141141 :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,
157157 :param datetime.datetime to: :class:`datetime.datetime` where the report
158158 should end (exclusive). (defaults to `datetime.now()` if undefined)
159159 :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
161161 :param emails: One or multiple email addresses that should get
162162 notified once the report is finished and ready to download.
163163 :type emails: str or list
164164 :param bool fast: if `False` the report will always be run against the low level data.
165165 This is useful for billing reports for example.
166166 The default is `True` which means it will always try to use aggregate data
167167 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')
168170 :return: A :class:`atomx.models.Report` model
169171 """
170172 report_json = {'timezone' : timezone , 'fast' : fast }
@@ -198,19 +200,26 @@ def report(self, scope=None, groups=None, metrics=None, where=None,
198200 if where :
199201 report_json ['where' ] = where
200202
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
205207 else :
206- report_json [ 'from' ] = from_
208+ is_scheduled_report = False
207209
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
214223
215224 if emails :
216225 if not isinstance (emails , list ):
@@ -227,6 +236,9 @@ def report(self, scope=None, groups=None, metrics=None, where=None,
227236 del r_json ['report' ]
228237 self .last_response = r_json
229238
239+ if is_scheduled_report :
240+ return models .ScheduledReport (self , query = r .json ()['query' ], ** report )
241+
230242 return models .Report (self , query = r .json ()['query' ], ** report )
231243
232244 def report_status (self , report ):
@@ -324,7 +336,7 @@ def get(self, resource, *args, **kwargs):
324336 # is equivalent to atomx.get('advertiser/42/profiles')
325337
326338 :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>`_
328340 in the wiki.
329341
330342 Example:
@@ -354,6 +366,11 @@ def get(self, resource, *args, **kwargs):
354366 if isinstance (res , list ):
355367 return [getattr (models , model )(self , ** m ) for m in res ]
356368 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+ }
357374 return res
358375
359376 def post (self , resource , json , ** kwargs ):
0 commit comments