dub 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. checksums.yaml +7 -0
  2. data/lib/dub.rb +23 -0
  3. data/lib/open_api_sdk/analytics.rb +99 -0
  4. data/lib/open_api_sdk/domains.rb +577 -0
  5. data/lib/open_api_sdk/dub.rb +107 -0
  6. data/lib/open_api_sdk/links.rb +724 -0
  7. data/lib/open_api_sdk/metatags.rb +58 -0
  8. data/lib/open_api_sdk/models/operations/adddomain_request.rb +30 -0
  9. data/lib/open_api_sdk/models/operations/adddomain_requestbody.rb +42 -0
  10. data/lib/open_api_sdk/models/operations/adddomain_response.rb +60 -0
  11. data/lib/open_api_sdk/models/operations/bulkcreatelinks_request.rb +30 -0
  12. data/lib/open_api_sdk/models/operations/bulkcreatelinks_response.rb +60 -0
  13. data/lib/open_api_sdk/models/operations/color.rb +24 -0
  14. data/lib/open_api_sdk/models/operations/createlink_request.rb +30 -0
  15. data/lib/open_api_sdk/models/operations/createlink_requestbody.rb +92 -0
  16. data/lib/open_api_sdk/models/operations/createlink_response.rb +60 -0
  17. data/lib/open_api_sdk/models/operations/createtag_request.rb +30 -0
  18. data/lib/open_api_sdk/models/operations/createtag_requestbody.rb +27 -0
  19. data/lib/open_api_sdk/models/operations/createtag_response.rb +60 -0
  20. data/lib/open_api_sdk/models/operations/createworkspace_requestbody.rb +30 -0
  21. data/lib/open_api_sdk/models/operations/createworkspace_response.rb +60 -0
  22. data/lib/open_api_sdk/models/operations/deletedomain_request.rb +30 -0
  23. data/lib/open_api_sdk/models/operations/deletedomain_response.rb +60 -0
  24. data/lib/open_api_sdk/models/operations/deletedomain_responsebody.rb +24 -0
  25. data/lib/open_api_sdk/models/operations/deletelink_request.rb +30 -0
  26. data/lib/open_api_sdk/models/operations/deletelink_response.rb +60 -0
  27. data/lib/open_api_sdk/models/operations/deletelink_responsebody.rb +24 -0
  28. data/lib/open_api_sdk/models/operations/event.rb +21 -0
  29. data/lib/open_api_sdk/models/operations/getlinkinfo_request.rb +39 -0
  30. data/lib/open_api_sdk/models/operations/getlinkinfo_response.rb +60 -0
  31. data/lib/open_api_sdk/models/operations/getlinks_request.rb +57 -0
  32. data/lib/open_api_sdk/models/operations/getlinks_response.rb +60 -0
  33. data/lib/open_api_sdk/models/operations/getlinkscount_request.rb +54 -0
  34. data/lib/open_api_sdk/models/operations/getlinkscount_response.rb +60 -0
  35. data/lib/open_api_sdk/models/operations/getmetatags_request.rb +24 -0
  36. data/lib/open_api_sdk/models/operations/getmetatags_response.rb +33 -0
  37. data/lib/open_api_sdk/models/operations/getmetatags_responsebody.rb +30 -0
  38. data/lib/open_api_sdk/models/operations/getqrcode_request.rb +39 -0
  39. data/lib/open_api_sdk/models/operations/getqrcode_response.rb +60 -0
  40. data/lib/open_api_sdk/models/operations/gettags_request.rb +27 -0
  41. data/lib/open_api_sdk/models/operations/gettags_response.rb +60 -0
  42. data/lib/open_api_sdk/models/operations/getworkspace_request.rb +24 -0
  43. data/lib/open_api_sdk/models/operations/getworkspace_response.rb +60 -0
  44. data/lib/open_api_sdk/models/operations/getworkspaces_response.rb +60 -0
  45. data/lib/open_api_sdk/models/operations/groupby.rb +28 -0
  46. data/lib/open_api_sdk/models/operations/interval.rb +25 -0
  47. data/lib/open_api_sdk/models/operations/level.rb +21 -0
  48. data/lib/open_api_sdk/models/operations/listdomains_request.rb +27 -0
  49. data/lib/open_api_sdk/models/operations/listdomains_response.rb +60 -0
  50. data/lib/open_api_sdk/models/operations/paymentprocessor.rb +20 -0
  51. data/lib/open_api_sdk/models/operations/requestbody.rb +92 -0
  52. data/lib/open_api_sdk/models/operations/retrieveanalytics_request.rb +87 -0
  53. data/lib/open_api_sdk/models/operations/retrieveanalytics_response.rb +60 -0
  54. data/lib/open_api_sdk/models/operations/setprimarydomain_request.rb +30 -0
  55. data/lib/open_api_sdk/models/operations/setprimarydomain_response.rb +60 -0
  56. data/lib/open_api_sdk/models/operations/sort.rb +20 -0
  57. data/lib/open_api_sdk/models/operations/trackcustomer_requestbody.rb +33 -0
  58. data/lib/open_api_sdk/models/operations/trackcustomer_response.rb +60 -0
  59. data/lib/open_api_sdk/models/operations/trackcustomer_responsebody.rb +33 -0
  60. data/lib/open_api_sdk/models/operations/tracklead_requestbody.rb +42 -0
  61. data/lib/open_api_sdk/models/operations/tracklead_response.rb +60 -0
  62. data/lib/open_api_sdk/models/operations/tracklead_responsebody.rb +42 -0
  63. data/lib/open_api_sdk/models/operations/tracksale_requestbody.rb +39 -0
  64. data/lib/open_api_sdk/models/operations/tracksale_response.rb +60 -0
  65. data/lib/open_api_sdk/models/operations/tracksale_responsebody.rb +39 -0
  66. data/lib/open_api_sdk/models/operations/transferdomain_request.rb +33 -0
  67. data/lib/open_api_sdk/models/operations/transferdomain_requestbody.rb +24 -0
  68. data/lib/open_api_sdk/models/operations/transferdomain_response.rb +60 -0
  69. data/lib/open_api_sdk/models/operations/type.rb +19 -0
  70. data/lib/open_api_sdk/models/operations/updatedomain_request.rb +33 -0
  71. data/lib/open_api_sdk/models/operations/updatedomain_requestbody.rb +42 -0
  72. data/lib/open_api_sdk/models/operations/updatedomain_response.rb +60 -0
  73. data/lib/open_api_sdk/models/operations/updatedomain_type.rb +19 -0
  74. data/lib/open_api_sdk/models/operations/updatelink_request.rb +33 -0
  75. data/lib/open_api_sdk/models/operations/updatelink_requestbody.rb +92 -0
  76. data/lib/open_api_sdk/models/operations/updatelink_response.rb +60 -0
  77. data/lib/open_api_sdk/models/operations/upsertlink_request.rb +30 -0
  78. data/lib/open_api_sdk/models/operations/upsertlink_requestbody.rb +92 -0
  79. data/lib/open_api_sdk/models/operations/upsertlink_response.rb +60 -0
  80. data/lib/open_api_sdk/models/operations.rb +81 -0
  81. data/lib/open_api_sdk/models/shared/badrequest.rb +24 -0
  82. data/lib/open_api_sdk/models/shared/code.rb +18 -0
  83. data/lib/open_api_sdk/models/shared/color.rb +24 -0
  84. data/lib/open_api_sdk/models/shared/conflict.rb +24 -0
  85. data/lib/open_api_sdk/models/shared/conflict_code.rb +18 -0
  86. data/lib/open_api_sdk/models/shared/conflict_error.rb +30 -0
  87. data/lib/open_api_sdk/models/shared/countrycode.rb +267 -0
  88. data/lib/open_api_sdk/models/shared/domains.rb +27 -0
  89. data/lib/open_api_sdk/models/shared/domainschema.rb +54 -0
  90. data/lib/open_api_sdk/models/shared/error.rb +30 -0
  91. data/lib/open_api_sdk/models/shared/forbidden.rb +24 -0
  92. data/lib/open_api_sdk/models/shared/forbidden_code.rb +18 -0
  93. data/lib/open_api_sdk/models/shared/forbidden_error.rb +30 -0
  94. data/lib/open_api_sdk/models/shared/geo.rb +771 -0
  95. data/lib/open_api_sdk/models/shared/internalservererror.rb +24 -0
  96. data/lib/open_api_sdk/models/shared/internalservererror_code.rb +18 -0
  97. data/lib/open_api_sdk/models/shared/internalservererror_error.rb +30 -0
  98. data/lib/open_api_sdk/models/shared/inviteexpired.rb +24 -0
  99. data/lib/open_api_sdk/models/shared/inviteexpired_code.rb +18 -0
  100. data/lib/open_api_sdk/models/shared/inviteexpired_error.rb +30 -0
  101. data/lib/open_api_sdk/models/shared/linkgeotargeting.rb +771 -0
  102. data/lib/open_api_sdk/models/shared/linkschema.rb +139 -0
  103. data/lib/open_api_sdk/models/shared/notfound.rb +24 -0
  104. data/lib/open_api_sdk/models/shared/notfound_code.rb +18 -0
  105. data/lib/open_api_sdk/models/shared/notfound_error.rb +30 -0
  106. data/lib/open_api_sdk/models/shared/plan.rb +24 -0
  107. data/lib/open_api_sdk/models/shared/ratelimitexceeded.rb +24 -0
  108. data/lib/open_api_sdk/models/shared/ratelimitexceeded_code.rb +18 -0
  109. data/lib/open_api_sdk/models/shared/ratelimitexceeded_error.rb +30 -0
  110. data/lib/open_api_sdk/models/shared/role.rb +19 -0
  111. data/lib/open_api_sdk/models/shared/security.rb +24 -0
  112. data/lib/open_api_sdk/models/shared/tagschema.rb +30 -0
  113. data/lib/open_api_sdk/models/shared/type.rb +19 -0
  114. data/lib/open_api_sdk/models/shared/unauthorized.rb +24 -0
  115. data/lib/open_api_sdk/models/shared/unauthorized_code.rb +18 -0
  116. data/lib/open_api_sdk/models/shared/unauthorized_error.rb +30 -0
  117. data/lib/open_api_sdk/models/shared/unprocessableentity.rb +24 -0
  118. data/lib/open_api_sdk/models/shared/unprocessableentity_code.rb +18 -0
  119. data/lib/open_api_sdk/models/shared/unprocessableentity_error.rb +30 -0
  120. data/lib/open_api_sdk/models/shared/users.rb +24 -0
  121. data/lib/open_api_sdk/models/shared/workspaceschema.rb +81 -0
  122. data/lib/open_api_sdk/models/shared.rb +50 -0
  123. data/lib/open_api_sdk/qr_codes.rb +97 -0
  124. data/lib/open_api_sdk/sdkconfiguration.rb +54 -0
  125. data/lib/open_api_sdk/tags.rb +197 -0
  126. data/lib/open_api_sdk/track.rb +276 -0
  127. data/lib/open_api_sdk/utils/metadata_fields.rb +150 -0
  128. data/lib/open_api_sdk/utils/t.rb +59 -0
  129. data/lib/open_api_sdk/utils/utils.rb +772 -0
  130. data/lib/open_api_sdk/workspaces.rb +268 -0
  131. metadata +300 -0
