speakeasy_client_sdk_ruby 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/lib/sdk/apiendpoints.rb +338 -0
  3. data/lib/sdk/apis.rb +264 -0
  4. data/lib/sdk/embeds.rb +128 -0
  5. data/lib/sdk/metadata.rb +144 -0
  6. data/lib/sdk/models/operations/deleteapi.rb +52 -0
  7. data/lib/sdk/models/operations/deleteapiendpoint.rb +55 -0
  8. data/lib/sdk/models/operations/deleteschema.rb +55 -0
  9. data/lib/sdk/models/operations/deleteversionmetadata.rb +58 -0
  10. data/lib/sdk/models/operations/downloadschema.rb +55 -0
  11. data/lib/sdk/models/operations/downloadschemarevision.rb +58 -0
  12. data/lib/sdk/models/operations/findapiendpoint.rb +59 -0
  13. data/lib/sdk/models/operations/generateopenapispec.rb +56 -0
  14. data/lib/sdk/models/operations/generateopenapispecforapiendpoint.rb +59 -0
  15. data/lib/sdk/models/operations/generatepostmancollection.rb +55 -0
  16. data/lib/sdk/models/operations/generatepostmancollectionforapiendpoint.rb +58 -0
  17. data/lib/sdk/models/operations/generaterequestpostmancollection.rb +52 -0
  18. data/lib/sdk/models/operations/getallapiendpoints.rb +52 -0
  19. data/lib/sdk/models/operations/getallapiversions.rb +72 -0
  20. data/lib/sdk/models/operations/getallforversionapiendpoints.rb +55 -0
  21. data/lib/sdk/models/operations/getapiendpoint.rb +59 -0
  22. data/lib/sdk/models/operations/getapis.rb +69 -0
  23. data/lib/sdk/models/operations/getembedaccesstoken.rb +60 -0
  24. data/lib/sdk/models/operations/getplugins.rb +38 -0
  25. data/lib/sdk/models/operations/getrequestfromeventlog.rb +53 -0
  26. data/lib/sdk/models/operations/getschema.rb +56 -0
  27. data/lib/sdk/models/operations/getschemadiff.rb +62 -0
  28. data/lib/sdk/models/operations/getschemarevision.rb +59 -0
  29. data/lib/sdk/models/operations/getschemas.rb +55 -0
  30. data/lib/sdk/models/operations/getvalidembedaccesstokens.rb +38 -0
  31. data/lib/sdk/models/operations/getversionmetadata.rb +55 -0
  32. data/lib/sdk/models/operations/insertversionmetadata.rb +60 -0
  33. data/lib/sdk/models/operations/queryeventlog.rb +53 -0
  34. data/lib/sdk/models/operations/registerschema.rb +86 -0
  35. data/lib/sdk/models/operations/revokeembedaccesstoken.rb +49 -0
  36. data/lib/sdk/models/operations/runplugin.rb +56 -0
  37. data/lib/sdk/models/operations/upsertapi.rb +57 -0
  38. data/lib/sdk/models/operations/upsertapiendpoint.rb +63 -0
  39. data/lib/sdk/models/operations/upsertplugin.rb +39 -0
  40. data/lib/sdk/models/operations/validateapikey.rb +35 -0
  41. data/lib/sdk/models/shared/api.rb +69 -0
  42. data/lib/sdk/models/shared/apiendpoint.rb +84 -0
  43. data/lib/sdk/models/shared/boundedrequest.rb +64 -0
  44. data/lib/sdk/models/shared/embedaccesstokenresponse.rb +25 -0
  45. data/lib/sdk/models/shared/embedtoken.rb +52 -0
  46. data/lib/sdk/models/shared/error.rb +28 -0
  47. data/lib/sdk/models/shared/filter.rb +31 -0
  48. data/lib/sdk/models/shared/filters.rb +34 -0
  49. data/lib/sdk/models/shared/generateopenapispecdiff.rb +28 -0
  50. data/lib/sdk/models/shared/plugin.rb +43 -0
  51. data/lib/sdk/models/shared/requestmetadata.rb +28 -0
  52. data/lib/sdk/models/shared/schema.rb +40 -0
  53. data/lib/sdk/models/shared/schemadiff.rb +48 -0
  54. data/lib/sdk/models/shared/security.rb +25 -0
  55. data/lib/sdk/models/shared/unboundedrequest.rb +37 -0
  56. data/lib/sdk/models/shared/versionmetadata.rb +57 -0
  57. data/lib/sdk/plugins.rb +140 -0
  58. data/lib/sdk/requests.rb +136 -0
  59. data/lib/sdk/schemas.rb +334 -0
  60. data/lib/sdk/sdk.rb +173 -0
  61. data/lib/sdk/utils/metadata_fields.rb +154 -0
  62. data/lib/sdk/utils/retries.rb +130 -0
  63. data/lib/sdk/utils/utils.rb +769 -0
  64. data/lib/speakeasy_client_sdk_ruby.rb +70 -0
  65. metadata +206 -0
