brynq-sdk-salesforce 2.0.1__tar.gz → 3.0.0__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_salesforce
3
- Version: 2.0.1
3
+ Version: 3.0.0
4
4
  Summary: Salesforce wrapper from BrynQ
5
5
  Home-page: UNKNOWN
6
6
  Author: BrynQ
@@ -3,7 +3,7 @@ import urllib.parse
3
3
  import warnings
4
4
  import requests
5
5
  import json
6
- from typing import Union, List
6
+ from typing import Union, List, Literal, Optional
7
7
  import pandas as pd
8
8
  import os
9
9
 
@@ -13,21 +13,21 @@ class Salesforce(BrynQ):
13
13
  This class is meant to be a simple wrapper around the Salesforce API. In order to start using it, authorize your application is BrynQ.
14
14
  You will receive a code which you can use to obtain a refresh token using the get_refresh_token method. Use this refresh token to refresh your access token always before you make a data call.
15
15
  """
16
- def __init__(self, label: Union[str, List], debug: bool = False, sandbox: bool = False):
16
+ def __init__(self, system_type: Optional[Literal['source', 'target']] = None, debug: bool = False, sandbox: bool = False):
17
17
  super().__init__()
18
18
  if sandbox:
19
19
  self.system = 'salesforce-sandbox'
20
20
  else:
21
21
  self.system = 'salesforce'
22
- self.credentials = self.get_system_credential(system=self.system, label=label)
23
- self.credential_id = self.credentials['id']
24
- self.customer_url = self.credentials['auth']['instance_url']
22
+ credentials = self.interfaces.credentials.get(system=self.system, system_type=system_type)
23
+ self.credentials = credentials.get('data')
24
+ self.customer_url = self.credentials['instance_url']
25
25
  self.debug = debug
26
26
  self.api_version = 56.0
27
+ self.timeout = 3600
27
28
 
28
29
  def __get_headers(self) -> dict:
29
- credentials = self.refresh_system_credential(system=self.system, system_id=self.credential_id)
30
- headers = {"Authorization": f"Bearer {credentials['access_token']}",
30
+ headers = {"Authorization": f"Bearer {self.credentials['access_token']}",
31
31
  "Content-Type": "application/json"}
32
32
  if self.debug:
33
33
  print(f"Headers: {headers}")
@@ -50,7 +50,7 @@ class Salesforce(BrynQ):
50
50
  done = False
51
51
  url = f"{self.customer_url}/services/data/v37.0/query/?"
52
52
  while done is False:
53
- response = requests.get(url=url, params=params_str, headers=self.__get_headers())
53
+ response = requests.get(url=url, params=params_str, headers=self.__get_headers(), timeout=self.timeout)
54
54
  response.raise_for_status()
55
55
  response = response.json()
56
56
  done = response['done']
@@ -79,7 +79,7 @@ class Salesforce(BrynQ):
79
79
  done = False
80
80
  url = f"{self.customer_url}/services/data/v37.0/query/?"
81
81
  while done is False:
82
- response = requests.get(url=url, params=params_str, headers=self.__get_headers())
82
+ response = requests.get(url=url, params=params_str, headers=self.__get_headers(), timeout=self.timeout)
83
83
  response.raise_for_status()
84
84
  response = response.json()
85
85
  done = response['done']
@@ -119,7 +119,7 @@ class Salesforce(BrynQ):
119
119
  if self.debug:
120
120
  print(f"Payload: {body}")
121
121
 
122
- response = requests.post(url=f"{self.customer_url}/services/data/v37.0/sobjects/Contact", data=body, headers=self.__get_headers())
122
+ response = requests.post(url=f"{self.customer_url}/services/data/v37.0/sobjects/Contact", data=body, headers=self.__get_headers(), timeout=self.timeout)
123
123
  response.raise_for_status()
124
124
  if self.debug:
125
125
  print(f"Response: {response.content, response.text}")
@@ -156,7 +156,7 @@ class Salesforce(BrynQ):
156
156
  if self.debug:
157
157
  print(f"Payload: {body}")
158
158
 
159
- response = requests.patch(url=f"{self.customer_url}/services/data/v37.0/sobjects/Contact/{data['contact_id']}", data=body, headers=self.__get_headers())
159
+ response = requests.patch(url=f"{self.customer_url}/services/data/v37.0/sobjects/Contact/{data['contact_id']}", data=body, headers=self.__get_headers(), timeout=self.timeout)
160
160
  response.raise_for_status()
161
161
  if self.debug:
162
162
  print(f"Response: {response.content, response.text}")
@@ -181,7 +181,7 @@ class Salesforce(BrynQ):
181
181
  :return: data or error
182
182
  """
183
183
  url = f"{self.customer_url}/services/data/v{self.api_version}/sobjects/{table}/describe/"
184
- response = requests.get(url, headers=self.__get_headers())
184
+ response = requests.get(url, headers=self.__get_headers(), timeout=self.timeout)
185
185
  return response
186
186
 
187
187
  def query_table(self, data_dir: str, table: str, fields: Union[str, List], filter: str = None, filename: str = None) -> pd.DataFrame:
@@ -262,7 +262,7 @@ class Salesforce(BrynQ):
262
262
 
263
263
  # With the created URL and parameters, call the API
264
264
  while not done:
265
- response = requests.get(url=url, params=params_str, headers=self.__get_headers())
265
+ response = requests.get(url=url, params=params_str, headers=self.__get_headers(), timeout=self.timeout)
266
266
  response.raise_for_status()
267
267
  done = response.json()['done']
268
268
  df_temp = pd.DataFrame(response.json()['records'])
@@ -287,7 +287,7 @@ class Salesforce(BrynQ):
287
287
  df_del = pd.DataFrame()
288
288
  url = f'{self.customer_url}/services/data/v{self.api_version}/queryAll/?'
289
289
  while done is False:
290
- response = requests.get(url=url, params=params_str, headers=self.__get_headers())
290
+ response = requests.get(url=url, params=params_str, headers=self.__get_headers(), timeout=self.timeout)
291
291
  response.raise_for_status()
292
292
  done = response.json()['done']
293
293
  df_temp = pd.DataFrame(response.json()['records'])
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.0
2
2
  Name: brynq-sdk-salesforce
3
- Version: 2.0.1
3
+ Version: 3.0.0
4
4
  Summary: Salesforce wrapper from BrynQ
5
5
  Home-page: UNKNOWN
6
6
  Author: BrynQ
@@ -1,4 +1,4 @@
1
- brynq-sdk-brynq>=2
1
+ brynq-sdk-brynq<5,>=4
2
2
  requests<=3,>=2
3
3
  pandas<3,>=1
4
4
  pyarrow>=10
@@ -2,7 +2,7 @@ from setuptools import setup, find_namespace_packages
2
2
 
3
3
  setup(
4
4
  name='brynq_sdk_salesforce',
5
- version='2.0.1',
5
+ version='3.0.0',
6
6
  description='Salesforce wrapper from BrynQ',
7
7
  long_description='Salesforce wrapper from BrynQ',
8
8
  author='BrynQ',
@@ -10,7 +10,7 @@ setup(
10
10
  packages=find_namespace_packages(include=['brynq_sdk*']),
11
11
  license='BrynQ License',
12
12
  install_requires=[
13
- 'brynq-sdk-brynq>=2',
13
+ 'brynq-sdk-brynq>=4,<5',
14
14
  'requests>=2,<=3',
15
15
  'pandas>=1,<3',
16
16
  'pyarrow>=10'