speakeasy_client_sdk_ruby 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/sdk/apiendpoints.rb +338 -0
- data/lib/sdk/apis.rb +264 -0
- data/lib/sdk/embeds.rb +128 -0
- data/lib/sdk/metadata.rb +144 -0
- data/lib/sdk/models/operations/deleteapi.rb +52 -0
- data/lib/sdk/models/operations/deleteapiendpoint.rb +55 -0
- data/lib/sdk/models/operations/deleteschema.rb +55 -0
- data/lib/sdk/models/operations/deleteversionmetadata.rb +58 -0
- data/lib/sdk/models/operations/downloadschema.rb +55 -0
- data/lib/sdk/models/operations/downloadschemarevision.rb +58 -0
- data/lib/sdk/models/operations/findapiendpoint.rb +59 -0
- data/lib/sdk/models/operations/generateopenapispec.rb +56 -0
- data/lib/sdk/models/operations/generateopenapispecforapiendpoint.rb +59 -0
- data/lib/sdk/models/operations/generatepostmancollection.rb +55 -0
- data/lib/sdk/models/operations/generatepostmancollectionforapiendpoint.rb +58 -0
- data/lib/sdk/models/operations/generaterequestpostmancollection.rb +52 -0
- data/lib/sdk/models/operations/getallapiendpoints.rb +52 -0
- data/lib/sdk/models/operations/getallapiversions.rb +72 -0
- data/lib/sdk/models/operations/getallforversionapiendpoints.rb +55 -0
- data/lib/sdk/models/operations/getapiendpoint.rb +59 -0
- data/lib/sdk/models/operations/getapis.rb +69 -0
- data/lib/sdk/models/operations/getembedaccesstoken.rb +60 -0
- data/lib/sdk/models/operations/getplugins.rb +38 -0
- data/lib/sdk/models/operations/getrequestfromeventlog.rb +53 -0
- data/lib/sdk/models/operations/getschema.rb +56 -0
- data/lib/sdk/models/operations/getschemadiff.rb +62 -0
- data/lib/sdk/models/operations/getschemarevision.rb +59 -0
- data/lib/sdk/models/operations/getschemas.rb +55 -0
- data/lib/sdk/models/operations/getvalidembedaccesstokens.rb +38 -0
- data/lib/sdk/models/operations/getversionmetadata.rb +55 -0
- data/lib/sdk/models/operations/insertversionmetadata.rb +60 -0
- data/lib/sdk/models/operations/queryeventlog.rb +53 -0
- data/lib/sdk/models/operations/registerschema.rb +86 -0
- data/lib/sdk/models/operations/revokeembedaccesstoken.rb +49 -0
- data/lib/sdk/models/operations/runplugin.rb +56 -0
- data/lib/sdk/models/operations/upsertapi.rb +57 -0
- data/lib/sdk/models/operations/upsertapiendpoint.rb +63 -0
- data/lib/sdk/models/operations/upsertplugin.rb +39 -0
- data/lib/sdk/models/operations/validateapikey.rb +35 -0
- data/lib/sdk/models/shared/api.rb +69 -0
- data/lib/sdk/models/shared/apiendpoint.rb +84 -0
- data/lib/sdk/models/shared/boundedrequest.rb +64 -0
- data/lib/sdk/models/shared/embedaccesstokenresponse.rb +25 -0
- data/lib/sdk/models/shared/embedtoken.rb +52 -0
- data/lib/sdk/models/shared/error.rb +28 -0
- data/lib/sdk/models/shared/filter.rb +31 -0
- data/lib/sdk/models/shared/filters.rb +34 -0
- data/lib/sdk/models/shared/generateopenapispecdiff.rb +28 -0
- data/lib/sdk/models/shared/plugin.rb +43 -0
- data/lib/sdk/models/shared/requestmetadata.rb +28 -0
- data/lib/sdk/models/shared/schema.rb +40 -0
- data/lib/sdk/models/shared/schemadiff.rb +48 -0
- data/lib/sdk/models/shared/security.rb +25 -0
- data/lib/sdk/models/shared/unboundedrequest.rb +37 -0
- data/lib/sdk/models/shared/versionmetadata.rb +57 -0
- data/lib/sdk/plugins.rb +140 -0
- data/lib/sdk/requests.rb +136 -0
- data/lib/sdk/schemas.rb +334 -0
- data/lib/sdk/sdk.rb +173 -0
- data/lib/sdk/utils/metadata_fields.rb +154 -0
- data/lib/sdk/utils/retries.rb +130 -0
- data/lib/sdk/utils/utils.rb +769 -0
- data/lib/speakeasy_client_sdk_ruby.rb +70 -0
- metadata +206 -0
data/lib/sdk/schemas.rb
ADDED
@@ -0,0 +1,334 @@
|
|
1
|
+
# Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
2
|
+
|
3
|
+
# typed: true
|
4
|
+
# frozen_string_literal: true
|
5
|
+
|
6
|
+
require 'faraday'
|
7
|
+
require 'faraday/multipart'
|
8
|
+
require 'sorbet-runtime'
|
9
|
+
|
10
|
+
module SpeakeasyClientSDK
|
11
|
+
extend T::Sig
|
12
|
+
class Schemas
|
13
|
+
extend T::Sig
|
14
|
+
sig { params(sdk: SpeakeasyClientSDK::SDK, client: Faraday::Connection, server_url: String, language: String, sdk_version: String, gen_version: String).void }
|
15
|
+
def initialize(sdk, client, server_url, language, sdk_version, gen_version)
|
16
|
+
@sdk = sdk
|
17
|
+
@client = client
|
18
|
+
@server_url = server_url
|
19
|
+
@language = language
|
20
|
+
@sdk_version = sdk_version
|
21
|
+
@gen_version = gen_version
|
22
|
+
end
|
23
|
+
|
24
|
+
sig { params(request: Operations::DeleteSchemaRequest).returns(Utils::FieldAugmented) }
|
25
|
+
def delete_schema(request)
|
26
|
+
# delete_schema - Delete a particular schema revision for an Api.
|
27
|
+
base_url = @server_url
|
28
|
+
url = Utils.generate_url(
|
29
|
+
Operations::DeleteSchemaRequest,
|
30
|
+
base_url,
|
31
|
+
'/v1/apis/{apiID}/version/{versionID}/schema/{revisionID}',
|
32
|
+
request
|
33
|
+
)
|
34
|
+
headers = {}
|
35
|
+
headers['Accept'] = 'application/json'
|
36
|
+
headers['user-agent'] = "speakeasy-sdk/#{@language} #{@sdk_version} #{@gen_version}"
|
37
|
+
|
38
|
+
r = @client.delete(url) do |req|
|
39
|
+
req.headers = headers
|
40
|
+
Utils.configure_request_security(req, @sdk.security) if !@sdk.nil? && !@sdk.security.nil?
|
41
|
+
end
|
42
|
+
|
43
|
+
content_type = r.headers.fetch('Content-Type', 'application/octet-stream')
|
44
|
+
|
45
|
+
res = Operations::DeleteSchemaResponse.new(
|
46
|
+
status_code: r.status, content_type: content_type, raw_response: r
|
47
|
+
)
|
48
|
+
if r.status == 200
|
49
|
+
else
|
50
|
+
if Utils.match_content_type(content_type, 'application/json')
|
51
|
+
out = Utils.unmarshal_complex(r.env.response_body, Shared::Error)
|
52
|
+
res.error = out
|
53
|
+
end
|
54
|
+
end
|
55
|
+
res
|
56
|
+
end
|
57
|
+
|
58
|
+
sig { params(request: Operations::DownloadSchemaRequest).returns(Utils::FieldAugmented) }
|
59
|
+
def download_schema(request)
|
60
|
+
# download_schema - Download the latest schema for a particular apiID.
|
61
|
+
base_url = @server_url
|
62
|
+
url = Utils.generate_url(
|
63
|
+
Operations::DownloadSchemaRequest,
|
64
|
+
base_url,
|
65
|
+
'/v1/apis/{apiID}/version/{versionID}/schema/download',
|
66
|
+
request
|
67
|
+
)
|
68
|
+
headers = {}
|
69
|
+
headers['Accept'] = 'application/json;q=1, application/json;q=0.7, application/x-yaml;q=0'
|
70
|
+
headers['user-agent'] = "speakeasy-sdk/#{@language} #{@sdk_version} #{@gen_version}"
|
71
|
+
|
72
|
+
r = @client.get(url) do |req|
|
73
|
+
req.headers = headers
|
74
|
+
Utils.configure_request_security(req, @sdk.security) if !@sdk.nil? && !@sdk.security.nil?
|
75
|
+
end
|
76
|
+
|
77
|
+
content_type = r.headers.fetch('Content-Type', 'application/octet-stream')
|
78
|
+
|
79
|
+
res = Operations::DownloadSchemaResponse.new(
|
80
|
+
status_code: r.status, content_type: content_type, raw_response: r
|
81
|
+
)
|
82
|
+
if r.status == 200
|
83
|
+
res.schema = r.env.response_body if Utils.match_content_type(content_type, 'application/json')
|
84
|
+
res.schema = r.env.response_body if Utils.match_content_type(content_type, 'application/x-yaml')
|
85
|
+
else
|
86
|
+
if Utils.match_content_type(content_type, 'application/json')
|
87
|
+
out = Utils.unmarshal_complex(r.env.response_body, Shared::Error)
|
88
|
+
res.error = out
|
89
|
+
end
|
90
|
+
end
|
91
|
+
res
|
92
|
+
end
|
93
|
+
|
94
|
+
sig { params(request: Operations::DownloadSchemaRevisionRequest).returns(Utils::FieldAugmented) }
|
95
|
+
def download_schema_revision(request)
|
96
|
+
# download_schema_revision - Download a particular schema revision for an Api.
|
97
|
+
base_url = @server_url
|
98
|
+
url = Utils.generate_url(
|
99
|
+
Operations::DownloadSchemaRevisionRequest,
|
100
|
+
base_url,
|
101
|
+
'/v1/apis/{apiID}/version/{versionID}/schema/{revisionID}/download',
|
102
|
+
request
|
103
|
+
)
|
104
|
+
headers = {}
|
105
|
+
headers['Accept'] = 'application/json;q=1, application/json;q=0.7, application/x-yaml;q=0'
|
106
|
+
headers['user-agent'] = "speakeasy-sdk/#{@language} #{@sdk_version} #{@gen_version}"
|
107
|
+
|
108
|
+
r = @client.get(url) do |req|
|
109
|
+
req.headers = headers
|
110
|
+
Utils.configure_request_security(req, @sdk.security) if !@sdk.nil? && !@sdk.security.nil?
|
111
|
+
end
|
112
|
+
|
113
|
+
content_type = r.headers.fetch('Content-Type', 'application/octet-stream')
|
114
|
+
|
115
|
+
res = Operations::DownloadSchemaRevisionResponse.new(
|
116
|
+
status_code: r.status, content_type: content_type, raw_response: r
|
117
|
+
)
|
118
|
+
if r.status == 200
|
119
|
+
res.schema = r.env.response_body if Utils.match_content_type(content_type, 'application/json')
|
120
|
+
res.schema = r.env.response_body if Utils.match_content_type(content_type, 'application/x-yaml')
|
121
|
+
else
|
122
|
+
if Utils.match_content_type(content_type, 'application/json')
|
123
|
+
out = Utils.unmarshal_complex(r.env.response_body, Shared::Error)
|
124
|
+
res.error = out
|
125
|
+
end
|
126
|
+
end
|
127
|
+
res
|
128
|
+
end
|
129
|
+
|
130
|
+
sig { params(request: Operations::GetSchemaRequest).returns(Utils::FieldAugmented) }
|
131
|
+
def get_schema(request)
|
132
|
+
# get_schema - Get information about the latest schema.
|
133
|
+
# Returns information about the last uploaded schema for a particular API version.
|
134
|
+
# This won't include the schema itself, that can be retrieved via the downloadSchema operation.
|
135
|
+
base_url = @server_url
|
136
|
+
url = Utils.generate_url(
|
137
|
+
Operations::GetSchemaRequest,
|
138
|
+
base_url,
|
139
|
+
'/v1/apis/{apiID}/version/{versionID}/schema',
|
140
|
+
request
|
141
|
+
)
|
142
|
+
headers = {}
|
143
|
+
headers['Accept'] = 'application/json;q=1, application/json;q=0'
|
144
|
+
headers['user-agent'] = "speakeasy-sdk/#{@language} #{@sdk_version} #{@gen_version}"
|
145
|
+
|
146
|
+
r = @client.get(url) do |req|
|
147
|
+
req.headers = headers
|
148
|
+
Utils.configure_request_security(req, @sdk.security) if !@sdk.nil? && !@sdk.security.nil?
|
149
|
+
end
|
150
|
+
|
151
|
+
content_type = r.headers.fetch('Content-Type', 'application/octet-stream')
|
152
|
+
|
153
|
+
res = Operations::GetSchemaResponse.new(
|
154
|
+
status_code: r.status, content_type: content_type, raw_response: r
|
155
|
+
)
|
156
|
+
if r.status == 200
|
157
|
+
if Utils.match_content_type(content_type, 'application/json')
|
158
|
+
out = Utils.unmarshal_complex(r.env.response_body, Shared::Schema)
|
159
|
+
res.schema = out
|
160
|
+
end
|
161
|
+
else
|
162
|
+
if Utils.match_content_type(content_type, 'application/json')
|
163
|
+
out = Utils.unmarshal_complex(r.env.response_body, Shared::Error)
|
164
|
+
res.error = out
|
165
|
+
end
|
166
|
+
end
|
167
|
+
res
|
168
|
+
end
|
169
|
+
|
170
|
+
sig { params(request: Operations::GetSchemaDiffRequest).returns(Utils::FieldAugmented) }
|
171
|
+
def get_schema_diff(request)
|
172
|
+
# get_schema_diff - Get a diff of two schema revisions for an Api.
|
173
|
+
base_url = @server_url
|
174
|
+
url = Utils.generate_url(
|
175
|
+
Operations::GetSchemaDiffRequest,
|
176
|
+
base_url,
|
177
|
+
'/v1/apis/{apiID}/version/{versionID}/schema/{baseRevisionID}/diff/{targetRevisionID}',
|
178
|
+
request
|
179
|
+
)
|
180
|
+
headers = {}
|
181
|
+
headers['Accept'] = 'application/json;q=1, application/json;q=0'
|
182
|
+
headers['user-agent'] = "speakeasy-sdk/#{@language} #{@sdk_version} #{@gen_version}"
|
183
|
+
|
184
|
+
r = @client.get(url) do |req|
|
185
|
+
req.headers = headers
|
186
|
+
Utils.configure_request_security(req, @sdk.security) if !@sdk.nil? && !@sdk.security.nil?
|
187
|
+
end
|
188
|
+
|
189
|
+
content_type = r.headers.fetch('Content-Type', 'application/octet-stream')
|
190
|
+
|
191
|
+
res = Operations::GetSchemaDiffResponse.new(
|
192
|
+
status_code: r.status, content_type: content_type, raw_response: r
|
193
|
+
)
|
194
|
+
if r.status == 200
|
195
|
+
if Utils.match_content_type(content_type, 'application/json')
|
196
|
+
out = Utils.unmarshal_complex(r.env.response_body, Shared::SchemaDiff)
|
197
|
+
res.schema_diff = out
|
198
|
+
end
|
199
|
+
else
|
200
|
+
if Utils.match_content_type(content_type, 'application/json')
|
201
|
+
out = Utils.unmarshal_complex(r.env.response_body, Shared::Error)
|
202
|
+
res.error = out
|
203
|
+
end
|
204
|
+
end
|
205
|
+
res
|
206
|
+
end
|
207
|
+
|
208
|
+
sig { params(request: Operations::GetSchemaRevisionRequest).returns(Utils::FieldAugmented) }
|
209
|
+
def get_schema_revision(request)
|
210
|
+
# get_schema_revision - Get information about a particular schema revision for an Api.
|
211
|
+
# Returns information about the last uploaded schema for a particular schema revision.
|
212
|
+
# This won't include the schema itself, that can be retrieved via the downloadSchema operation.
|
213
|
+
base_url = @server_url
|
214
|
+
url = Utils.generate_url(
|
215
|
+
Operations::GetSchemaRevisionRequest,
|
216
|
+
base_url,
|
217
|
+
'/v1/apis/{apiID}/version/{versionID}/schema/{revisionID}',
|
218
|
+
request
|
219
|
+
)
|
220
|
+
headers = {}
|
221
|
+
headers['Accept'] = 'application/json;q=1, application/json;q=0'
|
222
|
+
headers['user-agent'] = "speakeasy-sdk/#{@language} #{@sdk_version} #{@gen_version}"
|
223
|
+
|
224
|
+
r = @client.get(url) do |req|
|
225
|
+
req.headers = headers
|
226
|
+
Utils.configure_request_security(req, @sdk.security) if !@sdk.nil? && !@sdk.security.nil?
|
227
|
+
end
|
228
|
+
|
229
|
+
content_type = r.headers.fetch('Content-Type', 'application/octet-stream')
|
230
|
+
|
231
|
+
res = Operations::GetSchemaRevisionResponse.new(
|
232
|
+
status_code: r.status, content_type: content_type, raw_response: r
|
233
|
+
)
|
234
|
+
if r.status == 200
|
235
|
+
if Utils.match_content_type(content_type, 'application/json')
|
236
|
+
out = Utils.unmarshal_complex(r.env.response_body, Shared::Schema)
|
237
|
+
res.schema = out
|
238
|
+
end
|
239
|
+
else
|
240
|
+
if Utils.match_content_type(content_type, 'application/json')
|
241
|
+
out = Utils.unmarshal_complex(r.env.response_body, Shared::Error)
|
242
|
+
res.error = out
|
243
|
+
end
|
244
|
+
end
|
245
|
+
res
|
246
|
+
end
|
247
|
+
|
248
|
+
sig { params(request: Operations::GetSchemasRequest).returns(Utils::FieldAugmented) }
|
249
|
+
def get_schemas(request)
|
250
|
+
# get_schemas - Get information about all schemas associated with a particular apiID.
|
251
|
+
# Returns information the schemas associated with a particular apiID.
|
252
|
+
# This won't include the schemas themselves, they can be retrieved via the downloadSchema operation.
|
253
|
+
base_url = @server_url
|
254
|
+
url = Utils.generate_url(
|
255
|
+
Operations::GetSchemasRequest,
|
256
|
+
base_url,
|
257
|
+
'/v1/apis/{apiID}/version/{versionID}/schemas',
|
258
|
+
request
|
259
|
+
)
|
260
|
+
headers = {}
|
261
|
+
headers['Accept'] = 'application/json;q=1, application/json;q=0'
|
262
|
+
headers['user-agent'] = "speakeasy-sdk/#{@language} #{@sdk_version} #{@gen_version}"
|
263
|
+
|
264
|
+
r = @client.get(url) do |req|
|
265
|
+
req.headers = headers
|
266
|
+
Utils.configure_request_security(req, @sdk.security) if !@sdk.nil? && !@sdk.security.nil?
|
267
|
+
end
|
268
|
+
|
269
|
+
content_type = r.headers.fetch('Content-Type', 'application/octet-stream')
|
270
|
+
|
271
|
+
res = Operations::GetSchemasResponse.new(
|
272
|
+
status_code: r.status, content_type: content_type, raw_response: r
|
273
|
+
)
|
274
|
+
if r.status == 200
|
275
|
+
if Utils.match_content_type(content_type, 'application/json')
|
276
|
+
out = Utils.unmarshal_complex(r.env.response_body, T::Array[Shared::Schema])
|
277
|
+
res.schemata = out
|
278
|
+
end
|
279
|
+
else
|
280
|
+
if Utils.match_content_type(content_type, 'application/json')
|
281
|
+
out = Utils.unmarshal_complex(r.env.response_body, Shared::Error)
|
282
|
+
res.error = out
|
283
|
+
end
|
284
|
+
end
|
285
|
+
res
|
286
|
+
end
|
287
|
+
|
288
|
+
sig { params(request: Operations::RegisterSchemaRequest).returns(Utils::FieldAugmented) }
|
289
|
+
def register_schema(request)
|
290
|
+
# register_schema - Register a schema.
|
291
|
+
# Allows uploading a schema for a particular API version.
|
292
|
+
# This will be used to populate ApiEndpoints and used as a base for any schema generation if present.
|
293
|
+
base_url = @server_url
|
294
|
+
url = Utils.generate_url(
|
295
|
+
Operations::RegisterSchemaRequest,
|
296
|
+
base_url,
|
297
|
+
'/v1/apis/{apiID}/version/{versionID}/schema',
|
298
|
+
request
|
299
|
+
)
|
300
|
+
headers = {}
|
301
|
+
req_content_type, data, form = Utils.serialize_request_body(request, :request_body, :multipart)
|
302
|
+
headers['content-type'] = req_content_type
|
303
|
+
raise StandardError, 'request body is required' if data.nil? && form.nil?
|
304
|
+
headers['Accept'] = 'application/json'
|
305
|
+
headers['user-agent'] = "speakeasy-sdk/#{@language} #{@sdk_version} #{@gen_version}"
|
306
|
+
|
307
|
+
r = @client.post(url) do |req|
|
308
|
+
req.headers = headers
|
309
|
+
Utils.configure_request_security(req, @sdk.security) if !@sdk.nil? && !@sdk.security.nil?
|
310
|
+
if form
|
311
|
+
req.body = Utils.encode_form(form)
|
312
|
+
elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded')
|
313
|
+
req.body = URI.encode_www_form(data)
|
314
|
+
else
|
315
|
+
req.body = data
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
content_type = r.headers.fetch('Content-Type', 'application/octet-stream')
|
320
|
+
|
321
|
+
res = Operations::RegisterSchemaResponse.new(
|
322
|
+
status_code: r.status, content_type: content_type, raw_response: r
|
323
|
+
)
|
324
|
+
if r.status == 200
|
325
|
+
else
|
326
|
+
if Utils.match_content_type(content_type, 'application/json')
|
327
|
+
out = Utils.unmarshal_complex(r.env.response_body, Shared::Error)
|
328
|
+
res.error = out
|
329
|
+
end
|
330
|
+
end
|
331
|
+
res
|
332
|
+
end
|
333
|
+
end
|
334
|
+
end
|
data/lib/sdk/sdk.rb
ADDED
@@ -0,0 +1,173 @@
|
|
1
|
+
# Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
2
|
+
|
3
|
+
# typed: true
|
4
|
+
# frozen_string_literal: true
|
5
|
+
|
6
|
+
require 'faraday'
|
7
|
+
require 'faraday/multipart'
|
8
|
+
require 'sorbet-runtime'
|
9
|
+
module SpeakeasyClientSDK
|
10
|
+
extend T::Sig
|
11
|
+
SERVER_PROD = 'prod'
|
12
|
+
SERVERS = {
|
13
|
+
SERVER_PROD: 'https://api.prod.speakeasyapi.dev'
|
14
|
+
}.freeze
|
15
|
+
class SDK
|
16
|
+
extend T::Sig
|
17
|
+
|
18
|
+
attr_accessor :api_endpoints, :apis, :embeds, :metadata, :plugins, :requests, :schemas
|
19
|
+
|
20
|
+
attr_accessor :security, :language, :sdk_version, :gen_version
|
21
|
+
|
22
|
+
sig do
|
23
|
+
params(security: Shared::Security,
|
24
|
+
server: String,
|
25
|
+
server_url: String,
|
26
|
+
url_params: T::Hash[Symbol, String],
|
27
|
+
client: Faraday::Request).void
|
28
|
+
end
|
29
|
+
def initialize(security: nil,
|
30
|
+
server: nil,
|
31
|
+
server_url: nil,
|
32
|
+
url_params: nil,
|
33
|
+
client: nil)
|
34
|
+
|
35
|
+
## Instantiates the SDK configuring it with the provided parameters.
|
36
|
+
# @param [Shared::Security] security The security details required for authentication
|
37
|
+
# @param [String] server The server by name to use for all operations
|
38
|
+
# @param [String] server_url The server URL to use for all operations
|
39
|
+
# @param [Hash<Symbol, String>] url_params Parameters to optionally template the server URL with
|
40
|
+
# @param [Faraday::Request] client The faraday HTTP client to use for all operations
|
41
|
+
|
42
|
+
@client = Faraday.new(request: {
|
43
|
+
params_encoder: Faraday::FlatParamsEncoder
|
44
|
+
}) do |f|
|
45
|
+
f.request :multipart, {}
|
46
|
+
# f.response :logger
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
@security = nil
|
53
|
+
@server_url = SERVERS[SERVER_PROD]
|
54
|
+
@language = 'ruby'
|
55
|
+
@sdk_version = '1.0.1'
|
56
|
+
@gen_version = '2.35.9'
|
57
|
+
init_sdks
|
58
|
+
end
|
59
|
+
|
60
|
+
sig { params(server_url: String, params: T.nilable(T::Hash[Symbol, String])).void }
|
61
|
+
def config_server_url(server_url, params)
|
62
|
+
if params.nil?
|
63
|
+
@server_url = server_url
|
64
|
+
else
|
65
|
+
@server_url = Utils.template_url(server_url, params)
|
66
|
+
end
|
67
|
+
init_sdks
|
68
|
+
end
|
69
|
+
|
70
|
+
sig { params(server: String, params: T.nilable(T::Hash[Symbol, String])).void }
|
71
|
+
def config_server(server, params)
|
72
|
+
raise StandardError, 'Invalid server' if !SERVERS.include? server
|
73
|
+
|
74
|
+
config_server_url(SERVERS[server], params)
|
75
|
+
init_sdks
|
76
|
+
end
|
77
|
+
|
78
|
+
sig { params(security: Shared::Security).void }
|
79
|
+
def config_security(security)
|
80
|
+
@security = security
|
81
|
+
end
|
82
|
+
|
83
|
+
sig { void }
|
84
|
+
def init_sdks
|
85
|
+
@api_endpoints = ApiEndpoints.new(
|
86
|
+
self,
|
87
|
+
@client,
|
88
|
+
@server_url,
|
89
|
+
@language,
|
90
|
+
@sdk_version,
|
91
|
+
@gen_version
|
92
|
+
)
|
93
|
+
@apis = Apis.new(
|
94
|
+
self,
|
95
|
+
@client,
|
96
|
+
@server_url,
|
97
|
+
@language,
|
98
|
+
@sdk_version,
|
99
|
+
@gen_version
|
100
|
+
)
|
101
|
+
@embeds = Embeds.new(
|
102
|
+
self,
|
103
|
+
@client,
|
104
|
+
@server_url,
|
105
|
+
@language,
|
106
|
+
@sdk_version,
|
107
|
+
@gen_version
|
108
|
+
)
|
109
|
+
@metadata = Metadata.new(
|
110
|
+
self,
|
111
|
+
@client,
|
112
|
+
@server_url,
|
113
|
+
@language,
|
114
|
+
@sdk_version,
|
115
|
+
@gen_version
|
116
|
+
)
|
117
|
+
@plugins = Plugins.new(
|
118
|
+
self,
|
119
|
+
@client,
|
120
|
+
@server_url,
|
121
|
+
@language,
|
122
|
+
@sdk_version,
|
123
|
+
@gen_version
|
124
|
+
)
|
125
|
+
@requests = Requests.new(
|
126
|
+
self,
|
127
|
+
@client,
|
128
|
+
@server_url,
|
129
|
+
@language,
|
130
|
+
@sdk_version,
|
131
|
+
@gen_version
|
132
|
+
)
|
133
|
+
@schemas = Schemas.new(
|
134
|
+
self,
|
135
|
+
@client,
|
136
|
+
@server_url,
|
137
|
+
@language,
|
138
|
+
@sdk_version,
|
139
|
+
@gen_version
|
140
|
+
)
|
141
|
+
end
|
142
|
+
|
143
|
+
|
144
|
+
sig { returns(Utils::FieldAugmented) }
|
145
|
+
def validate_api_key
|
146
|
+
# validate_api_key - Validate the current api key.
|
147
|
+
base_url = @server_url
|
148
|
+
url = "#{base_url.delete_suffix('/')}/v1/auth/validate"
|
149
|
+
headers = {}
|
150
|
+
headers['Accept'] = 'application/json'
|
151
|
+
headers['user-agent'] = "speakeasy-sdk/#{@language} #{@sdk_version} #{@gen_version}"
|
152
|
+
|
153
|
+
r = @client.get(url) do |req|
|
154
|
+
req.headers = headers
|
155
|
+
Utils.configure_request_security(req, @sdk.security) if !@sdk.nil? && !@sdk.security.nil?
|
156
|
+
end
|
157
|
+
|
158
|
+
content_type = r.headers.fetch('Content-Type', 'application/octet-stream')
|
159
|
+
|
160
|
+
res = Operations::ValidateApiKeyResponse.new(
|
161
|
+
status_code: r.status, content_type: content_type, raw_response: r
|
162
|
+
)
|
163
|
+
if r.status == 200
|
164
|
+
else
|
165
|
+
if Utils.match_content_type(content_type, 'application/json')
|
166
|
+
out = Utils.unmarshal_complex(r.env.response_body, Shared::Error)
|
167
|
+
res.error = out
|
168
|
+
end
|
169
|
+
end
|
170
|
+
res
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
# Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
2
|
+
|
3
|
+
# typed: true
|
4
|
+
# frozen_string_literal: true
|
5
|
+
|
6
|
+
module SpeakeasyClientSDK
|
7
|
+
module MetadataFields
|
8
|
+
extend T::Sig
|
9
|
+
|
10
|
+
class Field
|
11
|
+
attr_accessor :name, :type, :metadata
|
12
|
+
|
13
|
+
def initialize(name, type, metadata)
|
14
|
+
@name = name
|
15
|
+
@type = type
|
16
|
+
@metadata = metadata
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module ClassMethods
|
21
|
+
extend T::Sig
|
22
|
+
|
23
|
+
def fields
|
24
|
+
@__fields__ = [] if @__fields__.nil?
|
25
|
+
|
26
|
+
@__fields__
|
27
|
+
end
|
28
|
+
|
29
|
+
def field(field_name, type, metadata = {})
|
30
|
+
attr_accessor field_name
|
31
|
+
|
32
|
+
fields << Field.new(field_name, type, metadata)
|
33
|
+
end
|
34
|
+
|
35
|
+
def unmarshal_single(field_type, value, decoder = nil)
|
36
|
+
if field_type.respond_to? :unmarshal_json
|
37
|
+
unmarshalled = field_type.unmarshal_json(value)
|
38
|
+
return unmarshalled
|
39
|
+
elsif field_type.to_s == 'Object'
|
40
|
+
# rubocop:disable Lint/SuppressedException
|
41
|
+
begin
|
42
|
+
value = JSON.parse(value)
|
43
|
+
rescue TypeError, JSON::ParserError
|
44
|
+
end
|
45
|
+
# rubocop:enable Lint/SuppressedException
|
46
|
+
return value
|
47
|
+
end
|
48
|
+
if decoder.nil?
|
49
|
+
value
|
50
|
+
else
|
51
|
+
decoder.call(value)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
sig { params(json_obj: T.any(String, T::Hash[Symbol, String])).returns(Utils::FieldAugmented) }
|
56
|
+
def unmarshal_json(json_obj)
|
57
|
+
to_build = new
|
58
|
+
begin
|
59
|
+
d = JSON.parse(json_obj)
|
60
|
+
rescue TypeError, JSON::ParserError
|
61
|
+
d = json_obj
|
62
|
+
end
|
63
|
+
fields.each do |field|
|
64
|
+
field_type = field.type
|
65
|
+
if field.type.respond_to?(:types) && field.type.types.length == 2
|
66
|
+
type2 = field.type.types[1]
|
67
|
+
if type2.raw_type == NilClass
|
68
|
+
field_type = field.type.types[0]
|
69
|
+
field_type = field_type.raw_type if field_type.respond_to? :raw_type
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
key = "#{field.name}="
|
75
|
+
lookup = field.metadata.fetch(:format_json, {}).fetch(:letter_case, nil).call
|
76
|
+
value = d[lookup]
|
77
|
+
next if value.nil?
|
78
|
+
|
79
|
+
if field_type.to_s.start_with? 'T::Array'
|
80
|
+
inner_type = field_type.type.raw_type
|
81
|
+
unmarshalled_array = value.map { |f| unmarshal_single(inner_type, f) }
|
82
|
+
to_build.send(key, unmarshalled_array)
|
83
|
+
elsif field_type.to_s.start_with? 'T::Hash'
|
84
|
+
_, val_type = field_type.type.types
|
85
|
+
# rubocop:disable Style/HashTransformValues
|
86
|
+
unmarshalled_hash = value.map { |k, v| [k, unmarshal_single(val_type.raw_type, v)] }.to_h
|
87
|
+
# rubocop:enable Style/HashTransformValues
|
88
|
+
to_build.send(key, unmarshalled_hash)
|
89
|
+
else
|
90
|
+
decoder = field.metadata.fetch(:format_json, {}).fetch(:decoder, nil)
|
91
|
+
final_value = unmarshal_single(field_type, value, decoder)
|
92
|
+
to_build.send(key, final_value)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
to_build
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def initialize
|
100
|
+
instance = allocate
|
101
|
+
fields.each { |mod| instance.singleton_class.include(mod) }
|
102
|
+
instance.send(:initialize)
|
103
|
+
end
|
104
|
+
|
105
|
+
def self.included(base)
|
106
|
+
base.extend(ClassMethods)
|
107
|
+
end
|
108
|
+
|
109
|
+
def fields
|
110
|
+
self.class.fields
|
111
|
+
end
|
112
|
+
|
113
|
+
def field(field_name)
|
114
|
+
fields.each do |f|
|
115
|
+
return f if f.name == field_name
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def marshal_single(field)
|
120
|
+
if field.respond_to? :marshal_json
|
121
|
+
field.marshal_json(encode: false)
|
122
|
+
else
|
123
|
+
Utils.val_to_string(field, primitives: false)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def marshal_json(encode: true)
|
128
|
+
d = {}
|
129
|
+
fields.sort_by(&:name).each do |field|
|
130
|
+
f = send(field.name)
|
131
|
+
next if f.nil?
|
132
|
+
|
133
|
+
format_json_meta = field.metadata[:format_json]
|
134
|
+
if !format_json_meta.nil? && format_json_meta.include?(:letter_case)
|
135
|
+
key = format_json_meta[:letter_case].call(field.name)
|
136
|
+
else
|
137
|
+
key = field.name
|
138
|
+
end
|
139
|
+
if f.is_a? Array
|
140
|
+
d[key] = f.map { |o| marshal_single(o) }
|
141
|
+
elsif f.is_a? Hash
|
142
|
+
d[key] = f.map { |k, v| [k, marshal_single(v)] }
|
143
|
+
else
|
144
|
+
d[key] = marshal_single(f)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
if encode
|
148
|
+
JSON.dump(d)
|
149
|
+
else
|
150
|
+
d
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|