1
0
mirror of synced 2026-01-10 09:04:48 -05:00
Files
airbyte/airbyte-integrations/connectors/source-freshservice/source_freshservice/source.py
Sajarin a3cd983dbb [non-forked] Source Freshservice API: add stream for customer satisfaction survey responses endpoint (#25929)
* Source Freshservice API: change field data type from integer to string to match API

* Source Freshservice API: correct data types for phone number fields

* Source Freshservice API: correct data types for phone number fields

* add missing testing dependencies

* remove unnecessary install

* Source Freshservice: add stream for customer satisfaction survey responses

* version bump

* fix: linting

* update integration test files with new stream

* bump dockerfile, readme and metadata.yaml

* fix dockerfile and broken cat schema file

* Automated Change

* Automated Change

* fix dockerfile whitespace and add null to schema fields for csat stream

* Automated Change

* Update freshservice.md

* Automated Change

---------

Co-authored-by: Adam Roderick <aroder@gmail.com>
Co-authored-by: Adam Roderick <23650+aroder@users.noreply.github.com>
Co-authored-by: sajarin <sajarin@users.noreply.github.com>
Co-authored-by: Marcos Marx <marcosmarxm@users.noreply.github.com>
2023-05-19 13:58:17 -04:00

75 lines
2.3 KiB
Python

#
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
#
import base64
from typing import Any, List, Mapping, Tuple
import requests
from airbyte_cdk.logger import AirbyteLogger
from airbyte_cdk.models import SyncMode
from airbyte_cdk.sources import AbstractSource
from airbyte_cdk.sources.streams import Stream
from airbyte_cdk.sources.streams.http.requests_native_auth import TokenAuthenticator
from .streams import (
Agents,
Assets,
Changes,
Locations,
Problems,
Products,
PurchaseOrders,
Releases,
Requesters,
SatisfactionSurveyResponses,
Software,
Tickets,
Vendors,
)
# Source
class HttpBasicAuthenticator(TokenAuthenticator):
def __init__(self, auth: Tuple[str, str], auth_method: str = "Basic", **kwargs):
auth_string = f"{auth[0]}:{auth[1]}".encode("utf8")
b64_encoded = base64.b64encode(auth_string).decode("utf8")
super().__init__(token=b64_encoded, auth_method=auth_method, **kwargs)
class SourceFreshservice(AbstractSource):
def check_connection(self, logger: AirbyteLogger, config: Mapping[str, Any]) -> Tuple[bool, any]:
kwargs = {
"authenticator": HttpBasicAuthenticator((config["api_key"], "")),
"start_date": config["start_date"],
"domain_name": config["domain_name"],
}
try:
tickets = Tickets(**kwargs).read_records(sync_mode=SyncMode.full_refresh)
next(tickets)
return True, None
except requests.exceptions.RequestException as e:
return False, e
def streams(self, config: Mapping[str, Any]) -> List[Stream]:
kwargs = {
"authenticator": HttpBasicAuthenticator((config["api_key"], "")),
"start_date": config["start_date"],
"domain_name": config["domain_name"],
}
return [
Tickets(**kwargs),
Problems(**kwargs),
Changes(**kwargs),
Releases(**kwargs),
Requesters(**kwargs),
Agents(**kwargs),
Locations(**kwargs),
Products(**kwargs),
Vendors(**kwargs),
Assets(**kwargs),
PurchaseOrders(**kwargs),
SatisfactionSurveyResponses(**kwargs),
Software(**kwargs),
]