Skip to content

Commit

Permalink
[dwallace0723#2] Allows headers with methods using _post
Browse files Browse the repository at this point in the history
* Allow DbtCloudReponse standard import
  • Loading branch information
hans2520 committed Mar 15, 2022
1 parent c6e026b commit 9ebd2b1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pydbtcloud/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .client import DbtCloud
from .client import DbtCloud, DbtCloudResponse
16 changes: 10 additions & 6 deletions pydbtcloud/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ def _get(self, url_suffix: str, params: Dict = None) -> Dict:
response.raise_for_status()
return response.json()

def _post(self, url_suffix: str, params: Dict = None, data: Dict = None) -> Dict:
def _post(self, url_suffix: str, params: Dict = None, data: Dict = None,
headers: Dict = None) -> Dict:
url = self.api_base + url_suffix
headers = self._construct_headers()
headers = headers or self._construct_headers()
response = requests.post(url, headers=headers, params=params, data=data)
response.raise_for_status()
return response.json()
Expand Down Expand Up @@ -77,14 +78,17 @@ def get_connection(self, connection_id: int, params: Dict = None):
response = self._get(url_suffix, params)
return DbtCloudResponse(self, url_suffix, params, response)

def run_job(self, job_id: int, params: Dict = None, data: Dict = {'cause': 'Kicked off via pydbtcloud SDK'}):
def run_job(self, job_id: int, params: Dict = None,
data: Dict = {'cause': 'Kicked off via pydbtcloud SDK'},
headers: Dict = None):
url_suffix = f"/accounts/{self.account_id}/jobs/{job_id}/run/"
response = self._post(url_suffix, params, data)
response = self._post(url_suffix, params, data, headers)
return DbtCloudResponse(self, url_suffix, params, response)

def cancel_run(self, run_id: int, params: Dict = None, data: Dict = None):
def cancel_run(self, run_id: int, params: Dict = None, data: Dict = None,
headers: Dict = None):
url_suffix = f"/accounts/{self.account_id}/runs/{run_id}/cancel/"
response = self._post(url_suffix, params, data)
response = self._post(url_suffix, params, data, headers)
return DbtCloudResponse(self, url_suffix, params, response)


Expand Down

0 comments on commit 9ebd2b1

Please sign in to comment.