1
0
mirror of synced 2025-12-21 02:51:29 -05:00
Files
airbyte/airbyte-integrations/connectors/source-iterable/source_iterable/source.py
midavadim 7ae67d1b0d 🎉 Source Iterable - added new events streams (#16067)
* increased unit test coverage

* added additional events streams

* updated tests

* bumped connector version, update changelog

* fixed indentations

* api.py and iterable_streams.py merged into one stream.py file

* Fix unit tests

* updated release stage

* fixed import

* Updated version in seed

* auto-bump connector version [ci skip]

* updated source_specs.yaml

Co-authored-by: Serhii Lazebnyi <serhii.lazebnyi@globallogic.com>
Co-authored-by: Serhii Lazebnyi <53845333+lazebnyi@users.noreply.github.com>
Co-authored-by: Octavia Squidington III <octavia-squidington-iii@users.noreply.github.com>
2022-09-05 23:00:13 +03:00

125 lines
5.6 KiB
Python

#
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
#
from typing import Any, List, Mapping, Tuple
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 (
Campaigns,
CampaignsMetrics,
Channels,
CustomEvent,
EmailBounce,
EmailClick,
EmailComplaint,
EmailOpen,
EmailSend,
EmailSendSkip,
EmailSubscribe,
EmailUnsubscribe,
Events,
HostedUnsubscribeClick,
InAppClick,
InAppClose,
InAppDelete,
InAppDelivery,
InAppOpen,
InAppSend,
InAppSendSkip,
InboxMessageImpression,
InboxSession,
Lists,
ListUsers,
MessageTypes,
Metadata,
Purchase,
PushBounce,
PushOpen,
PushSend,
PushSendSkip,
PushUninstall,
SmsBounce,
SmsClick,
SmsReceived,
SmsSend,
SmsSendSkip,
SmsUsageInfo,
Templates,
Users,
WebPushClick,
WebPushSend,
WebPushSendSkip,
)
class SourceIterable(AbstractSource):
"""
Note: there are some redundant endpoints
(e.g. [`export/userEvents`](https://api.iterable.com/api/docs#export_exportUserEvents)
and [`events/{email}`](https://api.iterable.com/api/docs#events_User_events)).
In this case it's better to use the one which takes params as a query param rather than as part of the url param.
"""
def check_connection(self, logger, config) -> Tuple[bool, any]:
try:
authenticator = TokenAuthenticator(token=config["api_key"], auth_header="Api-Key", auth_method="")
list_gen = Lists(authenticator=authenticator).read_records(sync_mode=SyncMode.full_refresh)
next(list_gen)
return True, None
except Exception as e:
return False, f"Unable to connect to Iterable API with the provided credentials - {e}"
def streams(self, config: Mapping[str, Any]) -> List[Stream]:
authenticator = TokenAuthenticator(token=config["api_key"], auth_header="Api-Key", auth_method="")
return [
Campaigns(authenticator=authenticator),
CampaignsMetrics(authenticator=authenticator, start_date=config["start_date"]),
Channels(authenticator=authenticator),
EmailBounce(authenticator=authenticator, start_date=config["start_date"]),
EmailClick(authenticator=authenticator, start_date=config["start_date"]),
EmailComplaint(authenticator=authenticator, start_date=config["start_date"]),
EmailOpen(authenticator=authenticator, start_date=config["start_date"]),
EmailSend(authenticator=authenticator, start_date=config["start_date"]),
EmailSendSkip(authenticator=authenticator, start_date=config["start_date"]),
EmailSubscribe(authenticator=authenticator, start_date=config["start_date"]),
EmailUnsubscribe(authenticator=authenticator, start_date=config["start_date"]),
PushSend(authenticator=authenticator, start_date=config["start_date"]),
PushSendSkip(authenticator=authenticator, start_date=config["start_date"]),
PushOpen(authenticator=authenticator, start_date=config["start_date"]),
PushUninstall(authenticator=authenticator, start_date=config["start_date"]),
PushBounce(authenticator=authenticator, start_date=config["start_date"]),
WebPushSend(authenticator=authenticator, start_date=config["start_date"]),
WebPushClick(authenticator=authenticator, start_date=config["start_date"]),
WebPushSendSkip(authenticator=authenticator, start_date=config["start_date"]),
InAppSend(authenticator=authenticator, start_date=config["start_date"]),
InAppOpen(authenticator=authenticator, start_date=config["start_date"]),
InAppClick(authenticator=authenticator, start_date=config["start_date"]),
InAppClose(authenticator=authenticator, start_date=config["start_date"]),
InAppDelete(authenticator=authenticator, start_date=config["start_date"]),
InAppDelivery(authenticator=authenticator, start_date=config["start_date"]),
InAppSendSkip(authenticator=authenticator, start_date=config["start_date"]),
InboxSession(authenticator=authenticator, start_date=config["start_date"]),
InboxMessageImpression(authenticator=authenticator, start_date=config["start_date"]),
SmsSend(authenticator=authenticator, start_date=config["start_date"]),
SmsBounce(authenticator=authenticator, start_date=config["start_date"]),
SmsClick(authenticator=authenticator, start_date=config["start_date"]),
SmsReceived(authenticator=authenticator, start_date=config["start_date"]),
SmsSendSkip(authenticator=authenticator, start_date=config["start_date"]),
SmsUsageInfo(authenticator=authenticator, start_date=config["start_date"]),
Purchase(authenticator=authenticator, start_date=config["start_date"]),
CustomEvent(authenticator=authenticator, start_date=config["start_date"]),
HostedUnsubscribeClick(authenticator=authenticator, start_date=config["start_date"]),
Events(authenticator=authenticator),
Lists(authenticator=authenticator),
ListUsers(authenticator=authenticator),
MessageTypes(authenticator=authenticator),
Metadata(authenticator=authenticator),
Templates(authenticator=authenticator, start_date=config["start_date"]),
Users(authenticator=authenticator, start_date=config["start_date"]),
]