🎉 Source Iterable - API key is passed in headers (#15670)
* API key is passed in headers * updated docs * removed log * formatted * fixed tests * increased timeout for incremental stream * bumper source version * bumper source version in seed * auto-bump connector version [ci skip] Co-authored-by: Octavia Squidington III <octavia-squidington-iii@users.noreply.github.com>
This commit is contained in:
@@ -32,7 +32,7 @@ class ListUsers(IterableStream):
|
||||
return f"lists/{self.data_field}?listId={stream_slice['list_id']}"
|
||||
|
||||
def stream_slices(self, **kwargs) -> Iterable[Optional[Mapping[str, any]]]:
|
||||
lists = Lists(api_key=self._api_key)
|
||||
lists = Lists(authenticator=self._cred)
|
||||
for list_record in lists.read_records(sync_mode=kwargs.get("sync_mode", SyncMode.full_refresh)):
|
||||
yield {"list_id": list_record["id"]}
|
||||
|
||||
@@ -62,11 +62,11 @@ class CampaignsMetrics(IterableStream):
|
||||
primary_key = None
|
||||
data_field = None
|
||||
|
||||
def __init__(self, api_key: str, start_date: str):
|
||||
def __init__(self, start_date: str, **kwargs):
|
||||
"""
|
||||
https://api.iterable.com/api/docs#campaigns_metrics
|
||||
"""
|
||||
super().__init__(api_key)
|
||||
super().__init__(**kwargs)
|
||||
self.start_date = start_date
|
||||
|
||||
def path(self, **kwargs) -> str:
|
||||
@@ -80,7 +80,7 @@ class CampaignsMetrics(IterableStream):
|
||||
return params
|
||||
|
||||
def stream_slices(self, **kwargs) -> Iterable[Optional[Mapping[str, any]]]:
|
||||
lists = Campaigns(api_key=self._api_key)
|
||||
lists = Campaigns(authenticator=self._cred)
|
||||
campaign_ids = []
|
||||
for list_record in lists.read_records(sync_mode=kwargs.get("sync_mode", SyncMode.full_refresh)):
|
||||
campaign_ids.append(list_record["id"])
|
||||
@@ -201,7 +201,7 @@ class Events(IterableStream):
|
||||
return params
|
||||
|
||||
def stream_slices(self, **kwargs) -> Iterable[Optional[Mapping[str, any]]]:
|
||||
lists = ListUsers(api_key=self._api_key)
|
||||
lists = ListUsers(authenticator=self._cred)
|
||||
stream_slices = lists.stream_slices()
|
||||
|
||||
for stream_slice in stream_slices:
|
||||
|
||||
@@ -24,9 +24,9 @@ class IterableStream(HttpStream, ABC):
|
||||
url_base = "https://api.iterable.com/api/"
|
||||
primary_key = "id"
|
||||
|
||||
def __init__(self, api_key, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self._api_key = api_key
|
||||
def __init__(self, authenticator):
|
||||
self._cred = authenticator
|
||||
super().__init__(authenticator)
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
@@ -44,9 +44,6 @@ class IterableStream(HttpStream, ABC):
|
||||
"""
|
||||
return None
|
||||
|
||||
def request_params(self, **kwargs) -> MutableMapping[str, Any]:
|
||||
return {"api_key": self._api_key}
|
||||
|
||||
def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapping]:
|
||||
response_json = response.json()
|
||||
records = response_json.get(self.data_field, [])
|
||||
@@ -70,7 +67,7 @@ class IterableExportStream(IterableStream, ABC):
|
||||
cursor_field = "createdAt"
|
||||
primary_key = None
|
||||
|
||||
def __init__(self, start_date, **kwargs):
|
||||
def __init__(self, start_date=None, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self._start_date = pendulum.parse(start_date)
|
||||
self.stream_params = {"dataTypeName": self.data_field}
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
# 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 .api import (
|
||||
Campaigns,
|
||||
@@ -41,30 +41,32 @@ class SourceIterable(AbstractSource):
|
||||
|
||||
def check_connection(self, logger, config) -> Tuple[bool, any]:
|
||||
try:
|
||||
list_gen = Lists(api_key=config["api_key"]).read_records(sync_mode=SyncMode.full_refresh)
|
||||
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(api_key=config["api_key"]),
|
||||
CampaignsMetrics(api_key=config["api_key"], start_date=config["start_date"]),
|
||||
Channels(api_key=config["api_key"]),
|
||||
EmailBounce(api_key=config["api_key"], start_date=config["start_date"]),
|
||||
EmailClick(api_key=config["api_key"], start_date=config["start_date"]),
|
||||
EmailComplaint(api_key=config["api_key"], start_date=config["start_date"]),
|
||||
EmailOpen(api_key=config["api_key"], start_date=config["start_date"]),
|
||||
EmailSend(api_key=config["api_key"], start_date=config["start_date"]),
|
||||
EmailSendSkip(api_key=config["api_key"], start_date=config["start_date"]),
|
||||
EmailSubscribe(api_key=config["api_key"], start_date=config["start_date"]),
|
||||
EmailUnsubscribe(api_key=config["api_key"], start_date=config["start_date"]),
|
||||
Events(api_key=config["api_key"]),
|
||||
Lists(api_key=config["api_key"]),
|
||||
ListUsers(api_key=config["api_key"]),
|
||||
MessageTypes(api_key=config["api_key"]),
|
||||
Metadata(api_key=config["api_key"]),
|
||||
Templates(api_key=config["api_key"], start_date=config["start_date"]),
|
||||
Users(api_key=config["api_key"], start_date=config["start_date"]),
|
||||
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"]),
|
||||
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"]),
|
||||
]
|
||||
|
||||
@@ -5,20 +5,22 @@
|
||||
"title": "Iterable Spec",
|
||||
"type": "object",
|
||||
"required": ["start_date", "api_key"],
|
||||
"additionalProperties": false,
|
||||
"additionalProperties": true,
|
||||
"properties": {
|
||||
"api_key": {
|
||||
"type": "string",
|
||||
"title": "API Key",
|
||||
"description": "Iterable API Key. See the <a href=\"https://docs.airbyte.io/integrations/sources/iterable\">docs</a> for more information on how to obtain this key.",
|
||||
"airbyte_secret": true,
|
||||
"order": 0
|
||||
},
|
||||
"start_date": {
|
||||
"type": "string",
|
||||
"title": "Start Date",
|
||||
"description": "The date from which you'd like to replicate data for Iterable, in the format YYYY-MM-DDT00:00:00Z. All data generated after this date will be replicated.",
|
||||
"examples": ["2021-04-01T00:00:00Z"],
|
||||
"pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
|
||||
},
|
||||
"api_key": {
|
||||
"type": "string",
|
||||
"title": "API Key",
|
||||
"description": "Iterable API Key. See the <a href=\"https://docs.airbyte.io/integrations/sources/iterable\">docs</a> for more information on how to obtain this key.",
|
||||
"airbyte_secret": true
|
||||
"pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$",
|
||||
"order": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user