Skip to content

Commit

Permalink
feat(api): add events, event subscriptions, and associated cursor page
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot authored and rattrayalex committed Feb 18, 2023
1 parent 36cf2fe commit 0a651fc
Show file tree
Hide file tree
Showing 25 changed files with 1,391 additions and 99 deletions.
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
configured_endpoints: 40
configured_endpoints: 52
37 changes: 37 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,43 @@ Custom Methods:
- `get_embed_html`
- `get_embed_url`

# Events

Types:

```python
from lithic.types import Event, EventSubscription
```

Methods:

- <code title="get /events/{event_token}">client.events.<a href="./src/lithic/resources/events/events.py">retrieve</a>(event_token) -> <a href="./src/lithic/types/event.py">Event</a></code>
- <code title="get /events">client.events.<a href="./src/lithic/resources/events/events.py">list</a>(\*\*<a href="src/lithic/types/event_list_params.py">params</a>) -> <a href="./src/lithic/types/event.py">SyncCursorPage[Event]</a></code>

Custom Methods:

- `resend`

## Subscriptions

Types:

```python
from lithic.types.events import SubscriptionRetrieveSecretResponse
```

Methods:

- <code title="post /event_subscriptions">client.events.subscriptions.<a href="./src/lithic/resources/events/subscriptions.py">create</a>(\*\*<a href="src/lithic/types/events/subscription_create_params.py">params</a>) -> <a href="./src/lithic/types/event_subscription.py">EventSubscription</a></code>
- <code title="get /event_subscriptions/{event_subscription_token}">client.events.subscriptions.<a href="./src/lithic/resources/events/subscriptions.py">retrieve</a>(event_subscription_token) -> <a href="./src/lithic/types/event_subscription.py">EventSubscription</a></code>
- <code title="patch /event_subscriptions/{event_subscription_token}">client.events.subscriptions.<a href="./src/lithic/resources/events/subscriptions.py">update</a>(event_subscription_token, \*\*<a href="src/lithic/types/events/subscription_update_params.py">params</a>) -> <a href="./src/lithic/types/event_subscription.py">EventSubscription</a></code>
- <code title="get /event_subscriptions">client.events.subscriptions.<a href="./src/lithic/resources/events/subscriptions.py">list</a>(\*\*<a href="src/lithic/types/events/subscription_list_params.py">params</a>) -> <a href="./src/lithic/types/event_subscription.py">SyncCursorPage[EventSubscription]</a></code>
- <code title="delete /event_subscriptions/{event_subscription_token}">client.events.subscriptions.<a href="./src/lithic/resources/events/subscriptions.py">delete</a>(event_subscription_token) -> None</code>
- <code title="post /event_subscriptions/{event_subscription_token}/recover">client.events.subscriptions.<a href="./src/lithic/resources/events/subscriptions.py">recover</a>(event_subscription_token) -> None</code>
- <code title="post /event_subscriptions/{event_subscription_token}/replay_missing">client.events.subscriptions.<a href="./src/lithic/resources/events/subscriptions.py">replay_missing</a>(event_subscription_token) -> None</code>
- <code title="get /event_subscriptions/{event_subscription_token}/secret">client.events.subscriptions.<a href="./src/lithic/resources/events/subscriptions.py">retrieve_secret</a>(event_subscription_token) -> <a href="./src/lithic/types/events/subscription_retrieve_secret_response.py">SubscriptionRetrieveSecretResponse</a></code>
- <code title="post /event_subscriptions/{event_subscription_token}/secret/rotate">client.events.subscriptions.<a href="./src/lithic/resources/events/subscriptions.py">rotate_secret</a>(event_subscription_token) -> None</code>

# FundingSources

Types:
Expand Down
4 changes: 4 additions & 0 deletions src/lithic/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Lithic(SyncAPIClient):
auth_rules: resources.AuthRules
auth_stream_enrollment: resources.AuthStreamEnrollmentResource
cards: resources.Cards
events: resources.Events
funding_sources: resources.FundingSources
transactions: resources.Transactions

