1
0
mirror of synced 2026-01-01 00:02:54 -05:00
Files
airbyte/airbyte-integrations/connectors/source-google-sheets/source_google_sheets/client.py
Serhii Chvaliuk a431a52aaa Source Google Sheets: slugify column names (#23057)
Signed-off-by: Sergey Chvalyuk <grubberr@gmail.com>
2023-02-23 18:10:46 +02:00

40 lines
1.3 KiB
Python

#
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
#
from typing import Dict, List
import backoff
from googleapiclient import errors
from requests import codes as status_codes
from .helpers import SCOPES, Helpers
def give_up(error):
code = error.resp.status
# Stop retrying if it's not a problem with the rate limit or on the server end
return not (code == status_codes.TOO_MANY_REQUESTS or 500 <= code < 600)
class GoogleSheetsClient:
def __init__(self, credentials: Dict[str, str], scopes: List[str] = SCOPES):
self.client = Helpers.get_authenticated_sheets_client(credentials, scopes)
@backoff.on_exception(backoff.expo, errors.HttpError, max_time=120, giveup=give_up)
def get(self, **kwargs):
return self.client.get(**kwargs).execute()
@backoff.on_exception(backoff.expo, errors.HttpError, max_time=120, giveup=give_up)
def create(self, **kwargs):
return self.client.create(**kwargs).execute()
@backoff.on_exception(backoff.expo, errors.HttpError, max_time=120, giveup=give_up)
def get_values(self, **kwargs):
return self.client.values().batchGet(**kwargs).execute()
@backoff.on_exception(backoff.expo, errors.HttpError, max_time=120, giveup=give_up)
def update_values(self, **kwargs):
return self.client.values().batchUpdate(**kwargs).execute()