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,1097 @@
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 "../runtime"
6
+ require_relative "errors"
7
+ require_relative "models"
8
+
9
+ module Hook0
10
+ # One class per entity the API declares, one method per operation it groups under it.
11
+ module Generated
12
+ # What the API declares under `applicationSecrets`, issued through the transport it is handed.
13
+ class ApplicationSecretsApi
14
+ # @param transport [Object] what one request is issued through
15
+ def initialize(transport)
16
+ @transport = transport
17
+ end
18
+
19
+ # Create a new application secret
20
+ #
21
+ # @param body [ApplicationSecretPost] what the operation reads
22
+ # @return [ApplicationSecret]
23
+ def create(body)
24
+ read_answer(
25
+ @transport.request(
26
+ "POST",
27
+ "/api/v1/application_secrets/",
28
+ [],
29
+ body.to_h
30
+ ),
31
+ ApplicationSecret.method(:from_json)
32
+ )
33
+ end
34
+
35
+ # Delete an application secret
36
+ #
37
+ # @param application_secret_token [String] carries `application_secret_token`.
38
+ # @param application_id [String] carries `application_id`.
39
+ # @return [void]
40
+ def delete(application_secret_token, application_id)
41
+ check_answer(
42
+ @transport.request(
43
+ "DELETE",
44
+ Runtime.path(
45
+ "/api/v1/application_secrets/{application_secret_token}",
46
+ "application_secret_token" => application_secret_token
47
+ ),
48
+ Runtime.query(
49
+ [
50
+ ["application_id", application_id]
51
+ ],
52
+ []
53
+ ),
54
+ nil
55
+ )
56
+ )
57
+ end
58
+
59
+ # List application secrets
60
+ #
61
+ # @param application_id [String] carries `application_id`.
62
+ # @return [Array<ApplicationSecret>]
63
+ def read(application_id)
64
+ read_answer(
65
+ @transport.request(
66
+ "GET",
67
+ "/api/v1/application_secrets/",
68
+ Runtime.query(
69
+ [
70
+ ["application_id", application_id]
71
+ ],
72
+ []
73
+ ),
74
+ nil
75
+ ),
76
+ Runtime.list(ApplicationSecret.method(:from_json))
77
+ )
78
+ end
79
+
80
+ # Update an application secret
81
+ #
82
+ # @param application_secret_token [String] carries `application_secret_token`.
83
+ # @param body [ApplicationSecretPost] what the operation reads
84
+ # @return [ApplicationSecret]
85
+ def update(application_secret_token, body)
86
+ read_answer(
87
+ @transport.request(
88
+ "PUT",
89
+ Runtime.path(
90
+ "/api/v1/application_secrets/{application_secret_token}",
91
+ "application_secret_token" => application_secret_token
92
+ ),
93
+ [],
94
+ body.to_h
95
+ ),
96
+ ApplicationSecret.method(:from_json)
97
+ )
98
+ end
99
+
100
+ private
101
+
102
+ # Raise what the API reported, and answer nothing when it reported nothing.
103
+ #
104
+ # @param answered [Array] the status and the body the transport answered
105
+ # @return [void]
106
+ def check_answer(answered)
107
+ status, payload = answered
108
+ Generated.raise_for_status(status, payload)
109
+ nil
110
+ end
111
+
112
+ # Raise what the API reported, or read back the value it answered.
113
+ #
114
+ # @param answered [Array] the status and the body the transport answered
115
+ # @param reader [#call] what turns that body into the value the API declares
116
+ # @return [Object]
117
+ def read_answer(answered, reader)
118
+ status, payload = answered
119
+ Generated.raise_for_status(status, payload)
120
+ reader.call(Runtime.decode_payload(payload))
121
+ end
122
+ end
123
+
124
+ # What the API declares under `applications`, issued through the transport it is handed.
125
+ class ApplicationsApi
126
+ # @param transport [Object] what one request is issued through
127
+ def initialize(transport)
128
+ @transport = transport
129
+ end
130
+
131
+ # Create a new application
132
+ #
133
+ # @param body [ApplicationPost] what the operation reads
134
+ # @return [Application]
135
+ def create(body)
136
+ read_answer(
137
+ @transport.request(
138
+ "POST",
139
+ "/api/v1/applications/",
140
+ [],
141
+ body.to_h
142
+ ),
143
+ Application.method(:from_json)
144
+ )
145
+ end
146
+
147
+ # Delete an application
148
+ #
149
+ # @param application_id [String] carries `application_id`.
150
+ # @return [void]
151
+ def delete(application_id)
152
+ check_answer(
153
+ @transport.request(
154
+ "DELETE",
155
+ Runtime.path(
156
+ "/api/v1/applications/{application_id}",
157
+ "application_id" => application_id
158
+ ),
159
+ [],
160
+ nil
161
+ )
162
+ )
163
+ end
164
+
165
+ # Get an application by its ID
166
+ #
167
+ # @param application_id [String] carries `application_id`.
168
+ # @return [ApplicationInfo]
169
+ def get(application_id)
170
+ read_answer(
171
+ @transport.request(
172
+ "GET",
173
+ Runtime.path(
174
+ "/api/v1/applications/{application_id}",
175
+ "application_id" => application_id
176
+ ),
177
+ [],
178
+ nil
179
+ ),
180
+ ApplicationInfo.method(:from_json)
181
+ )
182
+ end
183
+
184
+ # List applications
185
+ #
186
+ # @param organization_id [String] carries `organization_id`.
187
+ # @return [Array<Application>]
188
+ def list(organization_id)
189
+ read_answer(
190
+ @transport.request(
191
+ "GET",
192
+ "/api/v1/applications/",
193
+ Runtime.query(
194
+ [
195
+ ["organization_id", organization_id]
196
+ ],
197
+ []
198
+ ),
199
+ nil
200
+ ),
201
+ Runtime.list(Application.method(:from_json))
202
+ )
203
+ end
204
+
205
+ # Edit an application
206
+ #
207
+ # @param application_id [String] carries `application_id`.
208
+ # @param body [ApplicationPost] what the operation reads
209
+ # @return [Application]
210
+ def update(application_id, body)
211
+ read_answer(
212
+ @transport.request(
213
+ "PUT",
214
+ Runtime.path(
215
+ "/api/v1/applications/{application_id}",
216
+ "application_id" => application_id
217
+ ),
218
+ [],
219
+ body.to_h
220
+ ),
221
+ Application.method(:from_json)
222
+ )
223
+ end
224
+
225
+ private
226
+
227
+ # Raise what the API reported, and answer nothing when it reported nothing.
228
+ #
229
+ # @param answered [Array] the status and the body the transport answered
230
+ # @return [void]
231
+ def check_answer(answered)
232
+ status, payload = answered
233
+ Generated.raise_for_status(status, payload)
234
+ nil
235
+ end
236
+
237
+ # Raise what the API reported, or read back the value it answered.
238
+ #
239
+ # @param answered [Array] the status and the body the transport answered
240
+ # @param reader [#call] what turns that body into the value the API declares
241
+ # @return [Object]
242
+ def read_answer(answered, reader)
243
+ status, payload = answered
244
+ Generated.raise_for_status(status, payload)
245
+ reader.call(Runtime.decode_payload(payload))
246
+ end
247
+ end
248
+
249
+ # What the API declares under `errors`, issued through the transport it is handed.
250
+ class ErrorsApi
251
+ # @param transport [Object] what one request is issued through
252
+ def initialize(transport)
253
+ @transport = transport
254
+ end
255
+
256
+ # List errors
257
+ #
258
+ # @return [Array<Problem>]
259
+ def list
260
+ read_answer(
261
+ @transport.request(
262
+ "GET",
263
+ "/api/v1/errors/",
264
+ [],
265
+ nil
266
+ ),
267
+ Runtime.list(Problem.method(:from_json))
268
+ )
269
+ end
270
+
271
+ private
272
+
273
+ # Raise what the API reported, or read back the value it answered.
274
+ #
275
+ # @param answered [Array] the status and the body the transport answered
276
+ # @param reader [#call] what turns that body into the value the API declares
277
+ # @return [Object]
278
+ def read_answer(answered, reader)
279
+ status, payload = answered
280
+ Generated.raise_for_status(status, payload)
281
+ reader.call(Runtime.decode_payload(payload))
282
+ end
283
+ end
284
+
285
+ # What the API declares under `eventTypes`, issued through the transport it is handed.
286
+ class EventTypesApi
287
+ # @param transport [Object] what one request is issued through
288
+ def initialize(transport)
289
+ @transport = transport
290
+ end
291
+
292
+ # Create a new event type
293
+ #
294
+ # @param body [EventTypePost] what the operation reads
295
+ # @return [EventType]
296
+ def create(body)
297
+ read_answer(
298
+ @transport.request(
299
+ "POST",
300
+ "/api/v1/event_types/",
301
+ [],
302
+ body.to_h
303
+ ),
304
+ EventType.method(:from_json)
305
+ )
306
+ end
307
+
308
+ # Delete an event type
309
+ #
310
+ # @param event_type_name [String] carries `event_type_name`.
311
+ # @param application_id [String] carries `application_id`.
312
+ # @return [void]
313
+ def delete(event_type_name, application_id)
314
+ check_answer(
315
+ @transport.request(
316
+ "DELETE",
317
+ Runtime.path(
318
+ "/api/v1/event_types/{event_type_name}",
319
+ "event_type_name" => event_type_name
320
+ ),
321
+ Runtime.query(
322
+ [
323
+ ["application_id", application_id]
324
+ ],
325
+ []
326
+ ),
327
+ nil
328
+ )
329
+ )
330
+ end
331
+
332
+ # Get an event type by its name
333
+ #
334
+ # @param event_type_name [String] carries `event_type_name`.
335
+ # @param application_id [String] carries `application_id`.
336
+ # @return [EventType]
337
+ def get(event_type_name, application_id)
338
+ read_answer(
339
+ @transport.request(
340
+ "GET",
341
+ Runtime.path(
342
+ "/api/v1/event_types/{event_type_name}",
343
+ "event_type_name" => event_type_name
344
+ ),
345
+ Runtime.query(
346
+ [
347
+ ["application_id", application_id]
348
+ ],
349
+ []
350
+ ),
351
+ nil
352
+ ),
353
+ EventType.method(:from_json)
354
+ )
355
+ end
356
+
357
+ # List event types
358
+ #
359
+ # @param application_id [String] carries `application_id`.
360
+ # @return [Array<EventType>]
361
+ def list(application_id)
362
+ read_answer(
363
+ @transport.request(
364
+ "GET",
365
+ "/api/v1/event_types/",
366
+ Runtime.query(
367
+ [
368
+ ["application_id", application_id]
369
+ ],
370
+ []
371
+ ),
372
+ nil
373
+ ),
374
+ Runtime.list(EventType.method(:from_json))
375
+ )
376
+ end
377
+
378
+ private
379
+
380
+ # Raise what the API reported, and answer nothing when it reported nothing.
381
+ #
382
+ # @param answered [Array] the status and the body the transport answered
383
+ # @return [void]
384
+ def check_answer(answered)
385
+ status, payload = answered
386
+ Generated.raise_for_status(status, payload)
387
+ nil
388
+ end
389
+
390
+ # Raise what the API reported, or read back the value it answered.
391
+ #
392
+ # @param answered [Array] the status and the body the transport answered
393
+ # @param reader [#call] what turns that body into the value the API declares
394
+ # @return [Object]
395
+ def read_answer(answered, reader)
396
+ status, payload = answered
397
+ Generated.raise_for_status(status, payload)
398
+ reader.call(Runtime.decode_payload(payload))
399
+ end
400
+ end
401
+
402
+ # What the API declares under `events`, issued through the transport it is handed.
403
+ class EventsApi
404
+ # @param transport [Object] what one request is issued through
405
+ def initialize(transport)
406
+ @transport = transport
407
+ end
408
+
409
+ # Get an event by its ID
410
+ #
411
+ # @param event_id [String] carries `event_id`.
412
+ # @param application_id [String] carries `application_id`.
413
+ # @return [EventWithPayload]
414
+ def get(event_id, application_id)
415
+ read_answer(
416
+ @transport.request(
417
+ "GET",
418
+ Runtime.path(
419
+ "/api/v1/events/{event_id}",
420
+ "event_id" => event_id
421
+ ),
422
+ Runtime.query(
423
+ [
424
+ ["application_id", application_id]
425
+ ],
426
+ []
427
+ ),
428
+ nil
429
+ ),
430
+ EventWithPayload.method(:from_json)
431
+ )
432
+ end
433
+
434
+ # Ingest an event
435
+ #
436
+ # @param body [EventPost] what the operation reads
437
+ # @return [IngestedEvent]
438
+ def ingest(body)
439
+ read_answer(
440
+ @transport.request(
441
+ "POST",
442
+ "/api/v1/event/",
443
+ [],
444
+ body.to_h
445
+ ),
446
+ IngestedEvent.method(:from_json)
447
+ )
448
+ end
449
+
450
+ # List latest events
451
+ #
452
+ # @param application_id [String] carries `application_id`.
453
+ # @return [Array<Event>]
454
+ def list(application_id)
455
+ read_answer(
456
+ @transport.request(
457
+ "GET",
458
+ "/api/v1/events/",
459
+ Runtime.query(
460
+ [
461
+ ["application_id", application_id]
462
+ ],
463
+ []
464
+ ),
465
+ nil
466
+ ),
467
+ Runtime.list(Event.method(:from_json))
468
+ )
469
+ end
470
+
471
+ # Replay an event
472
+ #
473
+ # @param event_id [String] carries `event_id`.
474
+ # @param body [ReplayEvent] what the operation reads
475
+ # @return [void]
476
+ def replay(event_id, body)
477
+ check_answer(
478
+ @transport.request(
479
+ "POST",
480
+ Runtime.path(
481
+ "/api/v1/events/{event_id}/replay",
482
+ "event_id" => event_id
483
+ ),
484
+ [],
485
+ body.to_h
486
+ )
487
+ )
488
+ end
489
+
490
+ private
491
+
492
+ # Raise what the API reported, and answer nothing when it reported nothing.
493
+ #
494
+ # @param answered [Array] the status and the body the transport answered
495
+ # @return [void]
496
+ def check_answer(answered)
497
+ status, payload = answered
498
+ Generated.raise_for_status(status, payload)
499
+ nil
500
+ end
501
+
502
+ # Raise what the API reported, or read back the value it answered.
503
+ #
504
+ # @param answered [Array] the status and the body the transport answered
505
+ # @param reader [#call] what turns that body into the value the API declares
506
+ # @return [Object]
507
+ def read_answer(answered, reader)
508
+ status, payload = answered
509
+ Generated.raise_for_status(status, payload)
510
+ reader.call(Runtime.decode_payload(payload))
511
+ end
512
+ end
513
+
514
+ # What the API declares under `events_per_day`, issued through the transport it is handed.
515
+ class EventsPerDayApi
516
+ # @param transport [Object] what one request is issued through
517
+ def initialize(transport)
518
+ @transport = transport
519
+ end
520
+
521
+ # List events per day for an application
522
+ #
523
+ # @param application_id [String] carries `application_id`.
524
+ # @param from [String, nil] carries `from`: Start of date range (inclusive). Defaults to 30 days before `to`.
525
+ # @param to [String, nil] carries `to`: End of date range (inclusive). Defaults to today.
526
+ # @return [Array<EventsPerDayEntry>]
527
+ def list_for_application(application_id, from: nil, to: nil)
528
+ read_answer(
529
+ @transport.request(
530
+ "GET",
531
+ "/api/v1/events_per_day/application",
532
+ Runtime.query(
533
+ [
534
+ ["application_id", application_id]
535
+ ],
536
+ [
537
+ ["from", from],
538
+ ["to", to]
539
+ ]
540
+ ),
541
+ nil
542
+ ),
543
+ Runtime.list(EventsPerDayEntry.method(:from_json))
544
+ )
545
+ end
546
+
547
+ # List events per day for an organization
548
+ #
549
+ # @param organization_id [String] carries `organization_id`.
550
+ # @param from [String, nil] carries `from`: Start of date range (inclusive). Defaults to 30 days before `to`.
551
+ # @param to [String, nil] carries `to`: End of date range (inclusive). Defaults to today.
552
+ # @return [Array<EventsPerDayEntry>]
553
+ def list_for_organization(organization_id, from: nil, to: nil)
554
+ read_answer(
555
+ @transport.request(
556
+ "GET",
557
+ "/api/v1/events_per_day/organization",
558
+ Runtime.query(
559
+ [
560
+ ["organization_id", organization_id]
561
+ ],
562
+ [
563
+ ["from", from],
564
+ ["to", to]
565
+ ]
566
+ ),
567
+ nil
568
+ ),
569
+ Runtime.list(EventsPerDayEntry.method(:from_json))
570
+ )
571
+ end
572
+
573
+ private
574
+
575
+ # Raise what the API reported, or read back the value it answered.
576
+ #
577
+ # @param answered [Array] the status and the body the transport answered
578
+ # @param reader [#call] what turns that body into the value the API declares
579
+ # @return [Object]
580
+ def read_answer(answered, reader)
581
+ status, payload = answered
582
+ Generated.raise_for_status(status, payload)
583
+ reader.call(Runtime.decode_payload(payload))
584
+ end
585
+ end
586
+
587
+ # What the API declares under `instance`, issued through the transport it is handed.
588
+ class InstanceApi
589
+ # @param transport [Object] what one request is issued through
590
+ def initialize(transport)
591
+ @transport = transport
592
+ end
593
+
594
+ # Get instance configuration
595
+ #
596
+ # @return [InstanceConfig]
597
+ def get
598
+ read_answer(
599
+ @transport.request(
600
+ "GET",
601
+ "/api/v1/instance/",
602
+ [],
603
+ nil
604
+ ),
605
+ InstanceConfig.method(:from_json)
606
+ )
607
+ end
608
+
609
+ private
610
+
611
+ # Raise what the API reported, or read back the value it answered.
612
+ #
613
+ # @param answered [Array] the status and the body the transport answered
614
+ # @param reader [#call] what turns that body into the value the API declares
615
+ # @return [Object]
616
+ def read_answer(answered, reader)
617
+ status, payload = answered
618
+ Generated.raise_for_status(status, payload)
619
+ reader.call(Runtime.decode_payload(payload))
620
+ end
621
+ end
622
+
623
+ # What the API declares under `payload_content_types`, issued through the transport it is handed.
624
+ class PayloadContentTypesApi
625
+ # @param transport [Object] what one request is issued through
626
+ def initialize(transport)
627
+ @transport = transport
628
+ end
629
+
630
+ # List supported event payload content types
631
+ #
632
+ # @return [Array<String>]
633
+ def list
634
+ read_answer(
635
+ @transport.request(
636
+ "GET",
637
+ "/api/v1/payload_content_types/",
638
+ [],
639
+ nil
640
+ ),
641
+ Runtime.list(Runtime::TEXT)
642
+ )
643
+ end
644
+
645
+ private
646
+
647
+ # Raise what the API reported, or read back the value it answered.
648
+ #
649
+ # @param answered [Array] the status and the body the transport answered
650
+ # @param reader [#call] what turns that body into the value the API declares
651
+ # @return [Object]
652
+ def read_answer(answered, reader)
653
+ status, payload = answered
654
+ Generated.raise_for_status(status, payload)
655
+ reader.call(Runtime.decode_payload(payload))
656
+ end
657
+ end
658
+
659
+ # What the API declares under `quotas`, issued through the transport it is handed.
660
+ class QuotasApi
661
+ # @param transport [Object] what one request is issued through
662
+ def initialize(transport)
663
+ @transport = transport
664
+ end
665
+
666
+ # Get quotas
667
+ #
668
+ # @return [QuotasResponse]
669
+ def get
670
+ read_answer(
671
+ @transport.request(
672
+ "GET",
673
+ "/api/v1/quotas/",
674
+ [],
675
+ nil
676
+ ),
677
+ QuotasResponse.method(:from_json)
678
+ )
679
+ end
680
+
681
+ private
682
+
683
+ # Raise what the API reported, or read back the value it answered.
684
+ #
685
+ # @param answered [Array] the status and the body the transport answered
686
+ # @param reader [#call] what turns that body into the value the API declares
687
+ # @return [Object]
688
+ def read_answer(answered, reader)
689
+ status, payload = answered
690
+ Generated.raise_for_status(status, payload)
691
+ reader.call(Runtime.decode_payload(payload))
692
+ end
693
+ end
694
+
695
+ # What the API declares under `requestAttempts`, issued through the transport it is handed.
696
+ class RequestAttemptsApi
697
+ # @param transport [Object] what one request is issued through
698
+ def initialize(transport)
699
+ @transport = transport
700
+ end
701
+
702
+ # Get a request attempt by its ID
703
+ #
704
+ # @param request_attempt_id [String] carries `request_attempt_id`.
705
+ # @param application_id [String] carries `application_id`.
706
+ # @return [RequestAttempt]
707
+ def get(request_attempt_id, application_id)
708
+ read_answer(
709
+ @transport.request(
710
+ "GET",
711
+ Runtime.path(
712
+ "/api/v1/request_attempts/{request_attempt_id}",
713
+ "request_attempt_id" => request_attempt_id
714
+ ),
715
+ Runtime.query(
716
+ [
717
+ ["application_id", application_id]
718
+ ],
719
+ []
720
+ ),
721
+ nil
722
+ ),
723
+ RequestAttempt.method(:from_json)
724
+ )
725
+ end
726
+
727
+ # List request attempts
728
+ #
729
+ # @param application_id [String] carries `application_id`.
730
+ # @param event_event_type_names [String, nil] carries `event.event_type_names`: Comma-separated event types
731
+ # @param event_id [String, nil] carries `event_id`.
732
+ # @param max_created_at [String, nil] carries `max_created_at`.
733
+ # @param min_created_at [String, nil] carries `min_created_at`.
734
+ # @param pagination_cursor [String, nil] carries `pagination_cursor`.
735
+ # @param subscription_id [String, nil] carries `subscription_id`.
736
+ # @return [Array<RequestAttempt>]
737
+ def read(
738
+ application_id,
739
+ event_event_type_names: nil,
740
+ event_id: nil,
741
+ max_created_at: nil,
742
+ min_created_at: nil,
743
+ pagination_cursor: nil,
744
+ subscription_id: nil
745
+ )
746
+ read_answer(
747
+ @transport.request(
748
+ "GET",
749
+ "/api/v1/request_attempts/",
750
+ Runtime.query(
751
+ [
752
+ ["application_id", application_id]
753
+ ],
754
+ [
755
+ ["event.event_type_names", event_event_type_names],
756
+ ["event_id", event_id],
757
+ ["max_created_at", max_created_at],
758
+ ["min_created_at", min_created_at],
759
+ ["pagination_cursor", pagination_cursor],
760
+ ["subscription_id", subscription_id]
761
+ ]
762
+ ),
763
+ nil
764
+ ),
765
+ Runtime.list(RequestAttempt.method(:from_json))
766
+ )
767
+ end
768
+
769
+ private
770
+
771
+ # Raise what the API reported, or read back the value it answered.
772
+ #
773
+ # @param answered [Array] the status and the body the transport answered
774
+ # @param reader [#call] what turns that body into the value the API declares
775
+ # @return [Object]
776
+ def read_answer(answered, reader)
777
+ status, payload = answered
778
+ Generated.raise_for_status(status, payload)
779
+ reader.call(Runtime.decode_payload(payload))
780
+ end
781
+ end
782
+
783
+ # What the API declares under `response`, issued through the transport it is handed.
784
+ class ResponseApi
785
+ # @param transport [Object] what one request is issued through
786
+ def initialize(transport)
787
+ @transport = transport
788
+ end
789
+
790
+ # Get a response by its ID
791
+ #
792
+ # @param response_id [String] carries `response_id`.
793
+ # @param application_id [String] carries `application_id`.
794
+ # @return [Response]
795
+ def get(response_id, application_id)
796
+ read_answer(
797
+ @transport.request(
798
+ "GET",
799
+ Runtime.path(
800
+ "/api/v1/responses/{response_id}",
801
+ "response_id" => response_id
802
+ ),
803
+ Runtime.query(
804
+ [
805
+ ["application_id", application_id]
806
+ ],
807
+ []
808
+ ),
809
+ nil
810
+ ),
811
+ Response.method(:from_json)
812
+ )
813
+ end
814
+
815
+ private
816
+
817
+ # Raise what the API reported, or read back the value it answered.
818
+ #
819
+ # @param answered [Array] the status and the body the transport answered
820
+ # @param reader [#call] what turns that body into the value the API declares
821
+ # @return [Object]
822
+ def read_answer(answered, reader)
823
+ status, payload = answered
824
+ Generated.raise_for_status(status, payload)
825
+ reader.call(Runtime.decode_payload(payload))
826
+ end
827
+ end
828
+
829
+ # What the API declares under `serviceToken`, issued through the transport it is handed.
830
+ class ServiceTokenApi
831
+ # @param transport [Object] what one request is issued through
832
+ def initialize(transport)
833
+ @transport = transport
834
+ end
835
+
836
+ # Create a new service token
837
+ #
838
+ # @param body [ServiceTokenPost] what the operation reads
839
+ # @return [ServiceToken]
840
+ def create(body)
841
+ read_answer(
842
+ @transport.request(
843
+ "POST",
844
+ "/api/v1/service_token/",
845
+ [],
846
+ body.to_h
847
+ ),
848
+ ServiceToken.method(:from_json)
849
+ )
850
+ end
851
+
852
+ # Delete a service token
853
+ #
854
+ # @param service_token_id [String] carries `service_token_id`.
855
+ # @param organization_id [String] carries `organization_id`.
856
+ # @return [void]
857
+ def delete(service_token_id, organization_id)
858
+ check_answer(
859
+ @transport.request(
860
+ "DELETE",
861
+ Runtime.path(
862
+ "/api/v1/service_token/{service_token_id}",
863
+ "service_token_id" => service_token_id
864
+ ),
865
+ Runtime.query(
866
+ [
867
+ ["organization_id", organization_id]
868
+ ],
869
+ []
870
+ ),
871
+ nil
872
+ )
873
+ )
874
+ end
875
+
876
+ # Edit a service token
877
+ #
878
+ # @param service_token_id [String] carries `service_token_id`.
879
+ # @param body [ServiceTokenPost] what the operation reads
880
+ # @return [ServiceToken]
881
+ def edit(service_token_id, body)
882
+ read_answer(
883
+ @transport.request(
884
+ "PUT",
885
+ Runtime.path(
886
+ "/api/v1/service_token/{service_token_id}",
887
+ "service_token_id" => service_token_id
888
+ ),
889
+ [],
890
+ body.to_h
891
+ ),
892
+ ServiceToken.method(:from_json)
893
+ )
894
+ end
895
+
896
+ # Get a service token
897
+ #
898
+ # @param service_token_id [String] carries `service_token_id`.
899
+ # @param organization_id [String] carries `organization_id`.
900
+ # @return [ServiceToken]
901
+ def get(service_token_id, organization_id)
902
+ read_answer(
903
+ @transport.request(
904
+ "GET",
905
+ Runtime.path(
906
+ "/api/v1/service_token/{service_token_id}",
907
+ "service_token_id" => service_token_id
908
+ ),
909
+ Runtime.query(
910
+ [
911
+ ["organization_id", organization_id]
912
+ ],
913
+ []
914
+ ),
915
+ nil
916
+ ),
917
+ ServiceToken.method(:from_json)
918
+ )
919
+ end
920
+
921
+ # List service tokens
922
+ #
923
+ # @param organization_id [String] carries `organization_id`.
924
+ # @return [Array<ServiceToken>]
925
+ def list(organization_id)
926
+ read_answer(
927
+ @transport.request(
928
+ "GET",
929
+ "/api/v1/service_token/",
930
+ Runtime.query(
931
+ [
932
+ ["organization_id", organization_id]
933
+ ],
934
+ []
935
+ ),
936
+ nil
937
+ ),
938
+ Runtime.list(ServiceToken.method(:from_json))
939
+ )
940
+ end
941
+
942
+ private
943
+
944
+ # Raise what the API reported, and answer nothing when it reported nothing.
945
+ #
946
+ # @param answered [Array] the status and the body the transport answered
947
+ # @return [void]
948
+ def check_answer(answered)
949
+ status, payload = answered
950
+ Generated.raise_for_status(status, payload)
951
+ nil
952
+ end
953
+
954
+ # Raise what the API reported, or read back the value it answered.
955
+ #
956
+ # @param answered [Array] the status and the body the transport answered
957
+ # @param reader [#call] what turns that body into the value the API declares
958
+ # @return [Object]
959
+ def read_answer(answered, reader)
960
+ status, payload = answered
961
+ Generated.raise_for_status(status, payload)
962
+ reader.call(Runtime.decode_payload(payload))
963
+ end
964
+ end
965
+
966
+ # What the API declares under `subscriptions`, issued through the transport it is handed.
967
+ class SubscriptionsApi
968
+ # @param transport [Object] what one request is issued through
969
+ def initialize(transport)
970
+ @transport = transport
971
+ end
972
+
973
+ # Create a new subscription
974
+ #
975
+ # @param body [SubscriptionPost] what the operation reads
976
+ # @return [Subscription]
977
+ def create(body)
978
+ read_answer(
979
+ @transport.request(
980
+ "POST",
981
+ "/api/v1/subscriptions/",
982
+ [],
983
+ body.to_h
984
+ ),
985
+ Subscription.method(:from_json)
986
+ )
987
+ end
988
+
989
+ # Delete a subscription
990
+ #
991
+ # @param subscription_id [String] carries `subscription_id`.
992
+ # @param application_id [String] carries `application_id`.
993
+ # @return [void]
994
+ def delete(subscription_id, application_id)
995
+ check_answer(
996
+ @transport.request(
997
+ "DELETE",
998
+ Runtime.path(
999
+ "/api/v1/subscriptions/{subscription_id}",
1000
+ "subscription_id" => subscription_id
1001
+ ),
1002
+ Runtime.query(
1003
+ [
1004
+ ["application_id", application_id]
1005
+ ],
1006
+ []
1007
+ ),
1008
+ nil
1009
+ )
1010
+ )
1011
+ end
1012
+
1013
+ # Get a subscription by its ID
1014
+ #
1015
+ # @param subscription_id [String] carries `subscription_id`.
1016
+ # @return [Subscription]
1017
+ def get(subscription_id)
1018
+ read_answer(
1019
+ @transport.request(
1020
+ "GET",
1021
+ Runtime.path(
1022
+ "/api/v1/subscriptions/{subscription_id}",
1023
+ "subscription_id" => subscription_id
1024
+ ),
1025
+ [],
1026
+ nil
1027
+ ),
1028
+ Subscription.method(:from_json)
1029
+ )
1030
+ end
1031
+
1032
+ # List subscriptions
1033
+ #
1034
+ # @param application_id [String] carries `application_id`.
1035
+ # @return [Array<Subscription>]
1036
+ def list(application_id)
1037
+ read_answer(
1038
+ @transport.request(
1039
+ "GET",
1040
+ "/api/v1/subscriptions/",
1041
+ Runtime.query(
1042
+ [
1043
+ ["application_id", application_id]
1044
+ ],
1045
+ []
1046
+ ),
1047
+ nil
1048
+ ),
1049
+ Runtime.list(Subscription.method(:from_json))
1050
+ )
1051
+ end
1052
+
1053
+ # Update a subscription
1054
+ #
1055
+ # @param subscription_id [String] carries `subscription_id`.
1056
+ # @param body [SubscriptionPost] what the operation reads
1057
+ # @return [Subscription]
1058
+ def update(subscription_id, body)
1059
+ read_answer(
1060
+ @transport.request(
1061
+ "PUT",
1062
+ Runtime.path(
1063
+ "/api/v1/subscriptions/{subscription_id}",
1064
+ "subscription_id" => subscription_id
1065
+ ),
1066
+ [],
1067
+ body.to_h
1068
+ ),
1069
+ Subscription.method(:from_json)
1070
+ )
1071
+ end
1072
+
1073
+ private
1074
+
1075
+ # Raise what the API reported, and answer nothing when it reported nothing.
1076
+ #
1077
+ # @param answered [Array] the status and the body the transport answered
1078
+ # @return [void]
1079
+ def check_answer(answered)
1080
+ status, payload = answered
1081
+ Generated.raise_for_status(status, payload)
1082
+ nil
1083
+ end
1084
+
1085
+ # Raise what the API reported, or read back the value it answered.
1086
+ #
1087
+ # @param answered [Array] the status and the body the transport answered
1088
+ # @param reader [#call] what turns that body into the value the API declares
1089
+ # @return [Object]
1090
+ def read_answer(answered, reader)
1091
+ status, payload = answered
1092
+ Generated.raise_for_status(status, payload)
1093
+ reader.call(Runtime.decode_payload(payload))
1094
+ end
1095
+ end
1096
+ end
1097
+ end