Expand Down Expand Up @@ -123,6 +124,7 @@ def __init__(
self.auth_rules = resources.AuthRules(self)
self.auth_stream_enrollment = resources.AuthStreamEnrollmentResource(self)
self.cards = resources.Cards(self)
self.events = resources.Events(self)
self.funding_sources = resources.FundingSources(self)
self.transactions = resources.Transactions(self)

Expand Down Expand Up @@ -209,6 +211,7 @@ class AsyncLithic(AsyncAPIClient):
auth_rules: resources.AsyncAuthRules
auth_stream_enrollment: resources.AsyncAuthStreamEnrollmentResource
cards: resources.AsyncCards
events: resources.AsyncEvents
funding_sources: resources.AsyncFundingSources
transactions: resources.AsyncTransactions

Expand Down Expand Up @@ -278,6 +281,7 @@ def __init__(
self.auth_rules = resources.AsyncAuthRules(self)
self.auth_stream_enrollment = resources.AsyncAuthStreamEnrollmentResource(self)
self.cards = resources.AsyncCards(self)
self.events = resources.AsyncEvents(self)
self.funding_sources = resources.AsyncFundingSources(self)
self.transactions = resources.AsyncTransactions(self)

Expand Down
64 changes: 62 additions & 2 deletions src/lithic/pagination.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
# File generated from our OpenAPI spec by Stainless.

from typing import List, Generic, TypeVar, Optional
from typing import Any, List, Generic, TypeVar, Optional, cast
from typing_extensions import Protocol, runtime_checkable

from ._types import ModelT
from ._models import BaseModel
from ._base_client import BasePage, PageInfo, BaseSyncPage, BaseAsyncPage

__all__ = ["SyncPage", "AsyncPage"]
__all__ = ["SyncPage", "AsyncPage", "SyncCursorPage", "AsyncCursorPage"]

_BaseModelT = TypeVar("_BaseModelT", bound=BaseModel)


@runtime_checkable
class CursorPageItem(Protocol):
token: str


class SyncPage(BaseSyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):
data: List[ModelT]
page: int
Expand Down Expand Up @@ -41,3 +47,57 @@ def next_page_info(self) -> Optional[PageInfo]:
if not current_page < self.total_pages:
return None
return PageInfo(params={"page": current_page + 1})


class SyncCursorPage(BaseSyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):
data: List[ModelT]
has_more: bool

def _get_page_items(self) -> List[ModelT]:
return self.data

def next_page_info(self) -> Optional[PageInfo]:
is_forwards = not self._options.params.get("ending_before", False)

if len(self.data) > 0:
return None

if is_forwards:
item = cast(Any, self.data[-1])
if not isinstance(item, CursorPageItem):
# TODO emit warning log
return None
return PageInfo(params={"staring_after": item.token})
else:
item = cast(Any, self.data[0])
if not isinstance(item, CursorPageItem):
# TODO emit warning log
return None
return PageInfo(params={"ending_before": item.token})


class AsyncCursorPage(BaseAsyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):
data: List[ModelT]
has_more: bool

def _get_page_items(self) -> List[ModelT]:
return self.data

def next_page_info(self) -> Optional[PageInfo]:
is_forwards = not self._options.params.get("ending_before", False)

if len(self.data) > 0:
return None

if is_forwards:
item = cast(Any, self.data[-1])
if not isinstance(item, CursorPageItem):
# TODO emit warning log
return None
return PageInfo(params={"staring_after": item.token})
else:
item = cast(Any, self.data[0])
if not isinstance(item, CursorPageItem):
# TODO emit warning log
return None
return PageInfo(params={"ending_before": item.token})
3 changes: 3 additions & 0 deletions src/lithic/resources/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# File generated from our OpenAPI spec by Stainless.

from .cards import Cards, AsyncCards
from .events import Events, AsyncEvents
from .accounts import Accounts, AsyncAccounts
from .auth_rules import AuthRules, AsyncAuthRules
from .transactions import Transactions, AsyncTransactions
Expand All @@ -22,6 +23,8 @@
"AsyncAuthStreamEnrollmentResource",
"Cards",
"AsyncCards",
"Events",
"AsyncEvents",
"FundingSources",
"AsyncFundingSources",
"Transactions",
Expand Down
4 changes: 0 additions & 4 deletions src/lithic/resources/auth_stream_enrollment.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def disenroll(
extra_body: Body | None = None,
) -> None:
"""Disenroll Authorization Stream Access (ASA) in Sandbox."""
extra_headers = {"Accept": "*/*", **(extra_headers or {})}
return self._delete(
"/auth_stream",
options=make_request_options(extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body),
Expand Down Expand Up @@ -80,7 +79,6 @@ def enroll(
extra_body: Add additional JSON properties to the request
"""
extra_headers = {"Accept": "*/*", **(extra_headers or {})}
return self._post(
"/auth_stream",
body={"webhook_url": webhook_url},
Expand Down Expand Up @@ -119,7 +117,6 @@ async def disenroll(
extra_body: Body | None = None,
) -> None:
"""Disenroll Authorization Stream Access (ASA) in Sandbox."""
extra_headers = {"Accept": "*/*", **(extra_headers or {})}
return await self._delete(
"/auth_stream",
options=make_request_options(extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body),
Expand Down Expand Up @@ -159,7 +156,6 @@ async def enroll(
extra_body: Add additional JSON properties to the request
"""
extra_headers = {"Accept": "*/*", **(extra_headers or {})}
return await self._post(
"/auth_stream",
body={"webhook_url": webhook_url},
Expand Down
6 changes: 6 additions & 0 deletions src/lithic/resources/events/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# File generated from our OpenAPI spec by Stainless.

from .events import Events, AsyncEvents
from .subscriptions import Subscriptions, AsyncSubscriptions

__all__ = ["Subscriptions", "AsyncSubscriptions", "Events", "AsyncEvents"]
Loading

0 comments on commit 0a651fc

Please sign in to comment.