@@ -0,0 +1,276 @@
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 OpenApiSDK
11
+ extend T::Sig
12
+ class Track
13
+ extend T::Sig
14
+
15
+
16
+ sig { params(sdk_config: SDKConfiguration).void }
17
+ def initialize(sdk_config)
18
+ @sdk_configuration = sdk_config
19
+ end
20
+
21
+
22
+ sig { params(request: T.nilable(::OpenApiSDK::Operations::TrackLeadRequestBody)).returns(::OpenApiSDK::Operations::TrackLeadResponse) }
23
+ def lead(request)
24
+ # lead - Track a lead
25
+ # Track a lead for a short link.
26
+ url, params = @sdk_configuration.get_server_details
27
+ base_url = Utils.template_url(url, params)
28
+ url = "#{base_url}/track/lead"
29
+ headers = {}
30
+ req_content_type, data, form = Utils.serialize_request_body(request, :request, :json)
31
+ headers['content-type'] = req_content_type
32
+ headers['Accept'] = 'application/json'
33
+ headers['user-agent'] = @sdk_configuration.user_agent
34
+
35
+ r = @sdk_configuration.client.post(url) do |req|
36
+ req.headers = headers
37
+ Utils.configure_request_security(req, @sdk_configuration.security) if !@sdk_configuration.nil? && !@sdk_configuration.security.nil?
38
+ if form
39
+ req.body = Utils.encode_form(form)
40
+ elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded')
41
+ req.body = URI.encode_www_form(data)
42
+ else
43
+ req.body = data
44
+ end
45
+ end
46
+
47
+ content_type = r.headers.fetch('Content-Type', 'application/octet-stream')
48
+
49
+ res = ::OpenApiSDK::Operations::TrackLeadResponse.new(
50
+ status_code: r.status, content_type: content_type, raw_response: r
51
+ )
52
+ if r.status == 200
53
+ if Utils.match_content_type(content_type, 'application/json')
54
+ out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Operations::TrackLeadResponseBody)
55
+ res.object = out
56
+ end
57
+ elsif r.status == 400
58
+ if Utils.match_content_type(content_type, 'application/json')
59
+ out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::BadRequest)
60
+ res.bad_request = out
61
+ end
62
+ elsif r.status == 401
63
+ if Utils.match_content_type(content_type, 'application/json')
64
+ out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::Unauthorized)
65
+ res.unauthorized = out
66
+ end
67
+ elsif r.status == 403
68
+ if Utils.match_content_type(content_type, 'application/json')
69
+ out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::Forbidden)
70
+ res.forbidden = out
71
+ end
72
+ elsif r.status == 404
73
+ if Utils.match_content_type(content_type, 'application/json')
74
+ out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::NotFound)
75
+ res.not_found = out
76
+ end
77
+ elsif r.status == 409
78
+ if Utils.match_content_type(content_type, 'application/json')
79
+ out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::Conflict)
80
+ res.conflict = out
81
+ end
82
+ elsif r.status == 410
83
+ if Utils.match_content_type(content_type, 'application/json')
84
+ out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::InviteExpired)
85
+ res.invite_expired = out
86
+ end
87
+ elsif r.status == 422
88
+ if Utils.match_content_type(content_type, 'application/json')
89
+ out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::UnprocessableEntity)
90
+ res.unprocessable_entity = out
91
+ end
92
+ elsif r.status == 429
93
+ if Utils.match_content_type(content_type, 'application/json')
94
+ out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::RateLimitExceeded)
95
+ res.rate_limit_exceeded = out
96
+ end
97
+ elsif r.status == 500
98
+ if Utils.match_content_type(content_type, 'application/json')
99
+ out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::InternalServerError)
100
+ res.internal_server_error = out
101
+ end
102
+ end
103
+ res
104
+ end
105
+
106
+
107
+ sig { params(request: T.nilable(::OpenApiSDK::Operations::TrackSaleRequestBody)).returns(::OpenApiSDK::Operations::TrackSaleResponse) }
108
+ def sale(request)
109
+ # sale - Track a sale
110
+ # Track a sale for a short link.
111
+ url, params = @sdk_configuration.get_server_details
112
+ base_url = Utils.template_url(url, params)
113
+ url = "#{base_url}/track/sale"
114
+ headers = {}
115
+ req_content_type, data, form = Utils.serialize_request_body(request, :request, :json)
116
+ headers['content-type'] = req_content_type
117
+ headers['Accept'] = 'application/json'
118
+ headers['user-agent'] = @sdk_configuration.user_agent
119
+
120
+ r = @sdk_configuration.client.post(url) do |req|
121
+ req.headers = headers
122
+ Utils.configure_request_security(req, @sdk_configuration.security) if !@sdk_configuration.nil? && !@sdk_configuration.security.nil?
123
+ if form
124
+ req.body = Utils.encode_form(form)
125
+ elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded')
126
+ req.body = URI.encode_www_form(data)
127
+ else
128
+ req.body = data
129
+ end
130
+ end
131
+
132
+ content_type = r.headers.fetch('Content-Type', 'application/octet-stream')
133
+
134
+ res = ::OpenApiSDK::Operations::TrackSaleResponse.new(
135
+ status_code: r.status, content_type: content_type, raw_response: r
136
+ )
137
+ if r.status == 200
138
+ if Utils.match_content_type(content_type, 'application/json')
139
+ out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Operations::TrackSaleResponseBody)
140
+ res.object = out
141
+ end
142
+ elsif r.status == 400
143
+ if Utils.match_content_type(content_type, 'application/json')
144
+ out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::BadRequest)
145
+ res.bad_request = out
146
+ end
147
+ elsif r.status == 401
148
+ if Utils.match_content_type(content_type, 'application/json')
149
+ out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::Unauthorized)
150
+ res.unauthorized = out
151
+ end
152
+ elsif r.status == 403
153
+ if Utils.match_content_type(content_type, 'application/json')
154
+ out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::Forbidden)
155
+ res.forbidden = out
156
+ end
157
+ elsif r.status == 404
158
+ if Utils.match_content_type(content_type, 'application/json')
159
+ out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::NotFound)
160
+ res.not_found = out
161
+ end
162
+ elsif r.status == 409
163
+ if Utils.match_content_type(content_type, 'application/json')
164
+ out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::Conflict)
165
+ res.conflict = out
166
+ end
167
+ elsif r.status == 410
168
+ if Utils.match_content_type(content_type, 'application/json')
169
+ out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::InviteExpired)
170
+ res.invite_expired = out
171
+ end
172
+ elsif r.status == 422
173
+ if Utils.match_content_type(content_type, 'application/json')
174
+ out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::UnprocessableEntity)
175
+ res.unprocessable_entity = out
176
+ end
177
+ elsif r.status == 429
178
+ if Utils.match_content_type(content_type, 'application/json')
179
+ out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::RateLimitExceeded)
180
+ res.rate_limit_exceeded = out
181
+ end
182
+ elsif r.status == 500
183
+ if Utils.match_content_type(content_type, 'application/json')
184
+ out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::InternalServerError)
185
+ res.internal_server_error = out
186
+ end
187
+ end
188
+ res
189
+ end
190
+
191
+
192
+ sig { params(request: T.nilable(::OpenApiSDK::Operations::TrackCustomerRequestBody)).returns(::OpenApiSDK::Operations::TrackCustomerResponse) }
193
+ def customer(request)
194
+ # customer - Track a customer
195
+ # Track a customer for an authenticated workspace.
196
+ url, params = @sdk_configuration.get_server_details
197
+ base_url = Utils.template_url(url, params)
198
+ url = "#{base_url}/track/customer"
199
+ headers = {}
200
+ req_content_type, data, form = Utils.serialize_request_body(request, :request, :json)
201
+ headers['content-type'] = req_content_type
202
+ headers['Accept'] = 'application/json'
203
+ headers['user-agent'] = @sdk_configuration.user_agent
204
+
205
+ r = @sdk_configuration.client.post(url) do |req|
206
+ req.headers = headers
207
+ Utils.configure_request_security(req, @sdk_configuration.security) if !@sdk_configuration.nil? && !@sdk_configuration.security.nil?
208
+ if form
209
+ req.body = Utils.encode_form(form)
210
+ elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded')
211
+ req.body = URI.encode_www_form(data)
212
+ else
213
+ req.body = data
214
+ end
215
+ end
216
+
217
+ content_type = r.headers.fetch('Content-Type', 'application/octet-stream')
218
+
219
+ res = ::OpenApiSDK::Operations::TrackCustomerResponse.new(
220
+ status_code: r.status, content_type: content_type, raw_response: r
221
+ )
222
+ if r.status == 200
223
+ if Utils.match_content_type(content_type, 'application/json')
224
+ out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Operations::TrackCustomerResponseBody)
225
+ res.object = out
226
+ end
227
+ elsif r.status == 400
228
+ if Utils.match_content_type(content_type, 'application/json')
229
+ out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::BadRequest)
230
+ res.bad_request = out
231
+ end
232
+ elsif r.status == 401
233
+ if Utils.match_content_type(content_type, 'application/json')
234
+ out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::Unauthorized)
235
+ res.unauthorized = out
236
+ end
237
+ elsif r.status == 403
238
+ if Utils.match_content_type(content_type, 'application/json')
239
+ out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::Forbidden)
240
+ res.forbidden = out
241
+ end
242
+ elsif r.status == 404
243
+ if Utils.match_content_type(content_type, 'application/json')
244
+ out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::NotFound)
245
+ res.not_found = out
246
+ end
247
+ elsif r.status == 409
248
+ if Utils.match_content_type(content_type, 'application/json')
249
+ out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::Conflict)
250
+ res.conflict = out
251
+ end
252
+ elsif r.status == 410
253
+ if Utils.match_content_type(content_type, 'application/json')
254
+ out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::InviteExpired)
255
+ res.invite_expired = out
256
+ end
257
+ elsif r.status == 422
258
+ if Utils.match_content_type(content_type, 'application/json')
259
+ out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::UnprocessableEntity)
260
+ res.unprocessable_entity = out
261
+ end
262
+ elsif r.status == 429
263
+ if Utils.match_content_type(content_type, 'application/json')
264
+ out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::RateLimitExceeded)
265
+ res.rate_limit_exceeded = out
266
+ end
267
+ elsif r.status == 500
268
+ if Utils.match_content_type(content_type, 'application/json')
269
+ out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::InternalServerError)
270
+ res.internal_server_error = out
271
+ end
272
+ end
273
+ res
274
+ end
275
+ end
276
+ end
@@ -0,0 +1,150 @@
1
+ # Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
2
+
3
+ # typed: true
4
+ # frozen_string_literal: true
5
+
6
+ module OpenApiSDK
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 T.nilable? field_type
66
+ field_type = T.nilable_of(field_type)
67
+ end
68
+
69
+ key = "#{field.name}="
70
+ lookup = field.metadata.fetch(:format_json, {}).fetch(:letter_case, nil).call
71
+ value = d[lookup]
72
+ next if value.nil?
73
+
74
+ if T.arr? field_type
75
+ inner_type = T.arr_of(field_type)
76
+ unmarshalled_array = value.map { |f| unmarshal_single(inner_type, f) }
77
+ to_build.send(key, unmarshalled_array)
78
+ elsif T.hash? field_type
79
+ val_type = T.hash_of(field_type)
80
+
81
+ # rubocop:disable Style/HashTransformValues
82
+ unmarshalled_hash = value.map { |k, v| [k, unmarshal_single(val_type, v)] }.to_h
83
+ # rubocop:enable Style/HashTransformValues
84
+ to_build.send(key, unmarshalled_hash)
85
+ else
86
+ decoder = field.metadata.fetch(:format_json, {}).fetch(:decoder, nil)
87
+ final_value = unmarshal_single(field_type, value, decoder)
88
+ to_build.send(key, final_value)
89
+ end
90
+ end
91
+ to_build
92
+ end
93
+ end
94
+
95
+ def initialize
96
+ instance = allocate
97
+ fields.each { |mod| instance.singleton_class.include(mod) }
98
+ instance.send(:initialize)
99
+ end
100
+
101
+ def self.included(base)
102
+ base.extend(ClassMethods)
103
+ end
104
+
105
+ def fields
106
+ self.class.fields
107
+ end
108
+
109
+ def field(field_name)
110
+ fields.each do |f|
111
+ return f if f.name == field_name
112
+ end
113
+ end
114
+
115
+ def marshal_single(field)
116
+ if field.respond_to? :marshal_json
117
+ field.marshal_json(encode: false)
118
+ else
119
+ Utils.val_to_string(field, primitives: false)
120
+ end
121
+ end
122
+
123
+ def marshal_json(encode: true)
124
+ d = {}
125
+ fields.sort_by(&:name).each do |field|
126
+ f = send(field.name)
127
+ next if f.nil?
128
+
129
+ format_json_meta = field.metadata[:format_json]
130
+ if !format_json_meta.nil? && format_json_meta.include?(:letter_case)
131
+ key = format_json_meta[:letter_case].call(field.name)
132
+ else
133
+ key = field.name
134
+ end
135
+ if f.is_a? Array
136
+ d[key] = f.map { |o| marshal_single(o) }
137
+ elsif f.is_a? Hash
138
+ d[key] = f.map { |k, v| [k, marshal_single(v)] }
139
+ else
140
+ d[key] = marshal_single(f)
141
+ end
142
+ end
143
+ if encode
144
+ JSON.dump(d)
145
+ else
146
+ d
147
+ end
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,59 @@
1
+ # Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
2
+
3
+ # typed: true
4
+ # frozen_string_literal: true
5
+
6
+ module T
7
+ def self.arr?(t)
8
+ if t.respond_to? :underlying_class
9
+ return t.underlying_class == ::Array
10
+ end
11
+ false
12
+ end
13
+
14
+ def self.arr_of(t)
15
+ get_raw_type(t.type)
16
+ end
17
+
18
+ def self.hash?(t)
19
+ if t.respond_to? :underlying_class
20
+ return t.underlying_class == ::Hash
21
+ end
22
+ false
23
+ end
24
+
25
+ def self.hash_of(t)
26
+ get_raw_type(t.values)
27
+ end
28
+
29
+ def self.nilable?(t)
30
+ t.respond_to? :unwrap_nilable
31
+ end
32
+
33
+ def self.nilable_of(t)
34
+ if t.respond_to? :unwrap_nilable
35
+ return simplify_type t.unwrap_nilable
36
+ end
37
+ nil
38
+ end
39
+
40
+ def self.simplifiable?(t)
41
+ return t.is_a? T::Types::Simple
42
+ end
43
+
44
+ def self.simplify_type(t)
45
+ if t.is_a? T::Types::Simple
46
+ return t.raw_type
47
+ end
48
+ t
49
+ end
50
+
51
+ def self.get_raw_type(t)
52
+ if t.respond_to? :raw_type
53
+ return t.raw_type
54
+ elsif t.respond_to? :raw_a
55
+ return T::Boolean if t.raw_a in [TrueClass, FalseClass]
56
+ end
57
+ t
58
+ end
59
+ end