@@ -58,17 +58,41 @@ def search(self, query):
5858 for v in search_result [m ]]
5959 return search_result
6060
61- def report (self , ** kwargs ):
62- if 'to' not in kwargs :
63- kwargs ['to' ] = datetime .now ()
64- if isinstance (kwargs ['to' ], datetime ): # TODO: support timezones
65- kwargs ['to' ] = kwargs ['to' ].strftime ("%Y-%m-%d %H:00:00Z" )
66- if isinstance (kwargs .get ('from_' ), datetime ):
67- kwargs ['from' ] = kwargs ['from_' ].strftime ("%Y-%m-%d %H:00:00Z" )
61+ def report (self , scope , groups , sums , where , from_ , to = None , timezone = 'UTC' , fast = True ):
62+ """Create a report.
63+
64+ :param str scope: either 'advertiser' or 'publisher' to select the type of report.
65+ :param list groups: columns to group by (see http://wiki.atomx.com/doku.php?id=reporting#groups)
66+ :param list sums: columns to sum on (see http://wiki.atomx.com/doku.php?id=reporting#sums)
67+ :param list where: is a list of expression lists.
68+ An expression list is in the form of `[column, op, value]`.
69+ `column` can be any of the :param:`groups` or :param:`sums` columns.
70+ `op` can be any of `==`, `!=`, `<=`, `>=`, `<`, `>`, `in` or `not in` as a string.
71+ `value` is either a number or in case of `in` and `not in` a list of numbers.
72+ :param datetime from_: `datetime` where the report should start (inclusive)
73+ :param datetime to: `datetime` where the report should end (exclusive).
74+ (defaults to `datetime.now()` if undefined)
75+ :param str timezone: Timezone used for all times. (defaults to `UTC`)
76+ For a supported list see http://wiki.atomx.com/doku.php?id=timezones
77+ :param bool fast: if `False` the report will always be run against the low level data.
78+ This is useful for billing reports for example.
79+ The default is `True` which means it will always try to use aggregate data
80+ to speed up the query.
81+ :return: A :class:`atomx.models.Report` model
82+ """
83+ report_json = locals ().copy ()
84+ del report_json ['self' ]
85+
86+ if to is None :
87+ report_json ['to' ] = datetime .now ()
88+ if isinstance (report_json ['to' ], datetime ):
89+ report_json ['to' ] = report_json ['to' ].strftime ("%Y-%m-%d %H:00:00" )
90+ if isinstance (report_json .get ('from_' ), datetime ):
91+ report_json ['from' ] = report_json ['from_' ].strftime ("%Y-%m-%d %H:00:00" )
6892 else :
69- kwargs ['from' ] = kwargs ['from_' ]
70- del kwargs ['from_' ]
71- r = self .session .post (self .api_endpoint + 'report' , json = kwargs )
93+ report_json ['from' ] = report_json ['from_' ]
94+ del report_json ['from_' ]
95+ r = self .session .post (self .api_endpoint + 'report' , json = report_json )
7296 if not r .ok :
7397 raise APIError (r .json ()['error' ])
7498 return models .Report (self , query = r .json ()['query' ], ** r .json ()['report' ])
0 commit comments