@@ -41,6 +41,7 @@ class Atomx(object):
41
41
"""
42
42
def __init__ (self , email , password , api_endpoint = API_ENDPOINT ):
43
43
self .auth_tkt = None
44
+ self .user = None
44
45
self .email = email
45
46
self .password = password
46
47
self .api_endpoint = api_endpoint .rstrip ('/' ) + '/'
@@ -72,10 +73,12 @@ def login(self, email=None, password=None):
72
73
raise InvalidCredentials
73
74
raise APIError (r .json ()['error' ])
74
75
self .auth_tkt = r .json ()['auth_tkt' ]
76
+ self .user = models .User (** r .json ()['user' ])
75
77
76
78
def logout (self ):
77
79
"""Removes authentication token from session."""
78
80
self .auth_tkt = None
81
+ self .user = None
79
82
self .session .get (self .api_endpoint + 'logout' )
80
83
81
84
def search (self , query ):
@@ -117,22 +120,22 @@ def search(self, query):
117
120
for v in search_result [m ]]
118
121
return search_result
119
122
120
- def report (self , scope = None , groups = None , sums = None , where = None ,
123
+ def report (self , scope = None , groups = None , metrics = None , where = None ,
121
124
from_ = None , to = None , timezone = 'UTC' , fast = True ):
122
125
"""Create a report.
123
126
124
127
See the `reporting atomx wiki <http://wiki.atomx.com/doku.php?id=reporting>`_
125
- for details about parameters and available groups, sums .
128
+ for details about parameters and available groups, metrics .
126
129
127
- :param str scope: either 'advertiser' or 'publisher ' to select the type of report.
128
- If undefined but the groups column have an unambiguous attribute that's
129
- unique to a certain scope, it's set automatically .
130
+ :param str scope: either 'advertiser', 'publisher' or 'network ' to select the type
131
+ of report. If undefined it tries to determine the `scope` automatically based
132
+ on the `groups` and `metrics` parameters and the access rights of the api user .
130
133
:param list groups: columns to group by.
131
- :param list sums : columns to sum on.
134
+ :param list metrics : columns to sum on.
132
135
:param list where: is a list of expression lists.
133
136
An expression list is in the form of ``[column, op, value]``:
134
137
135
- - ``column`` can be any of the ``groups`` or ``sums `` parameter columns.
138
+ - ``column`` can be any of the ``groups`` or ``metrics `` parameter columns.
136
139
- ``op`` can be any of ``==``, ``!=``, ``<=``, ``>=``,
137
140
``<``, ``>``, ``in`` or ``not in`` as a string.
138
141
- ``value`` is either a number or in case of ``in``
@@ -154,22 +157,26 @@ def report(self, scope=None, groups=None, sums=None, where=None,
154
157
155
158
if groups :
156
159
report_json ['groups' ] = groups
157
- if sums :
158
- report_json ['sums ' ] = sums
160
+ if metrics :
161
+ report_json ['metrics ' ] = metrics
159
162
elif not groups :
160
- raise MissingArgumentError ('Either `groups` or `sums ` have to be set.' )
163
+ raise MissingArgumentError ('Either `groups` or `metrics ` have to be set.' )
161
164
162
165
if scope is None :
163
- for i in report_json .get ('groups' , []) + report_json .get ('sums ' , []):
164
- if i . split ( '_' )[ 0 ] in [ 'advertiser' , 'campaign' , 'creative' , 'conversion_pixel' ] :
165
- scope = 'advertiser '
166
+ for i in report_json .get ('groups' , []) + report_json .get ('metrics ' , []):
167
+ if '_network' in i :
168
+ scope = 'network '
166
169
break
167
170
else :
168
- for i in report_json .get ('groups' , []) + report_json .get ('sums' , []):
169
- if i .split ('_' )[0 ] in ['site' , 'placement' , 'user' ]:
170
- scope = 'publisher'
171
- break
172
- else :
171
+ user = self .user
172
+ if len (user .networks ) > 0 :
173
+ pass # user has network access so could be any report (leave scope as None)
174
+ elif len (user .publishers ) > 0 and len (user .advertisers ) == 0 :
175
+ scope = 'publishers'
176
+ elif len (user .advertisers ) > 0 and len (user .publishers ) == 0 :
177
+ scope = 'advertisers'
178
+
179
+ if scope is None :
173
180
raise MissingArgumentError ('Unable to detect scope automatically. '
174
181
'Please set `scope` parameter.' )
175
182
report_json ['scope' ] = scope
0 commit comments