hook0-client 2.0.0

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.
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hook0
4
+ # The one failure this client reports.
5
+ #
6
+ # Sending an event, upserting an event type and verifying a webhook all raise this, so a caller
7
+ # has one thing to rescue whatever it asked the client to do. The failures the *API* reports are a
8
+ # different matter: those are the problems it names in its own error contract, and the generated
9
+ # half of this gem raises one exception per problem.
10
+ #
11
+ # The constructors below are what the client raises through; each one exists so that the same
12
+ # situation always reads the same way, whichever call it came out of.
13
+ class ClientError < StandardError
14
+ # A send the API refused for a reason repeating it would not change.
15
+ #
16
+ # @param event_id [String]
17
+ # @param detail [String]
18
+ # @return [ClientError]
19
+ def self.event_sending(event_id, detail)
20
+ new("Sending event #{event_id} failed: #{detail}")
21
+ end
22
+
23
+ # A send that ran out of attempts, or out of the delay budget its attempts share.
24
+ #
25
+ # A send that gave up and a single refused request are otherwise indistinguishable to a caller,
26
+ # which is the difference between a transient outage and a request that will never be accepted.
27
+ #
28
+ # @param event_id [String]
29
+ # @param attempts [Integer]
30
+ # @param waited [Float] seconds spent waiting between the attempts
31
+ # @param detail [String]
32
+ # @return [ClientError]
33
+ def self.retries_exhausted(event_id, attempts, waited, detail)
34
+ new(
35
+ "Sending event #{event_id} failed: gave up after #{attempts} attempts " \
36
+ "spread over #{format("%.3f", waited)}s of retry delay; last failure: #{detail}"
37
+ )
38
+ end
39
+
40
+ # A payload above what the client agrees to send, refused before a socket is opened.
41
+ #
42
+ # @param event_id [String]
43
+ # @param size [Integer]
44
+ # @param maximum [Integer]
45
+ # @return [ClientError]
46
+ def self.payload_too_large(event_id, size, maximum)
47
+ new(
48
+ "Sending event #{event_id} failed: event payload is #{size} bytes, which is more than " \
49
+ "the #{maximum} bytes this client sends at most; nothing was sent"
50
+ )
51
+ end
52
+
53
+ # An event type that does not read as `service.resource_type.verb`.
54
+ #
55
+ # @param event_type [String]
56
+ # @return [ClientError]
57
+ def self.invalid_event_type(event_type)
58
+ new("Provided event type '#{event_type}' does not have a valid syntax (service.resource_type.verb)")
59
+ end
60
+
61
+ # The list of event types the application already declares could not be read.
62
+ #
63
+ # @param detail [String]
64
+ # @return [ClientError]
65
+ def self.available_event_types(detail)
66
+ new("Getting available event types failed: #{detail}")
67
+ end
68
+
69
+ # An event type that could not be created.
70
+ #
71
+ # @param event_type [String]
72
+ # @param detail [String]
73
+ # @return [ClientError]
74
+ def self.creating_event_type(event_type, detail)
75
+ new("Creating event type '#{event_type}' failed: #{detail}")
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,7 @@
1
+ # Generated by hook0-sdkgen from the OpenAPI snapshot the API crate commits.
2
+ # Do not edit by hand: run `UPDATE_SDK=ruby cargo test -p hook0-sdkgen sdk_targets` and commit the result.
3
+ # frozen_string_literal: true
4
+
5
+ require_relative "api"
6
+ require_relative "errors"
7
+ require_relative "models"