Module AnalyticsClient
[hide private]
[frames] | no frames]

Source Code for Module AnalyticsClient

   1  #$Id$ 
   2  from io import StringIO 
   3  import urllib 
   4  import json 
   5  import requests 
   6  import math 
   7  import time 
   8   
9 -class AnalyticsClient:
10 """ 11 AnalyticsClient provides the python based language binding to the https based API of Zoho Analytics. 12 """ 13 14 CLIENT_VERSION = "2.6.0" 15 COMMON_ENCODE_CHAR = "UTF-8" 16
17 - def __init__(self, client_id, client_secret, refresh_token):
18 """ 19 Creates a new C{AnalyticsClient} instance. 20 @param client_id: User client id for OAUth 21 @type client_id:string 22 @param client_secret: User client secret for OAuth 23 @type client_secret:string 24 @param refresh_token: User's refresh token for OAUth). 25 @type refresh_token:string 26 """ 27 28 self.proxy = False 29 self.proxy_host = None 30 self.proxy_port = None 31 self.proxy_user_name = None 32 self.proxy_password = None 33 34 self.accounts_server_url = "https://accounts.zoho.com" 35 self.analytics_server_url = "https://analyticsapi.zoho.com" 36 37 self.client_id = client_id 38 self.client_secret = client_secret 39 self.refresh_token = refresh_token 40 self.access_token = None
41
42 - def get_org_instance(self, org_id):
43 """ 44 Returns a new C{OrgAPI} instance. 45 @param org_id: The id of the organization. 46 @type org_id:string 47 """ 48 org_instance = AnalyticsClient.OrgAPI(self, org_id) 49 return org_instance
50
51 - def get_workspace_instance(self, org_id, workspace_id):
52 """ 53 Returns a new C{WorkspaceAPI} instance. 54 @param org_id: The id of the organization. 55 @type org_id:string 56 @param workspace_id: The id of the workspace. 57 @type workspace_id:string 58 """ 59 workspace_instance = AnalyticsClient.WorkspaceAPI(self, org_id, workspace_id) 60 return workspace_instance
61
62 - def get_view_instance(self, org_id, workspace_id, view_id):
63 """ 64 Returns a new C{ViewAPI} instance. 65 @param org_id: The id of the organization. 66 @type org_id:string 67 @param workspace_id: The id of the workspace. 68 @type workspace_id:string 69 @param view_id: The id of the view. 70 @type view_id:string 71 """ 72 view_instance = AnalyticsClient.ViewAPI(self, org_id, workspace_id, view_id) 73 return view_instance
74
75 - def get_bulk_instance(self, org_id, workspace_id):
76 """ 77 Returns a new C{BulkAPI} instance. 78 @param org_id: The id of the organization. 79 @type org_id:string 80 @param workspace_id: The id of the workspace. 81 @type workspace_id:string 82 """ 83 data_instance = AnalyticsClient.BulkAPI(self, org_id, workspace_id) 84 return data_instance
85 86
87 - def get_orgs(self):
88 """ 89 Returns list of all accessible organizations. 90 @return: Organization list. 91 @rtype:list 92 @raise ServerError: If the server has received the request but did not process the request 93 due to some error. 94 @raise ParseError: If the server has responded but client was not able to parse the response. 95 """ 96 endpoint = "/restapi/v2/orgs" 97 response = self.send_api_request("GET", endpoint, None, None) 98 return response["data"]["orgs"]
99
100 - def get_workspaces(self):
101 """ 102 Returns list of all accessible workspaces. 103 @return: Workspace list. 104 @rtype:list 105 @raise ServerError: If the server has received the request but did not process the request 106 due to some error. 107 @raise ParseError: If the server has responded but client was not able to parse the response. 108 """ 109 endpoint = "/restapi/v2/workspaces" 110 response = self.send_api_request("GET", endpoint, None, None) 111 return response["data"]
112
113 - def get_owned_workspaces(self):
114 """ 115 Returns list of owned workspaces. 116 @return: Workspace list. 117 @rtype:list 118 @raise ServerError: If the server has received the request but did not process the request 119 due to some error. 120 @raise ParseError: If the server has responded but client was not able to parse the response. 121 """ 122 endpoint = "/restapi/v2/workspaces/owned" 123 response = self.send_api_request("GET", endpoint, None, None) 124 return response["data"]["workspaces"]
125
126 - def get_shared_workspaces(self):
127 """ 128 Returns list of shared workspaces. 129 @return: Workspace list. 130 @rtype:list 131 @raise ServerError: If the server has received the request but did not process the request 132 due to some error. 133 @raise ParseError: If the server has responded but client was not able to parse the response. 134 """ 135 endpoint = "/restapi/v2/workspaces/shared" 136 response = self.send_api_request("GET", endpoint, None, None) 137 return response["data"]["workspaces"]
138
139 - def get_recent_views(self):
140 """ 141 Returns list of recently accessed views. 142 @return: View list. 143 @rtype:list 144 @raise ServerError: If the server has received the request but did not process the request 145 due to some error. 146 @raise ParseError: If the server has responded but client was not able to parse the response. 147 """ 148 endpoint = "/restapi/v2/recentviews" 149 response = self.send_api_request("GET", endpoint, None, None) 150 return response["data"]["views"]
151
152 - def get_dashboards(self):
153 """ 154 Returns list of all accessible dashboards. 155 @return: Dashboard list. 156 @rtype:list 157 @raise ServerError: If the server has received the request but did not process the request 158 due to some error. 159 @raise ParseError: If the server has responded but client was not able to parse the response. 160 """ 161 endpoint = "/restapi/v2/dashboards" 162 response = self.send_api_request("GET", endpoint, None, None) 163 return response["data"]
164
165 - def get_owned_dashboards(self):
166 """ 167 Returns list of owned dashboards. 168 @return: Dashboard list. 169 @rtype:list 170 @raise ServerError: If the server has received the request but did not process the request 171 due to some error. 172 @raise ParseError: If the server has responded but client was not able to parse the response. 173 """ 174 endpoint = "/restapi/v2/dashboards/owned" 175 response = self.send_api_request("GET", endpoint, None, None) 176 return response["data"]["views"]
177
178 - def get_shared_dashboards(self):
179 """ 180 Returns list of shared dashboards. 181 @return: Dashboard list. 182 @rtype:list 183 @raise ServerError: If the server has received the request but did not process the request 184 due to some error. 185 @raise ParseError: If the server has responded but client was not able to parse the response. 186 """ 187 endpoint = "/restapi/v2/dashboards/shared" 188 response = self.send_api_request("GET", endpoint, None, None) 189 return response["data"]["views"]
190
191 - def get_workspace_details(self, workspace_id):
192 """ 193 Returns details of the specified workspace. 194 @param workspace_id: Id of the workspace. 195 @type workspace_id: string 196 @raise ServerError: If the server has received the request but did not process the request due to some error. 197 @raise ParseError: If the server has responded but client was not able to parse the response. 198 @return: Workspace details. 199 @rtype:dictionary 200 """ 201 endpoint = "/restapi/v2/workspaces/" + workspace_id 202 response = self.send_api_request("GET", endpoint, None, None) 203 return response["data"]["workspaces"]
204
205 - def get_view_details(self, view_id, config = {}):
206 """ 207 Returns details of the specified view. 208 @param view_id: Id of the view. 209 @type view_id: string 210 @param config: Contains any additional control parameters. Can be C{None}. 211 @type config:dictionary 212 @raise ServerError: If the server has received the request but did not process the request due to some error. 213 @raise ParseError: If the server has responded but client was not able to parse the response. 214 @return: View details. 215 @rtype:dictionary 216 """ 217 endpoint = "/restapi/v2/views/" + view_id 218 response = self.send_api_request("GET", endpoint, config, None) 219 return response["data"]["views"]
220 221
222 - class OrgAPI:
223 """ 224 OrgAPI contains organization level operations. 225 """
226 - def __init__(self, ac, org_id):
227 self.ac = ac 228 self.request_headers = {} 229 self.request_headers["ZANALYTICS-ORGID"] = org_id
230
231 - def create_workspace(self, workspace_name, config = {}):
232 """ 233 Create a blank workspace in the specified organization. 234 @param workspace_name: The name of the workspace. 235 @type workspace_name:string 236 @param config: Contains any additional control parameters. Can be C{None}. 237 @type config:dictionary 238 @raise ServerError: If the server has received the request but did not process the request due to some error. 239 @raise ParseError: If the server has responded but client was not able to parse the response. 240 @return: Created workspace id. 241 @rtype:string 242 """ 243 config["workspaceName"] = workspace_name 244 endpoint = "/restapi/v2/workspaces/" 245 response = self.ac.send_api_request("POST", endpoint, config, self.request_headers) 246 return int(response["data"]["workspaceId"])
247
248 - def get_admins(self):
249 """ 250 Returns list of admins for a specified organization. 251 @raise ServerError: If the server has received the request but did not process the request due to some error. 252 @raise ParseError: If the server has responded but client was not able to parse the response. 253 @return: Organization admin list. 254 @rtype:list 255 """ 256 endpoint = "/restapi/v2/orgadmins" 257 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers) 258 return response["data"]["orgAdmins"]
259
260 - def get_users(self):
261 """ 262 Returns list of users for the specified organization. 263 @raise ServerError: If the server has received the request but did not process the request due to some error. 264 @raise ParseError: If the server has responded but client was not able to parse the response. 265 @return: User list. 266 @rtype:list 267 """ 268 endpoint = "/restapi/v2/users" 269 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers) 270 return response["data"]["users"]
271
272 - def add_users(self, email_ids, config = {}):
273 """ 274 Add users to the specified organization. 275 @param email_ids: The email address of the users to be added. 276 @type email_ids:list 277 @param config: Contains any additional control parameters. Can be C{None}. 278 @type config:dictionary 279 @raise ServerError: If the server has received the request but did not process the request due to some error. 280 @raise ParseError: If the server has responded but client was not able to parse the response. 281 """ 282 config["emailIds"] = email_ids 283 endpoint = "/restapi/v2/users" 284 self.ac.send_api_request("POST", endpoint, config, self.request_headers)
285
286 - def remove_users(self, email_ids, config = {}):
287 """ 288 Remove users from the specified organization. 289 @param email_ids: The email address of the users to be removed. 290 @type email_ids:list 291 @param config: Contains any additional control parameters. Can be C{None}. 292 @type config:dictionary 293 @raise ServerError: If the server has received the request but did not process the request due to some error. 294 @raise ParseError: If the server has responded but client was not able to parse the response. 295 """ 296 config["emailIds"] = email_ids 297 endpoint = "/restapi/v2/users" 298 self.ac.send_api_request("DELETE", endpoint, config, self.request_headers)
299
300 - def activate_users(self, email_ids, config = {}):
301 """ 302 Activate users in the specified organization. 303 @param email_ids: The email address of the users to be activated. 304 @type email_ids:list 305 @param config: Contains any additional control parameters. Can be C{None}. 306 @type config:dictionary 307 @raise ServerError: If the server has received the request but did not process the request due to some error. 308 @raise ParseError: If the server has responded but client was not able to parse the response. 309 """ 310 config["emailIds"] = email_ids 311 endpoint = "/restapi/v2/users/active" 312 self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
313
314 - def deactivate_users(self, email_ids, config = {}):
315 """ 316 Deactivate users in the specified organization. 317 @param email_ids: The email address of the users to be deactivated. 318 @type email_ids:list 319 @param config: Contains any additional control parameters. Can be C{None}. 320 @type config:dictionary 321 @raise ServerError: If the server has received the request but did not process the request due to some error. 322 @raise ParseError: If the server has responded but client was not able to parse the response. 323 """ 324 config["emailIds"] = email_ids 325 endpoint = "/restapi/v2/users/inactive" 326 self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
327
328 - def change_user_role(self, email_ids, role, config = {}):
329 """ 330 Change role for the specified users. 331 @param email_ids: The email address of the users to be deactivated. 332 @type email_ids:list 333 @param role: New role for the users. 334 @type role:string 335 @param config: Contains any additional control parameters. Can be C{None}. 336 @type config:dictionary 337 @raise ServerError: If the server has received the request but did not process the request due to some error. 338 @raise ParseError: If the server has responded but client was not able to parse the response. 339 """ 340 config["emailIds"] = email_ids 341 config["role"] = role 342 endpoint = "/restapi/v2/users/role" 343 self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
344
345 - def get_subscription_details(self):
346 """ 347 Returns subscription details of the specified organization. 348 @raise ServerError: If the server has received the request but did not process the request due to some error. 349 @raise ParseError: If the server has responded but client was not able to parse the response. 350 @return: Subscription details. 351 @rtype:dictionary 352 """ 353 endpoint = "/restapi/v2/subscription" 354 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers) 355 return response["data"]["subscription"]
356 357
358 - def get_resource_details(self):
359 """ 360 Returns resource usage details of the specified organization. 361 @raise ServerError: If the server has received the request but did not process the request due to some error. 362 @raise ParseError: If the server has responded but client was not able to parse the response. 363 @return: Resource details. 364 @rtype:dictionary 365 """ 366 endpoint = "/restapi/v2/resources" 367 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers) 368 return response["data"]["resourceDetails"]
369
370 - def get_meta_details(self, workspace_name, view_name):
371 """ 372 Returns details of the specified workspace/view. 373 @param workspace_name: Name of the workspace. 374 @type workspace_name:string 375 @param view_name: Name of the view. 376 @type view_name:string 377 @raise ServerError: If the server has received the request but did not process the request due to some error. 378 @raise ParseError: If the server has responded but client was not able to parse the response. 379 @return: Workspace (or) View meta details. 380 @rtype:dictionary 381 """ 382 config = {} 383 config["workspaceName"] = workspace_name 384 if view_name != None: 385 config["viewName"] = view_name 386 endpoint = "/restapi/v2/metadetails" 387 response = self.ac.send_api_request("GET", endpoint, config, self.request_headers) 388 return response["data"]
389 390
391 - class WorkspaceAPI:
392 """ 393 WorkspaceAPI contains workspace level operations. 394 """
395 - def __init__(self, ac, org_id, workspace_id):
396 self.ac = ac 397 self.endpoint = "/restapi/v2/workspaces/" + workspace_id 398 self.request_headers = {} 399 self.request_headers["ZANALYTICS-ORGID"] = org_id
400
401 - def copy(self, new_workspace_name, config = {}, dest_org_id = None):
402 """ 403 Copy the specified workspace from one organization to another or within the organization. 404 @param new_workspace_name: Name of the new workspace. 405 @type new_workspace_name: string 406 @param config: Contains any additional control parameters. Can be C{None}. 407 @type config:dictionary 408 @param dest_org_id: Id of the organization where the destination workspace is present. Can be C{None}. 409 @type dest_org_id: string 410 @raise ServerError: If the server has received the request but did not process the request due to some error. 411 @raise ParseError: If the server has responded but client was not able to parse the response. 412 @return: Copied workspace id. 413 @rtype:string 414 """ 415 config["newWorkspaceName"] = new_workspace_name 416 headers = self.request_headers.copy() 417 if bool(dest_org_id): 418 headers["ZANALYTICS-DEST-ORGID"] = dest_org_id 419 response = self.ac.send_api_request("POST", self.endpoint, config, headers) 420 return int(response["data"]["workspaceId"])
421
422 - def rename(self, workspace_name, config = {}):
423 """ 424 Rename a specified workspace in the organization. 425 @param workspace_name: New name for the workspace. 426 @type workspace_name: string 427 @param config: Contains any additional control parameters. Can be C{None}. 428 @type config:dictionary 429 @raise ServerError: If the server has received the request but did not process the request due to some error. 430 @raise ParseError: If the server has responded but client was not able to parse the response. 431 """ 432 config["workspaceName"] = workspace_name 433 response = self.ac.send_api_request("PUT", self.endpoint, config, self.request_headers)
434
435 - def delete(self):
436 """ 437 Delete a specified workspace in the organization. 438 @raise ServerError: If the server has received the request but did not process the request due to some error. 439 @raise ParseError: If the server has responded but client was not able to parse the response. 440 """ 441 response = self.ac.send_api_request("DELETE", self.endpoint, None, self.request_headers)
442
443 - def get_secret_key(self, config = {}):
444 """ 445 Returns the secret key of the specified workspace. 446 @param config: Contains any additional control parameters. Can be C{None}. 447 @type config:dictionary 448 @raise ServerError: If the server has received the request but did not process the request due to some error. 449 @raise ParseError: If the server has responded but client was not able to parse the response. 450 @return: Workspace secret key. 451 @rtype:string 452 """ 453 endpoint = self.endpoint + "/secretkey" 454 response = self.ac.send_api_request("GET", endpoint, config, self.request_headers) 455 return response["data"]["workspaceKey"]
456
457 - def add_favorite(self):
458 """ 459 Adds a specified workspace as favorite. 460 @raise ServerError: If the server has received the request but did not process the request due to some error. 461 @raise ParseError: If the server has responded but client was not able to parse the response. 462 """ 463 endpoint = self.endpoint + "/favorite" 464 response = self.ac.send_api_request("POST", endpoint, None, self.request_headers)
465
466 - def remove_favorite(self):
467 """ 468 Remove a specified workspace from favorite. 469 @raise ServerError: If the server has received the request but did not process the request due to some error. 470 @raise ParseError: If the server has responded but client was not able to parse the response. 471 """ 472 endpoint = self.endpoint + "/favorite" 473 response = self.ac.send_api_request("DELETE", endpoint, None, self.request_headers)
474
475 - def add_default(self):
476 """ 477 Adds a specified workspace as default. 478 @raise ServerError: If the server has received the request but did not process the request due to some error. 479 @raise ParseError: If the server has responded but client was not able to parse the response. 480 """ 481 endpoint = self.endpoint + "/default" 482 response = self.ac.send_api_request("POST", endpoint, None, self.request_headers)
483
484 - def remove_default(self):
485 """ 486 Remove a specified workspace from default. 487 @raise ServerError: If the server has received the request but did not process the request due to some error. 488 @raise ParseError: If the server has responded but client was not able to parse the response. 489 """ 490 endpoint = self.endpoint + "/default" 491 response = self.ac.send_api_request("DELETE", endpoint, None, self.request_headers)
492
493 - def get_admins(self):
494 """ 495 Returns list of admins for the specified workspace. 496 @raise ServerError: If the server has received the request but did not process the request due to some error. 497 @raise ParseError: If the server has responded but client was not able to parse the response. 498 @return: Workspace admin list. 499 @rtype:list 500 """ 501 endpoint = self.endpoint + "/admins" 502 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers) 503 return response["data"]["workspaceAdmins"]
504
505 - def add_admins(self, email_ids, config = {}):
506 """ 507 Add admins for the specified workspace. 508 @param email_ids: The email address of the admin users to be added. 509 @type email_ids: list 510 @param config: Contains any additional control parameters. Can be C{None}. 511 @type config:dictionary 512 @raise ServerError: If the server has received the request but did not process the request due to some error. 513 @raise ParseError: If the server has responded but client was not able to parse the response. 514 """ 515 config["emailIds"] = email_ids 516 endpoint = self.endpoint + "/admins" 517 self.ac.send_api_request("POST", endpoint, config, self.request_headers)
518
519 - def remove_admins(self, email_ids, config = {}):
520 """ 521 Remove admins from the specified workspace. 522 @param email_ids: The email address of the admin users to be removed. 523 @type email_ids: list 524 @param config: Contains any additional control parameters. Can be C{None}. 525 @type config:dictionary 526 @raise ServerError: If the server has received the request but did not process the request due to some error. 527 @raise ParseError: If the server has responded but client was not able to parse the response. 528 """ 529 config["emailIds"] = email_ids 530 endpoint = self.endpoint + "/admins" 531 self.ac.send_api_request("DELETE", endpoint, config, self.request_headers)
532
533 - def get_share_info(self):
534 """ 535 Returns shared details of the specified workspace. 536 @raise ServerError: If the server has received the request but did not process the request due to some error. 537 @raise ParseError: If the server has responded but client was not able to parse the response. 538 @return: Workspace share info. 539 @rtype:dictionary 540 """ 541 endpoint = self.endpoint + "/share" 542 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers) 543 return response["data"]
544
545 - def share_views(self, view_ids, email_ids, permissions, config = {}):
546 """ 547 Share views to the specified users. 548 @param view_ids: View ids which to be shared. 549 @type view_ids: list 550 @param email_ids: The email address of the users to whom the views need to be shared. 551 @type email_ids: list 552 @param permissions: Contains permission details. 553 @type permissions: dictionary 554 @param config: Contains any additional control parameters. Can be C{None}. 555 @type config:dictionary 556 @raise ServerError: If the server has received the request but did not process the request due to some error. 557 @raise ParseError: If the server has responded but client was not able to parse the response. 558 """ 559 config["viewIds"] = view_ids 560 config["emailIds"] = email_ids 561 config["permissions"] = permissions 562 endpoint = self.endpoint + "/share" 563 self.ac.send_api_request("POST", endpoint, config, self.request_headers)
564
565 - def remove_share(self, view_ids, email_ids, config = {}):
566 """ 567 Remove shared views for the specified users. 568 @param view_ids: View ids whose sharing needs to be removed. 569 @type view_ids: list 570 @param email_ids: The email address of the users to whom the sharing need to be removed. 571 @type email_ids: list 572 @param config: Contains any additional control parameters. Can be C{None}. 573 @type config:dictionary 574 @raise ServerError: If the server has received the request but did not process the request due to some error. 575 @raise ParseError: If the server has responded but client was not able to parse the response. 576 """ 577 config["emailIds"] = email_ids 578 if view_ids != None: 579 config["viewIds"] = view_ids 580 endpoint = self.endpoint + "/share" 581 self.ac.send_api_request("DELETE", endpoint, config, self.request_headers)
582
583 - def get_shared_details_for_views(self, view_ids):
584 """ 585 Returns shared details of the specified views. 586 @param view_ids: View ids for which sharing details are required. 587 @type view_ids: list 588 @raise ServerError: If the server has received the request but did not process the request due to some error. 589 @raise ParseError: If the server has responded but client was not able to parse the response. 590 @return: Shared information. 591 @rtype:list 592 """ 593 config = {} 594 config["viewIds"] = view_ids 595 endpoint = self.endpoint + "/share/shareddetails" 596 response = self.ac.send_api_request("GET", endpoint, config, self.request_headers) 597 return response["data"]["sharedDetails"]
598
599 - def get_folders(self):
600 """ 601 Returns list of all accessible folders for the specified workspace. 602 @raise ServerError: If the server has received the request but did not process the request due to some error. 603 @raise ParseError: If the server has responded but client was not able to parse the response. 604 @return: Folder list. 605 @rtype:list 606 """ 607 endpoint = self.endpoint + "/folders" 608 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers) 609 return response["data"]["folders"]
610
611 - def create_folder(self, folder_name, config = {}):
612 """ 613 Create a folder in the specified workspace. 614 @param folder_name: Name of the folder to be created. 615 @type folder_name: string 616 @param config: Contains any additional control parameters. Can be C{None}. 617 @type config:dictionary 618 @raise ServerError: If the server has received the request but did not process the request due to some error. 619 @raise ParseError: If the server has responded but client was not able to parse the response. 620 @return: Created folder id. 621 @rtype:string 622 """ 623 config["folderName"] = folder_name 624 endpoint = self.endpoint + "/folders" 625 response = self.ac.send_api_request("POST", endpoint, config, self.request_headers) 626 return int(response["data"]["folderId"])
627
628 - def get_views(self, config = {}):
629 """ 630 Returns list of all accessible views for the specified workspace. 631 @param config: Contains any additional control parameters. Can be C{None}. 632 @type config:dictionary 633 @raise ServerError: If the server has received the request but did not process the request due to some error. 634 @raise ParseError: If the server has responded but client was not able to parse the response. 635 @return: View list. 636 @rtype:list 637 """ 638 endpoint = self.endpoint + "/views" 639 response = self.ac.send_api_request("GET", endpoint, config, self.request_headers) 640 return response["data"]["views"]
641
642 - def create_table(self, table_design):
643 """ 644 Create a table in the specified workspace. 645 @param table_design: Table structure. 646 @type table_design: dictionary 647 @raise ServerError: If the server has received the request but did not process the request due to some error. 648 @raise ParseError: If the server has responded but client was not able to parse the response. 649 @return: created table id. 650 @rtype:string 651 """ 652 config = {} 653 config["tableDesign"] = table_design 654 endpoint = self.endpoint + "/tables" 655 response = self.ac.send_api_request("POST", endpoint, config, self.request_headers) 656 return int(response["data"]["viewId"])
657
658 - def create_query_table(self, sql_query, query_table_name, config = {}):
659 """ 660 Create a new query table in the workspace. 661 @param sql_query: SQL query to construct the query table. 662 @type sql_query: string 663 @param query_table_name: Name of the query table to be created. 664 @type query_table_name: string 665 @param config: Contains any additional control parameters. Can be C{None}. 666 @type config:dictionary 667 @raise ServerError: If the server has received the request but did not process the request due to some error. 668 @raise ParseError: If the server has responded but client was not able to parse the response. 669 @return: created table id. 670 @rtype:string 671 """ 672 config["sqlQuery"] = sql_query 673 config["queryTableName"] = query_table_name 674 endpoint = self.endpoint + "/querytables" 675 response = self.ac.send_api_request("POST", endpoint, config, self.request_headers) 676 return int(response["data"]["viewId"])
677
678 - def edit_query_table(self, view_id, sql_query, config = {}):
679 """ 680 Update the mentioned query table in the workspace. 681 @param view_id: Id of the query table to be updated. 682 @type view_id: string 683 @param sql_query: New SQL query to be updated. 684 @type sql_query: string 685 @param config: Contains any additional control parameters. Can be C{None}. 686 @type config:dictionary 687 @raise ServerError: If the server has received the request but did not process the request due to some error. 688 @raise ParseError: If the server has responded but client was not able to parse the response. 689 """ 690 config["sqlQuery"] = sql_query 691 endpoint = self.endpoint + "/querytables/" + view_id 692 self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
693
694 - def copy_views(self, view_ids, dest_workspace_id, config = {}, dest_org_id = None):
695 """ 696 Copy the specified views from one workspace to another workspace. 697 @param view_ids: The id of the views to be copied. 698 @type view_ids: list 699 @param dest_workspace_id: The destination workspace id. 700 @type dest_workspace_id: string 701 @param dest_org_id: Id of the organization where the destination workspace is present. Can be C{None}. 702 @type dest_org_id: string 703 @param config: Contains any additional control parameters. Can be C{None}. 704 @type config:dictionary 705 @raise ServerError: If the server has received the request but did not process the request due to some error. 706 @raise ParseError: If the server has responded but client was not able to parse the response. 707 @return: View list. 708 @rtype:list 709 """ 710 config["viewIds"] = view_ids 711 config["destWorkspaceId"] = dest_workspace_id 712 endpoint = self.endpoint + "/views/copy" 713 headers = self.request_headers.copy() 714 if bool(dest_org_id): 715 headers["ZANALYTICS-DEST-ORGID"] = dest_org_id 716 response = self.ac.send_api_request("POST", endpoint, config, headers) 717 return response["data"]["views"]
718
719 - def enable_domain_access(self):
720 """ 721 Enable workspace to the specified white label domain. 722 @raise ServerError: If the server has received the request but did not process the request due to some error. 723 @raise ParseError: If the server has responded but client was not able to parse the response. 724 """ 725 endpoint = self.endpoint + "/wlaccess" 726 response = self.ac.send_api_request("POST", endpoint, None, self.request_headers)
727
728 - def disable_domain_access(self):
729 """ 730 Disable workspace from the specified white label domain. 731 @raise ServerError: If the server has received the request but did not process the request due to some error. 732 @raise ParseError: If the server has responded but client was not able to parse the response. 733 """ 734 endpoint = self.endpoint + "/wlaccess" 735 response = self.ac.send_api_request("DELETE", endpoint, None, self.request_headers)
736
737 - def rename_folder(self, folder_id, folder_name, config = {}):
738 """ 739 Rename a specified folder in the workspace. 740 @param folder_id: Id of the folder. 741 @type folder_id: string 742 @param folder_name: New name for the folder. 743 @type folder_name: string 744 @param config: Contains any additional control parameters. Can be C{None}. 745 @type config:dictionary 746 @raise ServerError: If the server has received the request but did not process the request due to some error. 747 @raise ParseError: If the server has responded but client was not able to parse the response. 748 """ 749 config["folderName"] = folder_name 750 endpoint = self.endpoint + "/folders/" + folder_id 751 self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
752
753 - def delete_folder(self, folder_id):
754 """ 755 Delete a specified folder in the workspace. 756 @param folder_id: Id of the folder to be deleted. 757 @type folder_id: string 758 @raise ServerError: If the server has received the request but did not process the request due to some error. 759 @raise ParseError: If the server has responded but client was not able to parse the response. 760 """ 761 endpoint = self.endpoint + "/folders/" + folder_id 762 self.ac.send_api_request("DELETE", endpoint, None, self.request_headers)
763
764 - def get_groups(self):
765 """ 766 Returns list of groups for the specified workspace. 767 @raise ServerError: If the server has received the request but did not process the request due to some error. 768 @raise ParseError: If the server has responded but client was not able to parse the response. 769 @return: Group list. 770 @rtype:list 771 """ 772 endpoint = self.endpoint + "/groups" 773 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers) 774 return response["data"]["groups"]
775
776 - def create_group(self, group_name, email_ids, config = {}):
777 """ 778 Create a group in the specified workspace. 779 @param group_name: Name of the group. 780 @type group_name: string 781 @param email_ids: The email address of the users to be added to the group. 782 @type email_ids: list 783 @param config: Contains any additional control parameters. Can be C{None}. 784 @type config:dictionary 785 @raise ServerError: If the server has received the request but did not process the request due to some error. 786 @raise ParseError: If the server has responded but client was not able to parse the response. 787 @return: Created group id. 788 @rtype:string 789 """ 790 config["groupName"] = group_name 791 config["emailIds"] = email_ids 792 endpoint = self.endpoint + "/groups" 793 response = self.ac.send_api_request("POST", endpoint, config, self.request_headers) 794 return int(response["data"]["groupId"])
795
796 - def get_group_details(self, group_id):
797 """ 798 Get the details of the specified group. 799 @param group_id: Id of the group. 800 @type group_id: string 801 @raise ServerError: If the server has received the request but did not process the request due to some error. 802 @raise ParseError: If the server has responded but client was not able to parse the response. 803 @return: Details of the specified group. 804 @rtype:dictionary 805 """ 806 endpoint = self.endpoint + "/groups/" + group_id 807 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers) 808 return response["data"]["groups"]
809
810 - def rename_group(self, group_id, group_name, config = {}):
811 """ 812 Rename a specified group. 813 @param group_id: Id of the group. 814 @type group_id: string 815 @param group_name: New name for the group. 816 @type group_name: string 817 @param config: Contains any additional control parameters. Can be C{None}. 818 @type config:dictionary 819 @raise ServerError: If the server has received the request but did not process the request due to some error. 820 @raise ParseError: If the server has responded but client was not able to parse the response. 821 """ 822 config["groupName"] = group_name 823 endpoint = self.endpoint + "/groups/" + group_id 824 self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
825
826 - def delete_group(self, group_id):
827 """ 828 Delete a specified group. 829 @param group_id: The id of the group. 830 @type group_id: string 831 @raise ServerError: If the server has received the request but did not process the request due to some error. 832 @raise ParseError: If the server has responded but client was not able to parse the response. 833 """ 834 endpoint = self.endpoint + "/groups/" + group_id 835 self.ac.send_api_request("DELETE", endpoint, None, self.request_headers)
836
837 - def add_group_members(self, group_id, email_ids, config = {}):
838 """ 839 Add users to the specified group. 840 @param group_id: Id of the group. 841 @type group_id: string 842 @param email_ids: The email address of the users to be added to the group. 843 @type email_ids: list 844 @param config: Contains any additional control parameters. Can be C{None}. 845 @type config:dictionary 846 @raise ServerError: If the server has received the request but did not process the request due to some error. 847 @raise ParseError: If the server has responded but client was not able to parse the response. 848 """ 849 config["emailIds"] = email_ids 850 endpoint = self.endpoint + "/groups/" + group_id + "/members" 851 self.ac.send_api_request("POST", endpoint, config, self.request_headers)
852
853 - def remove_group_members(self, group_id, email_ids, config = {}):
854 """ 855 Remove users from the specified group. 856 @param group_id: Id of the group. 857 @type group_id: string 858 @param email_ids: The email address of the users to be removed from the group. 859 @type email_ids: list 860 @param config: Contains any additional control parameters. Can be C{None}. 861 @type config:dictionary 862 @raise ServerError: If the server has received the request but did not process the request due to some error. 863 @raise ParseError: If the server has responded but client was not able to parse the response. 864 """ 865 config["emailIds"] = email_ids 866 endpoint = self.endpoint + "/groups/" + group_id + "/members" 867 self.ac.send_api_request("DELETE", endpoint, config, self.request_headers)
868
869 - def create_slideshow(self, slide_name, view_ids, config = {}):
870 """ 871 Create a slideshow in the specified workspace. 872 @param slide_name: Name of the slideshow to be created. 873 @type slide_name: string 874 @param view_ids: Ids of the view to be included in the slideshow. 875 @type view_ids: list 876 @param config: Contains any additional control parameters. Can be C{None}. 877 @type config:dictionary 878 @raise ServerError: If the server has received the request but did not process the request due to some error. 879 @raise ParseError: If the server has responded but client was not able to parse the response. 880 @return: Id of the created slideshow. 881 @rtype:string 882 """ 883 endpoint = self.endpoint + "/slides" 884 config["slideName"] = slide_name 885 config["viewIds"] = view_ids 886 response = self.ac.send_api_request("POST", endpoint, config, self.request_headers) 887 return int(response["data"]["slideId"])
888
889 - def update_slideshow(self, slide_id, config = {}):
890 """ 891 Update details of the specified slideshow. 892 @param slide_id: The id of the slideshow. 893 @type slide_id: string 894 @param config - Contains the control configurations. 895 @type config:dictionary 896 @raise ServerError: If the server has received the request but did not process the request due to some error. 897 @raise ParseError: If the server has responded but client was not able to parse the response. 898 """ 899 endpoint = self.endpoint + "/slides/" + slide_id 900 self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
901
902 - def delete_slideshow(self, slide_id):
903 """ 904 Delete a specified slideshow in the workspace. 905 @param slide_id: Id of the slideshow. 906 @type slide_id: string 907 @raise ServerError: If the server has received the request but did not process the request due to some error. 908 @raise ParseError: If the server has responded but client was not able to parse the response. 909 """ 910 endpoint = self.endpoint + "/slides/" + slide_id 911 self.ac.send_api_request("DELETE", endpoint, None, self.request_headers)
912
913 - def get_slideshows(self):
914 """ 915 Returns list of slideshows for the specified workspace. 916 @raise ServerError: If the server has received the request but did not process the request due to some error. 917 @raise ParseError: If the server has responded but client was not able to parse the response. 918 @return: Slideshow list. 919 @rtype:list 920 """ 921 endpoint = self.endpoint + "/slides" 922 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers) 923 return response["data"]["slideshows"]
924
925 - def get_slideshow_url(self, slide_id, config = {}):
926 """ 927 Returns slide URL to access the specified slideshow. 928 @param slide_id: Id of the slideshow. 929 @type slide_id: string 930 @param config: Contains any additional control parameters. Can be C{None}. 931 @type config:dictionary 932 @raise ServerError: If the server has received the request but did not process the request due to some error. 933 @raise ParseError: If the server has responded but client was not able to parse the response. 934 @return: Slideshow URL. 935 @rtype:string 936 """ 937 endpoint = self.endpoint + "/slides/" + slide_id + "/publish" 938 response = self.ac.send_api_request("GET", endpoint, config, self.request_headers) 939 return response["data"]["slideUrl"]
940
941 - def get_slideshow_details(self, slide_id):
942 """ 943 Returns details of the specified slideshow. 944 @param slide_id: Id of the slideshow. 945 @type slide_id: string 946 @raise ServerError: If the server has received the request but did not process the request due to some error. 947 @raise ParseError: If the server has responded but client was not able to parse the response. 948 @return: Slideshow details. 949 @rtype:dictionary 950 """ 951 endpoint = self.endpoint + "/slides/" + slide_id 952 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers) 953 return response["data"]["slideInfo"]
954
955 - def create_variable(self, variable_name, variable_datatype, variable_type, config = {}):
956 """ 957 Create a variable in the workspace. 958 @param variable_name: Name of the variable to be created. 959 @type variable_name: string 960 @param variable_datatype: Datatype of the variable to be created. 961 @type variable_datatype: string 962 @param variable_type: Type of the variable to be created. 963 @type variable_type: string 964 @param config: Contains the control parameters. 965 @type config:dictionary 966 @raise ServerError: If the server has received the request but did not process the request due to some error. 967 @raise ParseError: If the server has responded but client was not able to parse the response. 968 @return: Id of the created variable. 969 @rtype:string 970 """ 971 endpoint = self.endpoint + "/variables" 972 config["variableName"] = variable_name 973 config["variableDataType"] = variable_datatype 974 config["variableType"] = variable_type 975 response = self.ac.send_api_request("POST", endpoint, config, self.request_headers) 976 return int(response["data"]["variableId"])
977
978 - def update_variable(self, variable_id, variable_name, variable_datatype, variable_type, config = {}):
979 """ 980 Update details of the specified variable in the workspace. 981 @param variable_id: Id of the variable. 982 @type variable_id: string 983 @param variable_name: New name for the variable. 984 @type variable_name: string 985 @param variable_datatype: New datatype for the variable. 986 @type variable_datatype: string 987 @param variable_type: New type for the variable. 988 @type variable_type: string 989 @param config: Contains the control parameters. 990 @type config:dictionary 991 @raise ServerError: If the server has received the request but did not process the request due to some error. 992 @raise ParseError: If the server has responded but client was not able to parse the response. 993 """ 994 endpoint = self.endpoint + "/variables/" + variable_id 995 config["variableName"] = variable_name 996 config["variableDataType"] = variable_datatype 997 config["variableType"] = variable_type 998 response = self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
999
1000 - def delete_variable(self, variable_id):
1001 """ 1002 Delete the specified variable in the workspace. 1003 @param variable_id: Id of the variable. 1004 @type variable_id: string 1005 @raise ServerError: If the server has received the request but did not process the request due to some error. 1006 @raise ParseError: If the server has responded but client was not able to parse the response. 1007 """ 1008 endpoint = self.endpoint + "/variables/" + variable_id 1009 response = self.ac.send_api_request("DELETE", endpoint, None, self.request_headers)
1010
1011 - def get_variables(self):
1012 """ 1013 Returns list of variables for the specified workspace. 1014 @raise ServerError: If the server has received the request but did not process the request due to some error. 1015 @raise ParseError: If the server has responded but client was not able to parse the response. 1016 @return: Variable list. 1017 @rtype:list 1018 """ 1019 endpoint = self.endpoint + "/variables" 1020 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers) 1021 return response["data"]["variables"]
1022
1023 - def get_variable_details(self, variable_id):
1024 """ 1025 Returns list of variables for the specified workspace. 1026 @param variable_id: Id of the variable. 1027 @type variable_id: string 1028 @raise ServerError: If the server has received the request but did not process the request due to some error. 1029 @raise ParseError: If the server has responded but client was not able to parse the response. 1030 @return: Variable details. 1031 @rtype:dictionary 1032 """ 1033 endpoint = self.endpoint + "/variables/" + variable_id 1034 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers) 1035 return response["data"]
1036
1037 - def make_default_folder(self, folder_id):
1038 """ 1039 Make the specified folder as default. 1040 @param folder_id: Id of the folder. 1041 @type folder_id: string 1042 @raise ServerError: If the server has received the request but did not process the request due to some error. 1043 @raise ParseError: If the server has responded but client was not able to parse the response. 1044 """ 1045 endpoint = self.endpoint + "/folders/" + folder_id + "/default" 1046 response = self.ac.send_api_request("PUT", endpoint, None, self.request_headers)
1047
1048 - def get_datasources(self):
1049 """ 1050 Returns list of datasources for the specified workspace. 1051 @raise ServerError: If the server has received the request but did not process the request due to some error. 1052 @raise ParseError: If the server has responded but client was not able to parse the response. 1053 @return: Datasource list. 1054 @rtype:list 1055 """ 1056 endpoint = self.endpoint + "/datasources" 1057 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers) 1058 return response["data"]["dataSources"]
1059
1060 - def sync_data(self, datasource_id, config = {}):
1061 """ 1062 Initiate data sync for the specified datasource. 1063 @param datasource_id: Id of the datasource. 1064 @type datasource_id: string 1065 @param config: Contains any additional control parameters. Can be C{None}. 1066 @type config:dictionary 1067 @raise ServerError: If the server has received the request but did not process the request due to some error. 1068 @raise ParseError: If the server has responded but client was not able to parse the response. 1069 """ 1070 endpoint = self.endpoint + "/datasources/" + datasource_id + "/sync" 1071 response = self.ac.send_api_request("POST", endpoint, config, self.request_headers)
1072
1073 - def update_datasource_connection(self, datasource_id, config = {}):
1074 """ 1075 Update connection details for the specified datasource. 1076 @param datasource_id: Id of the datasource. 1077 @type datasource_id: string 1078 @param config: Contains the control parameters. 1079 @type config:dictionary 1080 @raise ServerError: If the server has received the request but did not process the request due to some error. 1081 @raise ParseError: If the server has responded but client was not able to parse the response. 1082 """ 1083 endpoint = self.endpoint + "/datasources/" + datasource_id 1084 response = self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
1085
1086 - def get_trash_views(self):
1087 """ 1088 Initiate data sync for the specified datasource. 1089 @raise ServerError: If the server has received the request but did not process the request due to some error. 1090 @raise ParseError: If the server has responded but client was not able to parse the response. 1091 @return: Trash view list. 1092 @rtype:list 1093 """ 1094 endpoint = self.endpoint + "/trash" 1095 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers) 1096 return response["data"]["views"]
1097
1098 - def restore_trash_views(self, view_id, config = {}):
1099 """ 1100 Restore the specified view from trash. 1101 @param view_id: Id of the view. 1102 @type view_id: string 1103 @param config: Contains any additional control parameters. Can be C{None}. 1104 @type config:dictionary 1105 @raise ServerError: If the server has received the request but did not process the request due to some error. 1106 @raise ParseError: If the server has responded but client was not able to parse the response. 1107 """ 1108 endpoint = self.endpoint + "/trash/" + view_id 1109 response = self.ac.send_api_request("POST", endpoint, None, self.request_headers)
1110
1111 - def delete_trash_views(self, view_id, config = {}):
1112 """ 1113 Delete the specified view permanently from trash. 1114 @param view_id: Id of the view. 1115 @type view_id: string 1116 @param config: Contains any additional control parameters. Can be C{None}. 1117 @type config:dictionary 1118 @raise ServerError: If the server has received the request but did not process the request due to some error. 1119 @raise ParseError: If the server has responded but client was not able to parse the response. 1120 """ 1121 endpoint = self.endpoint + "/trash/" + view_id 1122 response = self.ac.send_api_request("DELETE", endpoint, None, self.request_headers)
1123
1124 - def change_folder_hierarchy(self, folder_id, hierarchy, config = {}):
1125 """ 1126 Swaps the hierarchy of a parent folder and a subfolder. 1127 @param folder_id: Id of the folder. 1128 @type folder_id: string 1129 @param hierarchy: New hierarchy for the folder. (0 - Parent; 1 - Child). 1130 @type hierarchy: string 1131 @param config: Contains any additional control parameters. Can be C{None}. 1132 @type config:dictionary 1133 @raise ServerError: If the server has received the request but did not process the request due to some error. 1134 @raise ParseError: If the server has responded but client was not able to parse the response. 1135 """ 1136 endpoint = self.endpoint + "/folders/" + folder_id + "/move"; 1137 config["hierarchy"] = hierarchy 1138 self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
1139
1140 - def change_folder_position(self, folder_id, reference_folder_id, config = {}):
1141 """ 1142 Place the folder above the reference folder. 1143 @param folder_id: Id of the folder. 1144 @type folder_id: string 1145 @param reference_folder_id: Id of the reference folder. 1146 @type reference_folder_id: string 1147 @param config: Contains any additional control parameters. Can be C{None}. 1148 @type config:dictionary 1149 @raise ServerError: If the server has received the request but did not process the request due to some error. 1150 @raise ParseError: If the server has responded but client was not able to parse the response. 1151 """ 1152 endpoint = self.endpoint + "/folders/" + folder_id + "/reorder"; 1153 config["referenceFolderId"] = reference_folder_id 1154 self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
1155
1156 - def move_views_to_folder(self, folder_id, view_ids, config = {}):
1157 """ 1158 Move views to the mentioned folder. 1159 @param folder_id: Id of the folder. 1160 @type folder_id: string 1161 @param view_ids: View ids to be moved. 1162 @type view_ids: list 1163 @param config: Contains any additional control parameters. Can be C{None}. 1164 @type config:dictionary 1165 @raise ServerError: If the server has received the request but did not process the request due to some error. 1166 @raise ParseError: If the server has responded but client was not able to parse the response. 1167 """ 1168 endpoint = self.endpoint + "/views/movetofolder"; 1169 config["folderId"] = folder_id 1170 config["viewIds"] = view_ids 1171 self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
1172
1173 - def export_as_template(self, view_ids, file_path, config = {}):
1174 """ 1175 Export the mentioned views as templates. 1176 @param view_ids: Ids of the views to be exported. 1177 @type view_ids: list 1178 @param file_path: Path of the file where the data exported to be stored. ( Should be in 'atpt' format ) 1179 @type file_path: string 1180 @param config: Contains any additional control parameters. Can be C{None}. 1181 @type config:dictionary 1182 @raise ServerError: If the server has received the request but did not process the request due to some error. 1183 @raise ParseError: If the server has responded but client was not able to parse the response. 1184 """ 1185 endpoint = self.endpoint + "/template/data" 1186 config["viewIds"] = view_ids 1187 self.ac.send_export_api_request(endpoint, config, self.request_headers, file_path)
1188
1189 - def get_workspace_users(self):
1190 """ 1191 Returns list of users for the specified workspace. 1192 @raise ServerError: If the server has received the request but did not process the request due to some error. 1193 @raise ParseError: If the server has responded but client was not able to parse the response. 1194 @return: User list. 1195 @rtype:list 1196 """ 1197 endpoint = self.endpoint + "/users"; 1198 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers) 1199 return response["data"]["users"]
1200
1201 - def add_workspace_users(self, email_ids, role, config = {}):
1202 """ 1203 Add users to the specified workspace. 1204 @param email_ids: The email address of the users to be added. 1205 @type email_ids:list 1206 @param role: Role of the user to be added. 1207 @type role:string 1208 @param config: Contains any additional control parameters. Can be C{None}. 1209 @type config:dictionary 1210 @raise ServerError: If the server has received the request but did not process the request due to some error. 1211 @raise ParseError: If the server has responded but client was not able to parse the response. 1212 """ 1213 config["emailIds"] = email_ids 1214 config["role"] = role 1215 endpoint = self.endpoint + "/users"; 1216 self.ac.send_api_request("POST", endpoint, config, self.request_headers)
1217
1218 - def remove_workspace_users(self, email_ids, config = {}):
1219 """ 1220 Remove users from the specified workspace. 1221 @param email_ids: The email address of the users to be removed. 1222 @type email_ids:list 1223 @param config: Contains any additional control parameters. Can be C{None}. 1224 @type config:dictionary 1225 @raise ServerError: If the server has received the request but did not process the request due to some error. 1226 @raise ParseError: If the server has responded but client was not able to parse the response. 1227 """ 1228 config["emailIds"] = email_ids 1229 endpoint = self.endpoint + "/users"; 1230 self.ac.send_api_request("DELETE", endpoint, config, self.request_headers)
1231
1232 - def change_workspace_user_status(self, email_ids, operation, config = {}):
1233 """ 1234 Change users status in the specified workspace. 1235 @param email_ids: The email address of the users. 1236 @type email_ids:list 1237 @param operation: New status for the users ( Values - activate | deactivate ). 1238 @type operation:string 1239 @param config: Contains any additional control parameters. Can be C{None}. 1240 @type config:dictionary 1241 @raise ServerError: If the server has received the request but did not process the request due to some error. 1242 @raise ParseError: If the server has responded but client was not able to parse the response. 1243 """ 1244 config["emailIds"] = email_ids 1245 config["operation"] = operation 1246 endpoint = self.endpoint + "/users/status"; 1247 self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
1248
1249 - def change_workspace_user_role(self, email_ids, role, config = {}):
1250 """ 1251 Change role for the specified users. 1252 @param email_ids: The email address of the users. 1253 @type email_ids:list 1254 @param role: New role for the users. 1255 @type role:string 1256 @param config: Contains any additional control parameters. Can be C{None}. 1257 @type config:dictionary 1258 @raise ServerError: If the server has received the request but did not process the request due to some error. 1259 @raise ParseError: If the server has responded but client was not able to parse the response. 1260 """ 1261 config["emailIds"] = email_ids 1262 config["role"] = role 1263 endpoint = self.endpoint + "/users/role"; 1264 self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
1265 1266
1267 - def get_email_schedules(self):
1268 """ 1269 Returns list of email schedules available in the specified workspace. 1270 @raise ServerError: If the server has received the request but did not process the request due to some error. 1271 @raise ParseError: If the server has responded but client was not able to parse the response. 1272 @return: List of email schedules. 1273 @rtype: list 1274 """ 1275 endpoint = self.endpoint + "/emailschedules" 1276 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers) 1277 return response["data"]["emailSchedules"]
1278
1279 - def create_email_schedule(self, schedule_name, view_ids, format, email_ids, schedule_details, config={}):
1280 """ 1281 Create an email schedule in the specified workspace. 1282 @param schedule_name: Name of the email schedule. 1283 @type schedule_name: string 1284 @param view_ids: View ids to be mailed. 1285 @type view_ids: list 1286 @param format: The format in which the data has to be mailed. 1287 @type format: string 1288 @param email_ids: The recipients' email addresses for sending views. 1289 @type email_ids: list 1290 @param schedule_details: Contains schedule frequency, date, and time info. 1291 @type schedule_details: dictionary 1292 @param config: Contains any additional control parameters. Can be None. 1293 @type config: dictionary 1294 @raise ServerError: If the server has received the request but did not process the request due to some error. 1295 @raise ParseError: If the server has responded but client was not able to parse the response. 1296 @return: Email schedule id. 1297 @rtype: string 1298 """ 1299 config["scheduleName"] = schedule_name 1300 config["viewIds"] = view_ids 1301 config["exportType"] = format 1302 config["emailIds"] = email_ids 1303 config["scheduleDetails"] = schedule_details 1304 endpoint = self.endpoint + "/emailschedules" 1305 response = self.ac.send_api_request("POST", endpoint, config, self.request_headers) 1306 return str(response["data"]["scheduleId"])
1307
1308 - def update_email_schedule(self, schedule_id, config):
1309 """ 1310 Update configurations of the specified email schedule in the workspace. 1311 @param schedule_id: Id for the email schedule. 1312 @type schedule_id: string 1313 @param config: Contains the control configurations. 1314 @type config: dictionary 1315 @raise ServerError: If the server has received the request but did not process the request due to some error. 1316 @raise ParseError: If the server has responded but client was not able to parse the response. 1317 @return: Updated schedule id. 1318 @rtype: string 1319 """ 1320 endpoint = self.endpoint + "/emailschedules/" + schedule_id 1321 response = self.ac.send_api_request("PUT", endpoint, config, self.request_headers) 1322 return str(response["data"]["scheduleId"])
1323
1324 - def trigger_email_schedule(self, schedule_id):
1325 """ 1326 Trigger configured email schedules instantly. 1327 @param schedule_id: Id for the email schedule. 1328 @type schedule_id: string 1329 @raise ServerError: If the server has received the request but did not process the request due to some error. 1330 @raise ParseError: If the server has responded but client was not able to parse the response. 1331 """ 1332 endpoint = self.endpoint + "/emailschedules/" + schedule_id 1333 self.ac.send_api_request("POST", endpoint, None, self.request_headers)
1334
1335 - def change_email_schedule_status(self, schedule_id, operation):
1336 """ 1337 Update email schedule status. 1338 @param schedule_id: Id for the email schedule. 1339 @type schedule_id: string 1340 @param operation: New status for the schedule ( Values - activate | deactivate ) 1341 @type operation: string 1342 @raise ServerError: If the server has received the request but did not process the request due to some error. 1343 @raise ParseError: If the server has responded but client was not able to parse the response. 1344 """ 1345 endpoint = self.endpoint + "/emailschedules/" + schedule_id + "/status" 1346 config = {"operation": operation} 1347 self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
1348
1349 - def delete_email_schedule(self, schedule_id):
1350 """ 1351 Delete the specified email schedule in the workspace. 1352 @param schedule_id: Id for the email schedule. 1353 @type schedule_id: string 1354 @raise ServerError: If the server has received the request but did not process the request due to some error. 1355 @raise ParseError: If the server has responded but client was not able to parse the response. 1356 """ 1357 endpoint = self.endpoint + "/emailschedules/" + schedule_id 1358 self.ac.send_api_request("DELETE", endpoint, None, self.request_headers)
1359
1360 - def get_aggregate_formulas(self, config = {}):
1361 """ 1362 Returns list of all aggregate formulas for the specified workspace. 1363 @param config: Contains any additional control parameters. Can be C{None}. 1364 @type config:dictionary 1365 @raise ServerError: If the server has received the request but did not process the request due to some error. 1366 @raise ParseError: If the server has responded but client was not able to parse the response. 1367 @return: Aggregate formula list. 1368 @rtype:list 1369 """ 1370 endpoint = self.endpoint + "/aggregateformulas" 1371 response = self.ac.send_api_request("GET", endpoint, config, self.request_headers) 1372 return response["data"]["aggregateFormulas"]
1373
1374 - def get_aggregate_formula_dependents(self, formula_id):
1375 """ 1376 Returns list of all dependent views and formulas for the specified aggregate formula. 1377 @param formula_id: Id of the aggregate formula 1378 @type formula_id: string 1379 @raise ServerError: If the server has received the request but did not process the request due to some error. 1380 @raise ParseError: If the server has responded but client was not able to parse the response. 1381 @return: Dependent details. 1382 @rtype:dictionary 1383 """ 1384 endpoint = self.endpoint + "/aggregateformulas/" + formula_id + "/dependents" 1385 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers) 1386 return response["data"]
1387
1388 - def get_aggregate_formula_value(self, formula_id):
1389 """ 1390 Returns the value of the aggregate formula. 1391 @param formula_id: Id of the aggregate formula 1392 @type formula_id: string 1393 @raise ServerError: If the server has received the request but did not process the request due to some error. 1394 @raise ParseError: If the server has responded but client was not able to parse the response. 1395 @return: Aggregate formula value. 1396 @rtype:string 1397 """ 1398 endpoint = self.endpoint + "/aggregateformulas/" + formula_id + "/value" 1399 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers) 1400 return response["data"]["formulaValue"]
1401
1402 - def create_report(self, config = {}):
1403 """ 1404 Create a report in the specified workspace. 1405 @param config: Contains the control parameters. 1406 @type config:dictionary 1407 @raise ServerError: If the server has received the request but did not process the request due to some error. 1408 @raise ParseError: If the server has responded but client was not able to parse the response. 1409 @return: Id of the created view. 1410 @rtype:string 1411 """ 1412 endpoint = self.endpoint + "/reports" 1413 response = self.ac.send_api_request("POST", endpoint, config, self.request_headers) 1414 return int(response["data"]["viewId"])
1415
1416 - def update_report(self, view_id, config = {}):
1417 """ 1418 Update the design and configuration of the specified report. 1419 @param view_id: Id of the view. 1420 @type view_id: string 1421 @param config: Contains the control parameters. 1422 @type config:dictionary 1423 @raise ServerError: If the server has received the request but did not process the request due to some error. 1424 @raise ParseError: If the server has responded but client was not able to parse the response. 1425 """ 1426 endpoint = self.endpoint + "/reports/" + view_id 1427 response = self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
1428 1429
1430 - class ViewAPI:
1431 """ 1432 ViewAPI contains view level operations. 1433 """
1434 - def __init__(self, ac, org_id, workspace_id, view_id):
1435 self.ac = ac 1436 self.endpoint = "/restapi/v2/workspaces/" + workspace_id + "/views/" + view_id 1437 self.request_headers = {} 1438 self.request_headers["ZANALYTICS-ORGID"] = org_id
1439
1440 - def rename(self, view_name, config = {}):
1441 """ 1442 Rename a specified view in the workspace. 1443 @param view_name: New name of the view. 1444 @type view_name: string 1445 @param config: Contains any additional control parameters. Can be C{None}. 1446 @type config:dictionary 1447 @raise ServerError: If the server has received the request but did not process the request due to some error. 1448 @raise ParseError: If the server has responded but client was not able to parse the response. 1449 """ 1450 config["viewName"] = view_name 1451 response = self.ac.send_api_request("PUT", self.endpoint, config, self.request_headers)
1452
1453 - def delete(self, config = {}):
1454 """ 1455 Delete a specified view in the workspace. 1456 @param config: Contains any additional control parameters. Can be C{None}. 1457 @type config:dictionary 1458 @raise ServerError: If the server has received the request but did not process the request due to some error. 1459 @raise ParseError: If the server has responded but client was not able to parse the response. 1460 """ 1461 response = self.ac.send_api_request("DELETE", self.endpoint, config, self.request_headers)
1462
1463 - def save_as(self, new_view_name, config = {}):
1464 """ 1465 Copy a specified view within the workspace. 1466 @param new_view_name: The name of the new view. 1467 @type new_view_name: string 1468 @param config: Contains any additional control parameters. Can be C{None}. 1469 @type config:dictionary 1470 @raise ServerError: If the server has received the request but did not process the request due to some error. 1471 @raise ParseError: If the server has responded but client was not able to parse the response. 1472 @return: Created view id. 1473 @rtype:string 1474 """ 1475 config["viewName"] = new_view_name 1476 endpoint = self.endpoint + "/saveas" 1477 response = self.ac.send_api_request("POST", endpoint, config, self.request_headers) 1478 return int(response["data"]["viewId"])
1479
1480 - def copy_formulas(self, formula_names, dest_workspace_id, config = {}, dest_org_id = None):
1481 """ 1482 Copy the specified formulas from one table to another within the workspace or across workspaces. 1483 @param formula_names: The name of the formula columns to be copied. 1484 @type formula_names: list 1485 @param dest_workspace_id: The ID of the destination workspace. 1486 @type dest_workspace_id: string 1487 @param dest_org_id: Id of the organization where the destination workspace is present. Can be C{None}. 1488 @type dest_org_id: string 1489 @param config: Contains any additional control parameters. Can be C{None}. 1490 @type config:dictionary 1491 @raise ServerError: If the server has received the request but did not process the request due to some error. 1492 @raise ParseError: If the server has responded but client was not able to parse the response. 1493 """ 1494 config["formulaColumnNames"] = formula_names 1495 config["destWorkspaceId"] = dest_workspace_id 1496 endpoint = self.endpoint + "/formulas/copy" 1497 headers = self.request_headers.copy() 1498 if bool(dest_org_id): 1499 headers["ZANALYTICS-DEST-ORGID"] = dest_org_id 1500 self.ac.send_api_request("POST", endpoint, config, headers)
1501
1502 - def add_favorite(self):
1503 """ 1504 Adds a specified view as favorite. 1505 @raise ServerError: If the server has received the request but did not process the request due to some error. 1506 @raise ParseError: If the server has responded but client was not able to parse the response. 1507 """ 1508 endpoint = self.endpoint + "/favorite" 1509 response = self.ac.send_api_request("POST", endpoint, None, self.request_headers)
1510
1511 - def remove_favorite(self):
1512 """ 1513 Remove a specified view from favorite. 1514 @raise ServerError: If the server has received the request but did not process the request due to some error. 1515 @raise ParseError: If the server has responded but client was not able to parse the response. 1516 """ 1517 endpoint = self.endpoint + "/favorite" 1518 response = self.ac.send_api_request("DELETE", endpoint, None, self.request_headers)
1519
1520 - def create_similar_views(self, ref_view_id, folder_id, config = {}):
1521 """ 1522 Create reports for the specified table based on the reference table. 1523 @param ref_view_id: The ID of the reference view. 1524 @type ref_view_id: string 1525 @param folder_id: The folder id where the views to be saved. 1526 @type folder_id: string 1527 @param config: Contains any additional control parameters. Can be C{None}. 1528 @type config:dictionary 1529 @raise ServerError: If the server has received the request but did not process the request due to some error. 1530 @raise ParseError: If the server has responded but client was not able to parse the response. 1531 """ 1532 config["referenceViewId"] = ref_view_id 1533 config["folderId"] = folder_id 1534 endpoint = self.endpoint + "/similarviews" 1535 self.ac.send_api_request("POST", endpoint, config, self.request_headers)
1536
1537 - def auto_analyse(self, config = {}):
1538 """ 1539 Auto generate reports for the specified table. 1540 @param config: Contains any additional control parameters. Can be C{None}. 1541 @type config:dictionary 1542 @raise ServerError: If the server has received the request but did not process the request due to some error. 1543 @raise ParseError: If the server has responded but client was not able to parse the response. 1544 """ 1545 endpoint = self.endpoint + "/autoanalyse" 1546 self.ac.send_api_request("POST", endpoint, config, self.request_headers)
1547
1548 - def get_my_permissions(self):
1549 """ 1550 Returns permissions for the specified view. 1551 @raise ServerError: If the server has received the request but did not process the request due to some error. 1552 @raise ParseError: If the server has responded but client was not able to parse the response. 1553 @return: Permission details. 1554 @rtype:dictionary 1555 """ 1556 endpoint = self.endpoint + "/share/userpermissions" 1557 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers) 1558 return response["data"]["permissions"]
1559
1560 - def get_view_url(self, config = {}):
1561 """ 1562 Returns the URL to access the specified view. 1563 @param config: Contains any additional control parameters. Can be C{None}. 1564 @type config:dictionary 1565 @raise ServerError: If the server has received the request but did not process the request due to some error. 1566 @raise ParseError: If the server has responded but client was not able to parse the response. 1567 @return: View URL. 1568 @rtype:string 1569 """ 1570 endpoint = self.endpoint + "/publish" 1571 response = self.ac.send_api_request("GET", endpoint, config, self.request_headers) 1572 return response["data"]["viewUrl"]
1573
1574 - def get_embed_url(self, config = {}):
1575 """ 1576 Returns embed URL to access the specified view. 1577 @param config: Contains any additional control parameters. Can be C{None}. 1578 @type config:dictionary 1579 @raise ServerError: If the server has received the request but did not process the request due to some error. 1580 @raise ParseError: If the server has responded but client was not able to parse the response. 1581 @return: Embed URL. 1582 @rtype:string 1583 """ 1584 endpoint = self.endpoint + "/publish/embed" 1585 response = self.ac.send_api_request("GET", endpoint, config, self.request_headers) 1586 return response["data"]["embedUrl"]
1587
1588 - def get_private_url(self, config = {}):
1589 """ 1590 Returns private URL to access the specified view. 1591 @param config: Contains any additional control parameters. Can be C{None}. 1592 @type config:dictionary 1593 @raise ServerError: If the server has received the request but did not process the request due to some error. 1594 @raise ParseError: If the server has responded but client was not able to parse the response. 1595 @return: Private URL. 1596 @rtype:string 1597 """ 1598 endpoint = self.endpoint + "/publish/privatelink" 1599 response = self.ac.send_api_request("GET", endpoint, config, self.request_headers) 1600 return response["data"]["privateUrl"]
1601
1602 - def create_private_url(self, config = {}):
1603 """ 1604 Create a private URL for the specified view. 1605 @param config: Contains any additional control parameters. Can be C{None}. 1606 @type config:dictionary 1607 @raise ServerError: If the server has received the request but did not process the request due to some error. 1608 @raise ParseError: If the server has responded but client was not able to parse the response. 1609 @return: Private URL. 1610 @rtype:string 1611 """ 1612 endpoint = self.endpoint + "/publish/privatelink" 1613 response = self.ac.send_api_request("POST", endpoint, config, self.request_headers) 1614 return response["data"]["privateUrl"]
1615
1616 - def remove_private_access(self):
1617 """ 1618 Remove private link access for the specified view. 1619 @raise ServerError: If the server has received the request but did not process the request due to some error. 1620 @raise ParseError: If the server has responded but client was not able to parse the response. 1621 """ 1622 endpoint = self.endpoint + "/publish/privatelink" 1623 response = self.ac.send_api_request("DELETE", endpoint, None, self.request_headers)
1624
1625 - def make_view_public(self, config = {}):
1626 """ 1627 Make the specified view publically accessible. 1628 @param config: Contains any additional control parameters. Can be C{None}. 1629 @type config:dictionary 1630 @raise ServerError: If the server has received the request but did not process the request due to some error. 1631 @raise ParseError: If the server has responded but client was not able to parse the response. 1632 @return: Public URL. 1633 @rtype:string 1634 """ 1635 endpoint = self.endpoint + "/publish/public" 1636 response = self.ac.send_api_request("POST", endpoint, config, self.request_headers) 1637 return response["data"]["publicUrl"]
1638
1639 - def remove_public_access(self):
1640 """ 1641 Remove public access for the specified view. 1642 @raise ServerError: If the server has received the request but did not process the request due to some error. 1643 @raise ParseError: If the server has responded but client was not able to parse the response. 1644 """ 1645 response = endpoint = self.endpoint + "/publish/public" 1646 self.ac.send_api_request("DELETE", endpoint, None, self.request_headers)
1647
1648 - def get_publish_configurations(self):
1649 """ 1650 Returns publish configurations for the specified view. 1651 @raise ServerError: If the server has received the request but did not process the request due to some error. 1652 @raise ParseError: If the server has responded but client was not able to parse the response. 1653 @return: Publish details. 1654 @rtype:dictionary 1655 """ 1656 endpoint = self.endpoint + "/publish/config" 1657 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers) 1658 return response["data"]
1659
1660 - def update_publish_configurations(self, config = {}):
1661 """ 1662 Update publish configurations for the specified view. 1663 @param config: Contains the control parameters. 1664 @type config:dictionary 1665 @raise ServerError: If the server has received the request but did not process the request due to some error. 1666 @raise ParseError: If the server has responded but client was not able to parse the response. 1667 """ 1668 endpoint = self.endpoint + "/publish/config" 1669 response = self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
1670
1671 - def add_column(self, column_name, data_type, config = {}):
1672 """ 1673 Add a column in the specified table. 1674 @param column_name: The name of the column. 1675 @type column_name: string 1676 @param data_type: The data-type of the column. 1677 @type data_type: string 1678 @param config: Contains any additional control parameters. Can be C{None}. 1679 @type config:dictionary 1680 @raise ServerError: If the server has received the request but did not process the request due to some error. 1681 @raise ParseError: If the server has responded but client was not able to parse the response. 1682 @return: Created column id. 1683 @rtype:string 1684 """ 1685 config["columnName"] = column_name 1686 config["dataType"] = data_type 1687 endpoint = self.endpoint + "/columns" 1688 response = self.ac.send_api_request("POST", endpoint, config, self.request_headers) 1689 return int(response["data"]["columnId"])
1690
1691 - def hide_columns(self, column_ids):
1692 """ 1693 Hide the specified columns in the table. 1694 @param column_ids: Ids of the columns to be hidden. 1695 @type column_ids: list 1696 @raise ServerError: If the server has received the request but did not process the request due to some error. 1697 @raise ParseError: If the server has responded but client was not able to parse the response. 1698 """ 1699 config = {} 1700 config["columnIds"] = column_ids 1701 endpoint = self.endpoint + "/columns/hide" 1702 self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
1703
1704 - def show_columns(self, column_ids):
1705 """ 1706 Show the specified hidden columns in the table. 1707 @param column_ids: Ids of the columns to be shown. 1708 @type column_ids: list 1709 @raise ServerError: If the server has received the request but did not process the request due to some error. 1710 @raise ParseError: If the server has responded but client was not able to parse the response. 1711 """ 1712 config = {} 1713 config["columnIds"] = column_ids 1714 endpoint = self.endpoint + "/columns/show" 1715 self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
1716
1717 - def add_row(self, column_values, config = {}):
1718 """ 1719 Add a single row in the specified table. 1720 @param column_values: Contains the values for the row. The column names are the key. 1721 @type column_values: dictionary 1722 @param config: Contains any additional control parameters. Can be C{None}. 1723 @type config:dictionary 1724 @raise ServerError: If the server has received the request but did not process the request due to some error. 1725 @raise ParseError: If the server has responded but client was not able to parse the response. 1726 @return: Column Names and Added Row Values. 1727 @rtype:dictionary 1728 """ 1729 config["columns"] = column_values 1730 endpoint = self.endpoint + "/rows" 1731 response = self.ac.send_api_request("POST", endpoint, config, self.request_headers) 1732 return response["data"]
1733
1734 - def update_row(self, column_values, criteria, config = {}):
1735 """ 1736 Update rows in the specified table. 1737 @param column_values: Contains the values for the row. The column names are the key. 1738 @type column_values: dictionary 1739 @param criteria: The criteria to be applied for updating data. Only rows matching the criteria will be updated. Should be null for update all rows. 1740 @type criteria: string 1741 @param config: Contains any additional control parameters. Can be C{None}. 1742 @type config:dictionary 1743 @raise ServerError: If the server has received the request but did not process the request due to some error. 1744 @raise ParseError: If the server has responded but client was not able to parse the response. 1745 @return: Updated Columns List and Updated Rows Count. 1746 @rtype:dictionary 1747 """ 1748 config["columns"] = column_values 1749 if criteria != None: 1750 config["criteria"] = criteria 1751 endpoint = self.endpoint + "/rows" 1752 response = self.ac.send_api_request("PUT", endpoint, config, self.request_headers) 1753 return response["data"]
1754
1755 - def delete_row(self, criteria, config = {}):
1756 """ 1757 Delete rows in the specified table. 1758 @param criteria: The criteria to be applied for deleting data. Only rows matching the criteria will be deleted. Should be null for delete all rows. 1759 @type criteria: string 1760 @param config: Contains any additional control parameters. Can be C{None}. 1761 @type config:dictionary 1762 @raise ServerError: If the server has received the request but did not process the request due to some error. 1763 @raise ParseError: If the server has responded but client was not able to parse the response. 1764 @return: Deleted rows details. 1765 @rtype:string 1766 """ 1767 if criteria != None: 1768 config["criteria"] = criteria 1769 endpoint = self.endpoint + "/rows" 1770 response = self.ac.send_api_request("DELETE", endpoint, config, self.request_headers) 1771 return response["data"]["deletedRows"]
1772
1773 - def rename_column(self, column_id, column_name, config = {}):
1774 """ 1775 Rename a specified column in the table. 1776 @param column_id: Id of the column. 1777 @type column_id: string 1778 @param column_name: New name for the column. 1779 @type column_name: string 1780 @param config: Contains any additional control parameters. Can be C{None}. 1781 @type config:dictionary 1782 @raise ServerError: If the server has received the request but did not process the request due to some error. 1783 @raise ParseError: If the server has responded but client was not able to parse the response. 1784 """ 1785 config["columnName"] = column_name 1786 endpoint = self.endpoint + "/columns/" + column_id 1787 self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
1788
1789 - def delete_column(self, column_id, config = {}):
1790 """ 1791 Delete a specified column in the table. 1792 @param column_id: Id of the column. 1793 @type column_id: string 1794 @param config: Contains any additional control parameters. Can be C{None}. 1795 @type config:dictionary 1796 @raise ServerError: If the server has received the request but did not process the request due to some error. 1797 @raise ParseError: If the server has responded but client was not able to parse the response. 1798 """ 1799 endpoint = self.endpoint + "/columns/" + column_id 1800 self.ac.send_api_request("DELETE", endpoint, config, self.request_headers)
1801
1802 - def add_lookup(self, column_id, ref_view_id, ref_column_id, config = {}):
1803 """ 1804 Add a lookup in the specified child table. 1805 @param column_id: Id of the column. 1806 @type column_id: string 1807 @param ref_view_id: The id of the table contains the parent column. 1808 @type ref_view_id: string 1809 @param ref_column_id: The id of the parent column. 1810 @type ref_column_id: string 1811 @param config: Contains any additional control parameters. Can be C{None}. 1812 @type config:dictionary 1813 @raise ServerError: If the server has received the request but did not process the request due to some error. 1814 @raise ParseError: If the server has responded but client was not able to parse the response. 1815 """ 1816 config["referenceViewId"] = ref_view_id; 1817 config["referenceColumnId"] = ref_column_id 1818 endpoint = self.endpoint + "/columns/" + column_id + "/lookup" 1819 self.ac.send_api_request("POST", endpoint, config, self.request_headers)
1820
1821 - def remove_lookup(self, column_id, config = {}):
1822 """ 1823 Remove the lookup for the specified column in the table. 1824 @param column_id: Id of the column. 1825 @type column_id: string 1826 @param config: Contains any additional control parameters. Can be C{None}. 1827 @type config:dictionary 1828 @raise ServerError: If the server has received the request but did not process the request due to some error. 1829 @raise ParseError: If the server has responded but client was not able to parse the response. 1830 """ 1831 endpoint = self.endpoint + "/columns/" + column_id + "/lookup" 1832 self.ac.send_api_request("DELETE", endpoint, config, self.request_headers)
1833
1834 - def auto_analyse_column(self, column_id, config = {}):
1835 """ 1836 Auto generate reports for the specified column. 1837 @param column_id: Id of the column. 1838 @type column_id: string 1839 @param config: Contains any additional control parameters. Can be C{None}. 1840 @type config:dictionary 1841 @raise ServerError: If the server has received the request but did not process the request due to some error. 1842 @raise ParseError: If the server has responded but client was not able to parse the response. 1843 """ 1844 endpoint = self.endpoint + "/columns/" + column_id + "/autoanalyse" 1845 self.ac.send_api_request("POST", endpoint, config, self.request_headers)
1846
1847 - def refetch_data(self, config = {}):
1848 """ 1849 Sync data from available datasource for the specified view. 1850 @param config: Contains any additional control parameters. Can be C{None}. 1851 @type config:dictionary 1852 @raise ServerError: If the server has received the request but did not process the request due to some error. 1853 @raise ParseError: If the server has responded but client was not able to parse the response. 1854 """ 1855 endpoint = self.endpoint + "/sync" 1856 response = self.ac.send_api_request("POST", endpoint, config, self.request_headers)
1857
1858 - def get_last_import_details(self):
1859 """ 1860 Returns last import details of the specified view. 1861 @raise ServerError: If the server has received the request but did not process the request due to some error. 1862 @raise ParseError: If the server has responded but client was not able to parse the response. 1863 @return: Last import details. 1864 @rtype:dictionary 1865 """ 1866 endpoint = self.endpoint + "/importdetails" 1867 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers) 1868 return response["data"]
1869
1870 - def get_formula_columns(self):
1871 """ 1872 Returns list of all formula columns for the specified table. 1873 @raise ServerError: If the server has received the request but did not process the request due to some error. 1874 @raise ParseError: If the server has responded but client was not able to parse the response. 1875 @return: Formula column list. 1876 @rtype:list 1877 """ 1878 endpoint = self.endpoint + "/formulacolumns" 1879 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers) 1880 return response["data"]["formulaColumns"]
1881
1882 - def add_formula_column(self, formula_name, expression, config = {}):
1883 """ 1884 Add a formula column in the specified table. 1885 @param formula_name: Name of the formula column to be created. 1886 @type formula_name: string 1887 @param expression: Formula expression. 1888 @type expression: string 1889 @param config: Contains any additional control parameters. Can be C{None}. 1890 @type config:dictionary 1891 @raise ServerError: If the server has received the request but did not process the request due to some error. 1892 @raise ParseError: If the server has responded but client was not able to parse the response. 1893 @return: Created formula id. 1894 @rtype:string 1895 """ 1896 endpoint = self.endpoint + "/formulacolumns" 1897 config["formulaName"] = formula_name; 1898 config["expression"] = expression; 1899 response = self.ac.send_api_request("POST", endpoint, config, self.request_headers) 1900 return response["data"]["formulaId"]
1901
1902 - def edit_formula_column(self, formula_id, expression, config = {}):
1903 """ 1904 Edit the specified formula column. 1905 @param formula_id: Id of the formula column to be updated. 1906 @type formula_id: string 1907 @param expression: Formula expression. 1908 @type expression: string 1909 @param config: Contains any additional control parameters. Can be C{None}. 1910 @type config:dictionary 1911 @raise ServerError: If the server has received the request but did not process the request due to some error. 1912 @raise ParseError: If the server has responded but client was not able to parse the response. 1913 """ 1914 endpoint = self.endpoint + "/formulacolumns/" + formula_id 1915 config["expression"] = expression; 1916 self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
1917
1918 - def delete_formula_column(self, formula_id, config = {}):
1919 """ 1920 Delete the specified formula column. 1921 @param formula_id: Id of the formula column to be deleted. 1922 @type formula_id: string 1923 @param config: Contains any additional control parameters. Can be C{None}. 1924 @type config:dictionary 1925 @raise ServerError: If the server has received the request but did not process the request due to some error. 1926 @raise ParseError: If the server has responded but client was not able to parse the response. 1927 """ 1928 endpoint = self.endpoint + "/formulacolumns/" + formula_id 1929 self.ac.send_api_request("DELETE", endpoint, config, self.request_headers)
1930
1931 - def get_aggregate_formulas(self):
1932 """ 1933 Returns list of all aggregate formulas for the specified table. 1934 @raise ServerError: If the server has received the request but did not process the request due to some error. 1935 @raise ParseError: If the server has responded but client was not able to parse the response. 1936 @return: Aggregate Formula list. 1937 @rtype:list 1938 """ 1939 endpoint = self.endpoint + "/aggregateformulas" 1940 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers) 1941 return response["data"]["aggregateFormulas"]
1942
1943 - def add_aggregate_formula(self, formula_name, expression, config = {}):
1944 """ 1945 Add an aggregate formula in the specified table. 1946 @param formula_name: Name of the aggregate formula to be created. 1947 @type formula_name: string 1948 @param expression: Formula expression. 1949 @type expression: string 1950 @param config: Contains any additional control parameters. Can be C{None}. 1951 @type config:dictionary 1952 @raise ServerError: If the server has received the request but did not process the request due to some error. 1953 @raise ParseError: If the server has responded but client was not able to parse the response. 1954 @return: Created formula id. 1955 @rtype:string 1956 """ 1957 endpoint = self.endpoint + "/aggregateformulas" 1958 config["formulaName"] = formula_name; 1959 config["expression"] = expression; 1960 response = self.ac.send_api_request("POST", endpoint, config, self.request_headers) 1961 return response["data"]["formulaId"]
1962
1963 - def edit_aggregate_formula(self, formula_id, expression, config = {}):
1964 """ 1965 Edit the specified aggregate formula. 1966 @param formula_id: Id of the aggregate formula to be updated. 1967 @type formula_id: string 1968 @param expression: Formula expression. 1969 @type expression: string 1970 @param config: Contains any additional control parameters. Can be C{None}. 1971 @type config:dictionary 1972 @raise ServerError: If the server has received the request but did not process the request due to some error. 1973 @raise ParseError: If the server has responded but client was not able to parse the response. 1974 """ 1975 endpoint = self.endpoint + "/aggregateformulas/" + formula_id 1976 config["expression"] = expression; 1977 self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
1978
1979 - def delete_aggregate_formula(self, formula_id, config = {}):
1980 """ 1981 Delete the specified aggregate formula. 1982 @param formula_id: Id of the aggregate formula to be deleted. 1983 @type formula_id: string 1984 @param config: Contains any additional control parameters. Can be C{None}. 1985 @type config:dictionary 1986 @raise ServerError: If the server has received the request but did not process the request due to some error. 1987 @raise ParseError: If the server has responded but client was not able to parse the response. 1988 """ 1989 endpoint = self.endpoint + "/aggregateformulas/" + formula_id 1990 self.ac.send_api_request("DELETE", endpoint, config, self.request_headers)
1991
1992 - def get_view_dependents(self):
1993 """ 1994 Returns list of dependents views for the specified view. 1995 @raise ServerError: If the server has received the request but did not process the request due to some error. 1996 @raise ParseError: If the server has responded but client was not able to parse the response. 1997 @return: Dependent view list. 1998 @rtype:list 1999 """ 2000 endpoint = self.endpoint + "/dependents" 2001 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers) 2002 return response["data"]["views"]
2003
2004 - def get_column_dependents(self, column_id):
2005 """ 2006 Returns list of dependents views and formulas for the specified column. 2007 @raise ServerError: If the server has received the request but did not process the request due to some error. 2008 @raise ParseError: If the server has responded but client was not able to parse the response. 2009 @return: Dependent details. 2010 @rtype:dictionary 2011 """ 2012 endpoint = self.endpoint + "/columns/" + column_id + "/dependents" 2013 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers) 2014 return response["data"]
2015
2016 - def update_shared_details(self, config = {}):
2017 """ 2018 Update shared details of the specified view. 2019 @param config: Contains the control parameters. 2020 @type config:dictionary 2021 @raise ServerError: If the server has received the request but did not process the request due to some error. 2022 @raise ParseError: If the server has responded but client was not able to parse the response. 2023 """ 2024 endpoint = self.endpoint + "/share" 2025 self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
2026 2027
2028 - class BulkAPI:
2029 """ 2030 BulkAPI contains data operations. 2031 """
2032 - def __init__(self, ac, org_id, workspace_id):
2033 self.ac = ac 2034 self.endpoint = "/restapi/v2/workspaces/" + workspace_id 2035 self.bulk_endpoint = "/restapi/v2/bulk/workspaces/" + workspace_id 2036 self.request_headers = {} 2037 self.request_headers["ZANALYTICS-ORGID"] = org_id
2038
2039 - def import_data_in_new_table(self, table_name, file_type, auto_identify, file_path, config = {}):
2040 """ 2041 Create a new table and import the data contained in the mentioned file into the created table. 2042 @param table_name: Name of the new table to be created. 2043 @type table_name: string 2044 @param file_type: Type of the file to be imported. 2045 @type file_type: string 2046 @param auto_identify: Used to specify whether to auto identify the CSV format. Allowable values - true/false. 2047 @type auto_identify: string 2048 @param file_path: Path of the file to be imported. 2049 @type file_path: string 2050 @param config: Contains any additional control parameters. Can be C{None}. 2051 @type config:dictionary 2052 @raise ServerError: If the server has received the request but did not process the request due to some error. 2053 @raise ParseError: If the server has responded but client was not able to parse the response. 2054 @return Import result 2055 @rtype:dictionary 2056 """ 2057 endpoint = self.endpoint + "/data" 2058 config["tableName"] = table_name 2059 config["fileType"] = file_type 2060 config["autoIdentify"] = auto_identify 2061 response = self.ac.send_import_api_request(endpoint, config, self.request_headers, file_path) 2062 return response["data"]
2063
2064 - def import_data_in_new_table_as_batches(self, table_name, auto_identify, file_path, batch_size, 2065 config={}, tool_config={}):
2066 """ 2067 Create a new table and import the data contained in the mentioned file into the created table. 2068 @param table_name: Name of the new table to be created. 2069 @type table_name: string 2070 @param auto_identify: Used to specify whether to auto identify the CSV format. Allowable values - true/false. 2071 @type auto_identify: string 2072 @param file_path: Path of the file to be imported. 2073 @type file_path: string 2074 @param batch_size: Number of lines per batch. 2075 @type batch_size:int 2076 @param config: Contains any additional control parameters. Can be C{None}. 2077 @type config:dictionary 2078 @param tool_config: Contains any additional control parameters for the library. Can be C{None}. 2079 @type tool_config:dictionary 2080 @raise ServerError: If the server has received the request but did not process the request due to some error. 2081 @raise ParseError: If the server has responded but client was not able to parse the response. 2082 @return Import job id 2083 @rtype:string 2084 """ 2085 endpoint = self.bulk_endpoint + "/data/batch" 2086 config["tableName"] = table_name 2087 config["autoIdentify"] = auto_identify 2088 response = self.ac.send_batch_import_api_request(endpoint, config, self.request_headers, file_path, 2089 batch_size, tool_config) 2090 return response["data"]["jobId"]
2091
2092 - def import_raw_data_in_new_table(self, table_name, file_type, auto_identify, data, config={}):
2093 """ 2094 Create a new table and import the raw data provided into the created table. 2095 @param table_name: Name of the new table to be created. 2096 @type table_name: string 2097 @param file_type: Type of the file to be imported. 2098 @type file_type: string 2099 @param auto_identify: Used to specify whether to auto identify the CSV format. Allowable values - true/false. 2100 @type auto_identify: string 2101 @param data: Raw data to be imported. 2102 @type data: string 2103 @param config: Contains any additional control parameters. Can be C{None}. 2104 @type config:dictionary 2105 @raise ServerError: If the server has received the request but did not process the request due to some error. 2106 @raise ParseError: If the server has responded but client was not able to parse the response. 2107 @return Import result 2108 @rtype:dictionary 2109 """ 2110 endpoint = self.endpoint + "/data" 2111 config["tableName"] = table_name 2112 config["fileType"] = file_type 2113 config["autoIdentify"] = auto_identify 2114 response = self.ac.send_import_api_request(endpoint, config, self.request_headers, None, data) 2115 return response["data"]
2116
2117 - def import_data(self, view_id, import_type, file_type, auto_identify, file_path, config = {}):
2118 """ 2119 Import the data contained in the mentioned file into the table. 2120 @param view_id: Id of the view where the data to be imported. 2121 @type view_id: string 2122 @param import_type: The type of import. Can be one of - append, truncateadd, updateadd. 2123 @type import_type: string 2124 @param file_type: Type of the file to be imported. 2125 @type file_type: string 2126 @param auto_identify: Used to specify whether to auto identify the CSV format. Allowable values - true/false. 2127 @type auto_identify: string 2128 @param file_path: Path of the file to be imported. 2129 @type file_path: string 2130 @param config: Contains any additional control parameters. Can be C{None}. 2131 @type config:dictionary 2132 @raise ServerError: If the server has received the request but did not process the request due to some error. 2133 @raise ParseError: If the server has responded but client was not able to parse the response. 2134 @return Import result 2135 @rtype:dictionary 2136 """ 2137 endpoint = self.endpoint + "/views/" + view_id + "/data" 2138 config["fileType"] = file_type 2139 config["autoIdentify"] = auto_identify 2140 config["importType"] = import_type 2141 response = self.ac.send_import_api_request(endpoint, config, self.request_headers, file_path) 2142 return response["data"]
2143
2144 - def import_raw_data(self, view_id, import_type, file_type, auto_identify, data, config = {}):
2145 """ 2146 Import the raw data provided into the table. 2147 @param view_id: Id of the view where the data to be imported. 2148 @type view_id: string 2149 @param import_type: The type of import. Can be one of - append, truncateadd, updateadd. 2150 @type import_type: string 2151 @param file_type: Type of the file to be imported. 2152 @type file_type: string 2153 @param auto_identify: Used to specify whether to auto identify the CSV format. Allowable values - true/false. 2154 @type auto_identify: string 2155 @param data: Raw data to be imported. 2156 @type data: string 2157 @param config: Contains any additional control parameters. Can be C{None}. 2158 @type config:dictionary 2159 @raise ServerError: If the server has received the request but did not process the request due to some error. 2160 @raise ParseError: If the server has responded but client was not able to parse the response. 2161 @return Import result 2162 @rtype:dictionary 2163 """ 2164 endpoint = self.endpoint + "/views/" + view_id + "/data" 2165 config["fileType"] = file_type 2166 config["autoIdentify"] = auto_identify 2167 config["importType"] = import_type 2168 response = self.ac.send_import_api_request(endpoint, config, self.request_headers, None, data) 2169 return response["data"]
2170
2171 - def import_bulk_data_in_new_table(self, table_name, file_type, auto_identify, file_path, config = {}):
2172 """ 2173 Asynchronously create a new table and import the data contained in the mentioned file into the created table. 2174 @param table_name: Name of the new table to be created. 2175 @type table_name: string 2176 @param file_type: Type of the file to be imported. 2177 @type file_type: string 2178 @param auto_identify: Used to specify whether to auto identify the CSV format. Allowable values - true/false. 2179 @type auto_identify: string 2180 @param file_path: Path of the file to be imported. 2181 @type file_path: string 2182 @param config: Contains any additional control parameters. Can be C{None}. 2183 @type config:dictionary 2184 @raise ServerError: If the server has received the request but did not process the request due to some error. 2185 @raise ParseError: If the server has responded but client was not able to parse the response. 2186 @return Import job id 2187 @rtype:string 2188 """ 2189 endpoint = self.bulk_endpoint + "/data" 2190 config["tableName"] = table_name 2191 config["fileType"] = file_type 2192 config["autoIdentify"] = auto_identify 2193 response = self.ac.send_import_api_request(endpoint, config, self.request_headers, file_path) 2194 return response["data"]["jobId"]
2195
2196 - def import_bulk_data(self, view_id, import_type, file_type, auto_identify, file_path, config = {}):
2197 """ 2198 Asynchronously import the data contained in the mentioned file into the table. 2199 @param view_id: Id of the view where the data to be imported. 2200 @type view_id: string 2201 @param import_type: The type of import. Can be one of - append, truncateadd, updateadd. 2202 @type import_type: string 2203 @param file_type: Type of the file to be imported. 2204 @type file_type: string 2205 @param auto_identify: Used to specify whether to auto identify the CSV format. Allowable values - true/false. 2206 @type auto_identify: string 2207 @param file_path: Path of the file to be imported. 2208 @type file_path: string 2209 @param config: Contains any additional control parameters. Can be C{None}. 2210 @type config:dictionary 2211 @raise ServerError: If the server has received the request but did not process the request due to some error. 2212 @raise ParseError: If the server has responded but client was not able to parse the response. 2213 @return Import job id 2214 @rtype:string 2215 """ 2216 endpoint = self.bulk_endpoint + "/views/" + view_id + "/data" 2217 config["fileType"] = file_type 2218 config["autoIdentify"] = auto_identify 2219 config["importType"] = import_type 2220 response = self.ac.send_import_api_request(endpoint, config, self.request_headers, file_path) 2221 return response["data"]["jobId"]
2222
2223 - def import_data_as_batches(self, view_id, import_type, auto_identify, file_path, batch_size, 2224 config={}, tool_config={}):
2225 """ 2226 Asynchronously import the data contained in the mentioned file into the table. 2227 @param view_id: Id of the view where the data to be imported. 2228 @type view_id: string 2229 @param import_type: The type of import. Can be one of - append, truncateadd, updateadd. 2230 @type import_type: string 2231 @param auto_identify: Used to specify whether to auto identify the CSV format. Allowable values - true/false. 2232 @type auto_identify: string 2233 @param file_path: Path of the file to be imported. 2234 @type file_path: string 2235 @param batch_size: Number of lines per batch. 2236 @type batch_size:int 2237 @param config: Contains any additional control parameters. Can be C{None}. 2238 @type config:dictionary 2239 @param tool_config: Contains any additional control parameters for the library. Can be C{None}. 2240 @type tool_config:dictionary 2241 @raise ServerError: If the server has received the request but did not process the request due to some error. 2242 @raise ParseError: If the server has responded but client was not able to parse the response. 2243 @return Import job id 2244 @rtype:string 2245 """ 2246 endpoint = self.bulk_endpoint + "/views/" + view_id + "/data/batch" 2247 config["importType"] = import_type 2248 config["autoIdentify"] = auto_identify 2249 response = self.ac.send_batch_import_api_request(endpoint, config, self.request_headers, file_path, 2250 batch_size, tool_config) 2251 return response["data"]["jobId"]
2252
2253 - def get_import_job_details(self, job_id):
2254 """ 2255 Returns the details of the import job. 2256 @param job_id: Id of the job. 2257 @type job_id: string 2258 @raise ServerError: If the server has received the request but did not process the request due to some error. 2259 @raise ParseError: If the server has responded but client was not able to parse the response. 2260 @return Import job details 2261 @rtype:dictionary 2262 """ 2263 endpoint = self.bulk_endpoint + "/importjobs/" + job_id 2264 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers) 2265 return response["data"]
2266
2267 - def export_data(self, view_id, response_format, file_path, config = {}):
2268 """ 2269 Export the mentioned table (or) view data. 2270 @param view_id: Id of the view to be exported. 2271 @type view_id: string 2272 @param response_format: The format in which the data is to be exported. 2273 @type response_format: string 2274 @param file_path: Path of the file where the data exported to be stored. 2275 @type file_path: string 2276 @param config: Contains any additional control parameters. Can be C{None}. 2277 @type config:dictionary 2278 @raise ServerError: If the server has received the request but did not process the request due to some error. 2279 @raise ParseError: If the server has responded but client was not able to parse the response. 2280 """ 2281 endpoint = self.endpoint + "/views/" + view_id + "/data" 2282 config["responseFormat"] = response_format 2283 self.ac.send_export_api_request(endpoint, config, self.request_headers, file_path)
2284
2285 - def initiate_bulk_export(self, view_id, response_format, config = {}):
2286 """ 2287 Initiate asynchronous export for the mentioned table (or) view data. 2288 @param view_id: Id of the view to be exported. 2289 @type view_id: string 2290 @param response_format: The format in which the data is to be exported. 2291 @type response_format: string 2292 @param config: Contains any additional control parameters. Can be C{None}. 2293 @type config:dictionary 2294 @raise ServerError: If the server has received the request but did not process the request due to some error. 2295 @raise ParseError: If the server has responded but client was not able to parse the response. 2296 @return Export job id 2297 @rtype:string 2298 """ 2299 endpoint = self.bulk_endpoint + "/views/" + view_id + "/data" 2300 config["responseFormat"] = response_format 2301 response = self.ac.send_api_request("GET", endpoint, config, self.request_headers) 2302 return response["data"]["jobId"]
2303
2304 - def initiate_bulk_export_using_sql(self, sql_query, response_format, config = {}):
2305 """ 2306 Initiate asynchronous export with the given SQL Query. 2307 @param sql_query: SQL Query. 2308 @type sql_query: string 2309 @param response_format: The format in which the data is to be exported. 2310 @type response_format: string 2311 @param config: Contains any additional control parameters. Can be C{None}. 2312 @type config:dictionary 2313 @raise ServerError: If the server has received the request but did not process the request due to some error. 2314 @raise ParseError: If the server has responded but client was not able to parse the response. 2315 @return Export job id 2316 @rtype:string 2317 """ 2318 endpoint = self.bulk_endpoint + "/data" 2319 config["responseFormat"] = response_format 2320 config["sqlQuery"] = sql_query 2321 response = self.ac.send_api_request("GET", endpoint, config, self.request_headers) 2322 return response["data"]["jobId"]
2323
2324 - def get_export_job_details(self, job_id):
2325 """ 2326 Returns the details of the export job. 2327 @param job_id: Id of the export job. 2328 @type job_id: string 2329 @raise ServerError: If the server has received the request but did not process the request due to some error. 2330 @raise ParseError: If the server has responded but client was not able to parse the response. 2331 @return Export job details 2332 @rtype:dictionary 2333 """ 2334 endpoint = self.bulk_endpoint + "/exportjobs/" + job_id 2335 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers) 2336 return response["data"]
2337
2338 - def export_bulk_data(self, job_id, file_path):
2339 """ 2340 Download the exported data for the mentioned job id. 2341 @param job_id: Id of the job to be exported. 2342 @type job_id: string 2343 @param file_path: Path of the file where the data exported to be stored. 2344 @type file_path: string 2345 @raise ServerError: If the server has received the request but did not process the request due to some error. 2346 @raise ParseError: If the server has responded but client was not able to parse the response. 2347 """ 2348 endpoint = self.bulk_endpoint + "/exportjobs/" + job_id + "/data" 2349 self.ac.send_export_api_request(endpoint, None, self.request_headers, file_path)
2350 2351
2352 - def set_proxy(self, proxy_host, proxy_port, proxy_user_name, proxy_password):
2353 """ 2354 Internal method to handle proxy details. 2355 """ 2356 self.proxy = True 2357 self.proxy_host = proxy_host 2358 self.proxy_port = proxy_port 2359 self.proxy_user_name = proxy_user_name 2360 self.proxy_password = proxy_password
2361
2362 - def send_batch_import_api_request(self, request_url, config, request_headers, file_path, batch_size, tool_config):
2363 if self.access_token is None: 2364 self.regenerate_analytics_oauth_token() 2365 2366 file_header = open(file_path, 'r').readline() 2367 file_content = open(file_path, 'r').readlines() 2368 file_content.__delitem__(0) 2369 total_lines = len(file_content) 2370 total_batch_count = math.ceil(total_lines / batch_size) 2371 config["batchKey"] = "start" 2372 request_url = self.analytics_server_url + request_url 2373 2374 for i in range(total_batch_count): 2375 batch = ("".join(file_content[batch_size * i:batch_size + (i * batch_size)])) 2376 batch_file = StringIO( file_header + batch ) 2377 files = {'FILE': batch_file} 2378 2379 config["isLastBatch"] = "true" if (i == (total_batch_count - 1)) else "false" 2380 config_data = "CONFIG=" + urllib.parse.quote_plus(json.dumps(config)) 2381 2382 resp_obj = self.submit_import_request(request_url, config_data, request_headers, self.access_token, files) 2383 2384 if not (str(resp_obj.status_code).startswith("2")): 2385 if self.is_oauth_expired(resp_obj): 2386 self.regenerate_analytics_oauth_token() 2387 resp_obj = self.submit_import_request(request_url, config_data, request_headers, self.access_token, 2388 files) 2389 if not (str(resp_obj.status_code).startswith("2")): 2390 raise ServerError(resp_obj.resp_content, False) 2391 else: 2392 raise ServerError(resp_obj.resp_content, False) 2393 2394 response = resp_obj.resp_content 2395 response = json.loads(response) 2396 config["batchKey"] = response["data"]["batchKey"] 2397 time.sleep(2) 2398 2399 return response
2400
2401 - def send_import_api_request(self, request_url, config, request_headers, file_path, data=None):
2402 """ 2403 Internal method to handle HTTP request. 2404 """ 2405 if self.access_token == None: 2406 self.regenerate_analytics_oauth_token() 2407 2408 request_url = self.analytics_server_url + request_url 2409 config_data = None 2410 if bool(config): 2411 config_data = "CONFIG=" + urllib.parse.quote_plus(json.dumps(config)) 2412 2413 if bool(data): 2414 if(bool(config_data)): 2415 config_data += "&" 2416 else: 2417 config_data = "" 2418 2419 config_data += "DATA=" + urllib.parse.quote_plus(json.dumps(data)) 2420 resp_obj = self.submit_import_request(request_url, config_data, request_headers, self.access_token) 2421 else: 2422 files = {'FILE': open(file_path,'rb')} 2423 resp_obj = self.submit_import_request(request_url, config_data, request_headers, self.access_token, files) 2424 2425 2426 if not (str(resp_obj.status_code).startswith("2")): 2427 if(self.is_oauth_expired(resp_obj)): 2428 self.regenerate_analytics_oauth_token() 2429 if bool(data): 2430 resp_obj = self.submit_import_request(request_url, config_data, request_headers, self.access_token) 2431 else: 2432 resp_obj = self.submit_import_request(request_url, config_data, request_headers, self.access_token, files) 2433 if not (str(resp_obj.status_code).startswith("2")): 2434 raise ServerError(resp_obj.resp_content, False) 2435 else: 2436 raise ServerError(resp_obj.resp_content, False) 2437 2438 response = resp_obj.resp_content 2439 response = json.loads(response) 2440 return response
2441 2442
2443 - def submit_import_request(self, request_url, parameters, request_headers = {}, access_token = None, files = None):
2444 """ 2445 Internal method to send request to server. 2446 """ 2447 try: 2448 if request_headers == None: 2449 request_headers = {} 2450 2451 if access_token != None: 2452 request_headers["Authorization"] = "Zoho-oauthtoken " + access_token 2453 2454 request_headers["User-Agent"] = "Analytics Python Client v" + self.CLIENT_VERSION 2455 2456 req_obj = req_obj = requests.Session() 2457 if self.proxy: 2458 proxy_details = { 2459 "http" : "http://" + self.proxy_host + ":" + self.proxy_port, 2460 "https": "http://" + self.proxy_host + ":" + self.proxy_port 2461 } 2462 req_obj.proxies = proxy_details 2463 if self.proxy_user_name != None and self.proxy_password != None: 2464 proxy_auth_details = HTTPProxyDigestAuth(self.proxy_user_name, self.proxy_password) 2465 req_obj.auth = proxy_auth_details 2466 2467 if bool(files): 2468 resp_obj = req_obj.post(request_url, params = parameters, files = files, headers = request_headers) 2469 else: 2470 resp_obj = req_obj.post(request_url, params = parameters, headers = request_headers) 2471 2472 resp_obj = response_obj(resp_obj) 2473 except Exception as ex: 2474 resp_obj = response_obj(ex) 2475 2476 return resp_obj
2477
2478 - def send_export_api_request(self, request_url, config, request_headers, file_path):
2479 """ 2480 Internal method to handle HTTP request. 2481 """ 2482 file = open(file_path,"wb") 2483 2484 if self.access_token == None: 2485 self.regenerate_analytics_oauth_token() 2486 2487 request_url = self.analytics_server_url + request_url 2488 config_data = None 2489 if bool(config): 2490 config_data = "CONFIG=" + urllib.parse.quote_plus(json.dumps(config)) 2491 2492 resp_obj = self.submit_export_request(request_url, config_data, request_headers, self.access_token) 2493 2494 if not (str(resp_obj.status_code).startswith("2")): 2495 resp_obj = response_obj(resp_obj) 2496 if(self.is_oauth_expired(resp_obj)): 2497 self.regenerate_analytics_oauth_token() 2498 resp_obj = self.submit_export_request(request_url, config_data, request_headers, self.access_token) 2499 if not (str(resp_obj.status_code).startswith("2")): 2500 raise ServerError(resp_obj.resp_content, False) 2501 else: 2502 raise ServerError(resp_obj.resp_content, False) 2503 2504 file.write(resp_obj.content) 2505 file.close() 2506 return
2507 2508
2509 - def submit_export_request(self, request_url, parameters, request_headers = {}, access_token = None):
2510 """ 2511 Internal method to send request to server. 2512 """ 2513 try: 2514 if request_headers == None: 2515 request_headers = {} 2516 2517 if access_token != None: 2518 request_headers["Authorization"] = "Zoho-oauthtoken " + access_token 2519 2520 request_headers["User-Agent"] = "Analytics Python Client v" + self.CLIENT_VERSION 2521 2522 req_obj = req_obj = requests.Session() 2523 if self.proxy: 2524 proxy_details = { 2525 "http" : "http://" + self.proxy_host + ":" + self.proxy_port, 2526 "https": "http://" + self.proxy_host + ":" + self.proxy_port 2527 } 2528 req_obj.proxies = proxy_details 2529 if self.proxy_user_name != None and self.proxy_password != None: 2530 proxy_auth_details = HTTPProxyDigestAuth(self.proxy_user_name, self.proxy_password) 2531 req_obj.auth = proxy_auth_details 2532 2533 resp_obj = req_obj.get(request_url, params = parameters, headers = request_headers) 2534 2535 except Exception as ex: 2536 resp_obj = response_obj(ex) 2537 2538 return resp_obj
2539
2540 - def send_api_request(self, request_method, request_url, config, request_headers, is_json_response = True):
2541 """ 2542 Internal method to handle HTTP request. 2543 """ 2544 if self.access_token == None: 2545 self.regenerate_analytics_oauth_token() 2546 2547 request_url = self.analytics_server_url + request_url 2548 config_data = None 2549 if bool(config): 2550 config_data = "CONFIG=" + urllib.parse.quote_plus(json.dumps(config)) 2551 2552 resp_obj = self.submit_request(request_method, request_url, config_data, request_headers, self.access_token) 2553 2554 if not (str(resp_obj.status_code).startswith("2")): 2555 if(self.is_oauth_expired(resp_obj)): 2556 self.regenerate_analytics_oauth_token() 2557 resp_obj = self.submit_request(request_method, request_url, config_data, request_headers, self.access_token) 2558 if not (str(resp_obj.status_code).startswith("2")): 2559 raise ServerError(resp_obj.resp_content, False) 2560 else: 2561 raise ServerError(resp_obj.resp_content, False) 2562 2563 #API success - No response case 2564 if (str(resp_obj.status_code) != "200"): 2565 return 2566 2567 response = resp_obj.resp_content 2568 if is_json_response: 2569 response = json.loads(response) 2570 return response
2571 2572
2573 - def submit_request(self, request_method, request_url, parameters, request_headers = {}, access_token = None):
2574 """ 2575 Internal method to send request to server. 2576 """ 2577 try: 2578 if request_headers == None: 2579 request_headers = {} 2580 2581 if access_token != None: 2582 request_headers["Authorization"] = "Zoho-oauthtoken " + access_token 2583 2584 request_headers["User-Agent"] = "Analytics Python Client v" + self.CLIENT_VERSION 2585 2586 req_obj = req_obj = requests.Session() 2587 if self.proxy: 2588 proxy_details = { 2589 "http" : "http://" + self.proxy_host + ":" + self.proxy_port, 2590 "https": "http://" + self.proxy_host + ":" + self.proxy_port 2591 } 2592 req_obj.proxies = proxy_details 2593 if self.proxy_user_name != None and self.proxy_password != None: 2594 proxy_auth_details = HTTPProxyDigestAuth(self.proxy_user_name, self.proxy_password) 2595 req_obj.auth = proxy_auth_details 2596 2597 resp_obj = None 2598 2599 if request_method == "GET": 2600 resp_obj = req_obj.get(request_url, params = parameters, headers = request_headers) 2601 elif request_method == "POST": 2602 resp_obj = req_obj.post(request_url, params = parameters, headers = request_headers) 2603 elif request_method == "PUT": 2604 resp_obj = req_obj.put(request_url, params = parameters, headers = request_headers) 2605 elif request_method == "DELETE": 2606 resp_obj = req_obj.delete(request_url, params = parameters, headers = request_headers) 2607 2608 resp_obj = response_obj(resp_obj) 2609 except Exception as ex: 2610 resp_obj = response_obj(ex) 2611 2612 return resp_obj
2613
2614 - def get_request_obj(self):
2615 """ 2616 Internal method for getting OAuth token. 2617 """ 2618 req_obj = requests.Session() 2619 2620 if self.proxy: 2621 proxy_details = { 2622 "http" : "http://" + self.proxy_host + ":" + self.proxy_port, 2623 "https": "http://" + self.proxy_host + ":" + self.proxy_port 2624 } 2625 req_obj.proxies = proxy_details 2626 if self.proxy_user_name != None and self.proxy_password != None: 2627 proxy_auth_details = HTTPProxyDigestAuth(self.proxy_user_name, self.proxy_password) 2628 req_obj.auth = proxy_auth_details 2629 return req_obj
2630 2631
2632 - def is_oauth_expired(self, resp_obj):
2633 """ 2634 Internal method to check whether the accesstoken expired or not. 2635 """ 2636 try: 2637 resp_content = json.loads(resp_obj.resp_content) 2638 err_code = resp_content["data"]["errorCode"] 2639 return err_code == 8535 2640 except Exception: 2641 return False
2642 2643
2645 """ 2646 Internal method for getting OAuth token. 2647 """ 2648 oauth_params = {} 2649 oauth_params["client_id"] = self.client_id 2650 oauth_params["client_secret"] = self.client_secret 2651 oauth_params["refresh_token"] = self.refresh_token 2652 oauth_params["grant_type"] = "refresh_token" 2653 oauth_params = urllib.parse.urlencode(oauth_params) #.encode(self.COMMON_ENCODE_CHAR) 2654 req_url = self.accounts_server_url + "/oauth/v2/token" 2655 oauth_resp_obj = self.submit_request("POST", req_url, oauth_params) 2656 2657 if(oauth_resp_obj.status_code == 200): 2658 oauth_json_resp = json.loads(oauth_resp_obj.resp_content) 2659 if("access_token" in oauth_json_resp): 2660 self.access_token = oauth_json_resp["access_token"] 2661 return 2662 2663 raise ServerError(oauth_resp_obj.resp_content, True)
2664 2665
2666 -class response_obj:
2667 """ 2668 Internal class. 2669 """
2670 - def __init__(self, resp_obj):
2671 self.resp_content = resp_obj.text 2672 self.status_code = resp_obj.status_code 2673 self.headers = resp_obj.headers
2674 2675
2676 -class ServerError(Exception):
2677 """ 2678 ServerError is thrown if the analytics server has received the request but did not process the 2679 request due to some error. For example if authorization failure. 2680 """ 2681
2682 - def __init__(self, response, is_IAM_Error):
2683 self.errorCode = 0 2684 self.message = response 2685 2686 try: 2687 error_data = json.loads(response) 2688 if is_IAM_Error : 2689 self.message = "Exception while generating oauth token. Response - " + response 2690 else: 2691 self.errorCode = error_data["data"]["errorCode"] 2692 self.message = error_data["data"]["errorMessage"] 2693 except Exception as inst : 2694 print(inst) 2695 self.parseError = inst
2696
2697 - def __str__(self):
2698 return repr(self.message)
2699 2700
2701 -class ParseError(Exception):
2702 """ 2703 ParseError is thrown if the server has responded but client was not able to parse the response. 2704 Possible reasons could be version mismatch.The client might have to be updated to a newer version. 2705 """
2706 - def __init__(self, responseContent, message, origExcep):
2707 self.responseContent= responseContent #: The complete response content as sent by the server. 2708 self.message=message #: The message describing the error. 2709 self.origExcep= origExcep #: The original exception that occurred during parsing(Can be C{None}).
2710
2711 - def __str__(self):
2712 return repr(self.message)
2713