wesley-key-sdk 4.2.0 → 4.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +34 -47
- data/bin/console +4 -4
- data/lib/{swagger_petstore_open_api30 → webhooks_and_callbacks_api}/api_helper.rb +2 -2
- data/lib/{swagger_petstore_open_api30 → webhooks_and_callbacks_api}/apis/base_api.rb +3 -3
- data/lib/webhooks_and_callbacks_api/apis/orders_api.rb +34 -0
- data/lib/{swagger_petstore_open_api30 → webhooks_and_callbacks_api}/client.rb +15 -34
- data/lib/{swagger_petstore_open_api30 → webhooks_and_callbacks_api}/configuration.rb +20 -30
- data/lib/webhooks_and_callbacks_api/events/callbacks/callbacks_a_handler.rb +66 -0
- data/lib/webhooks_and_callbacks_api/events/callbacks/callbacks_b_handler.rb +78 -0
- data/lib/webhooks_and_callbacks_api/events/signature_verification_failure.rb +33 -0
- data/lib/webhooks_and_callbacks_api/events/signature_verification_result.rb +14 -0
- data/lib/webhooks_and_callbacks_api/events/unknown_event.rb +32 -0
- data/lib/webhooks_and_callbacks_api/events/webhooks/webhooks_a_handler.rb +67 -0
- data/lib/webhooks_and_callbacks_api/events/webhooks/webhooks_b_handler.rb +86 -0
- data/lib/webhooks_and_callbacks_api/events/webhooks/webhooks_c_handler.rb +79 -0
- data/lib/webhooks_and_callbacks_api/events/webhooks/webhooks_handler.rb +67 -0
- data/lib/webhooks_and_callbacks_api/events/webhooks/webhooks_no_verification_handler.rb +39 -0
- data/lib/{swagger_petstore_open_api30 → webhooks_and_callbacks_api}/exceptions/api_exception.rb +2 -2
- data/lib/webhooks_and_callbacks_api/exceptions/error_exception.rb +57 -0
- data/lib/{swagger_petstore_open_api30 → webhooks_and_callbacks_api}/http/api_response.rb +2 -2
- data/lib/{swagger_petstore_open_api30 → webhooks_and_callbacks_api}/http/auth/api_key.rb +15 -15
- data/lib/webhooks_and_callbacks_api/http/auth/bearer_auth.rb +53 -0
- data/lib/{swagger_petstore_open_api30 → webhooks_and_callbacks_api}/http/http_call_back.rb +2 -2
- data/lib/{swagger_petstore_open_api30 → webhooks_and_callbacks_api}/http/http_method_enum.rb +2 -2
- data/lib/{swagger_petstore_open_api30 → webhooks_and_callbacks_api}/http/http_request.rb +2 -2
- data/lib/{swagger_petstore_open_api30 → webhooks_and_callbacks_api}/http/http_response.rb +2 -2
- data/lib/{swagger_petstore_open_api30 → webhooks_and_callbacks_api}/http/proxy_settings.rb +2 -2
- data/lib/{swagger_petstore_open_api30 → webhooks_and_callbacks_api}/logging/configuration/api_logging_configuration.rb +2 -2
- data/lib/{swagger_petstore_open_api30 → webhooks_and_callbacks_api}/logging/sdk_logger.rb +2 -2
- data/lib/webhooks_and_callbacks_api/models/address.rb +114 -0
- data/lib/webhooks_and_callbacks_api/models/audit_log_event.rb +115 -0
- data/lib/{swagger_petstore_open_api30 → webhooks_and_callbacks_api}/models/base_model.rb +2 -2
- data/lib/webhooks_and_callbacks_api/models/create_order_request.rb +131 -0
- data/lib/{swagger_petstore_open_api30/models/tag.rb → webhooks_and_callbacks_api/models/delivery_details.rb} +35 -36
- data/lib/webhooks_and_callbacks_api/models/email_notification_callback.rb +97 -0
- data/lib/webhooks_and_callbacks_api/models/event.rb +52 -0
- data/lib/webhooks_and_callbacks_api/models/event_type.rb +26 -0
- data/lib/webhooks_and_callbacks_api/models/event_type1.rb +26 -0
- data/lib/webhooks_and_callbacks_api/models/event_type2.rb +26 -0
- data/lib/webhooks_and_callbacks_api/models/event_type3.rb +26 -0
- data/lib/webhooks_and_callbacks_api/models/fulfillment_callback.rb +411 -0
- data/lib/webhooks_and_callbacks_api/models/fulfillment_status.rb +40 -0
- data/lib/webhooks_and_callbacks_api/models/fulfillment_statuss.rb +40 -0
- data/lib/webhooks_and_callbacks_api/models/inventory_stock_decrease_event.rb +90 -0
- data/lib/webhooks_and_callbacks_api/models/inventory_stock_depleted_event.rb +90 -0
- data/lib/webhooks_and_callbacks_api/models/inventory_stock_increase_event.rb +90 -0
- data/lib/webhooks_and_callbacks_api/models/notification_callback.rb +119 -0
- data/lib/webhooks_and_callbacks_api/models/oauth_scope_oauth_acg.rb +44 -0
- data/lib/webhooks_and_callbacks_api/models/order.rb +161 -0
- data/lib/webhooks_and_callbacks_api/models/order_created_event.rb +314 -0
- data/lib/webhooks_and_callbacks_api/models/order_item.rb +102 -0
- data/lib/webhooks_and_callbacks_api/models/order_updated_event.rb +100 -0
- data/lib/{swagger_petstore_open_api30/models/category.rb → webhooks_and_callbacks_api/models/package.rb} +29 -39
- data/lib/webhooks_and_callbacks_api/models/payment_callback.rb +167 -0
- data/lib/webhooks_and_callbacks_api/models/payment_completed_event.rb +98 -0
- data/lib/webhooks_and_callbacks_api/models/payment_status.rb +40 -0
- data/lib/webhooks_and_callbacks_api/models/payment_status_created_event.rb +89 -0
- data/lib/webhooks_and_callbacks_api/models/payment_status_updated_event.rb +89 -0
- data/lib/webhooks_and_callbacks_api/models/primitive_collection_event.rb +98 -0
- data/lib/webhooks_and_callbacks_api/models/root_level_primitive_one_of_event_request.rb +40 -0
- data/lib/webhooks_and_callbacks_api/models/root_level_primitive_one_of_event_request1.rb +40 -0
- data/lib/webhooks_and_callbacks_api/models/sms_notification_callback.rb +95 -0
- data/lib/webhooks_and_callbacks_api/models/status.rb +44 -0
- data/lib/webhooks_and_callbacks_api/models/status1.rb +36 -0
- data/lib/webhooks_and_callbacks_api/models/status2.rb +36 -0
- data/lib/webhooks_and_callbacks_api/models/system_alert_notification_event.rb +90 -0
- data/lib/webhooks_and_callbacks_api/models/system_maintenance_notification_event.rb +90 -0
- data/lib/webhooks_and_callbacks_api/models/system_performance_notification_event.rb +90 -0
- data/lib/webhooks_and_callbacks_api/models/user_action_notification_event.rb +90 -0
- data/lib/webhooks_and_callbacks_api/models/user_preference_notification_event.rb +90 -0
- data/lib/webhooks_and_callbacks_api/models/user_status_notification_event.rb +90 -0
- data/lib/webhooks_and_callbacks_api/models/webhook.rb +142 -0
- data/lib/webhooks_and_callbacks_api/models/webhook_registration.rb +103 -0
- data/lib/webhooks_and_callbacks_api/models/webhook_update.rb +105 -0
- data/lib/{swagger_petstore_open_api30 → webhooks_and_callbacks_api}/utilities/date_time_helper.rb +2 -2
- data/lib/{swagger_petstore_open_api30 → webhooks_and_callbacks_api}/utilities/file_wrapper.rb +2 -2
- data/lib/webhooks_and_callbacks_api/utilities/union_type_lookup.rb +172 -0
- data/lib/webhooks_and_callbacks_api.rb +122 -0
- metadata +78 -37
- data/lib/swagger_petstore_open_api30/apis/pet_api.rb +0 -287
- data/lib/swagger_petstore_open_api30/apis/store_api.rb +0 -131
- data/lib/swagger_petstore_open_api30/apis/user_api.rb +0 -233
- data/lib/swagger_petstore_open_api30/exceptions/oauth_provider_exception.rb +0 -64
- data/lib/swagger_petstore_open_api30/http/auth/petstore_auth.rb +0 -112
- data/lib/swagger_petstore_open_api30/models/api_response.rb +0 -118
- data/lib/swagger_petstore_open_api30/models/oauth_provider_error.rb +0 -62
- data/lib/swagger_petstore_open_api30/models/oauth_scope_petstore_auth.rb +0 -36
- data/lib/swagger_petstore_open_api30/models/oauth_token.rb +0 -125
- data/lib/swagger_petstore_open_api30/models/order.rb +0 -167
- data/lib/swagger_petstore_open_api30/models/order_status.rb +0 -40
- data/lib/swagger_petstore_open_api30/models/pet.rb +0 -168
- data/lib/swagger_petstore_open_api30/models/pet_status.rb +0 -40
- data/lib/swagger_petstore_open_api30/models/user.rb +0 -182
- data/lib/swagger_petstore_open_api30/utilities/xml_utilities.rb +0 -12
- data/lib/swagger_petstore_open_api30.rb +0 -62
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# webhooks_and_callbacks_api
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by
|
|
4
|
+
# APIMATIC v3.0 ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module WebhooksAndCallbacksApi
|
|
7
|
+
# Represents a signature verification failure.
|
|
8
|
+
# @param errors [Array<String>] List of error messages describing why verification failed.
|
|
9
|
+
class SignatureVerificationFailure
|
|
10
|
+
# @return [Array<String>]
|
|
11
|
+
attr_reader :errors
|
|
12
|
+
|
|
13
|
+
# Initialize with the list of errors.
|
|
14
|
+
# @param errors [Array<String>] Error messages that caused the failure.
|
|
15
|
+
def initialize(errors)
|
|
16
|
+
@errors = errors
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Provides a user-friendly string representation of the failure.
|
|
20
|
+
# @return [String]
|
|
21
|
+
def to_s
|
|
22
|
+
class_name = self.class.name.split('::').last
|
|
23
|
+
"<#{class_name} errors: #{@errors}>"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Provides a debugging-friendly string with detailed object information.
|
|
27
|
+
# @return [String]
|
|
28
|
+
def inspect
|
|
29
|
+
class_name = self.class.name.split('::').last
|
|
30
|
+
"<#{class_name} errors: #{@errors.inspect}>"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# webhooks_and_callbacks_api
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by
|
|
4
|
+
# APIMATIC v3.0 ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module WebhooksAndCallbacksApi
|
|
7
|
+
# Outcome of signature verification.
|
|
8
|
+
# @!attribute [r] ok
|
|
9
|
+
# @return [Boolean] True if the signature verification passed.
|
|
10
|
+
# @!attribute [r] errors
|
|
11
|
+
# @return [Array<String>, nil] Optional list of errors raised by the verifier. None when ok=true.
|
|
12
|
+
class SignatureVerificationResult < CoreLibrary::SignatureVerificationResult
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# webhooks_and_callbacks_api
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by
|
|
4
|
+
# APIMATIC v3.0 ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module WebhooksAndCallbacksApi
|
|
7
|
+
# Represents an unrecognized or unsupported event during processing.
|
|
8
|
+
class UnknownEvent
|
|
9
|
+
# @return [Array<String>]
|
|
10
|
+
attr_reader :errors
|
|
11
|
+
|
|
12
|
+
# Initialize with the errors that caused the failure.
|
|
13
|
+
# @param errors [Array<String>] A list of error messages describing the reasons for verification failure.
|
|
14
|
+
def initialize(errors)
|
|
15
|
+
@errors = errors
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Provides a user-friendly string representation of the failure.
|
|
19
|
+
# @return [String]
|
|
20
|
+
def to_s
|
|
21
|
+
class_name = self.class.name.split('::').last
|
|
22
|
+
"<#{class_name} errors: #{@errors}>"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Provides a debugging-friendly string with detailed object information.
|
|
26
|
+
# @return [String]
|
|
27
|
+
def inspect
|
|
28
|
+
class_name = self.class.name.split('::').last
|
|
29
|
+
"<#{class_name} errors: #{@errors.inspect}>"
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# webhooks_and_callbacks_api
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by
|
|
4
|
+
# APIMATIC v3.0 ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module WebhooksAndCallbacksApi
|
|
7
|
+
# WebhooksAHandler is responsible for verifying request signatures
|
|
8
|
+
# and parsing incoming webhooksA events into strongly typed objects.
|
|
9
|
+
class WebhooksAHandler
|
|
10
|
+
include CoreLibrary
|
|
11
|
+
# Creates a new instance of the WebhooksAHandler.
|
|
12
|
+
# Initializes the handler.
|
|
13
|
+
# @param [String] secret_key
|
|
14
|
+
# The secret used to generate and validate HMAC signatures for verifying request authenticity.
|
|
15
|
+
# @raise [ArgumentError] If the secret_key is not provided.
|
|
16
|
+
def initialize(secret_key)
|
|
17
|
+
raise ArgumentError, 'secret_key must be provided for signature verification.' unless secret_key
|
|
18
|
+
|
|
19
|
+
@verifier = HmacSignatureVerifier.new(
|
|
20
|
+
secret_key: secret_key,
|
|
21
|
+
signature_header: 'X-Signature',
|
|
22
|
+
hash_algorithm: 'sha256',
|
|
23
|
+
encoder: HexEncoder.new,
|
|
24
|
+
signature_value_template: 'sha256={digest}'
|
|
25
|
+
)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Perform signature verification and return the result.
|
|
29
|
+
#
|
|
30
|
+
# @param [Rack::Request] request The incoming HTTP request to verify.
|
|
31
|
+
# @return [SignatureVerificationResult] The result of the signature verification.
|
|
32
|
+
def verify(request)
|
|
33
|
+
@verifier.verify(request)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Verify the request signature and parse the event.
|
|
37
|
+
#
|
|
38
|
+
# @param [Rack::Request] request The incoming HTTP request containing the event payload.
|
|
39
|
+
# @return[PaymentStatusUpdatedEvent, PaymentStatusCreatedEvent,
|
|
40
|
+
# SignatureVerificationFailure, UnknownEvent]
|
|
41
|
+
# PaymentStatusUpdatedEvent, PaymentStatusCreatedEvent for successful
|
|
42
|
+
# parsing;
|
|
43
|
+
# SignatureVerificationFailure when signature fails;
|
|
44
|
+
#
|
|
45
|
+
# UnknownEvent for unknown events.
|
|
46
|
+
def verify_and_parse_event(request)
|
|
47
|
+
unless request.respond_to?(:env) && request.env.is_a?(Hash)
|
|
48
|
+
return SignatureVerificationFailure.new(['Invalid request env.'])
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
raw_body = RackRequestHelper.read_raw_body(request)
|
|
52
|
+
return SignatureVerificationFailure.new(['Invalid request body.']) if raw_body.nil? || raw_body.empty?
|
|
53
|
+
|
|
54
|
+
verification_result = verify(request)
|
|
55
|
+
return SignatureVerificationFailure.new(verification_result.errors) unless verification_result.ok
|
|
56
|
+
|
|
57
|
+
# Deserialize payload
|
|
58
|
+
begin
|
|
59
|
+
union = UnionTypeLookUp.get(:WebhooksA)
|
|
60
|
+
raw = RackRequestHelper.read_raw_body(request)
|
|
61
|
+
APIHelper.deserialize_union_type(union, raw, false, true)
|
|
62
|
+
rescue StandardError => e
|
|
63
|
+
UnknownEvent.new(['Deserialization failed.', e.message])
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# webhooks_and_callbacks_api
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by
|
|
4
|
+
# APIMATIC v3.0 ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module WebhooksAndCallbacksApi
|
|
7
|
+
# WebhooksBHandler is responsible for verifying request signatures
|
|
8
|
+
# and parsing incoming webhooksB events into strongly typed objects.
|
|
9
|
+
class WebhooksBHandler
|
|
10
|
+
include CoreLibrary
|
|
11
|
+
# Creates a new instance of the WebhooksBHandler.
|
|
12
|
+
# Initializes the handler.
|
|
13
|
+
# @param [String] secret_key
|
|
14
|
+
# The secret used to generate and validate HMAC signatures for verifying request authenticity.
|
|
15
|
+
# @raise [ArgumentError] If the secret_key is not provided.
|
|
16
|
+
def initialize(secret_key)
|
|
17
|
+
raise ArgumentError, 'secret_key must be provided for signature verification.' unless secret_key
|
|
18
|
+
|
|
19
|
+
@verifier = HmacSignatureVerifier.new(
|
|
20
|
+
secret_key: secret_key,
|
|
21
|
+
signature_header: 'X-Webhook-Signature',
|
|
22
|
+
hash_algorithm: 'sha512',
|
|
23
|
+
encoder: Base64Encoder.new,
|
|
24
|
+
signature_value_template: 'v1={digest}',
|
|
25
|
+
canonical_message_builder: method(:_canonical_message_builder)
|
|
26
|
+
)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Perform signature verification and return the result.
|
|
30
|
+
#
|
|
31
|
+
# @param [Rack::Request] request The incoming HTTP request to verify.
|
|
32
|
+
# @return [SignatureVerificationResult] The result of the signature verification.
|
|
33
|
+
def verify(request)
|
|
34
|
+
@verifier.verify(request)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Verify the request signature and parse the event.
|
|
38
|
+
#
|
|
39
|
+
# @param [Rack::Request] request The incoming HTTP request containing the event payload.
|
|
40
|
+
# @return[UserActionNotificationEvent, UserStatusNotificationEvent,
|
|
41
|
+
# UserPreferenceNotificationEvent, SystemAlertNotificationEvent,
|
|
42
|
+
# SystemMaintenanceNotificationEvent, SystemPerformanceNotificationEvent,
|
|
43
|
+
# InventoryStockIncreaseEvent, InventoryStockDecreaseEvent,
|
|
44
|
+
# InventoryStockDepletedEvent, SignatureVerificationFailure, UnknownEvent]
|
|
45
|
+
# UserActionNotificationEvent, UserStatusNotificationEvent,
|
|
46
|
+
# UserPreferenceNotificationEvent, SystemAlertNotificationEvent,
|
|
47
|
+
# SystemMaintenanceNotificationEvent, SystemPerformanceNotificationEvent,
|
|
48
|
+
# InventoryStockIncreaseEvent, InventoryStockDecreaseEvent,
|
|
49
|
+
# InventoryStockDepletedEvent for successful parsing;
|
|
50
|
+
#
|
|
51
|
+
# SignatureVerificationFailure when signature fails;
|
|
52
|
+
# UnknownEvent for
|
|
53
|
+
# unknown events.
|
|
54
|
+
def verify_and_parse_event(request)
|
|
55
|
+
unless request.respond_to?(:env) && request.env.is_a?(Hash)
|
|
56
|
+
return SignatureVerificationFailure.new(['Invalid request env.'])
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
raw_body = RackRequestHelper.read_raw_body(request)
|
|
60
|
+
return SignatureVerificationFailure.new(['Invalid request body.']) if raw_body.nil? || raw_body.empty?
|
|
61
|
+
|
|
62
|
+
verification_result = verify(request)
|
|
63
|
+
return SignatureVerificationFailure.new(verification_result.errors) unless verification_result.ok
|
|
64
|
+
|
|
65
|
+
# Deserialize payload
|
|
66
|
+
begin
|
|
67
|
+
union = UnionTypeLookUp.get(:WebhooksB)
|
|
68
|
+
raw = RackRequestHelper.read_raw_body(request)
|
|
69
|
+
APIHelper.deserialize_union_type(union, raw, false, true)
|
|
70
|
+
rescue StandardError => e
|
|
71
|
+
UnknownEvent.new(['Deserialization failed.', e.message])
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Builds the canonical message from the request for the signature verification.
|
|
76
|
+
#
|
|
77
|
+
# @param [Rack::Request] request The incoming HTTP request.
|
|
78
|
+
# @return [String, nil] The canonical message as a string, or nil if it could not be constructed.
|
|
79
|
+
def _canonical_message_builder(request)
|
|
80
|
+
payload = RackRequestHelper.read_raw_body(request)
|
|
81
|
+
method = request.request_method
|
|
82
|
+
x_timestamp = request.get_header(RackRequestHelper.prepend_header('X-Timestamp'))
|
|
83
|
+
"#{method}|#{x_timestamp}|#{payload}"
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# webhooks_and_callbacks_api
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by
|
|
4
|
+
# APIMATIC v3.0 ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module WebhooksAndCallbacksApi
|
|
7
|
+
# WebhooksCHandler is responsible for verifying request signatures
|
|
8
|
+
# and parsing incoming webhooksC events into strongly typed objects.
|
|
9
|
+
class WebhooksCHandler
|
|
10
|
+
include CoreLibrary
|
|
11
|
+
# Creates a new instance of the WebhooksCHandler.
|
|
12
|
+
# Initializes the handler.
|
|
13
|
+
# @param [String] secret_key
|
|
14
|
+
# The secret used to generate and validate HMAC signatures for verifying request authenticity.
|
|
15
|
+
# @raise [ArgumentError] If the secret_key is not provided.
|
|
16
|
+
def initialize(secret_key)
|
|
17
|
+
raise ArgumentError, 'secret_key must be provided for signature verification.' unless secret_key
|
|
18
|
+
|
|
19
|
+
@verifier = HmacSignatureVerifier.new(
|
|
20
|
+
secret_key: secret_key,
|
|
21
|
+
signature_header: 'X-Webhook-Signature',
|
|
22
|
+
hash_algorithm: 'sha512',
|
|
23
|
+
encoder: Base64UrlEncoder.new,
|
|
24
|
+
signature_value_template: 'v1={digest}',
|
|
25
|
+
canonical_message_builder: method(:_canonical_message_builder)
|
|
26
|
+
)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Perform signature verification and return the result.
|
|
30
|
+
#
|
|
31
|
+
# @param [Rack::Request] request The incoming HTTP request to verify.
|
|
32
|
+
# @return [SignatureVerificationResult] The result of the signature verification.
|
|
33
|
+
def verify(request)
|
|
34
|
+
@verifier.verify(request)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Verify the request signature and parse the event.
|
|
38
|
+
#
|
|
39
|
+
# @param [Rack::Request] request The incoming HTTP request containing the event payload.
|
|
40
|
+
# @return[String, Integer, Array<Float>, Hash[String, String],
|
|
41
|
+
# SignatureVerificationFailure, UnknownEvent]
|
|
42
|
+
# String, Integer, Array[Float], Hash[String, String] for successful
|
|
43
|
+
# parsing;
|
|
44
|
+
# SignatureVerificationFailure when signature fails;
|
|
45
|
+
#
|
|
46
|
+
# UnknownEvent for unknown events.
|
|
47
|
+
def verify_and_parse_event(request)
|
|
48
|
+
unless request.respond_to?(:env) && request.env.is_a?(Hash)
|
|
49
|
+
return SignatureVerificationFailure.new(['Invalid request env.'])
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
raw_body = RackRequestHelper.read_raw_body(request)
|
|
53
|
+
return SignatureVerificationFailure.new(['Invalid request body.']) if raw_body.nil? || raw_body.empty?
|
|
54
|
+
|
|
55
|
+
verification_result = verify(request)
|
|
56
|
+
return SignatureVerificationFailure.new(verification_result.errors) unless verification_result.ok
|
|
57
|
+
|
|
58
|
+
# Deserialize payload
|
|
59
|
+
begin
|
|
60
|
+
union = UnionTypeLookUp.get(:WebhooksC)
|
|
61
|
+
raw = RackRequestHelper.read_raw_body(request)
|
|
62
|
+
APIHelper.deserialize_union_type(union, raw, false, true)
|
|
63
|
+
rescue StandardError => e
|
|
64
|
+
UnknownEvent.new(['Deserialization failed.', e.message])
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Builds the canonical message from the request for the signature verification.
|
|
69
|
+
#
|
|
70
|
+
# @param [Rack::Request] request The incoming HTTP request.
|
|
71
|
+
# @return [String, nil] The canonical message as a string, or nil if it could not be constructed.
|
|
72
|
+
def _canonical_message_builder(request)
|
|
73
|
+
payload = RackRequestHelper.read_raw_body(request)
|
|
74
|
+
method = request.request_method
|
|
75
|
+
x_timestamp = request.get_header(RackRequestHelper.prepend_header('X-Timestamp'))
|
|
76
|
+
"#{method}|#{x_timestamp}|#{payload}"
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# webhooks_and_callbacks_api
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by
|
|
4
|
+
# APIMATIC v3.0 ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module WebhooksAndCallbacksApi
|
|
7
|
+
# WebhooksHandler is responsible for verifying request signatures
|
|
8
|
+
# and parsing incoming webhooks events into strongly typed objects.
|
|
9
|
+
class WebhooksHandler
|
|
10
|
+
include CoreLibrary
|
|
11
|
+
# Creates a new instance of the WebhooksHandler.
|
|
12
|
+
# Initializes the handler.
|
|
13
|
+
# @param [String] secret_key
|
|
14
|
+
# The secret used to generate and validate HMAC signatures for verifying request authenticity.
|
|
15
|
+
# @raise [ArgumentError] If the secret_key is not provided.
|
|
16
|
+
def initialize(secret_key)
|
|
17
|
+
raise ArgumentError, 'secret_key must be provided for signature verification.' unless secret_key
|
|
18
|
+
|
|
19
|
+
@verifier = HmacSignatureVerifier.new(
|
|
20
|
+
secret_key: secret_key,
|
|
21
|
+
signature_header: 'X-Signature',
|
|
22
|
+
hash_algorithm: 'sha256',
|
|
23
|
+
encoder: HexEncoder.new
|
|
24
|
+
)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Perform signature verification and return the result.
|
|
28
|
+
#
|
|
29
|
+
# @param [Rack::Request] request The incoming HTTP request to verify.
|
|
30
|
+
# @return [SignatureVerificationResult] The result of the signature verification.
|
|
31
|
+
def verify(request)
|
|
32
|
+
@verifier.verify(request)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Verify the request signature and parse the event.
|
|
36
|
+
#
|
|
37
|
+
# @param [Rack::Request] request The incoming HTTP request containing the event payload.
|
|
38
|
+
# @return[OrderCreatedEvent, OrderUpdatedEvent, PaymentCompletedEvent,
|
|
39
|
+
# PrimitiveCollectionEvent, SignatureVerificationFailure, UnknownEvent]
|
|
40
|
+
# OrderCreatedEvent, OrderUpdatedEvent, PaymentCompletedEvent,
|
|
41
|
+
# PrimitiveCollectionEvent for successful parsing;
|
|
42
|
+
#
|
|
43
|
+
# SignatureVerificationFailure when signature fails;
|
|
44
|
+
# UnknownEvent for
|
|
45
|
+
# unknown events.
|
|
46
|
+
def verify_and_parse_event(request)
|
|
47
|
+
unless request.respond_to?(:env) && request.env.is_a?(Hash)
|
|
48
|
+
return SignatureVerificationFailure.new(['Invalid request env.'])
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
raw_body = RackRequestHelper.read_raw_body(request)
|
|
52
|
+
return SignatureVerificationFailure.new(['Invalid request body.']) if raw_body.nil? || raw_body.empty?
|
|
53
|
+
|
|
54
|
+
verification_result = verify(request)
|
|
55
|
+
return SignatureVerificationFailure.new(verification_result.errors) unless verification_result.ok
|
|
56
|
+
|
|
57
|
+
# Deserialize payload
|
|
58
|
+
begin
|
|
59
|
+
union = UnionTypeLookUp.get(:Webhooks)
|
|
60
|
+
raw = RackRequestHelper.read_raw_body(request)
|
|
61
|
+
APIHelper.deserialize_union_type(union, raw, false, true)
|
|
62
|
+
rescue StandardError => e
|
|
63
|
+
UnknownEvent.new(['Deserialization failed.', e.message])
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# webhooks_and_callbacks_api
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by
|
|
4
|
+
# APIMATIC v3.0 ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module WebhooksAndCallbacksApi
|
|
7
|
+
# WebhooksNoVerificationHandler is responsible for verifying request signatures
|
|
8
|
+
# and parsing incoming webhooksNoVerification events into strongly typed objects.
|
|
9
|
+
class WebhooksNoVerificationHandler
|
|
10
|
+
include CoreLibrary
|
|
11
|
+
# Creates a new instance of the WebhooksNoVerificationHandler.
|
|
12
|
+
def initialize; end
|
|
13
|
+
|
|
14
|
+
# Parse the event.
|
|
15
|
+
#
|
|
16
|
+
# @param [Rack::Request] request The incoming HTTP request containing the event payload.
|
|
17
|
+
# @return[AuditLogEvent, RootLevelPrimitiveOneOfEventRequest, Integer,
|
|
18
|
+
# Array<RootLevelPrimitiveOneOfEventRequest1>, Array<Integer>, UnknownEvent]
|
|
19
|
+
# AuditLogEvent, RootLevelPrimitiveOneOfEventRequest, Integer,
|
|
20
|
+
# Array[RootLevelPrimitiveOneOfEventRequest1], Array[Integer] for successful
|
|
21
|
+
# parsing;
|
|
22
|
+
# UnknownEvent for unknown events.
|
|
23
|
+
def parse_event(request)
|
|
24
|
+
return UnknownEvent.new(['Invalid request env.']) unless request.respond_to?(:env) && request.env.is_a?(Hash)
|
|
25
|
+
|
|
26
|
+
raw_body = RackRequestHelper.read_raw_body(request)
|
|
27
|
+
return UnknownEvent.new(['Invalid request body.']) if raw_body.nil? || raw_body.empty?
|
|
28
|
+
|
|
29
|
+
# Deserialize payload
|
|
30
|
+
begin
|
|
31
|
+
union = UnionTypeLookUp.get(:WebhooksNoVerification)
|
|
32
|
+
raw = RackRequestHelper.read_raw_body(request)
|
|
33
|
+
APIHelper.deserialize_union_type(union, raw, false, true)
|
|
34
|
+
rescue StandardError => e
|
|
35
|
+
UnknownEvent.new(['Deserialization failed.', e.message])
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
data/lib/{swagger_petstore_open_api30 → webhooks_and_callbacks_api}/exceptions/api_exception.rb
RENAMED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# webhooks_and_callbacks_api
|
|
2
2
|
#
|
|
3
3
|
# This file was automatically generated by
|
|
4
4
|
# APIMATIC v3.0 ( https://www.apimatic.io ).
|
|
5
5
|
|
|
6
|
-
module
|
|
6
|
+
module WebhooksAndCallbacksApi
|
|
7
7
|
# Class for exceptions when there is a network error, status code error, etc.
|
|
8
8
|
class APIException < CoreLibrary::ApiException
|
|
9
9
|
# Provides a human-readable string representation of the object.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# webhooks_and_callbacks_api
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by
|
|
4
|
+
# APIMATIC v3.0 ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module WebhooksAndCallbacksApi
|
|
7
|
+
# Error class.
|
|
8
|
+
class ErrorException < APIException
|
|
9
|
+
SKIP = Object.new
|
|
10
|
+
private_constant :SKIP
|
|
11
|
+
|
|
12
|
+
# Error code
|
|
13
|
+
# @return [String]
|
|
14
|
+
attr_accessor :error
|
|
15
|
+
|
|
16
|
+
# Human-readable error message
|
|
17
|
+
# @return [String]
|
|
18
|
+
attr_accessor :message
|
|
19
|
+
|
|
20
|
+
# Additional error details
|
|
21
|
+
# @return [Object]
|
|
22
|
+
attr_accessor :details
|
|
23
|
+
|
|
24
|
+
# The constructor.
|
|
25
|
+
# @param [String] reason The reason for raising an exception.
|
|
26
|
+
# @param [HttpResponse] response The HttpReponse of the API call.
|
|
27
|
+
def initialize(reason, response)
|
|
28
|
+
super(reason, response)
|
|
29
|
+
hash = APIHelper.json_deserialize(@response.raw_body)
|
|
30
|
+
unbox(hash)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Populates this object by extracting properties from a hash.
|
|
34
|
+
# @param [Hash] hash The deserialized response sent by the server in the
|
|
35
|
+
# response body.
|
|
36
|
+
def unbox(hash)
|
|
37
|
+
return nil unless hash
|
|
38
|
+
|
|
39
|
+
@error = hash.key?('error') ? hash['error'] : nil
|
|
40
|
+
@message = hash.key?('message') ? hash['message'] : nil
|
|
41
|
+
@details = hash.key?('details') ? hash['details'] : SKIP
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Provides a human-readable string representation of the object.
|
|
45
|
+
def to_s
|
|
46
|
+
class_name = self.class.name.split('::').last
|
|
47
|
+
"<#{class_name} error: #{@error}, message: #{@message}, details: #{@details}>"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Provides a debugging-friendly string with detailed object information.
|
|
51
|
+
def inspect
|
|
52
|
+
class_name = self.class.name.split('::').last
|
|
53
|
+
"<#{class_name} error: #{@error.inspect}, message: #{@message.inspect}, details:"\
|
|
54
|
+
" #{@details.inspect}>"
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# webhooks_and_callbacks_api
|
|
2
2
|
#
|
|
3
3
|
# This file was automatically generated by
|
|
4
4
|
# APIMATIC v3.0 ( https://www.apimatic.io ).
|
|
5
5
|
|
|
6
|
-
module
|
|
6
|
+
module WebhooksAndCallbacksApi
|
|
7
7
|
# Http response received.
|
|
8
8
|
class ApiResponse < CoreLibrary::ApiResponse
|
|
9
9
|
# The constructor
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
#
|
|
1
|
+
# webhooks_and_callbacks_api
|
|
2
2
|
#
|
|
3
3
|
# This file was automatically generated by
|
|
4
4
|
# APIMATIC v3.0 ( https://www.apimatic.io ).
|
|
5
5
|
|
|
6
|
-
module
|
|
6
|
+
module WebhooksAndCallbacksApi
|
|
7
7
|
# Utility class for custom header authorization.
|
|
8
8
|
class ApiKey < CoreLibrary::HeaderAuth
|
|
9
9
|
# Display error message on occurrence of authentication failure.
|
|
10
10
|
# @returns [String] The oAuth error message.
|
|
11
11
|
def error_message
|
|
12
|
-
'ApiKey:
|
|
12
|
+
'ApiKey: x_api_key is undefined.'
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
# Initialization constructor.
|
|
16
16
|
def initialize(api_key_credentials)
|
|
17
17
|
auth_params = {}
|
|
18
|
-
auth_params['
|
|
19
|
-
api_key_credentials.nil? || api_key_credentials.
|
|
18
|
+
auth_params['X-API-Key'] = api_key_credentials.x_api_key unless
|
|
19
|
+
api_key_credentials.nil? || api_key_credentials.x_api_key.nil?
|
|
20
20
|
|
|
21
21
|
super auth_params
|
|
22
22
|
end
|
|
@@ -25,28 +25,28 @@ module SwaggerPetstoreOpenApi30
|
|
|
25
25
|
# Data class for ApiKeyCredentials.
|
|
26
26
|
# Data class for ApiKeyCredentials.
|
|
27
27
|
class ApiKeyCredentials
|
|
28
|
-
attr_reader :
|
|
28
|
+
attr_reader :x_api_key
|
|
29
29
|
|
|
30
|
-
def initialize(
|
|
31
|
-
raise ArgumentError, '
|
|
30
|
+
def initialize(x_api_key:)
|
|
31
|
+
raise ArgumentError, 'x_api_key cannot be nil' if x_api_key.nil?
|
|
32
32
|
|
|
33
|
-
@
|
|
33
|
+
@x_api_key = x_api_key
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
def self.from_env
|
|
37
|
-
|
|
37
|
+
x_api_key = ENV['API_KEY_X_API_KEY']
|
|
38
38
|
all_nil = [
|
|
39
|
-
|
|
39
|
+
x_api_key
|
|
40
40
|
].all?(&:nil?)
|
|
41
41
|
return nil if all_nil
|
|
42
42
|
|
|
43
|
-
new(
|
|
43
|
+
new(x_api_key: x_api_key)
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
def clone_with(
|
|
47
|
-
|
|
46
|
+
def clone_with(x_api_key: nil)
|
|
47
|
+
x_api_key ||= self.x_api_key
|
|
48
48
|
|
|
49
|
-
ApiKeyCredentials.new(
|
|
49
|
+
ApiKeyCredentials.new(x_api_key: x_api_key)
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
52
|
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# webhooks_and_callbacks_api
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by
|
|
4
|
+
# APIMATIC v3.0 ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module WebhooksAndCallbacksApi
|
|
7
|
+
# Utility class for OAuth 2 authorization and token management.
|
|
8
|
+
class BearerAuth < CoreLibrary::HeaderAuth
|
|
9
|
+
include CoreLibrary
|
|
10
|
+
# Display error message on occurrence of authentication failure.
|
|
11
|
+
# @returns [String] The oAuth error message.
|
|
12
|
+
def error_message
|
|
13
|
+
'BearerAuth: access_token is undefined.'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Initialization constructor.
|
|
17
|
+
def initialize(bearer_auth_credentials)
|
|
18
|
+
auth_params = {}
|
|
19
|
+
@_access_token = bearer_auth_credentials.access_token unless
|
|
20
|
+
bearer_auth_credentials.nil? || bearer_auth_credentials.access_token.nil?
|
|
21
|
+
auth_params[:Authorization] = "Bearer #{@_access_token}" unless @_access_token.nil?
|
|
22
|
+
|
|
23
|
+
super auth_params
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Data class for BearerAuthCredentials.
|
|
28
|
+
class BearerAuthCredentials
|
|
29
|
+
attr_reader :access_token
|
|
30
|
+
|
|
31
|
+
def initialize(access_token:)
|
|
32
|
+
raise ArgumentError, 'access_token cannot be nil' if access_token.nil?
|
|
33
|
+
|
|
34
|
+
@access_token = access_token
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.from_env
|
|
38
|
+
access_token = ENV['BEARER_AUTH_ACCESS_TOKEN']
|
|
39
|
+
all_nil = [
|
|
40
|
+
access_token
|
|
41
|
+
].all?(&:nil?)
|
|
42
|
+
return nil if all_nil
|
|
43
|
+
|
|
44
|
+
new(access_token: access_token)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def clone_with(access_token: nil)
|
|
48
|
+
access_token ||= self.access_token
|
|
49
|
+
|
|
50
|
+
BearerAuthCredentials.new(access_token: access_token)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# webhooks_and_callbacks_api
|
|
2
2
|
#
|
|
3
3
|
# This file was automatically generated by
|
|
4
4
|
# APIMATIC v3.0 ( https://www.apimatic.io ).
|
|
5
5
|
|
|
6
|
-
module
|
|
6
|
+
module WebhooksAndCallbacksApi
|
|
7
7
|
# HttpCallBack allows defining callables for pre and post API calls.
|
|
8
8
|
class HttpCallBack < CoreLibrary::HttpCallback
|
|
9
9
|
end
|
data/lib/{swagger_petstore_open_api30 → webhooks_and_callbacks_api}/http/http_method_enum.rb
RENAMED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# webhooks_and_callbacks_api
|
|
2
2
|
#
|
|
3
3
|
# This file was automatically generated by
|
|
4
4
|
# APIMATIC v3.0 ( https://www.apimatic.io ).
|
|
5
5
|
|
|
6
|
-
module
|
|
6
|
+
module WebhooksAndCallbacksApi
|
|
7
7
|
# HTTP Methods Enumeration.
|
|
8
8
|
class HttpMethodEnum < CoreLibrary::HttpMethod
|
|
9
9
|
end
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# webhooks_and_callbacks_api
|
|
2
2
|
#
|
|
3
3
|
# This file was automatically generated by
|
|
4
4
|
# APIMATIC v3.0 ( https://www.apimatic.io ).
|
|
5
5
|
|
|
6
|
-
module
|
|
6
|
+
module WebhooksAndCallbacksApi
|
|
7
7
|
# Represents a single Http Request.
|
|
8
8
|
class HttpRequest < CoreLibrary::HttpRequest
|
|
9
9
|
end
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# webhooks_and_callbacks_api
|
|
2
2
|
#
|
|
3
3
|
# This file was automatically generated by
|
|
4
4
|
# APIMATIC v3.0 ( https://www.apimatic.io ).
|
|
5
5
|
|
|
6
|
-
module
|
|
6
|
+
module WebhooksAndCallbacksApi
|
|
7
7
|
# Http response received.
|
|
8
8
|
class HttpResponse < CoreLibrary::HttpResponse
|
|
9
9
|
end
|