Skip to content

Commit

Permalink
Merge pull request #21 from hotgluexyz/feature/selectApiVersion
Browse files Browse the repository at this point in the history
added support for selecting salesforce api version
  • Loading branch information
hsyyid authored Jul 20, 2022
2 parents a74ae00 + 793e5dd commit 9620df2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
3 changes: 2 additions & 1 deletion tap_salesforce/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,8 @@ def main_impl():
default_start_date=CONFIG.get('start_date'),
api_type=CONFIG.get('api_type'),
list_reports=CONFIG.get('list_reports'),
list_views=CONFIG.get('list_views')
list_views=CONFIG.get('list_views'),
api_version=CONFIG.get('api_version')
)
sf.login()

Expand Down
9 changes: 6 additions & 3 deletions tap_salesforce/salesforce/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
NUMBER_TYPES = set([
'double',
'currency',
'percent'
'percent',
'long'
])

DATE_TYPES = set([
Expand Down Expand Up @@ -207,7 +208,8 @@ def __init__(self,
default_start_date=None,
api_type=None,
list_reports=False,
list_views=False):
list_views=False,
api_version=None):
self.api_type = api_type.upper() if api_type else None
self.refresh_token = refresh_token
self.token = token
Expand All @@ -232,7 +234,8 @@ def __init__(self,
self.rest_requests_attempted = 0
self.jobs_completed = 0
self.login_timer = None
self.data_url = "{}/services/data/v41.0/{}"
self.version = api_version or "41.0"
self.data_url = "{}/services/data/v" + self.version + "/{}"
self.pk_chunking = False

# validate start_date
Expand Down
12 changes: 9 additions & 3 deletions tap_salesforce/salesforce/bulk.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ def find_parent(stream):

class Bulk():

bulk_url = "{}/services/async/41.0/{}"
@property
def bulk_url(self):
return "{}/services/async/" + self.sf.version + "/{}"

def __init__(self, sf):
# Set csv max reading size to the platform's max size available.
Expand Down Expand Up @@ -73,10 +75,14 @@ def check_bulk_quota_usage(self):
with metrics.http_request_timer(endpoint):
resp = self.sf._make_request('GET', url, headers=self.sf._get_standard_headers()).json()

quota_max = resp['DailyBulkApiRequests']['Max']
quota = resp.get('DailyBulkApiRequests')
if not quota:
quota = resp.get('DailyBulkApiBatches')
quota_max = quota['Max']

max_requests_for_run = int((self.sf.quota_percent_per_run * quota_max) / 100)

quota_remaining = resp['DailyBulkApiRequests']['Remaining']
quota_remaining = quota['Remaining']
percent_used = (1 - (quota_remaining / quota_max)) * 100

if percent_used > self.sf.quota_percent_total:
Expand Down
2 changes: 1 addition & 1 deletion tap_salesforce/salesforce/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def _query_recur(
end_date=None,
retries=MAX_RETRIES):
params = {"q": query}
url = "{}/services/data/v41.0/queryAll".format(self.sf.instance_url)
url = "{}/services/data/v{}/queryAll".format(self.sf.instance_url, self.sf.version)
headers = self.sf._get_standard_headers()

sync_start = singer_utils.now()
Expand Down

0 comments on commit 9620df2

Please sign in to comment.