Skip to content

Commit 7ce6ec4

Browse files
updated generated and manually maintained code to move V2::Event, V2::EventDestination and V2::EventNotification to V2::Core, and UnknownEventNotification to Stripe::Events (stripe#1677)
Co-authored-by: Jesse Rosalia <jar@stripe.com>
1 parent 8330a2b commit 7ce6ec4

30 files changed

Lines changed: 669 additions & 645 deletions

lib/stripe.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
require "stripe/singleton_api_resource"
5353
require "stripe/webhook"
5454
require "stripe/stripe_configuration"
55-
require "stripe/event_notification"
55+
require "stripe/resources/v2/core/event_notification"
5656

5757
# Named API resources
5858
require "stripe/resources"

lib/stripe/event_notification.rb

Lines changed: 0 additions & 72 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
require "stripe/resources/v2/core/event_notification"
4+
5+
module Stripe
6+
module Events
7+
class UnknownEventNotification < Stripe::V2::Core::EventNotification
8+
attr_reader :related_object
9+
10+
def fetch_related_object
11+
return nil if @related_object.nil?
12+
13+
resp = @client.raw_request(:get, related_object.url, opts: { stripe_context: context },
14+
usage: ["fetch_related_object"])
15+
@client.deserialize(resp.http_body, api_mode: Util.get_api_mode(related_object.url))
16+
end
17+
end
18+
end
19+
end

lib/stripe/events/v1_billing_meter_error_report_triggered_event.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
module Stripe
55
module Events
66
# Occurs when a Meter has invalid async usage events.
7-
class V1BillingMeterErrorReportTriggeredEvent < Stripe::V2::Event
7+
class V1BillingMeterErrorReportTriggeredEvent < Stripe::V2::Core::Event
88
def self.lookup_type
99
"v1.billing.meter.error_report_triggered"
1010
end
@@ -101,7 +101,7 @@ def fetch_related_object
101101
end
102102

103103
# Occurs when a Meter has invalid async usage events.
104-
class V1BillingMeterErrorReportTriggeredEventNotification < Stripe::V2::EventNotification
104+
class V1BillingMeterErrorReportTriggeredEventNotification < Stripe::V2::Core::EventNotification
105105
def self.lookup_type
106106
"v1.billing.meter.error_report_triggered"
107107
end

lib/stripe/events/v1_billing_meter_no_meter_found_event.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
module Stripe
55
module Events
66
# Occurs when a Meter's id is missing or invalid in async usage events.
7-
class V1BillingMeterNoMeterFoundEvent < Stripe::V2::Event
7+
class V1BillingMeterNoMeterFoundEvent < Stripe::V2::Core::Event
88
def self.lookup_type
99
"v1.billing.meter.no_meter_found"
1010
end
@@ -91,7 +91,7 @@ def self.inner_class_types
9191
end
9292

9393
# Occurs when a Meter's id is missing or invalid in async usage events.
94-
class V1BillingMeterNoMeterFoundEventNotification < Stripe::V2::EventNotification
94+
class V1BillingMeterNoMeterFoundEventNotification < Stripe::V2::Core::EventNotification
9595
def self.lookup_type
9696
"v1.billing.meter.no_meter_found"
9797
end

lib/stripe/events/v2_core_event_destination_ping_event.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
module Stripe
55
module Events
66
# A ping event used to test the connection to an EventDestination.
7-
class V2CoreEventDestinationPingEvent < Stripe::V2::Event
7+
class V2CoreEventDestinationPingEvent < Stripe::V2::Core::Event
88
def self.lookup_type
99
"v2.core.event_destination.ping"
1010
end
@@ -22,7 +22,7 @@ def fetch_related_object
2222
end
2323

2424
# A ping event used to test the connection to an EventDestination.
25-
class V2CoreEventDestinationPingEventNotification < Stripe::V2::EventNotification
25+
class V2CoreEventDestinationPingEventNotification < Stripe::V2::Core::EventNotification
2626
def self.lookup_type
2727
"v2.core.event_destination.ping"
2828
end

lib/stripe/object_types.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ def self.v2_object_names_to_classes
162162
V2::Billing::MeterEvent.object_name => V2::Billing::MeterEvent,
163163
V2::Billing::MeterEventAdjustment.object_name => V2::Billing::MeterEventAdjustment,
164164
V2::Billing::MeterEventSession.object_name => V2::Billing::MeterEventSession,
165-
V2::Event.object_name => V2::Event,
166-
V2::EventDestination.object_name => V2::EventDestination,
165+
V2::Core::Event.object_name => V2::Core::Event,
166+
V2::Core::EventDestination.object_name => V2::Core::EventDestination,
167167
# v2 object classes: The end of the section generated from our OpenAPI spec
168168
}
169169
end

