コード例 #1
0
 def get(self, path, **kwargs) -> dict:
     """
     Args:
         path:
         **kwargs:
     """
     with handler_request(self, LOGGER):
         url = self.base_url + path
         response = self.request.get(url, **kwargs)
         if not response.ok:
             raise handler_request_exception(response)
         return response.json()
コード例 #2
0
    def delete(self, path: str, **kwargs) -> Union[bool, dict]:
        """
        Args:
            path (str):
            **kwargs:
        """
        with handler_request(self, LOGGER):
            url = self.base_url + path
            response = self.request.delete(url, **kwargs)
            if not response.ok:
                raise handler_request_exception(response)

            return True
コード例 #3
0
ファイル: client.py プロジェクト: ramon/getnet-py
    def auth(self) -> None:
        if self.access_token_expired():
            path = "/auth/oauth/v2/token"
            data = {"scope": "oob", "grant_type": "client_credentials"}

            response = self.request.post(
                self.base_url + path,
                data=data,
                auth=(self.client_id, self.client_secret),
            )
            if not response.ok:
                raise handler_request_exception(response)

            response_data = response.json()

            self.access_token = response_data.get("access_token")
            self.access_token_expires = int(
                datetime.timestamp(datetime.now() + timedelta(
                    seconds=response_data.get("expires_in"))))
            self.request.headers.update(
                {"Authorization": "Bearer {}".format(self.access_token)})