Package python ::
Module ReportClient
|
|
1
2 import xml.dom.minidom
3 import urllib
4 import StringIO
5 import ConfigParser
6 import urllib
7 import urllib2
8 import csv
9 import json
10
11
13 """
14 ReportClient provides the python based language binding to the https based api of ManageEngine Analytics Plus.
15
16 """
18 """
19 Creates a new C{ReportClient} instance.
20 @param authtoken: User's authtoken.
21 @type authtoken:string
22 """
23
24 self.reportServerURL="https://localhost:8443"
25 self.authtoken=authtoken
26 """
27 Internal method. To send request and receive response from server
28 """
29 - def __sendRequest(self,url,httpMethod,payLoad,action,callBackData):
30 respObj = self.getResp(url,httpMethod,payLoad)
31 if(respObj.status_code != 200):
32 raise ServerError(respObj)
33 else:
34 return self.handleResponse(respObj,action,callBackData)
35
37 """
38 Internal method. To be used by classes extending this.
39 """
40 if("ADDROW" == action):
41 resp = response.content
42 dom = ReportClientHelper.getAsDOM(resp)
43 try:
44 dict = {}
45 cols = dom.getElementsByTagName("column");
46 for el in cols:
47 content= ReportClientHelper.getText(el.childNodes).strip()
48 if("" == content):
49 content=None
50 dict[el.getAttribute("name")] = content
51 return dict
52 except Exception,inst:
53 raise ParseError(resp,"Retured XML format for ADDROW not proper.Could possibly be version mismatch",inst)
54 elif("UPDATE" == action):
55 return None
56 elif("GETCOPYDBKEY" == action):
57 resp = response.content
58 dom = ReportClientHelper.getAsDOM(resp)
59 return ReportClientHelper.getInfo(dom,"copydbkey",response)
60 elif("COPYDB" == action):
61 return None
62 elif("DELETE" == action):
63 return None
64 elif("EXPORT" == action):
65 f = callBackData
66 f.write(response.content)
67 return None
68 elif("IMPORT" == action):
69 return ImportResult(response.content)
70 elif("GETCOPYDBKEY" == action):
71 resp = response.content
72 dom = ReportClientHelper.getAsDOM(resp)
73 return ReportClientHelper.getInfo(dom,"copydbkey",response)
74 elif("GETDATABASENAME" == action):
75 resp = response.content
76 dom = ReportClientHelper.getAsDOM(resp)
77 return ReportClientHelper.getInfo(dom,"dbname",response)
78 elif("GETDATABASEID" == action):
79 resp = response.content
80 dom = ReportClientHelper.getAsDOM(resp)
81 return ReportClientHelper.getInfo(dom,"dbid",response)
82 elif("GETVIEWNAME" == action):
83 resp = response.content
84 dom = ReportClientHelper.getAsDOM(resp)
85 return ReportClientHelper.getInfo(dom,"viewname",response)
86 elif("GETINFO" == action):
87 resp = response.content
88 dom = ReportClientHelper.getAsDOM(resp)
89 result = {}
90 result['objid'] = ReportClientHelper.getInfo(dom,"objid",response)
91 result['dbid'] = ReportClientHelper.getInfo(dom,"dbid",response)
92 return result
93 elif("GETVIEWURL" == action):
94 resp = response.content
95 dom = ReportClientHelper.getAsDOM(resp)
96 return ReportClientHelper.getInfo(dom,"viewurl",response)
97 elif("GETEMBEDURL" == action):
98 resp = response.content
99 dom = ReportClientHelper.getAsDOM(resp)
100 return ReportClientHelper.getInfo(dom,"embedurl",response)
101 elif("DATABASEMETADATA" == action):
102 resp = response.content
103 resp = json.loads(resp)
104 return resp["response"]["result"]
105 elif("GETSHAREINFO" == action):
106 return ShareInfo(response.content)
107 elif("GETUSERPLANDETAILS" == action):
108 return PlanInfo(response.content)
109 elif("ISDBEXIST" == action):
110 resp = response.content
111 resp = json.loads(resp)
112 return resp["response"]["result"]["isdbexist"]
113 elif("GETUSERS" == action):
114 resp = response.content
115 resp = json.loads(resp)
116 return resp["response"]["result"]
117 elif("AUTOGENREPORTS" == action):
118 resp = response.content
119 resp = json.loads(resp)
120 return resp["response"]["result"]
121 elif("HIDECOLUMN" == action):
122 resp = response.content
123 resp = json.loads(resp)
124 return resp["response"]["result"]
125 elif("SHOWCOLUMN" == action):
126 resp = response.content
127 resp = json.loads(resp)
128 return resp["response"]["result"]
129 elif("ENABLEDOMAINDB" == action):
130 resp = response.content
131 resp = json.loads(resp)
132 return resp["response"]["result"]
133 elif("DISABLEDOMAINDB" == action):
134 resp = response.content
135 resp = json.loads(resp)
136 return resp["response"]["result"]
137 elif("CREATESIMILARVIEWS" == action):
138 resp = response.content
139 resp = json.loads(resp)
140 return resp["response"]["result"]
141
142
143 - def addRow(self,tableURI,columnValues,config=None):
144 """
145 Adds a row to the specified table identified by the URI.
146 @param tableURI: The URI of the table. See L{getURI<getURI>}.
147 @type tableURI:string
148 @param columnValues: Contains the values for the row. The column name(s) are the key.
149 @type columnValues:dictionary
150 @param config: Contains any additional control parameters. Can be C{None}.
151 @type config:dictionary
152 @return: The values of the row.
153 @rtype:dictionary
154 @raise ServerError: If the server has recieved the request but did not process the request
155 due to some error.
156 @raise ParseError: If the server has responded but client was not able to parse the response.
157 """
158 payLoad = ReportClientHelper.getAsPayLoad([columnValues,config],None,None)
159 url = ReportClientHelper.addQueryParams(tableURI,self.authtoken,"ADDROW","XML")
160 return self.__sendRequest(url,"POST",payLoad,"ADDROW",None)
161
163 """
164 Delete the data in the specified table identified by the URI.
165 @param tableURI: The URI of the table. See L{getURI<getURI>}.
166 @type tableURI:string
167 @param criteria: The criteria to be applied for deleting. Only rows matching the criteria will be
168 updated. Can be C{None}. Incase it is C{None}, then all rows will be deleted.
169 @type criteria:string
170 @param config: Contains any additional control parameters. Can be C{None}.
171 @type config:dictionary
172 @raise ServerError: If the server has recieved the request but did not process the request
173 due to some error.
174 @raise ParseError: If the server has responded but client was not able to parse the response.
175 """
176 payLoad = ReportClientHelper.getAsPayLoad([config],criteria,None)
177 url = ReportClientHelper.addQueryParams(tableURI,self.authtoken,"DELETE","XML")
178 self.__sendRequest(url,"POST",payLoad,"DELETE",None)
179
180 - def updateData(self,tableURI,columnValues,criteria,config=None):
181 """
182 update the data in the specified table identified by the URI.
183 @param tableURI: The URI of the table. See L{getURI<getURI>}.
184 @type tableURI:string
185 @param columnValues: Contains the values for the row. The column name(s) are the key.
186 @type columnValues:dictionary
187 @param criteria: The criteria to be applied for updating. Only rows matching the criteria will be
188 updated. Can be C{None}. Incase it is C{None}, then all rows will be updated.
189 @type criteria:string
190 @param config: Contains any additional control parameters. Can be C{None}.
191 @type config:dictionary
192 @raise ServerError: If the server has recieved the request but did not process the request
193 due to some error.
194 @raise ParseError: If the server has responded but client was not able to parse the response.
195 """
196 payLoad = ReportClientHelper.getAsPayLoad([columnValues,config],criteria,None)
197 url = ReportClientHelper.addQueryParams(tableURI,self.authtoken,"UPDATE","XML")
198 self.__sendRequest(url,"POST",payLoad,"UPDATE",None)
199
200 - def importData(self,tableURI,importType,importContent,importConfig=None):
201 """
202 Bulk import data into the table identified by the URI.
203 @param tableURI: The URI of the table. See L{getURI<getURI>}.
204 @type tableURI:string
205 @param importType: The type of import.
206 Can be one of
207 1. APPEND
208 2. TRUNCATEADD
209 3. UPDATEADD
210 See U{Import types<http://zohoreportsapi.wiki.zoho.com/Importing-CSV-File.html>} for more details.
211 @type importType:string
212 @param importContent: The data in csv format.
213 @type importContent:string
214 @param importConfig: Contains any additional control parameters.
215 See U{Import types<http://zohoreportsapi.wiki.zoho.com/Importing-CSV-File.html>} for more details.
216 @type importConfig:dictionary
217 @return: An L{ImportResult} containing the results of the Import
218 @rtype:L{ImportResult}
219 @raise ServerError: If the server has recieved the request but did not process the request
220 due to some error.
221 @raise ParseError: If the server has responded but client was not able to parse the response.
222 """
223 dict = {"ZOHO_AUTO_IDENTIFY":"true","ZOHO_ON_IMPORT_ERROR":"ABORT",
224 "ZOHO_CREATE_TABLE":"false","ZOHO_IMPORT_TYPE":importType,
225 "ZOHO_IMPORT_DATA":importContent};
226
227 payLoad = ReportClientHelper.getAsPayLoad([dict,importConfig],None,None);
228 url = ReportClientHelper.addQueryParams(tableURI,self.authtoken,"IMPORT","XML")
229 return self.__sendRequest(url,"POST",payLoad,"IMPORT",None)
230
232 """
233 Bulk import data into the table identified by the URI.
234 @param tableURI: The URI of the table. See L{getURI<getURI>}.
235 @type tableURI:string
236 @param importType: The type of import.
237 Can be one of
238 1. APPEND
239 2. TRUNCATEADD
240 3. UPDATEADD
241 See U{Import types<http://zohoreportsapi.wiki.zoho.com/Importing-CSV-File.html>} for more details.
242 @type importType:string
243 @param importContent: The data in csv format or json.
244 @type importContent:string
245 @param importConfig: Contains any additional control parameters.
246 See U{Import types<http://zohoreportsapi.wiki.zoho.com/Importing-CSV-File.html>} for more details.
247 @type importConfig:dictionary
248 @return: An L{ImportResult} containing the results of the Import.
249 @rtype:L{ImportResult}
250 @raise ServerError: If the server has recieved the request but did not process the request
251 due to some error.
252 @raise ParseError: If the server has responded but client was not able to parse the response.
253 """
254 dict = {"ZOHO_AUTO_IDENTIFY":"true","ZOHO_ON_IMPORT_ERROR":"ABORT",
255 "ZOHO_CREATE_TABLE":"false","ZOHO_IMPORT_TYPE":importType,
256 "ZOHO_IMPORT_DATA":importContent};
257
258 payLoad = ReportClientHelper.getAsPayLoad([dict,importConfig],None,None);
259 url = ReportClientHelper.addQueryParams(tableURI,self.authtoken,"IMPORT","XML")
260 return self.__sendRequest(url,"POST",payLoad,"IMPORT",None)
261
262 - def exportData(self,tableOrReportURI,format,exportToFileObj,criteria=None,config=None):
263 """
264 Export the data in the specified table identified by the URI.
265 @param tableOrReportURI: The URI of the table. See L{getURI<getURI>}.
266 @type tableOrReportURI:string
267 @param format: The format in which the data is to be exported.
268 See U{Supported Export Formats<http://zohoreportsapi.wiki.zoho.com/Export.html>} for
269 the supported types.
270 @type format:string
271 @param exportToFileObj: File (or file like object) to which the exported data is to be written
272 @type exportToFileObj:file
273 @param criteria: The criteria to be applied for exporting. Only rows matching the criteria will be
274 exported. Can be C{None}. Incase it is C{None}, then all rows will be exported.
275 @type criteria:string
276 @param config: Contains any additional control parameters. Can be C{None}.
277 @type config:dictionary
278 @raise ServerError: If the server has recieved the request but did not process the request
279 due to some error.
280 @raise ParseError: If the server has responded but client was not able to parse the response.
281 """
282 payLoad = ReportClientHelper.getAsPayLoad([config],criteria,None)
283 url = ReportClientHelper.addQueryParams(tableOrReportURI,self.authtoken,"EXPORT",format)
284 return self.__sendRequest(url,"POST",payLoad,"EXPORT",exportToFileObj)
285
287 """
288 Export the data with the specified SQL query identified by the URI.
289 @param tableOrReportURI: The URI of the database. See L{getDBURI<getDBURI>}.
290 @type tableOrReportURI:string
291 @param format: The format in which the data is to be exported.
292 See U{Supported Export Formats<http://zohoreportsapi.wiki.zoho.com/Export.html>} for
293 the supported types.
294 @type format:string
295 @param exportToFileObj: File (or file like object) to which the exported data is to be written
296 @type exportToFileObj:file
297 @param sql: The sql whose output need to be exported.
298 @type sql:string
299 @param config: Contains any additional control parameters. Can be C{None}.
300 @type config:dictionary
301 @raise ServerError: If the server has recieved the request but did not process the request
302 due to some error.
303 @raise ParseError: If the server has responded but client was not able to parse the response.
304 """
305 payLoad = ReportClientHelper.getAsPayLoad([config],None,sql)
306 url = ReportClientHelper.addQueryParams(tableOrReportURI,self.authtoken,"EXPORT",format)
307 return self.__sendRequest(url,"POST",payLoad,"EXPORT",exportToFileObj)
308
310 """
311 Copy the specified database identified by the URI.
312 @param dbURI: The URI of the database. See L{getDBURI<getDBURI>}.
313 @type dbURI:string
314 @param config: Contains any additional control parameters like ZOHO_DATABASE_NAME.
315 @type config:dictionary
316 @return: The new database id.
317 @rtype: string
318 @raise ServerError: If the server has recieved the request but did not process the request
319 due to some error.
320 @raise ParseError: If the server has responded but client was not able to parse the response.
321 """
322 payLoad = ReportClientHelper.getAsPayLoad([config],None,None)
323 url = ReportClientHelper.addQueryParams(dbURI,self.authtoken,"COPYDATABASE","XML")
324 return self.__sendRequest(url,"POST",payLoad,"COPYDB",None)
325
327 """
328 Delete the specified database.
329 @param userURI: The URI of the user. See L{getUserURI<getUserURI>}.
330 @type userURI:string
331 @param databaseName: The name of the database to be deleted.
332 @type databaseName:string
333 @param config: Contains any additional control parameters.
334 @type config:dictionary
335 @raise ServerError: If the server has recieved the request but did not process the request
336 due to some error.
337 @raise ParseError: If the server has responded but client was not able to parse the response.
338 """
339 payLoad = ReportClientHelper.getAsPayLoad([config],None,None)
340 url = ReportClientHelper.addQueryParams(userURI,self.authtoken,"DELETEDATABASE","XML")
341 url += "&ZOHO_DATABASE_NAME=" + urllib.quote(databaseName)
342 return self.__sendRequest(url,"POST",payLoad,"DELETEDATABASE",None)
343
344 - def enableDomainDB(self,userUri,dbName,domainName,config=None):
345 """
346 Enable database for custom domain.
347 @param userUri: The URI of the user. See L{getUserURI<getUserURI>}.
348 @type userUri:string
349 @param dbName: The database name.
350 @type dbName:string
351 @param domainName: The domain name.
352 @type domainName:string
353 @param config: Contains any additional control parameters. Can be C{None}.
354 @type config:dictionary
355 @return: Domain database status.
356 @rtype:dictionary
357 @raise ServerError: If the server has recieved the request but did not process the request
358 due to some error.
359 @raise ParseError: If the server has responded but client was not able to parse the response.
360 """
361 payLoad = ReportClientHelper.getAsPayLoad([config],None,None)
362 url = ReportClientHelper.addQueryParams(userUri,self.authtoken,"ENABLEDOMAINDB","JSON")
363 url += "&DBNAME=" + urllib.quote(dbName)
364 url += "&DOMAINNAME=" + urllib.quote(domainName)
365 return self.__sendRequest(url,"POST",payLoad,"ENABLEDOMAINDB",None)
366
367 - def disableDomainDB(self,userUri,dbName,domainName,config=None):
368 """
369 Disable database for custom domain.
370 @param userUri: The URI of the user. See L{getUserURI<getUserURI>}.
371 @type userUri:string
372 @param dbName: The database name.
373 @type dbName:string
374 @param domainName: The domain name.
375 @type domainName:string
376 @param config: Contains any additional control parameters. Can be C{None}.
377 @type config:dictionary
378 @return: Domain database status.
379 @rtype:dictionary
380 @raise ServerError: If the server has recieved the request but did not process the request
381 due to some error.
382 @raise ParseError: If the server has responded but client was not able to parse the response.
383 """
384 payLoad = ReportClientHelper.getAsPayLoad([config],None,None)
385 url = ReportClientHelper.addQueryParams(userUri,self.authtoken,"DISABLEDOMAINDB","JSON")
386 url += "&DBNAME=" + urllib.quote(dbName)
387 url += "&DOMAINNAME=" + urllib.quote(domainName)
388 return self.__sendRequest(url,"POST",payLoad,"DISABLEDOMAINDB",None)
389
391 """
392 Create a table in the specified database.
393 @param dbURI: The URI of the database. See L{getDBURI<getDBURI>}.
394 @type dbURI:string
395 @param tableDesign: Table structure in JSON format (includes table name, description, folder name, column and lookup details, is system table).
396 @type tableDesign:string
397 @param config: Contains any additional control parameters. Can be C{None}.
398 @type config:dictionary
399 @raise ServerError: If the server has recieved the request but did not process the request
400 due to some error.
401 @raise ParseError: If the server has responded but client was not able to parse the response.
402 """
403 payLoad = ReportClientHelper.getAsPayLoad([config],None,None)
404 url = ReportClientHelper.addQueryParams(dbURI,self.authtoken,"CREATETABLE","XML")
405 url += "&ZOHO_TABLE_DESIGN=" + urllib.quote(tableDesign)
406 self.__sendRequest(url,"POST",payLoad,"CREATETABLE",None)
407
409 """
410 Create a report in the specified database.
411 @param dbURI: The URI of the database. See L{getDBURI<getDBURI>}.
412 @type dbURI:string
413 @param viewDesign: View structure in JSON format.
414 @type viewDesign:string
415 @param config: Contains any additional control parameters. Can be C{None}.
416 @type config:dictionary
417 @raise ServerError: If the server has recieved the request but did not process the request
418 due to some error.
419 @raise ParseError: If the server has responded but client was not able to parse the response.
420 """
421 payLoad = ReportClientHelper.getAsPayLoad([config],None,None)
422 url = ReportClientHelper.addQueryParams(dbURI,self.authtoken,"CREATEANALYSISVIEW","XML")
423 url += "&ZOHO_VIEW_DATA=" + urllib.quote(viewDesign)
424 self.__sendRequest(url,"POST",payLoad,"CREATEANALYSISVIEW",None)
425
427 """
428 Generate reports for the particular table.
429 @param tableURI: The URI of the table. See L{getURI<getURI>}.
430 @type tableURI:string
431 @param source: Source should be column or table.
432 @type source:string
433 @param config: Contains any additional control parameters. Can be C{None}.
434 @type config:dictionary
435 @return: Auto generate report result.
436 @rtype:dictionary
437 @raise ServerError: If the server has recieved the request but did not process the request
438 due to some error.
439 @raise ParseError: If the server has responded but client was not able to parse the response.
440 """
441 payLoad = ReportClientHelper.getAsPayLoad([config],None,None)
442 url = ReportClientHelper.addQueryParams(tableURI,self.authtoken,"AUTOGENREPORTS","JSON")
443 url += "&ZOHO_SOURCE=" + urllib.quote(source)
444 return self.__sendRequest(url,"POST",payLoad,"AUTOGENREPORTS",None)
445
446 - def createSimilarViews(self,tableURI,refView,folderName,customFormula,aggFormula,config=None):
447 """
448 This method is used to create similar views .
449 @param tableURI: The URI of the table. See L{getURI<getURI>}.
450 @type tableURI:string
451 @param refView: It contains the refrence view name.
452 @type refView:string
453 @param folderName: It contains the folder name where the reports to be saved.
454 @type folderName:string
455 @param customFormula: If its true the reports created with custom formula.
456 @type customFormula:bool
457 @param aggFormula: If its true the reports created with aggrigate formula.
458 @type aggFormula:bool
459 @param config: Contains any additional control parameters. Can be C{None}.
460 @type config:dictionary
461 @return: Generated reports status.
462 @rtype:dictionary
463 @raise ServerError: If the server has recieved the request but did not process the request
464 due to some error.
465 @raise ParseError: If the server has responded but client was not able to parse the response.
466 """
467 payLoad = ReportClientHelper.getAsPayLoad([config],None,None)
468 url = ReportClientHelper.addQueryParams(tableURI,self.authtoken,"CREATESIMILARVIEWS","JSON")
469 url += "&ZOHO_REFVIEW=" + urllib.quote(refView)
470 url += "&ZOHO_FOLDERNAME=" + urllib.quote(folderName)
471 url += "&ISCOPYCUSTOMFORMULA=" + urllib.quote("true" if customFormula == True else "false")
472 url += "&ISCOPYAGGFORMULA=" + urllib.quote("true" if aggFormula == True else "false")
473 return self.__sendRequest(url,"POST",payLoad,"CREATESIMILARVIEWS",None)
474
475 - def renameView(self,dbURI,viewName,newViewName,viewDesc="",config=None):
476 """
477 Rename the specified view with the new name and description.
478 @param dbURI: The URI of the database. See L{getDBURI<getDBURI>}.
479 @type dbURI:string
480 @param viewName: Current name of the view.
481 @type viewName:string
482 @param newViewName: New name for the view.
483 @type newViewName:string
484 @param viewDesc: New description for the view.
485 @type viewDesc:string
486 @param config: Contains any additional control parameters. Can be C{None}.
487 @type config:dictionary
488 @raise ServerError: If the server has recieved the request but did not process the request
489 due to some error.
490 @raise ParseError: If the server has responded but client was not able to parse the response.
491 """
492 payLoad = ReportClientHelper.getAsPayLoad([config],None,None)
493 url = ReportClientHelper.addQueryParams(dbURI,self.authtoken,"RENAMEVIEW","XML")
494 url += "&ZOHO_VIEWNAME=" + urllib.quote(viewName)
495 url += "&ZOHO_NEW_VIEWNAME=" + urllib.quote(newViewName)
496 url += "&ZOHO_NEW_VIEWDESC=" + urllib.quote(viewDesc)
497 self.__sendRequest(url,"POST",payLoad,"RENAMEVIEW",None)
498
499 - def copyReports(self,dbURI,views,dbName,dbKey,config=None):
500 """
501 The Copy Reports API is used to copy one or more reports from one database to another within the same account or even across user accounts.
502 @param dbURI: The URI of the database. See L{getDBURI<getDBURI>}.
503 @type dbURI:string
504 @param views: This parameter holds the list of view names.
505 @type views:string
506 @param dbName: The database name where the report's had to be copied.
507 @type dbName:string
508 @param dbKey: The secret key used for allowing the user to copy the report.
509 @type dbKey:string
510 @param config: Contains any additional control parameters. Can be C{None}.
511 @type config:dictionary
512 @raise ServerError: If the server has recieved the request but did not process the request
513 due to some error.
514 @raise ParseError: If the server has responded but client was not able to parse the response.
515 """
516 payLoad = ReportClientHelper.getAsPayLoad([config],None,None)
517 url = ReportClientHelper.addQueryParams(dbURI,self.authtoken,"COPYREPORTS","XML")
518 url += "&ZOHO_VIEWTOCOPY=" + urllib.quote(views)
519 url += "&ZOHO_DATABASE_NAME=" + urllib.quote(dbName)
520 url += "&ZOHO_COPY_DB_KEY=" + urllib.quote(dbKey)
521 self.__sendRequest(url,"POST",payLoad,"COPYREPORTS",None)
522
546
547 - def addColumn(self,tableURI,columnName,dataType,config=None):
548 """
549 Adds a column into ManageEngine Analytics Plus Table.
550 @param tableURI: The URI of the table. See L{getURI<getURI>}.
551 @type tableURI:string
552 @param columnName: The column name to be added into ManageEngine Analytics Plus Table.
553 @type columnName:string
554 @param dataType: The data type of the column to be added into ManageEngine Analytics Plus Table.
555 @type dataType:string
556 @param config: Contains any additional control parameters.
557 @type config:dictionary
558 @raise ServerError: If the server has recieved the request but did not process the request
559 due to some error.
560 @raise ParseError: If the server has responded but client was not able to parse the response.
561 """
562 payLoad = ReportClientHelper.getAsPayLoad([config],None,None)
563 url = ReportClientHelper.addQueryParams(tableURI,self.authtoken,"ADDCOLUMN","XML")
564 url += "&ZOHO_COLUMNNAME=" + urllib.quote(columnName)
565 url += "&ZOHO_DATATYPE=" + urllib.quote(dataType)
566 return self.__sendRequest(url,"POST",payLoad,"ADDCOLUMN",None)
567
569 """
570 Deletes a column from ManageEngine Analytics Plus Table.
571 @param tableURI: The URI of the table. See L{getURI<getURI>}.
572 @type tableURI:string
573 @param columnName: The column name to be deleted from ManageEngine Analytics Plus Table.
574 @type columnName:string
575 @param config: Contains any additional control parameters.
576 @type config:dictionary
577 @raise ServerError: If the server has recieved the request but did not process the request
578 due to some error.
579 @raise ParseError: If the server has responded but client was not able to parse the response.
580 """
581 payLoad = ReportClientHelper.getAsPayLoad([config],None,None)
582 url = ReportClientHelper.addQueryParams(tableURI,self.authtoken,"DELETECOLUMN","XML")
583 url += "&ZOHO_COLUMNNAME=" + urllib.quote(columnName)
584 return self.__sendRequest(url,"POST",payLoad,"DELETECOLUMN",None)
585
586 - def renameColumn(self,tableURI,oldColumnName,newColumnName,config=None):
587 """
588 Deactivate the users in the ManageEngine Analytics Plus Account.
589 @param tableURI: The URI of the table. See L{getURI<getURI>}.
590 @type tableURI:string
591 @param oldColumnName: The column name to be renamed in ManageEngine Analytics Plus Table.
592 @type oldColumnName:string
593 @param newColumnName: New name for the column.
594 @type newColumnName:string
595 @param config: Contains any additional control parameters.
596 @type config:dictionary
597 @raise ServerError: If the server has recieved the request but did not process the request
598 due to some error.
599 @raise ParseError: If the server has responded but client was not able to parse the response.
600 """
601 payLoad = ReportClientHelper.getAsPayLoad([config],None,None)
602 url = ReportClientHelper.addQueryParams(tableURI,self.authtoken,"RENAMECOLUMN","XML")
603 url += "&OLDCOLUMNNAME=" + urllib.quote(oldColumnName)
604 url += "&NEWCOLUMNNAME=" + urllib.quote(newColumnName)
605 return self.__sendRequest(url,"POST",payLoad,"RENAMECOLUMN",None)
606
607 - def hideColumn(self,tableURI,columnNames,config=None):
608 """
609 Hide the columns in the table.
610 @param tableURI: The URI of the table. See L{getURI<getURI>}.
611 @type tableURI:string
612 @param columnNames: Contains list of column names.
613 @type columnNames:list
614 @param config: Contains any additional control parameters. Can be C{None}.
615 @type config:dictionary
616 @return: Column status.
617 @rtype:list
618 @raise ServerError: If the server has recieved the request but did not process the request
619 due to some error.
620 @raise ParseError: If the server has responded but client was not able to parse the response.
621 """
622 payLoad = ReportClientHelper.getAsPayLoad([config],None,None)
623 url = ReportClientHelper.addQueryParams(tableURI,self.authtoken,"HIDECOLUMN","JSON")
624 for columnName in columnNames:
625 url += "&ZOHO_COLUMNNAME=" + urllib.quote(columnName)
626 return self.__sendRequest(url,"POST",payLoad,"HIDECOLUMN",None)
627
628 - def showColumn(self,tableURI,columnNames,config=None):
629 """
630 Show the columns in the table.
631 @param tableURI: The URI of the table. See L{getURI<getURI>}.
632 @type tableURI:string
633 @param columnNames: Contains list of column names.
634 @type columnNames:list
635 @param config: Contains any additional control parameters. Can be C{None}.
636 @type config:dictionary
637 @return: Column status.
638 @rtype:list
639 @raise ServerError: If the server has recieved the request but did not process the request
640 due to some error.
641 @raise ParseError: If the server has responded but client was not able to parse the response.
642 """
643 payLoad = ReportClientHelper.getAsPayLoad([config],None,None)
644 url = ReportClientHelper.addQueryParams(tableURI,self.authtoken,"SHOWCOLUMN","JSON")
645 for columnName in columnNames:
646 url += "&ZOHO_COLUMNNAME=" + urllib.quote(columnName)
647 return self.__sendRequest(url,"POST",payLoad,"SHOWCOLUMN",None)
648
649 - def addLookup(self,tableURI,columnName,referedTable,referedColumn,onError,config=None):
650 """
651 Add the lookup for the given column.
652 @param tableURI: The URI of the table. See L{getURI<getURI>}.
653 @type tableURI:string
654 @param columnName: Name of the column (Child column).
655 @type columnName:string
656 @param referedTable: Name of the referred table (parent table).
657 @type referedTable:string
658 @param referedColumn: Name of the referred column (parent column).
659 @type referedColumn:string
660 @param onError: This parameter controls the action to be taken incase there is an error during lookup.
661 @type onError:string
662 @param config: Contains any additional control parameters. Can be C{None}.
663 @type config:dictionary
664 @raise ServerError: If the server has recieved the request but did not process the request
665 due to some error.
666 @raise ParseError: If the server has responded but client was not able to parse the response.
667 """
668 payLoad = ReportClientHelper.getAsPayLoad([config],None,None)
669 url = ReportClientHelper.addQueryParams(tableURI,self.authtoken,"ADDLOOKUP","XML")
670 url += "&ZOHO_COLUMNNAME=" + urllib.quote(columnName)
671 url += "&ZOHO_REFERREDTABLE=" + urllib.quote(referedTable)
672 url += "&ZOHO_REFERREDCOLUMN=" + urllib.quote(referedColumn)
673 url += "&ZOHO_IFERRORONCONVERSION=" + urllib.quote(onError)
674 self.__sendRequest(url,"POST",payLoad,"ADDLOOKUP",None)
675
677 """
678 Remove the lookup for the given column.
679 @param tableURI: The URI of the table. See L{getURI<getURI>}.
680 @type tableURI:string
681 @param columnName: Name of the column.
682 @type columnName:string
683 @param config: Contains any additional control parameters. Can be C{None}.
684 @type config:dictionary
685 @raise ServerError: If the server has recieved the request but did not process the request
686 due to some error.
687 @raise ParseError: If the server has responded but client was not able to parse the response.
688 """
689 payLoad = ReportClientHelper.getAsPayLoad([config],None,None)
690 url = ReportClientHelper.addQueryParams(tableURI,self.authtoken,"REMOVELOOKUP","XML")
691 url += "&ZOHO_COLUMNNAME=" + urllib.quote(columnName)
692 self.__sendRequest(url,"POST",payLoad,"REMOVELOOKUP",None)
693
713
715 """
716 Get database name for a specified database identified by the URI.
717 @param userURI: The URI of the user. See L{getUserURI<getUserURI>}.
718 @type userURI:string
719 @param dbid: The ID of the database.
720 @type dbid:string
721 @param config: Contains any additional control parameters. Can be C{None}.
722 @type config:dictionary
723 @return: The Database name.
724 @rtype: string
725 @raise ServerError: If the server has recieved the request but did not process the request
726 due to some error.
727 @raise ParseError: If the server has responded but client was not able to parse the response.
728 """
729 payLoad = ReportClientHelper.getAsPayLoad([config],None,None)
730 url = ReportClientHelper.addQueryParams(userURI,self.authtoken,"GETDATABASENAME","XML")
731 url += "&DBID=" + urllib.quote(dbid)
732 return self.__sendRequest(url,"POST",payLoad,"GETDATABASENAME",None)
733
735 """
736 Get database id for a specified database identified by the URI.
737 @param userURI: The URI of the user. See L{getUserURI<getUserURI>}.
738 @type userURI:string
739 @param dbName: The name of the database.
740 @type dbName:string
741 @param config: Contains any additional control parameters. Can be C{None}.
742 @type config:dictionary
743 @return: The Database name.
744 @rtype: string
745 @raise ServerError: If the server has recieved the request but did not process the request
746 due to some error.
747 @raise ParseError: If the server has responded but client was not able to parse the response.
748 """
749 payLoad = ReportClientHelper.getAsPayLoad([config],None,None)
750 url = ReportClientHelper.addQueryParams(userURI,self.authtoken,"GETDATABASEID","XML")
751 url += "&ZOHO_DATABASE_NAME=" + urllib.quote(dbName)
752 return self.__sendRequest(url,"POST",payLoad,"GETDATABASEID",None)
753
754 - def isDbExist(self,userURI,dbName,config=None):
755 """
756 Check wheather the database is exist or not.
757 @param userURI: The URI of the user. See L{getUserURI<getUserURI>}.
758 @type userURI:string
759 @param dbName: Database name.
760 @type dbName:string
761 @param config: Contains any additional control parameters. Can be C{None}.
762 @type config:dictionary
763 @return: Return wheather the database is exist or not.
764 @rtype:string
765 @raise ServerError: If the server has recieved the request but did not process the request
766 due to some error.
767 @raise ParseError: If the server has responded but client was not able to parse the response.
768 """
769 payLoad = ReportClientHelper.getAsPayLoad([config],None,None)
770 url = ReportClientHelper.addQueryParams(userURI,self.authtoken,"ISDBEXIST","JSON")
771 url += "&ZOHO_DB_NAME=" + urllib.quote(dbName)
772 return self.__sendRequest(url,"POST",payLoad,"ISDBEXIST",None)
773
775 """
776 Get copy database key for specified database identified by the URI.
777 @param dbURI: The URI of the database. See L{getDBURI<getDBURI>}.
778 @type dbURI:string
779 @param config: Contains any additional control parameters like ZOHO_REGENERATE_KEY. Can be C{None}.
780 @type config:dictionary
781 @return: Copy Database key.
782 @rtype:string
783 @raise ServerError: If the server has recieved the request but did not process the request
784 due to some error.
785 @raise ParseError: If the server has responded but client was not able to parse the response.
786 """
787 payLoad = ReportClientHelper.getAsPayLoad([config],None,None)
788 url = ReportClientHelper.addQueryParams(dbURI,self.authtoken,"GETCOPYDBKEY","XML")
789 return self.__sendRequest(url,"POST",payLoad,"GETCOPYDBKEY",None)
790
792 """
793 This function returns the name of a view in ManageEngine Analytics Plus.
794 @param userURI: The URI of the user. See L{getUserURI<getUserURI>}.
795 @type userURI:string
796 @param objid: The view id (object id).
797 @type objid:string
798 @param config: Contains any additional control parameters. Can be C{None}.
799 @type config:dictionary
800 @return: The View name.
801 @rtype: string
802 @raise ServerError: If the server has recieved the request but did not process the request
803 due to some error.
804 @raise ParseError: If the server has responded but client was not able to parse the response.
805 """
806 payLoad = ReportClientHelper.getAsPayLoad([config],None,None)
807 url = ReportClientHelper.addQueryParams(userURI,self.authtoken,"GETVIEWNAME","XML")
808 url += "&OBJID=" + urllib.quote(objid)
809 return self.__sendRequest(url,"POST",payLoad,"GETVIEWNAME",None)
810
811 - def getInfo(self,tableURI,config=None):
812 """
813 This method returns the Database ID (DBID) and View ID (OBJID) of the corresponding Database.
814 @param tableURI: The URI of the table. See L{getURI<getURI>}.
815 @type tableURI:string
816 @param config: Contains any additional control parameters. Can be C{None}.
817 @type config:dictionary
818 @return: The View-Id (object id) and Database-Id.
819 @rtype: dictionary
820 @raise ServerError: If the server has recieved the request but did not process the request
821 due to some error.
822 @raise ParseError: If the server has responded but client was not able to parse the response.
823 """
824 payLoad = ReportClientHelper.getAsPayLoad([config],None,None)
825 url = ReportClientHelper.addQueryParams(tableURI,self.authtoken,"GETINFO","XML")
826 return self.__sendRequest(url,"POST",payLoad,"GETINFO",None)
827
828 - def shareView(self,dbURI,emailIds,views,criteria=None,config=None):
829 """
830 This method is used to share the views (tables/reports/dashboards) created in ManageEngine Analytics Plus with users.
831 @param dbURI: The URI of the database. See L{getDBURI<getDBURI>}.
832 @type dbURI:string
833 @param emailIds: It contains the owners email-id.
834 @type emailIds:string
835 @param views: It contains the view names.
836 @type views:string
837 @param criteria: Set criteria for share. Can be C{None}.
838 @type criteria:string
839 @param config: Contains any additional control parameters. Can be C{None}.
840 @type config:dictionary
841 @raise ServerError: If the server has recieved the request but did not process the request
842 due to some error.
843 @raise ParseError: If the server has responded but client was not able to parse the response.
844 """
845 payLoad = ReportClientHelper.getAsPayLoad([config],criteria,None)
846 url = ReportClientHelper.addQueryParams(dbURI,self.authtoken,"SHARE","XML")
847 url += "&ZOHO_EMAILS=" + urllib.quote(emailIds)
848 url += "&ZOHO_VIEWS=" + urllib.quote(views)
849 self.__sendRequest(url,"POST",payLoad,"SHARE",None)
850
852 """
853 This method is used to remove the shared views (tables/reports/dashboards) in ManageEngine Analytics Plus from the users.
854 @param dbURI: The URI of the database. See L{getDBURI<getDBURI>}.
855 @type dbURI:string
856 @param emailIds: It contains the owners email-id.
857 @type emailIds:string
858 @param config: Contains any additional control parameters. Can be C{None}.
859 @type config:dictionary
860 @raise ServerError: If the server has recieved the request but did not process the request
861 due to some error.
862 @raise ParseError: If the server has responded but client was not able to parse the response.
863 """
864 payLoad = ReportClientHelper.getAsPayLoad([config],None,None)
865 url = ReportClientHelper.addQueryParams(dbURI,self.authtoken,"REMOVESHARE","XML")
866 url += "&ZOHO_EMAILS=" + urllib.quote(emailIds)
867 self.__sendRequest(url,"POST",payLoad,"REMOVESHARE",None)
868
870 """
871 This method is used to add new owners to the reports database.
872 @param dbURI: The URI of the database. See L{getDBURI<getDBURI>}.
873 @type dbURI:string
874 @param emailIds: It contains the owners email-id.
875 @type emailIds:string
876 @param config: Contains any additional control parameters. Can be C{None}.
877 @type config:dictionary
878 @raise ServerError: If the server has recieved the request but did not process the request
879 due to some error.
880 @raise ParseError: If the server has responded but client was not able to parse the response.
881 """
882 payLoad = ReportClientHelper.getAsPayLoad([config],None,None)
883 url = ReportClientHelper.addQueryParams(dbURI,self.authtoken,"ADDDBOWNER","XML")
884 url += "&ZOHO_EMAILS=" + urllib.quote(emailIds)
885 self.__sendRequest(url,"POST",payLoad,"ADDDBOWNER",None)
886
888 """
889 This method is used to remove the existing owners from the reports database.
890 @param dbURI: The URI of the database. See L{getDBURI<getDBURI>}.
891 @type dbURI:string
892 @param emailIds: It contains the owners email-id.
893 @type emailIds:string
894 @param config: Contains any additional control parameters. Can be C{None}.
895 @type config:dictionary
896 @raise ServerError: If the server has recieved the request but did not process the request
897 due to some error.
898 @raise ParseError: If the server has responded but client was not able to parse the response.
899 """
900 payLoad = ReportClientHelper.getAsPayLoad([config],None,None)
901 url = ReportClientHelper.addQueryParams(dbURI,self.authtoken,"REMOVEDBOWNER","XML")
902 url += "&ZOHO_EMAILS=" + urllib.quote(emailIds)
903 self.__sendRequest(url,"POST",payLoad,"REMOVEDBOWNER",None)
904
906 """
907 Get the shared informations.
908 @param dbURI: The URI of the database. See L{getDBURI<getDBURI>}.
909 @type dbURI:string
910 @param config: Contains any additional control parameters like ZOHO_REGENERATE_KEY. Can be C{None}.
911 @type config:dictionary
912 @return: ShareInfo object.
913 @rtype: ShareInfo
914 @raise ServerError: If the server has recieved the request but did not process the request
915 due to some error.
916 @raise ParseError: If the server has responded but client was not able to parse the response.
917 """
918 payLoad = ReportClientHelper.getAsPayLoad([config],None,None)
919 url = ReportClientHelper.addQueryParams(dbURI,self.authtoken,"GETSHAREINFO","JSON")
920 return self.__sendRequest(url,"POST",payLoad,"GETSHAREINFO",None)
921
923 """
924 This method returns the URL to access the mentioned view.
925 @param tableURI: The URI of the table. See L{getURI<getURI>}.
926 @type tableURI:string
927 @param config: Contains any additional control parameters. Can be C{None}.
928 @type config:dictionary
929 @return: The view URI.
930 @rtype: string
931 @raise ServerError: If the server has recieved the request but did not process the request
932 due to some error.
933 @raise ParseError: If the server has responded but client was not able to parse the response.
934 """
935 payLoad = ReportClientHelper.getAsPayLoad([config],None,None)
936 url = ReportClientHelper.addQueryParams(tableURI,self.authtoken,"GETVIEWURL","XML")
937 return self.__sendRequest(url,"POST",payLoad,"GETVIEWURL",None)
938
939 - def getEmbedUrl(self,tableURI,criteria=None,config=None):
940 """
941 This method is used to get the embed URL of the particular table / view. This API is available only for the White Label Administrator.
942 @param tableURI: The URI of the table. See L{getURI<getURI>}.
943 @type tableURI:string
944 @param criteria: Set criteria for url. Can be C{None}.
945 @type criteria:string
946 @param config: Contains any additional control parameters. Can be C{None}.
947 @type config:dictionary
948 @return: The embed URI.
949 @rtype: string
950 @raise ServerError: If the server has recieved the request but did not process the request
951 due to some error.
952 @raise ParseError: If the server has responded but client was not able to parse the response.
953 """
954 payLoad = ReportClientHelper.getAsPayLoad([config],criteria,None)
955 url = ReportClientHelper.addQueryParams(tableURI,self.authtoken,"GETEMBEDURL","XML")
956 return self.__sendRequest(url,"POST",payLoad,"GETEMBEDURL",None)
957
958 - def getUsers(self,userURI,config=None):
959 """
960 Get users list for the user account.
961 @param userURI: The URI of the user. See L{getUserURI<getUserURI>}.
962 @type userURI:string
963 @param config: Contains any additional control parameters. Can be C{None}.
964 @type config:dictionary
965 @return: The list of user details.
966 @rtype:list
967 @raise ServerError: If the server has recieved the request but did not process the request
968 due to some error.
969 @raise ParseError: If the server has responded but client was not able to parse the response.
970 """
971 payLoad = ReportClientHelper.getAsPayLoad([config],None,None)
972 url = ReportClientHelper.addQueryParams(userURI,self.authtoken,"GETUSERS","JSON")
973 return self.__sendRequest(url,"POST",payLoad,"GETUSERS",None)
974
975 - def addUser(self,userURI,emailIds,config=None):
976 """
977 Add the users to the ManageEngine Analytics Plus Account.
978 @param userURI: The URI of the user. See L{getUserURI<getUserURI>}.
979 @type userURI:string
980 @param emailIds: The email addresses of the users to be added to the ManageEngine Analytics Plus Account separated by comma.
981 @type emailIds:string
982 @param config: Contains any additional control parameters.
983 @type config:dictionary
984 @raise ServerError: If the server has recieved the request but did not process the request
985 due to some error.
986 @raise ParseError: If the server has responded but client was not able to parse the response.
987 """
988 payLoad = ReportClientHelper.getAsPayLoad([config],None,None)
989 url = ReportClientHelper.addQueryParams(userURI,self.authtoken,"ADDUSER","XML")
990 url += "&ZOHO_EMAILS=" + urllib.quote(emailIds)
991 return self.__sendRequest(url,"POST",payLoad,"ADDUSER",None)
992
993 - def removeUser(self,userURI,emailIds,config=None):
994 """
995 Remove the users from the ManageEngine Analytics Plus Account.
996 @param userURI: The URI of the user. See L{getUserURI<getUserURI>}.
997 @type userURI:string
998 @param emailIds: The email addresses of the users to be removed from the ManageEngine Analytics Plus Account separated by comma.
999 @type emailIds:string
1000 @param config: Contains any additional control parameters.
1001 @type config:dictionary
1002 @raise ServerError: If the server has recieved the request but did not process the request
1003 due to some error.
1004 @raise ParseError: If the server has responded but client was not able to parse the response.
1005 """
1006 payLoad = ReportClientHelper.getAsPayLoad([config],None,None)
1007 url = ReportClientHelper.addQueryParams(userURI,self.authtoken,"REMOVEUSER","XML")
1008 url += "&ZOHO_EMAILS=" + urllib.quote(emailIds)
1009 return self.__sendRequest(url,"POST",payLoad,"REMOVEUSER",None)
1010
1012 """
1013 Activate the users in the ManageEngine Analytics Plus Account.
1014 @param userURI: The URI of the user. See L{getUserURI<getUserURI>}.
1015 @type userURI:string
1016 @param emailIds: The email addresses of the users to be activated in the ManageEngine Analytics Plus Account separated by comma.
1017 @type emailIds:string
1018 @param config: Contains any additional control parameters.
1019 @type config:dictionary
1020 @raise ServerError: If the server has recieved the request but did not process the request
1021 due to some error.
1022 @raise ParseError: If the server has responded but client was not able to parse the response.
1023 """
1024 payLoad = ReportClientHelper.getAsPayLoad([config],None,None)
1025 url = ReportClientHelper.addQueryParams(userURI,self.authtoken,"ACTIVATEUSER","XML")
1026 url += "&ZOHO_EMAILS=" + urllib.quote(emailIds)
1027 return self.__sendRequest(url,"POST",payLoad,"ACTIVATEUSER",None)
1028
1030 """
1031 Deactivate the users in the ManageEngine Analytics Plus Account.
1032 @param userURI: The URI of the user. See L{getUserURI<getUserURI>}.
1033 @type userURI:string
1034 @param emailIds: The email addresses of the users to be deactivated in the ManageEngine Analytics Plus Account separated by comma.
1035 @type emailIds:string
1036 @param config: Contains any additional control parameters.
1037 @type config:dictionary
1038 @raise ServerError: If the server has recieved the request but did not process the request
1039 due to some error.
1040 @raise ParseError: If the server has responded but client was not able to parse the response.
1041 """
1042 payLoad = ReportClientHelper.getAsPayLoad([config],None,None)
1043 url = ReportClientHelper.addQueryParams(userURI,self.authtoken,"DEACTIVATEUSER","XML")
1044 url += "&ZOHO_EMAILS=" + urllib.quote(emailIds)
1045 return self.__sendRequest(url,"POST",payLoad,"DEACTIVATEUSER",None)
1046
1048 """
1049 Get the plan informations.
1050 @param userURI: The URI of the user. See L{getUserURI<getUserURI>}.
1051 @type userURI:string
1052 @param config: Contains any additional control parameters like ZOHO_REGENERATE_KEY. Can be C{None}.
1053 @type config:dictionary
1054 @return: PlanInfo object.
1055 @rtype: PlanInfo
1056 @raise ServerError: If the server has recieved the request but did not process the request
1057 due to some error.
1058 @raise ParseError: If the server has responded but client was not able to parse the response.
1059 """
1060 payLoad = ReportClientHelper.getAsPayLoad([config],None,None)
1061 url = ReportClientHelper.addQueryParams(userURI,self.authtoken,"GETUSERPLANDETAILS","XML")
1062 return self.__sendRequest(url,"POST",payLoad,"GETUSERPLANDETAILS",None)
1063
1065 """
1066 Returns the URI for the specified user..
1067 @param dbOwnerName: User email-id of the database.
1068 @type dbOwnerName:string
1069 @return: The URI for the specified user.
1070 @rtype:string
1071 """
1072 url = self.reportServerURL + "/api/" + urllib.quote(dbOwnerName)
1073 return url
1074
1075 - def getDBURI(self,dbOwnerName,dbName):
1076 """
1077 Returns the URI for the specified database.
1078 @param dbOwnerName: The owner of the database.
1079 @type dbOwnerName:string
1080 @param dbName: The name of the database.
1081 @type dbName:string
1082 @return: The URI for the specified database.
1083 @rtype:string
1084 """
1085 url = self.reportServerURL + "/api/" + urllib.quote(dbOwnerName)
1086 url += "/" + self.splCharReplace(urllib.quote(dbName))
1087 return url
1088
1089 - def getURI(self,dbOwnerName,dbName,tableOrReportName):
1090 """
1091 Returns the URI for the specified database table (or report).
1092 @param dbOwnerName: The owner of the database containing the table (or report).
1093 @type dbOwnerName:string
1094 @param dbName: The name of the database containing the table (or report).
1095 @type dbName:string
1096 @param tableOrReportName: The name of the table (or report).
1097 @type tableOrReportName:string
1098 @return: The URI for the specified table (or report).
1099 @rtype:string
1100 """
1101 url = self.reportServerURL + "/api/" + urllib.quote(dbOwnerName)
1102 url += "/" + self.splCharReplace(urllib.quote(dbName)) + "/" + self.splCharReplace(urllib.quote(tableOrReportName))
1103 return url
1104
1106 """
1107 Internal method for handling special charecters in tale or database name.
1108 """
1109 value = value.replace("/","(/)")
1110 value = value.replace("%5C","(//)")
1111 return value
1112
1113 - def getResp(self,url,httpMethod,payLoad):
1114 """
1115 Internal method.(For google app integ).
1116 """
1117 try:
1118 req = urllib2.Request(url,payLoad)
1119 req.get_method = lambda: httpMethod
1120 resp = urllib2.urlopen(req)
1121 respObj = ResponseObj(resp)
1122 except urllib2.HTTPError, e:
1123 respObj = ResponseObj(e)
1124 return respObj
1125
1126
1128 """
1129 It contains the database shared details.
1130 """
1132
1133 self.response = response
1134 """
1135 The unparsed complete response content as sent by the server.
1136 @type:string
1137 """
1138
1139 self.adminMembers = {}
1140 """
1141 Owners of the database.
1142 @type:dictionary
1143 """
1144
1145 self.groupMembers = {}
1146 """
1147 Group Members of the database.
1148 @type:dictionary
1149 """
1150
1151 self.sharedUsers = []
1152 """
1153 Shared Users of the database.
1154 @type:list
1155 """
1156
1157 self.userInfo = {}
1158 """
1159 The PermissionInfo for the shared user.
1160 @type:dictionary
1161 """
1162
1163 self.groupInfo = {}
1164 """
1165 The PermissionInfo for the groups.
1166 @type:dictionary
1167 """
1168
1169 self.publicInfo = {}
1170 """
1171 The PermissionInfo for the public link.
1172 @type:dictionary
1173 """
1174
1175 self.privateInfo = {}
1176 """
1177 The PermissionInfo for the private link.
1178 @type:dictionary
1179 """
1180
1181 jsonresult = json.loads(self.response)
1182
1183 sharelist = jsonresult["response"]["result"]
1184
1185 userinfo = sharelist["usershareinfo"]
1186 if(userinfo):
1187 self.userInfo = self.getKeyInfo(userinfo,"email")
1188
1189 groupinfo = sharelist["groupshareinfo"]
1190 if(groupinfo):
1191 self.groupInfo = self.getKeyInfo(groupinfo,"group")
1192
1193 publicinfo = sharelist["publicshareinfo"]
1194 if(publicinfo):
1195 self.publicInfo = self.getInfo(sharelist["publicshareinfo"])
1196
1197 privateinfo = sharelist["privatelinkshareinfo"]
1198 if(privateinfo):
1199 self.privateInfo = self.getInfo(privateinfo)
1200
1201 self.adminMembers = sharelist["dbownershareinfo"]["dbowners"]
1202
1204
1205 shareinfo = {}
1206 i = 0
1207 for ele in perminfo:
1208 if("email" == key):
1209 info = ele["shareinfo"]["permissions"]
1210 userid = ele["shareinfo"]["email"]
1211 self.sharedUsers.append(userid)
1212 else:
1213 info = ele["shareinfo"]["permissions"]
1214 userid = ele["shareinfo"]["groupName"]
1215 desc = ele["shareinfo"]["desc"]
1216 gmember = ele["shareinfo"]["groupmembers"]
1217 member = {}
1218 member["name"] = userid
1219 member["desc"] = desc
1220 member["member"] = gmember
1221 self.groupMembers[i] = member
1222 i+=1
1223
1224 memberlist = {}
1225 for ele2 in info:
1226 permlist = {}
1227 viewname = ele2["perminfo"]["viewname"]
1228 sharedby = ele2["perminfo"]["sharedby"]
1229 permissions = ele2["perminfo"]["permission"]
1230 permlist["sharedby"] = sharedby
1231 permlist["permissions"] = permissions
1232 memberlist[viewname] = permlist
1233 shareinfo[userid] = memberlist
1234 return shareinfo
1235
1237
1238 userid = perminfo["email"]
1239 shareinfo = {}
1240 memberlist = {}
1241 for ele in perminfo["permissions"]:
1242 permlist = {}
1243 viewname = ele["perminfo"]["viewname"]
1244 sharedby = ele["perminfo"]["sharedby"]
1245 permissions = ele["perminfo"]["permission"]
1246 permlist["sharedby"] = sharedby
1247 permlist["permissions"] = permissions
1248 memberlist[viewname] = permlist
1249 shareinfo[userid] = memberlist
1250 return shareinfo
1251
1252
1253
1255 """
1256 It contains the plan details.
1257 """
1259
1260 self.response = response
1261 """
1262 The unparsed complete response content as sent by the server.
1263 @type:string
1264 """
1265
1266 dom = ReportClientHelper.getAsDOM(response)
1267
1268 self.plan = ReportClientHelper.getInfo(dom,"plan",response)
1269 """
1270 The type of the user plan.
1271 @type:string
1272 """
1273
1274 self.addon = ReportClientHelper.getInfo(dom,"addon",response)
1275 """
1276 The addon details.
1277 @type:string
1278 """
1279
1280 self.billingDate = ReportClientHelper.getInfo(dom,"billingDate",response)
1281 """
1282 The billing date.
1283 @type:string
1284 """
1285
1286 self.rowsAllowed = int(ReportClientHelper.getInfo(dom,"rowsAllowed",response))
1287 """
1288 The total rows allowed to the user.
1289 @type:int
1290 """
1291
1292 self.rowsUsed = int(ReportClientHelper.getInfo(dom,"rowsUsed",response))
1293 """
1294 The number of rows used by the user.
1295 @type:int
1296 """
1297
1298 self.trialAvailed = ReportClientHelper.getInfo(dom,"TrialAvailed",response)
1299 """
1300 Used to identify the trial pack.
1301 @type:string
1302 """
1303
1304 if ("false" != self.trialAvailed):
1305 self.trialPlan = ReportClientHelper.getInfo(dom,"TrialPlan",response)
1306 """
1307 The trial plan detail.
1308 @type:string
1309 """
1310
1311 self.trialStatus = bool(ReportClientHelper.getInfo(dom,"TrialStatus",response))
1312 """
1313 The trial plan status.
1314 @type:bool
1315 """
1316
1317 self.trialEndDate = ReportClientHelper.getInfo(dom,"TrialEndDate",response)
1318 """
1319 The end date of the trial plan.
1320 @type:string
1321 """
1322
1324 """
1325 ServerError is thrown if the report server has recieved the request but did not process the
1326 request due to some error. For example if authorization failure.
1327 """
1328
1330 self.httpStatusCode = urlResp.status_code
1331 self.errorCode = self.httpStatusCode
1332 self.uri=""
1333 self.action=""
1334 self.message = urlResp.content
1335
1336 parseable= False
1337 contHeader = urlResp.headers["Content-Type"]
1338 if(contHeader.find("text/xml") > -1):
1339 self.__parseErrorResponse()
1340
1341
1343 try:
1344 dom = xml.dom.minidom.parseString(self.message)
1345 respEl = dom.getElementsByTagName("response")[0]
1346 self.uri = respEl.getAttribute("uri")
1347 self.action=respEl.getAttribute("action")
1348 self.errorCode = int(ReportClientHelper.getInfo(dom,"code",self.message))
1349 self.message = ReportClientHelper.getInfo(dom,"message",self.message)
1350 except Exception,inst :
1351 print inst
1352 self.parseError = inst
1353
1354
1355
1357 return repr(self.message)
1358
1360 """
1361 ParseError is thrown if the server has responded but client was not able to parse the response.
1362 Possible reasons could be version mismatch.The client might have to be updated to a newer version.
1363 """
1364 - def __init__(self, responseContent,message,origExcep):
1365 self.responseContent= responseContent
1366 self.message=message
1367 self.origExcep= origExcep
1368
1370 return repr(self.message)
1371
1372
1374
1375 """
1376 ImportResult contains the result of an import operation.
1377 """
1378
1380 self.response = response
1381 """
1382 The unparsed complete response content as sent by the server.
1383 @type:string
1384 """
1385
1386 dom = ReportClientHelper.getAsDOM(response)
1387
1388 self.totalColCount = int(ReportClientHelper.getInfo(dom,"totalColumnCount",response))
1389 """
1390 The total columns that were present in the imported file.
1391 @type:integer
1392 """
1393
1394 self.selectedColCount = int(ReportClientHelper.getInfo(dom,"selectedColumnCount",response))
1395 """
1396 The number of columns that were imported.See ZOHO_SELECTED_COLUMNS parameter.
1397 @type:integer
1398 """
1399
1400 self.totalRowCount = int(ReportClientHelper.getInfo(dom,"totalRowCount",response))
1401 """
1402 The total row count in the imported file.
1403 @type:integer
1404 """
1405
1406
1407 self.successRowCount = int(ReportClientHelper.getInfo(dom,"successRowCount",response))
1408 """
1409 The number of rows that were imported successfully without errors.
1410 @type:integer
1411 """
1412
1413 self.warningCount = int(ReportClientHelper.getInfo(dom,"warnings",response))
1414 """
1415 The number of rows that were imported with warnings. Applicable if ZOHO_ON_IMPORT_ERROR
1416 parameter has been set to SETCOLUMNEMPTY.
1417 @type:integer
1418 """
1419
1420 self.impErrors = ReportClientHelper.getInfo(dom,"importErrors",response)
1421 """
1422 The first 100 import errors. Applicable if ZOHO_ON_IMPORT_ERROR parameter is either
1423 SKIPROW or SETCOLUMNEMPTY. In case of ABORT , L{ServerError <ServerError>} is thrown.
1424 @type:string
1425 """
1426
1427 self.operation = ReportClientHelper.getInfo(dom,"importOperation",response)
1428 """
1429 The import operation. Can be either
1430 1. B{created} if the specified table has been created. For this ZOHO_CREATE_TABLE parameter
1431 should have been set to true
1432 2. B{updated} if the specified table already exists.
1433 @type:string
1434 """
1435
1436 self.dataTypeDict = {}
1437 """
1438 Contains the mapping of column name to datatype.
1439 @type:dictionary
1440 """
1441
1442 cols = dom.getElementsByTagName("column")
1443
1444 self.impCols = []
1445 """
1446 Contains the list of columns that were imported. See also L{dataTypeDict<dataTypeDict>}.
1447 @type:dictionary
1448 """
1449
1450
1451 for el in cols:
1452 content = ReportClientHelper.getText(el.childNodes)
1453 self.dataTypeDict[content] = el.getAttribute("datatype")
1454 self.impCols.append(content)
1455
1456
1457
1459 """
1460 Internal class.
1461 """
1463 self.content = resp.read()
1464 self.status_code = resp.code
1465 self.headers = {}
1466 self.headers = resp.headers;
1467
1468
1470 """
1471 Internal class.
1472 """
1473
1474 API_VERSION="1.0"
1475 """The api version of zoho reports based on which this library is written. This is a constant."""
1476
1477 - def getInfo(dom,elName,response):
1478 nodeList = dom.getElementsByTagName(elName)
1479 if(nodeList.length == 0):
1480 raise ParseError(response, elName + " element is not present in the response",None)
1481 el = nodeList[0]
1482 return ReportClientHelper.getText(el.childNodes)
1483
1484 getInfo = staticmethod(getInfo)
1485
1486
1487 - def getText(nodelist):
1488 txt = ""
1489 for node in nodelist:
1490 if node.nodeType == node.TEXT_NODE:
1491 txt = txt + node.data
1492 return txt
1493 getText = staticmethod(getText)
1494
1495
1497 try:
1498 dom = xml.dom.minidom.parseString(response)
1499 return dom
1500 except Exception, inst:
1501 raise ParseError(response,"Unable parse the response as xml",inst)
1502 getAsDOM = staticmethod(getAsDOM)
1503
1504
1505
1506
1508 url=ReportClientHelper.checkAndAppendQMark(url)
1509 if(authtoken == None):
1510 raise Exception,"Provide an AuthToken first"
1511 url += "&ZOHO_ERROR_FORMAT=XML&ZOHO_ACTION=" + urllib.quote(action);
1512 url += "&ZOHO_OUTPUT_FORMAT=" + urllib.quote(exportFormat)
1513 url += "&authtoken=" + urllib.quote(authtoken) + "&ZOHO_API_VERSION=" + ReportClientHelper.API_VERSION
1514 return url
1515 addQueryParams = staticmethod(addQueryParams)
1516
1517
1518
1520 dict = {}
1521 for i in separateDicts:
1522 if(i != None):
1523 dict.update(i)
1524
1525 if(criteria != None):
1526 dict["ZOHO_CRITERIA"] = criteria
1527
1528 if(sql != None):
1529 dict["ZOHO_SQLQUERY"] = sql
1530
1531 if(len(dict) != 0):
1532 dict = urllib.urlencode(dict)
1533 else:
1534 dict = None
1535 return dict
1536 getAsPayLoad = staticmethod(getAsPayLoad)
1537
1538
1540 if(url.find("?") == -1):
1541 url +="?"
1542 elif (url[len(url) -1 ] != '&'):
1543 url +="&"
1544 return url
1545 checkAndAppendQMark = staticmethod(checkAndAppendQMark)
1546