lib/stripe/resources.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@
141141
require "stripe/resources/v2/billing/meter_event"
142142
require "stripe/resources/v2/billing/meter_event_adjustment"
143143
require "stripe/resources/v2/billing/meter_event_session"
144+
require "stripe/resources/v2/core/event"
145+
require "stripe/resources/v2/core/event_destination"
144146
require "stripe/resources/v2/deleted_object"
145-
require "stripe/resources/v2/event"
146-
require "stripe/resources/v2/event_destination"
147147
require "stripe/resources/webhook_endpoint"
148148
require "stripe/events/v1_billing_meter_error_report_triggered_event"
149149
require "stripe/events/v1_billing_meter_no_meter_found_event"
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# File generated from our OpenAPI spec
2+
# frozen_string_literal: true
3+
4+
module Stripe
5+
module V2
6+
module Core
7+
# Events are generated to keep you informed of activity in your business account. APIs in the /v2 namespace generate [thin events](https://docs.stripe.com/event-destinations#benefits-of-thin-events) which have small, unversioned payloads that include a reference to the ID of the object that has changed. The Events v2 API returns these new thin events. [Retrieve the event object](https://docs.stripe.com/event-destinations#fetch-data) for additional data about the event. Use the related object ID in the event payload to [fetch the API resource](https://docs.stripe.com/event-destinations#retrieve-the-object-associated-with-thin-events) of the object associated with the event. Comparatively, events generated by most API v1 include a versioned snapshot of an API object in their payload.
8+
class Event < APIResource
9+
OBJECT_NAME = "v2.core.event"
10+
def self.object_name
11+
"v2.core.event"
12+
end
13+
14+
class Reason < Stripe::StripeObject
15+
class Request < Stripe::StripeObject
16+
# ID of the API request that caused the event.
17+
attr_reader :id
18+
# The idempotency key transmitted during the request.
19+
attr_reader :idempotency_key
20+
21+
def self.inner_class_types
22+
@inner_class_types = {}
23+
end
24+
25+
def self.field_remappings
26+
@field_remappings = {}
27+
end
28+
end
29+
# Event reason type.
30+
attr_reader :type
31+
# Information on the API request that instigated the event.
32+
attr_reader :request
33+
34+
def self.inner_class_types
35+
@inner_class_types = { request: Request }
36+
end
37+
38+
def self.field_remappings
39+
@field_remappings = {}
40+
end
41+
end
42+
# Authentication context needed to fetch the event or related object.
43+
attr_reader :context
44+
# Time at which the object was created.
45+
attr_reader :created
46+
# Unique identifier for the event.
47+
attr_reader :id
48+
# String representing the object's type. Objects of the same type share the same value of the object field.
49+
attr_reader :object
50+
# Reason for the event.
51+
attr_reader :reason
52+
# The type of the event.
53+
attr_reader :type
54+
# Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
55+
attr_reader :livemode
56+
57+
def self.inner_class_types
58+
@inner_class_types = { reason: Reason }
59+
end
60+
61+
def self.field_remappings
62+
@field_remappings = {}
63+
end
64+
end
65+
end
66+
end
67+
end
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# File generated from our OpenAPI spec
2+
# frozen_string_literal: true
3+
4+
module Stripe
5+
module V2
6+
module Core
7+
# Set up an event destination to receive events from Stripe across multiple destination types, including [webhook endpoints](https://docs.stripe.com/webhooks) and [Amazon EventBridge](https://docs.stripe.com/event-destinations/eventbridge). Event destinations support receiving [thin events](https://docs.stripe.com/api/v2/events) and [snapshot events](https://docs.stripe.com/api/events).
8+
class EventDestination < APIResource
9+
OBJECT_NAME = "v2.core.event_destination"
10+
def self.object_name
11+
"v2.core.event_destination"
12+
end
13+
14+
class StatusDetails < Stripe::StripeObject
15+
class Disabled < Stripe::StripeObject
16+
# Reason event destination has been disabled.
17+
attr_reader :reason
18+
19+
def self.inner_class_types
20+
@inner_class_types = {}
21+
end
22+
23+
def self.field_remappings
24+
@field_remappings = {}
25+
end
26+
end
27+
# Details about why the event destination has been disabled.
28+
attr_reader :disabled
29+
30+
def self.inner_class_types
31+
@inner_class_types = { disabled: Disabled }
32+
end
33+
34+
def self.field_remappings
35+
@field_remappings = {}
36+
end
37+
end
38+
39+
class AmazonEventbridge < Stripe::StripeObject
40+
# The AWS account ID.
41+
attr_reader :aws_account_id
42+
# The ARN of the AWS event source.
43+
attr_reader :aws_event_source_arn
44+
# The state of the AWS event source.
45+
attr_reader :aws_event_source_status
46+
47+
def self.inner_class_types
48+
@inner_class_types = {}
49+
end
50+
51+
def self.field_remappings
52+
@field_remappings = {}
53+
end
54+
end
55+
56+
class WebhookEndpoint < Stripe::StripeObject
57+
# The signing secret of the webhook endpoint, only includable on creation.
58+
attr_reader :signing_secret
59+
# The URL of the webhook endpoint, includable.
60+
attr_reader :url
61+
62+
def self.inner_class_types
63+
@inner_class_types = {}
64+
end
65+
66+
def self.field_remappings
67+
@field_remappings = {}
68+
end
69+
end
70+
# Time at which the object was created.
71+
attr_reader :created
72+
# An optional description of what the event destination is used for.
73+
attr_reader :description
74+
# The list of events to enable for this endpoint.
75+
attr_reader :enabled_events
76+
# Payload type of events being subscribed to.
77+
attr_reader :event_payload
78+
# Where events should be routed from.
79+
attr_reader :events_from
80+
# Unique identifier for the object.
81+
attr_reader :id
82+
# Metadata.
83+
attr_reader :metadata
84+
# Event destination name.
85+
attr_reader :name
86+
# String representing the object's type. Objects of the same type share the same value of the object field.
87+
attr_reader :object
88+
# If using the snapshot event payload, the API version events are rendered as.
89+
attr_reader :snapshot_api_version
90+
# Status. It can be set to either enabled or disabled.
91+
attr_reader :status
92+
# Additional information about event destination status.
93+
attr_reader :status_details
94+
# Event destination type.
95+
attr_reader :type
96+
# Time at which the object was last updated.
97+
attr_reader :updated
98+
# Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
99+
attr_reader :livemode
100+
# Amazon EventBridge configuration.
101+
attr_reader :amazon_eventbridge
102+
# Webhook endpoint configuration.
103+
attr_reader :webhook_endpoint
104+
105+
def self.inner_class_types
106+
@inner_class_types = {
107+
status_details: StatusDetails,
108+
amazon_eventbridge: AmazonEventbridge,
109+
webhook_endpoint: WebhookEndpoint,
110+
}
111+
end
112+
113+
def self.field_remappings
114+
@field_remappings = {}
115+
end
116+
end
117+
end
118+
end
119+
end

0 commit comments

Comments
 (0)