Skip to content

build SDK w/ new spec #1518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions stripe/_api_requestor.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ def request(
params=params,
requestor=requestor,
api_mode=api_mode,
v2_deleted_object=method == "delete" and api_mode == "V2",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the runtime code that ensures we turn delete responses into V2DeletedObject instead of EventDestination

We're not merging this second, but it's what we'll do when we are ready to merge.

)

return obj
Expand Down Expand Up @@ -234,6 +235,7 @@ async def request_async(
params=params,
requestor=requestor,
api_mode=api_mode,
v2_deleted_object=method == "delete" and api_mode == "V2",
)

return obj
Expand Down
15 changes: 14 additions & 1 deletion stripe/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ def get_thin_event_classes():
return THIN_EVENT_CLASSES


def get_deleted_object():
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

busting a circular import

from stripe.v2._deleted_object import DeletedObject

return DeletedObject


def get_object_classes(api_mode):
# This is here to avoid a circular dependency
if api_mode == "V2":
Expand Down Expand Up @@ -272,6 +278,7 @@ def _convert_to_stripe_object(
klass_: Optional[Type["StripeObject"]] = None,
requestor: "_APIRequestor",
api_mode: ApiMode,
v2_deleted_object: bool = False,
) -> "StripeObject": ...


Expand All @@ -283,6 +290,7 @@ def _convert_to_stripe_object(
klass_: Optional[Type["StripeObject"]] = None,
requestor: "_APIRequestor",
api_mode: ApiMode,
v2_deleted_object: bool = False,
) -> List["StripeObject"]: ...


Expand All @@ -293,6 +301,8 @@ def _convert_to_stripe_object(
klass_: Optional[Type["StripeObject"]] = None,
requestor: "_APIRequestor",
api_mode: ApiMode,
# whether we can't trust the object tag to represent the actual class we look up
v2_deleted_object: bool = False,
) -> Union["StripeObject", List["StripeObject"]]:
# If we get a StripeResponse, we'll want to return a
# StripeObject with the last_response field filled out with
Expand All @@ -314,14 +324,17 @@ def _convert_to_stripe_object(
requestor=requestor,
api_mode=api_mode,
klass_=klass_,
v2_deleted_object=v2_deleted_object,
)
for i in resp
]
elif isinstance(resp, dict) and not isinstance(resp, StripeObject):
resp = resp.copy()
klass_name = resp.get("object")
if isinstance(klass_name, str):
if api_mode == "V2" and klass_name == "v2.core.event":
if v2_deleted_object:
klass = get_deleted_object()
elif api_mode == "V2" and klass_name == "v2.core.event":
event_name = resp.get("type", "")
klass = get_thin_event_classes().get(
event_name, stripe.StripeObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,22 @@ class Request(StripeObject):
"""
_inner_class_types = {"error_types": ErrorType}

developer_message_summary: str
"""
Extra field included in the event's `data` when fetched from /v2/events.
"""
reason: Reason
"""
This contains information about why meter error happens.
"""
validation_end: str
developer_message_summary: str
"""
The end of the window that is encapsulated by this summary.
Extra field included in the event's `data` when fetched from /v2/events.
"""
validation_start: str
"""
The start of the window that is encapsulated by this summary.
"""
validation_end: str
"""
The end of the window that is encapsulated by this summary.
"""
_inner_class_types = {"reason": Reason}

data: V1BillingMeterErrorReportTriggeredEventData
Expand Down
12 changes: 6 additions & 6 deletions stripe/events/_v1_billing_meter_no_meter_found_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,22 @@ class Request(StripeObject):
"""
_inner_class_types = {"error_types": ErrorType}

developer_message_summary: str
"""
Extra field included in the event's `data` when fetched from /v2/events.
"""
reason: Reason
"""
This contains information about why meter error happens.
"""
validation_end: str
developer_message_summary: str
"""
The end of the window that is encapsulated by this summary.
Extra field included in the event's `data` when fetched from /v2/events.
"""
validation_start: str
"""
The start of the window that is encapsulated by this summary.
"""
validation_end: str
"""
The end of the window that is encapsulated by this summary.
"""
_inner_class_types = {"reason": Reason}

data: V1BillingMeterNoMeterFoundEventData
Expand Down
4 changes: 2 additions & 2 deletions stripe/v2/_billing_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
class BillingService(StripeService):
def __init__(self, requestor):
super().__init__(requestor)
self.meter_event_session = MeterEventSessionService(self._requestor)
self.meter_events = MeterEventService(self._requestor)
self.meter_event_adjustments = MeterEventAdjustmentService(
self._requestor,
)
self.meter_event_session = MeterEventSessionService(self._requestor)
self.meter_event_stream = MeterEventStreamService(self._requestor)
self.meter_events = MeterEventService(self._requestor)
2 changes: 1 addition & 1 deletion stripe/v2/_core_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
class CoreService(StripeService):
def __init__(self, requestor):
super().__init__(requestor)
self.event_destinations = EventDestinationService(self._requestor)
self.events = EventService(self._requestor)
self.event_destinations = EventDestinationService(self._requestor)
13 changes: 13 additions & 0 deletions stripe/v2/_deleted_object.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# -*- coding: utf-8 -*-
from stripe._stripe_object import StripeObject


class DeletedObject(StripeObject):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

manually written class, references to which will get spit out by codegen

object: str
"""
String representing the object's type. Objects of the same type share the same value of the object field.
"""
id: str
"""
The ID of the object that's being deleted.
"""
Loading