1
0
mirror of synced 2026-01-01 18:02:53 -05:00
Files
airbyte/airbyte-integrations/connectors/source-hellobaton/source_hellobaton/source.py
Cole Snodgrass 2e099acc52 update headers from 2022 -> 2023 (#22594)
* It's 2023!

* 2022 -> 2023

---------

Co-authored-by: evantahler <evan@airbyte.io>
2023-02-08 13:01:16 -08:00

60 lines
1.9 KiB
Python

#
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
#
from typing import Any, List, Mapping, Tuple
import requests
from airbyte_cdk import AirbyteLogger
from airbyte_cdk.sources import AbstractSource
from airbyte_cdk.sources.streams import Stream
from .streams import (
Activity,
Companies,
Milestones,
Phases,
ProjectAttachments,
Projects,
TaskAttachments,
Tasks,
Templates,
TimeEntries,
Users,
)
STREAMS = [Activity, Companies, Milestones, Projects, Phases, ProjectAttachments, Tasks, TaskAttachments, Templates, TimeEntries, Users]
# Source
class SourceHellobaton(AbstractSource):
def check_connection(self, logger: AirbyteLogger, config: Mapping[str, any]) -> Tuple[bool, any]:
"""
:param config: the user-input config object conforming to the connector's spec.json
:param logger: logger object
:return Tuple[bool, any]: (True, None) if the input config can be used to connect to the API successfully, (False, error) otherwise.
"""
url_template = "https://{company}.hellobaton.com/api/"
try:
params = {
"api_key": config["api_key"],
}
base_url = url_template.format(company=config["company"])
# This is just going to return a mapping of available endpoints
response = requests.get(base_url, params=params)
status_code = response.status_code
logger.info(f"Status code: {status_code}")
if status_code == 200:
return True, None
except Exception as e:
return False, e
def streams(self, config: Mapping[str, Any]) -> List[Stream]:
"""
:param config: A Mapping of the user input configuration as defined in the connector spec.
"""
return [stream(company=config["company"], api_key=config["api_key"]) for stream in STREAMS]