brynq-sdk-zoho 2.0.0__tar.gz → 2.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.0
2
2
  Name: brynq_sdk_zoho
3
- Version: 2.0.0
3
+ Version: 2.0.1
4
4
  Summary: ZOHO wrapper from BrynQ
5
5
  Home-page: UNKNOWN
6
6
  Author: BrynQ
@@ -0,0 +1 @@
1
+ from .upload_zoho_desk import UploadZohoDesk
@@ -0,0 +1,172 @@
1
+ import os
2
+ import sys
3
+ import pandas as pd
4
+ from typing import Union, List
5
+ import requests
6
+ import json
7
+ from brynq_sdk_brynq import BrynQ
8
+
9
+ basedir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
10
+ sys.path.append(basedir)
11
+
12
+
13
+ class ExtractZohoDesk(BrynQ):
14
+
15
+ def __init__(self, label: Union[str, List], debug: bool = False):
16
+ """
17
+ For the full documentation, see: https://avisi-apps.gitbook.io/tracket/api/
18
+ """
19
+ super().__init__()
20
+ self.headers = self._get_authentication(label=label)
21
+ self.base_url = "https://desk.zoho.com/api/v1/"
22
+ self.payload = {}
23
+
24
+ def _get_authentication(self, label):
25
+ """
26
+ Get the credentials for the Tracket API from BrynQ, with those credentials, get the access_token for Tracket.
27
+ Return the headers with the access_token.
28
+ """
29
+ # Get credentials from BrynQ
30
+ credentials = self.get_system_credential(system='zoho-desk', label=label)
31
+
32
+ # With those credentials, get the access_token from Tracket
33
+ zoho_system_id = credentials["id"]
34
+ token = BrynQ().refresh_system_credential(system="zoho-desk", system_id=zoho_system_id)["access_token"]
35
+ headers = {
36
+ 'Authorization': f'Zoho-oauthtoken {token}'
37
+ }
38
+ return headers
39
+
40
+ def get_zoho_accounts(self, query_params=""):
41
+ """
42
+ This function gets all the accounts from zoho and saves them as df_zoho_accounts
43
+ :return: df_zoho_accounts
44
+ """
45
+ base_url = f"{self.base_url}accounts"
46
+ return self._multiple_calls(base_url, query_params)
47
+
48
+ def get_zoho_agents(self, query_params=""):
49
+ """
50
+ This function gets the user data from zoho and saves the data to df_zoho_users
51
+ :return:
52
+ """
53
+ base_url = f"{self.base_url}agents"
54
+ return self._multiple_calls(base_url, query_params)
55
+
56
+ def get_zoho_agent(self, agent_id, query_params=""):
57
+ """
58
+ This function gets the user data from zoho and saves the data to df_zoho_users
59
+ :return:
60
+ """
61
+ url = f"{self.base_url}agents/{agent_id}?{query_params}"
62
+ return self._single_call(url)
63
+
64
+ def get_zoho_contacts(self, query_params=""):
65
+ """
66
+ This function gets the zoho contact information from zoho desk and saves the data to df_zoho_contacts
67
+ :return:
68
+ """
69
+ base_url = f"{self.base_url}contacts"
70
+ return self._multiple_calls(base_url, query_params)
71
+
72
+ def get_recent_zoho_tickets(self, query_params=""):
73
+ """
74
+ This function gets the newest 100 tickets form Zoho-Desk
75
+ :return:
76
+ """
77
+ url = f"{self.base_url}tickets?limit=100&from=0&{query_params}"
78
+ return self._single_call(url)
79
+
80
+ def get_all_zoho_tickets(self, query_params: str = "") -> pd.DataFrame:
81
+ """
82
+ This function gets the zoho contact information from zoho desk and saves the data to df_zoho_contacts
83
+ :return:
84
+ """
85
+ base_url = f"{self.base_url}tickets"
86
+ return self._multiple_calls(base_url, query_params)
87
+
88
+ def get_archived_zoho_tickets(self, query_params: str = "") -> pd.DataFrame:
89
+ """
90
+ This function gets the zoho contact information from zoho desk and saves the data to df_zoho_contacts
91
+ :return:
92
+ """
93
+ base_url = f"{self.base_url}tickets/archivedTickets"
94
+ return self._multiple_calls(base_url, query_params)
95
+
96
+ def get_active_ticket_timers(self, tickets: pd.DataFrame, query_params: str = "") -> pd.DataFrame:
97
+ """=
98
+ This function gets all the active ticket timers from the tickets given in the tickets dataframe.
99
+ :param tickets: dataframe with the ticket_id's
100
+ :param query_params: query parameters for the API call
101
+ :return: pd.DataFrame with the ticket timers
102
+ """
103
+ df = pd.DataFrame()
104
+ count = 0
105
+ for index, ticket in tickets.iterrows():
106
+ count = count + 1
107
+ print(f"Checking for ticket number {ticket.ticket_id}. ticket {count} / " + str(
108
+ len(tickets.index)))
109
+ url = f"{self.base_url}tickets/{ticket.ticket_id}/activeTimer?{query_params}"
110
+ df_temp = self._single_call(url)
111
+ df_temp['ticket_id'] = ticket.ticket_id
112
+ df_temp['link'] = ticket.link
113
+ df_temp['ticket_number'] = ticket.ticket_number
114
+ df = pd.concat([df, df_temp])
115
+ df = df.reset_index(drop=True)
116
+ return df
117
+
118
+ def get_zoho_ticket_timers(self, tickets, query_params=""):
119
+ """
120
+ This function gets all the ticket timers from the recent tickets if there already exists a database. Otherwise,
121
+ it will get all the ticket timers. the ticket timers are saved to df_zoho_ticket_timers
122
+ :return:
123
+ """
124
+ df = pd.DataFrame()
125
+ count = 0
126
+ for ticket_id in tickets["ticket_id"]:
127
+ count = count + 1
128
+ print(f"Checking for ticket number {ticket_id}. ticket {count} / " + str(
129
+ len(tickets.index)))
130
+ url = f"{self.base_url}tickets/{ticket_id}/timeEntry?{query_params}"
131
+ df_temp = self._single_call(url)
132
+ df = pd.concat([df, df_temp])
133
+ df = df.reset_index(drop=True)
134
+ return df
135
+
136
+ def _multiple_calls(self, base_url, query_params) -> pd.DataFrame:
137
+ """
138
+ This function helps the API calls to do multiple calls in one function
139
+ :return:
140
+ """
141
+ df = pd.DataFrame()
142
+ end_of_loop = False
143
+ offset = 0
144
+ while not end_of_loop:
145
+ url = f"{base_url}?from={offset}&limit=90&{query_params}"
146
+ df_temp = self._single_call(url)
147
+ df = pd.concat([df_temp, df])
148
+ if len(df_temp) != 90:
149
+ end_of_loop = True
150
+ else:
151
+ offset += 90
152
+ return df
153
+
154
+ def _single_call(self, url: str) -> pd.DataFrame:
155
+ """
156
+ This function helps the API calls to do a single call in one function
157
+ :return:
158
+ """
159
+ response = requests.request("GET", url, headers=self.headers, data=self.payload)
160
+ if response.status_code == 401:
161
+ response = requests.request("GET", url, headers=self.headers, data=self.payload)
162
+ if response.status_code == 200:
163
+ df = response.json()
164
+ if 'data' in df:
165
+ df = pd.json_normalize(df['data'])
166
+ else:
167
+ df = pd.json_normalize(df)
168
+ return df
169
+ elif response.status_code == 204:
170
+ return pd.DataFrame()
171
+ else:
172
+ raise Exception(response.text)
@@ -0,0 +1,49 @@
1
+ import os
2
+ import sys
3
+ import pandas as pd
4
+ from typing import Union, List
5
+ import requests
6
+ import json
7
+ from brynq_sdk_brynq import BrynQ
8
+
9
+ basedir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
10
+ sys.path.append(basedir)
11
+
12
+
13
+ class UploadZohoDesk(BrynQ):
14
+
15
+ def __init__(self, label: Union[str, List], debug: bool = False):
16
+ """
17
+ For the full documentation, see: https://avisi-apps.gitbook.io/tracket/api/
18
+ """
19
+ super().__init__()
20
+ self.headers = self._get_authentication(label=label)
21
+ self.base_url = "https://desk.zoho.com/api/v1/"
22
+
23
+ def _get_authentication(self, label):
24
+ """
25
+ Get the credentials for the Traket API from BrynQ, with those credentials, get the access_token for Tracket.
26
+ Return the headers with the access_token.
27
+ """
28
+ # Get credentials from BrynQ
29
+ credentials = self.get_system_credential(system='zoho-desk', label=label)
30
+
31
+ # With those credentials, get the access_token from Tracket
32
+ zoho_system_id = credentials["id"]
33
+ token = BrynQ().refresh_system_credential(system="zoho-desk", system_id=zoho_system_id)["access_token"]
34
+ headers = {
35
+ 'Authorization': f'Zoho-oauthtoken {token}',
36
+ 'Content-Type': 'application/json'
37
+ }
38
+ return headers
39
+
40
+ def update_ticket_time_entry(self, ticket_id, time_entry_id, payload):
41
+ """
42
+ This function updates the time entry of a ticket in zoho desk
43
+ :param ticket_id: str
44
+ :param time_entry_id: str
45
+ :param payload: dict
46
+ """
47
+ url = f"{self.base_url}tickets/{ticket_id}/timeEntry/{time_entry_id}"
48
+ response = requests.request("PATCH", url, headers=self.headers, data=json.dumps(payload))
49
+ return response
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.0
2
2
  Name: brynq-sdk-zoho
3
- Version: 2.0.0
3
+ Version: 2.0.1
4
4
  Summary: ZOHO wrapper from BrynQ
5
5
  Home-page: UNKNOWN
6
6
  Author: BrynQ
@@ -1,4 +1,7 @@
1
1
  setup.py
2
+ brynq_sdk_zoho/__init__.py
3
+ brynq_sdk_zoho/extract_zoho_desk.py
4
+ brynq_sdk_zoho/upload_zoho_desk.py
2
5
  brynq_sdk_zoho.egg-info/PKG-INFO
3
6
  brynq_sdk_zoho.egg-info/SOURCES.txt
4
7
  brynq_sdk_zoho.egg-info/dependency_links.txt
@@ -0,0 +1 @@
1
+ brynq_sdk_zoho
@@ -2,7 +2,7 @@ from setuptools import setup, find_namespace_packages
2
2
 
3
3
  setup(
4
4
  name='brynq_sdk_zoho',
5
- version='2.0.0',
5
+ version='2.0.1',
6
6
  description='ZOHO wrapper from BrynQ',
7
7
  long_description='ZOHO wrapper from BrynQ',
8
8
  author='BrynQ',
File without changes