@@ -0,0 +1,130 @@
1
+ # Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
2
+
3
+ # typed: true
4
+ # frozen_string_literal: true
5
+
6
+ require 'sorbet-runtime'
7
+
8
+ module SpeakeasyClientSDK
9
+ class BackoffStrategy
10
+ extend T::Sig
11
+
12
+ attr_accessor :initial_interval, :max_interval, :exponent, :max_elapsed_time
13
+
14
+ sig { params(initial_interval: Integer, max_interval: Integer, exponent: Float, max_elapsed_time: Integer).void }
15
+ def initialize(initial_interval, max_interval, exponent, max_elapsed_time)
16
+ @initial_interval = initial_interval
17
+ @max_interval = max_interval
18
+ @exponent = exponent
19
+ @max_elapsed_time = max_elapsed_time
20
+ end
21
+ end
22
+
23
+ class RetryConfig
24
+ extend T::Sig
25
+
26
+ attr_accessor :strategy, :backoff, :retry_connection_errors
27
+
28
+ sig { params(strategy: String, retry_connection_errors: bool).void }
29
+ def initialize(strategy, retry_connection_errors)
30
+ @strategy = strategy
31
+ @retry_connection_errors = retry_connection_errors
32
+ end
33
+ end
34
+
35
+ class RetriesContainer
36
+ extend T::Sig
37
+
38
+ attr_accessor :config, :status_codes
39
+
40
+ sig { params(config: RetryConfig, status_codes: Array[String]).void }
41
+ def initialize(config, status_codes)
42
+ @config = config
43
+ @status_codes = status_codes
44
+ end
45
+ end
46
+
47
+ class TemporaryError < StandardError
48
+ extend T::Sig
49
+
50
+ attr_accessor :response
51
+
52
+ sig { params(response: requests.Response).void }
53
+ def initialize(response)
54
+ @response = response
55
+ end
56
+ end
57
+
58
+ class PermanentError < StandardError
59
+ extend T::Sig
60
+
61
+ attr_accessor :inner
62
+
63
+ sig { params(inner: StandardError).void }
64
+ def initialize(inner)
65
+ @inner = inner
66
+ end
67
+ end
68
+
69
+ def self.retry(fun, retries)
70
+ if retries.config.strategy == 'backoff'
71
+ do_request = lambda do
72
+ begin
73
+ res = fun.call
74
+ retries.status_codes.each do |code|
75
+ if code.upcase.include? 'X'
76
+ code_range = code[0].to_i
77
+ s = res.status_code / 100
78
+ raise TemporaryError, res if s >= code_range && s < code_range + 1
79
+ else
80
+ parsed_code = code.to_i
81
+ raise TemporaryError, res if res.status_code == parsed_code
82
+ end
83
+ end
84
+ rescue Faraday::ConnectionFailed => e
85
+ if !retries.config.config.retry_connection_errors
86
+ raise
87
+ else
88
+ raise PermanentError, e
89
+ end
90
+ rescue Faraday::TimeoutError => e
91
+ if !retries.config.config.retry_connection_errors
92
+ raise
93
+ else
94
+ raise PermanentError, e
95
+ end
96
+ rescue TemporaryError
97
+ raise
98
+ rescue StandardError => e
99
+ raise PermanentError, e
100
+ end
101
+ return res
102
+ end
103
+ retry_with_backoff(do_request, retries.config.backoff.initial_interval,
104
+ retries.config.backoff.max_interval, retries.config.backoff.exponent,
105
+ retries.config.backoff.max_elapsed_time)
106
+ else
107
+ fun.call
108
+ end
109
+ end
110
+
111
+ def self.retry_with_backoff(fun, initial_interval = 500, max_interval = 60_000,
112
+ exponent = 1.5, max_elapsed_time = 3_600_000)
113
+ start = round(Time.now.to_i * 1000)
114
+ x = 0
115
+ loop do
116
+ return fun.call
117
+ rescue PermanentError => e
118
+ raise e.inner
119
+ rescue TemporaryError => e
120
+ now = round(Time.now.to_i * 1000)
121
+ return e.response if now - start > max_elapsed_time
122
+
123
+ sleep = ((initial_interval / 1000) * exponent**x + rand)
124
+ sleep = max_interval / 1000 if sleep > max_interval / 1000
125
+
126
+ sleep(sleep)
127
+ x += 1
128
+ end
129
+ end
130
+ end