weft-sdk 0.25.0 → 0.32.2

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.
Files changed (152) hide show
  1. checksums.yaml +4 -4
  2. data/docs/FetchApi.md +3 -3
  3. data/docs/FetchErrorResponse.md +1 -1
  4. data/docs/FetchRequest.md +6 -2
  5. data/docs/FetchResponse.md +5 -3
  6. data/docs/GetPurchaseIdParameter.md +48 -0
  7. data/docs/PaymentsApi.md +2 -0
  8. data/docs/Purchase.md +6 -0
  9. data/docs/PurchasesApi.md +2 -2
  10. data/docs/SearchApi.md +1 -1
  11. data/docs/SearchCompactAccess.md +23 -0
  12. data/docs/SearchCompactAccessPrice.md +23 -0
  13. data/docs/SearchCompactNextCall.md +23 -0
  14. data/docs/SearchCompactResult.md +47 -0
  15. data/docs/SearchCompactResultAttribution.md +21 -0
  16. data/docs/SearchCompactResultBlockedScopesInner.md +19 -0
  17. data/docs/SearchCompactResultOperation.md +21 -0
  18. data/docs/SearchCompactResultProvider.md +19 -0
  19. data/docs/SearchEndpointCall.md +1 -1
  20. data/docs/SearchEndpointCallInputSchema.md +14 -0
  21. data/docs/SearchEndpointHit.md +5 -1
  22. data/docs/SearchHelperDocs.md +23 -0
  23. data/docs/SearchRequest.md +3 -1
  24. data/docs/SearchResponse.md +9 -3
  25. data/docs/SearchWeftFetchCompatibility.md +3 -1
  26. data/docs/WebhooksApi.md +414 -0
  27. data/lib/weft/client.rb +271 -0
  28. data/lib/weft/error.rb +41 -0
  29. data/lib/weft/facilitator/client.rb +179 -42
  30. data/lib/weft/facilitator/echo.rb +99 -0
  31. data/lib/weft/facilitator/extensions.rb +183 -0
  32. data/lib/weft/facilitator/fee.rb +26 -11
  33. data/lib/weft/facilitator/handshake.rb +92 -0
  34. data/lib/weft/facilitator/json_wire.rb +74 -0
  35. data/lib/weft/facilitator/middleware.rb +562 -137
  36. data/lib/weft/facilitator/path_match.rb +179 -0
  37. data/lib/weft/facilitator/product.rb +380 -0
  38. data/lib/weft/facilitator/replay.rb +46 -0
  39. data/lib/weft/facilitator/settlement.rb +117 -0
  40. data/lib/weft/facilitator/x402.rb +355 -0
  41. data/lib/weft/generated/api/account_api.rb +2 -2
  42. data/lib/weft/generated/api/agent_bootstrap_api.rb +2 -2
  43. data/lib/weft/generated/api/api_keys_api.rb +2 -2
  44. data/lib/weft/generated/api/auth_api.rb +2 -2
  45. data/lib/weft/generated/api/balance_api.rb +2 -2
  46. data/lib/weft/generated/api/documentation_api.rb +2 -2
  47. data/lib/weft/generated/api/fetch_api.rb +6 -6
  48. data/lib/weft/generated/api/payments_api.rb +4 -2
  49. data/lib/weft/generated/api/purchases_api.rb +4 -4
  50. data/lib/weft/generated/api/resources_api.rb +2 -2
  51. data/lib/weft/generated/api/search_api.rb +4 -4
  52. data/lib/weft/generated/api/webhooks_api.rb +388 -0
  53. data/lib/weft/generated/api_client.rb +2 -2
  54. data/lib/weft/generated/api_error.rb +2 -2
  55. data/lib/weft/generated/api_model_base.rb +2 -2
  56. data/lib/weft/generated/configuration.rb +2 -2
  57. data/lib/weft/generated/models/account_bootstrap_approval.rb +2 -2
  58. data/lib/weft/generated/models/account_bootstrap_created.rb +2 -2
  59. data/lib/weft/generated/models/account_bootstrap_created_approval.rb +2 -2
  60. data/lib/weft/generated/models/account_bootstrap_created_response.rb +2 -2
  61. data/lib/weft/generated/models/account_bootstrap_request.rb +2 -2
  62. data/lib/weft/generated/models/account_bootstrap_status.rb +2 -2
  63. data/lib/weft/generated/models/account_bootstrap_status_response.rb +2 -2
  64. data/lib/weft/generated/models/account_details.rb +2 -2
  65. data/lib/weft/generated/models/api_key.rb +2 -2
  66. data/lib/weft/generated/models/api_key_created.rb +2 -2
  67. data/lib/weft/generated/models/api_key_created_response.rb +2 -2
  68. data/lib/weft/generated/models/api_key_list_response.rb +2 -2
  69. data/lib/weft/generated/models/auth_response.rb +2 -2
  70. data/lib/weft/generated/models/auth_response_data.rb +2 -2
  71. data/lib/weft/generated/models/balance_response.rb +2 -2
  72. data/lib/weft/generated/models/confirm_request.rb +2 -2
  73. data/lib/weft/generated/models/create_api_key_request.rb +2 -2
  74. data/lib/weft/generated/models/enrolled_resource.rb +2 -2
  75. data/lib/weft/generated/models/error.rb +2 -2
  76. data/lib/weft/generated/models/error_response.rb +2 -2
  77. data/lib/weft/generated/models/fetch403_response.rb +2 -2
  78. data/lib/weft/generated/models/fetch_balance_snapshot.rb +2 -2
  79. data/lib/weft/generated/models/fetch_error_response.rb +5 -5
  80. data/lib/weft/generated/models/fetch_request.rb +46 -5
  81. data/lib/weft/generated/models/fetch_request_body.rb +2 -2
  82. data/lib/weft/generated/models/fetch_response.rb +36 -64
  83. data/lib/weft/generated/models/get_purchase_id_parameter.rb +104 -0
  84. data/lib/weft/generated/models/insufficient_scope_response.rb +2 -2
  85. data/lib/weft/generated/models/me_api_key.rb +2 -2
  86. data/lib/weft/generated/models/me_api_key_creator.rb +2 -2
  87. data/lib/weft/generated/models/me_response.rb +2 -2
  88. data/lib/weft/generated/models/me_response_data.rb +2 -2
  89. data/lib/weft/generated/models/message_response.rb +2 -2
  90. data/lib/weft/generated/models/message_response_data.rb +2 -2
  91. data/lib/weft/generated/models/pagination.rb +2 -2
  92. data/lib/weft/generated/models/password_reset_request.rb +2 -2
  93. data/lib/weft/generated/models/password_update_request.rb +2 -2
  94. data/lib/weft/generated/models/payment.rb +2 -2
  95. data/lib/weft/generated/models/payment_list_response.rb +2 -2
  96. data/lib/weft/generated/models/payment_response.rb +2 -2
  97. data/lib/weft/generated/models/principal_wallet.rb +2 -2
  98. data/lib/weft/generated/models/promo_balance.rb +2 -2
  99. data/lib/weft/generated/models/purchase.rb +75 -3
  100. data/lib/weft/generated/models/purchase_artifact.rb +2 -2
  101. data/lib/weft/generated/models/purchase_list_response.rb +2 -2
  102. data/lib/weft/generated/models/purchase_response.rb +2 -2
  103. data/lib/weft/generated/models/rate_limit_response.rb +2 -2
  104. data/lib/weft/generated/models/resend_confirmation_request.rb +2 -2
  105. data/lib/weft/generated/models/resource_enrollment_request.rb +2 -2
  106. data/lib/weft/generated/models/resource_enrollment_response.rb +2 -2
  107. data/lib/weft/generated/models/resource_stats.rb +2 -2
  108. data/lib/weft/generated/models/search_access_method.rb +2 -2
  109. data/lib/weft/generated/models/search_capability_ref.rb +2 -2
  110. data/lib/weft/generated/models/search_compact_access.rb +179 -0
  111. data/lib/weft/generated/models/search_compact_access_price.rb +176 -0
  112. data/lib/weft/generated/models/search_compact_next_call.rb +275 -0
  113. data/lib/weft/generated/models/search_compact_result.rb +389 -0
  114. data/lib/weft/generated/models/search_compact_result_attribution.rb +166 -0
  115. data/lib/weft/generated/models/search_compact_result_blocked_scopes_inner.rb +156 -0
  116. data/lib/weft/generated/models/search_compact_result_operation.rb +183 -0
  117. data/lib/weft/generated/models/search_compact_result_provider.rb +156 -0
  118. data/lib/weft/generated/models/search_curated_callability.rb +2 -2
  119. data/lib/weft/generated/models/search_curated_execution.rb +2 -2
  120. data/lib/weft/generated/models/search_curated_operation.rb +2 -2
  121. data/lib/weft/generated/models/search_curated_service.rb +2 -2
  122. data/lib/weft/generated/models/search_curated_source.rb +2 -2
  123. data/lib/weft/generated/models/search_endpoint_call.rb +4 -4
  124. data/lib/weft/generated/models/search_endpoint_call_input_schema.rb +103 -0
  125. data/lib/weft/generated/models/search_endpoint_hit.rb +25 -6
  126. data/lib/weft/generated/models/search_endpoint_price.rb +2 -2
  127. data/lib/weft/generated/models/search_error_response.rb +4 -4
  128. data/lib/weft/generated/models/search_execution_mode_filter.rb +2 -2
  129. data/lib/weft/generated/models/search_filter_spec.rb +2 -2
  130. data/lib/weft/generated/models/search_helper_docs.rb +175 -0
  131. data/lib/weft/generated/models/search_method_filter.rb +2 -2
  132. data/lib/weft/generated/models/search_payment_offer.rb +2 -2
  133. data/lib/weft/generated/models/search_price_atomic_filter.rb +2 -2
  134. data/lib/weft/generated/models/search_price_usd_filter.rb +2 -2
  135. data/lib/weft/generated/models/search_protocol_filter.rb +2 -2
  136. data/lib/weft/generated/models/search_provider_ref.rb +2 -2
  137. data/lib/weft/generated/models/search_request.rb +50 -6
  138. data/lib/weft/generated/models/search_resource_type_filter.rb +2 -2
  139. data/lib/weft/generated/models/search_response.rb +71 -8
  140. data/lib/weft/generated/models/search_response_warnings_inner.rb +2 -2
  141. data/lib/weft/generated/models/search_result.rb +2 -2
  142. data/lib/weft/generated/models/search_string_set_filter.rb +2 -2
  143. data/lib/weft/generated/models/search_weft_fetch_compatibility.rb +28 -6
  144. data/lib/weft/generated/models/sign_in_request.rb +2 -2
  145. data/lib/weft/generated/models/sign_up_request.rb +2 -2
  146. data/lib/weft/generated/models/spending_policy.rb +2 -2
  147. data/lib/weft/generated/models/user.rb +2 -2
  148. data/lib/weft/generated/models/user_principal.rb +2 -2
  149. data/lib/weft/generated/models/wallet.rb +2 -2
  150. data/lib/weft/generated/version.rb +3 -3
  151. data/lib/weft/sdk.rb +3 -1
  152. metadata +39 -4
@@ -0,0 +1,414 @@
1
+ # Weft::WebhooksApi
2
+
3
+ All URIs are relative to *https://weft.network*
4
+
5
+ | Method | HTTP request | Description |
6
+ | ------ | ------------ | ----------- |
7
+ | [**create_webhook_endpoint**](WebhooksApi.md#create_webhook_endpoint) | **POST** /api/v1/webhook_endpoints | Create a webhook endpoint |
8
+ | [**delete_webhook_endpoint**](WebhooksApi.md#delete_webhook_endpoint) | **DELETE** /api/v1/webhook_endpoints/{id} | Delete a webhook endpoint |
9
+ | [**get_webhook_endpoint**](WebhooksApi.md#get_webhook_endpoint) | **GET** /api/v1/webhook_endpoints/{id} | Get a webhook endpoint |
10
+ | [**list_webhook_endpoints**](WebhooksApi.md#list_webhook_endpoints) | **GET** /api/v1/webhook_endpoints | List webhook endpoints |
11
+ | [**replace_webhook_endpoint**](WebhooksApi.md#replace_webhook_endpoint) | **PUT** /api/v1/webhook_endpoints/{id} | Replace a webhook endpoint |
12
+ | [**update_webhook_endpoint**](WebhooksApi.md#update_webhook_endpoint) | **PATCH** /api/v1/webhook_endpoints/{id} | Update a webhook endpoint |
13
+
14
+
15
+ ## create_webhook_endpoint
16
+
17
+ > create_webhook_endpoint
18
+
19
+ Create a webhook endpoint
20
+
21
+ Retired. Returns HTTP 410 with error code `gone`. The body is ignored.
22
+
23
+ ### Examples
24
+
25
+ ```ruby
26
+ require 'time'
27
+ require 'weft-sdk'
28
+ # setup authorization
29
+ Weft.configure do |config|
30
+ # Configure Bearer authorization (APIKey): bearerAuth
31
+ config.access_token = 'YOUR_BEARER_TOKEN'
32
+ end
33
+
34
+ api_instance = Weft::WebhooksApi.new
35
+
36
+ begin
37
+ # Create a webhook endpoint
38
+ api_instance.create_webhook_endpoint
39
+ rescue Weft::ApiError => e
40
+ puts "Error when calling WebhooksApi->create_webhook_endpoint: #{e}"
41
+ end
42
+ ```
43
+
44
+ #### Using the create_webhook_endpoint_with_http_info variant
45
+
46
+ This returns an Array which contains the response data (`nil` in this case), status code and headers.
47
+
48
+ > <Array(nil, Integer, Hash)> create_webhook_endpoint_with_http_info
49
+
50
+ ```ruby
51
+ begin
52
+ # Create a webhook endpoint
53
+ data, status_code, headers = api_instance.create_webhook_endpoint_with_http_info
54
+ p status_code # => 2xx
55
+ p headers # => { ... }
56
+ p data # => nil
57
+ rescue Weft::ApiError => e
58
+ puts "Error when calling WebhooksApi->create_webhook_endpoint_with_http_info: #{e}"
59
+ end
60
+ ```
61
+
62
+ ### Parameters
63
+
64
+ This endpoint does not need any parameter.
65
+
66
+ ### Return type
67
+
68
+ nil (empty response body)
69
+
70
+ ### Authorization
71
+
72
+ [bearerAuth](../README.md#bearerAuth)
73
+
74
+ ### HTTP request headers
75
+
76
+ - **Content-Type**: Not defined
77
+ - **Accept**: application/json
78
+
79
+
80
+ ## delete_webhook_endpoint
81
+
82
+ > delete_webhook_endpoint(id)
83
+
84
+ Delete a webhook endpoint
85
+
86
+ Retired. Returns HTTP 410 with error code `gone`. Stored rows are kept.
87
+
88
+ ### Examples
89
+
90
+ ```ruby
91
+ require 'time'
92
+ require 'weft-sdk'
93
+ # setup authorization
94
+ Weft.configure do |config|
95
+ # Configure Bearer authorization (APIKey): bearerAuth
96
+ config.access_token = 'YOUR_BEARER_TOKEN'
97
+ end
98
+
99
+ api_instance = Weft::WebhooksApi.new
100
+ id = 56 # Integer | Webhook endpoint ID. Ignored. The response is always HTTP 410.
101
+
102
+ begin
103
+ # Delete a webhook endpoint
104
+ api_instance.delete_webhook_endpoint(id)
105
+ rescue Weft::ApiError => e
106
+ puts "Error when calling WebhooksApi->delete_webhook_endpoint: #{e}"
107
+ end
108
+ ```
109
+
110
+ #### Using the delete_webhook_endpoint_with_http_info variant
111
+
112
+ This returns an Array which contains the response data (`nil` in this case), status code and headers.
113
+
114
+ > <Array(nil, Integer, Hash)> delete_webhook_endpoint_with_http_info(id)
115
+
116
+ ```ruby
117
+ begin
118
+ # Delete a webhook endpoint
119
+ data, status_code, headers = api_instance.delete_webhook_endpoint_with_http_info(id)
120
+ p status_code # => 2xx
121
+ p headers # => { ... }
122
+ p data # => nil
123
+ rescue Weft::ApiError => e
124
+ puts "Error when calling WebhooksApi->delete_webhook_endpoint_with_http_info: #{e}"
125
+ end
126
+ ```
127
+
128
+ ### Parameters
129
+
130
+ | Name | Type | Description | Notes |
131
+ | ---- | ---- | ----------- | ----- |
132
+ | **id** | **Integer** | Webhook endpoint ID. Ignored. The response is always HTTP 410. | |
133
+
134
+ ### Return type
135
+
136
+ nil (empty response body)
137
+
138
+ ### Authorization
139
+
140
+ [bearerAuth](../README.md#bearerAuth)
141
+
142
+ ### HTTP request headers
143
+
144
+ - **Content-Type**: Not defined
145
+ - **Accept**: application/json
146
+
147
+
148
+ ## get_webhook_endpoint
149
+
150
+ > get_webhook_endpoint(id)
151
+
152
+ Get a webhook endpoint
153
+
154
+ Retired. Returns HTTP 410 with error code `gone`.
155
+
156
+ ### Examples
157
+
158
+ ```ruby
159
+ require 'time'
160
+ require 'weft-sdk'
161
+ # setup authorization
162
+ Weft.configure do |config|
163
+ # Configure Bearer authorization (APIKey): bearerAuth
164
+ config.access_token = 'YOUR_BEARER_TOKEN'
165
+ end
166
+
167
+ api_instance = Weft::WebhooksApi.new
168
+ id = 56 # Integer | Webhook endpoint ID. Ignored. The response is always HTTP 410.
169
+
170
+ begin
171
+ # Get a webhook endpoint
172
+ api_instance.get_webhook_endpoint(id)
173
+ rescue Weft::ApiError => e
174
+ puts "Error when calling WebhooksApi->get_webhook_endpoint: #{e}"
175
+ end
176
+ ```
177
+
178
+ #### Using the get_webhook_endpoint_with_http_info variant
179
+
180
+ This returns an Array which contains the response data (`nil` in this case), status code and headers.
181
+
182
+ > <Array(nil, Integer, Hash)> get_webhook_endpoint_with_http_info(id)
183
+
184
+ ```ruby
185
+ begin
186
+ # Get a webhook endpoint
187
+ data, status_code, headers = api_instance.get_webhook_endpoint_with_http_info(id)
188
+ p status_code # => 2xx
189
+ p headers # => { ... }
190
+ p data # => nil
191
+ rescue Weft::ApiError => e
192
+ puts "Error when calling WebhooksApi->get_webhook_endpoint_with_http_info: #{e}"
193
+ end
194
+ ```
195
+
196
+ ### Parameters
197
+
198
+ | Name | Type | Description | Notes |
199
+ | ---- | ---- | ----------- | ----- |
200
+ | **id** | **Integer** | Webhook endpoint ID. Ignored. The response is always HTTP 410. | |
201
+
202
+ ### Return type
203
+
204
+ nil (empty response body)
205
+
206
+ ### Authorization
207
+
208
+ [bearerAuth](../README.md#bearerAuth)
209
+
210
+ ### HTTP request headers
211
+
212
+ - **Content-Type**: Not defined
213
+ - **Accept**: application/json
214
+
215
+
216
+ ## list_webhook_endpoints
217
+
218
+ > list_webhook_endpoints
219
+
220
+ List webhook endpoints
221
+
222
+ Retired. Returns HTTP 410 with error code `gone`.
223
+
224
+ ### Examples
225
+
226
+ ```ruby
227
+ require 'time'
228
+ require 'weft-sdk'
229
+ # setup authorization
230
+ Weft.configure do |config|
231
+ # Configure Bearer authorization (APIKey): bearerAuth
232
+ config.access_token = 'YOUR_BEARER_TOKEN'
233
+ end
234
+
235
+ api_instance = Weft::WebhooksApi.new
236
+
237
+ begin
238
+ # List webhook endpoints
239
+ api_instance.list_webhook_endpoints
240
+ rescue Weft::ApiError => e
241
+ puts "Error when calling WebhooksApi->list_webhook_endpoints: #{e}"
242
+ end
243
+ ```
244
+
245
+ #### Using the list_webhook_endpoints_with_http_info variant
246
+
247
+ This returns an Array which contains the response data (`nil` in this case), status code and headers.
248
+
249
+ > <Array(nil, Integer, Hash)> list_webhook_endpoints_with_http_info
250
+
251
+ ```ruby
252
+ begin
253
+ # List webhook endpoints
254
+ data, status_code, headers = api_instance.list_webhook_endpoints_with_http_info
255
+ p status_code # => 2xx
256
+ p headers # => { ... }
257
+ p data # => nil
258
+ rescue Weft::ApiError => e
259
+ puts "Error when calling WebhooksApi->list_webhook_endpoints_with_http_info: #{e}"
260
+ end
261
+ ```
262
+
263
+ ### Parameters
264
+
265
+ This endpoint does not need any parameter.
266
+
267
+ ### Return type
268
+
269
+ nil (empty response body)
270
+
271
+ ### Authorization
272
+
273
+ [bearerAuth](../README.md#bearerAuth)
274
+
275
+ ### HTTP request headers
276
+
277
+ - **Content-Type**: Not defined
278
+ - **Accept**: application/json
279
+
280
+
281
+ ## replace_webhook_endpoint
282
+
283
+ > replace_webhook_endpoint(id)
284
+
285
+ Replace a webhook endpoint
286
+
287
+ Retired. Returns HTTP 410 with error code `gone`. The body is ignored.
288
+
289
+ ### Examples
290
+
291
+ ```ruby
292
+ require 'time'
293
+ require 'weft-sdk'
294
+ # setup authorization
295
+ Weft.configure do |config|
296
+ # Configure Bearer authorization (APIKey): bearerAuth
297
+ config.access_token = 'YOUR_BEARER_TOKEN'
298
+ end
299
+
300
+ api_instance = Weft::WebhooksApi.new
301
+ id = 56 # Integer | Webhook endpoint ID. Ignored. The response is always HTTP 410.
302
+
303
+ begin
304
+ # Replace a webhook endpoint
305
+ api_instance.replace_webhook_endpoint(id)
306
+ rescue Weft::ApiError => e
307
+ puts "Error when calling WebhooksApi->replace_webhook_endpoint: #{e}"
308
+ end
309
+ ```
310
+
311
+ #### Using the replace_webhook_endpoint_with_http_info variant
312
+
313
+ This returns an Array which contains the response data (`nil` in this case), status code and headers.
314
+
315
+ > <Array(nil, Integer, Hash)> replace_webhook_endpoint_with_http_info(id)
316
+
317
+ ```ruby
318
+ begin
319
+ # Replace a webhook endpoint
320
+ data, status_code, headers = api_instance.replace_webhook_endpoint_with_http_info(id)
321
+ p status_code # => 2xx
322
+ p headers # => { ... }
323
+ p data # => nil
324
+ rescue Weft::ApiError => e
325
+ puts "Error when calling WebhooksApi->replace_webhook_endpoint_with_http_info: #{e}"
326
+ end
327
+ ```
328
+
329
+ ### Parameters
330
+
331
+ | Name | Type | Description | Notes |
332
+ | ---- | ---- | ----------- | ----- |
333
+ | **id** | **Integer** | Webhook endpoint ID. Ignored. The response is always HTTP 410. | |
334
+
335
+ ### Return type
336
+
337
+ nil (empty response body)
338
+
339
+ ### Authorization
340
+
341
+ [bearerAuth](../README.md#bearerAuth)
342
+
343
+ ### HTTP request headers
344
+
345
+ - **Content-Type**: Not defined
346
+ - **Accept**: application/json
347
+
348
+
349
+ ## update_webhook_endpoint
350
+
351
+ > update_webhook_endpoint(id)
352
+
353
+ Update a webhook endpoint
354
+
355
+ Retired. Returns HTTP 410 with error code `gone`. The body is ignored.
356
+
357
+ ### Examples
358
+
359
+ ```ruby
360
+ require 'time'
361
+ require 'weft-sdk'
362
+ # setup authorization
363
+ Weft.configure do |config|
364
+ # Configure Bearer authorization (APIKey): bearerAuth
365
+ config.access_token = 'YOUR_BEARER_TOKEN'
366
+ end
367
+
368
+ api_instance = Weft::WebhooksApi.new
369
+ id = 56 # Integer | Webhook endpoint ID. Ignored. The response is always HTTP 410.
370
+
371
+ begin
372
+ # Update a webhook endpoint
373
+ api_instance.update_webhook_endpoint(id)
374
+ rescue Weft::ApiError => e
375
+ puts "Error when calling WebhooksApi->update_webhook_endpoint: #{e}"
376
+ end
377
+ ```
378
+
379
+ #### Using the update_webhook_endpoint_with_http_info variant
380
+
381
+ This returns an Array which contains the response data (`nil` in this case), status code and headers.
382
+
383
+ > <Array(nil, Integer, Hash)> update_webhook_endpoint_with_http_info(id)
384
+
385
+ ```ruby
386
+ begin
387
+ # Update a webhook endpoint
388
+ data, status_code, headers = api_instance.update_webhook_endpoint_with_http_info(id)
389
+ p status_code # => 2xx
390
+ p headers # => { ... }
391
+ p data # => nil
392
+ rescue Weft::ApiError => e
393
+ puts "Error when calling WebhooksApi->update_webhook_endpoint_with_http_info: #{e}"
394
+ end
395
+ ```
396
+
397
+ ### Parameters
398
+
399
+ | Name | Type | Description | Notes |
400
+ | ---- | ---- | ----------- | ----- |
401
+ | **id** | **Integer** | Webhook endpoint ID. Ignored. The response is always HTTP 410. | |
402
+
403
+ ### Return type
404
+
405
+ nil (empty response body)
406
+
407
+ ### Authorization
408
+
409
+ [bearerAuth](../README.md#bearerAuth)
410
+
411
+ ### HTTP request headers
412
+
413
+ - **Content-Type**: Not defined
414
+ - **Accept**: application/json
@@ -0,0 +1,271 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ require_relative 'error'
6
+ require_relative 'generated'
7
+
8
+ module Weft
9
+ # Buyer façade over the generated API client.
10
+ class Client
11
+ def initialize(api_key: nil, access_token: nil, base_url: 'https://weft.network')
12
+ if !api_key.nil? && !access_token.nil?
13
+ raise ArgumentError, 'api_key and access_token are mutually exclusive'
14
+ end
15
+
16
+ raw = api_key.nil? ? access_token : api_key
17
+ credential = raw.is_a?(String) ? raw.strip : ''
18
+ if credential.empty?
19
+ raise ArgumentError, credential_error(api_key, access_token)
20
+ end
21
+
22
+ configuration = Configuration.new
23
+ apply_base_url(configuration, base_url)
24
+ configuration.access_token = credential
25
+ @api_client = ApiClient.new(configuration)
26
+ @account = AccountApi.new(@api_client)
27
+ @balance = BalanceApi.new(@api_client)
28
+ @search = SearchApi.new(@api_client)
29
+ @fetch = FetchApi.new(@api_client)
30
+ @purchases = PurchasesApi.new(@api_client)
31
+ end
32
+
33
+ def me
34
+ call { @account.get_me }
35
+ end
36
+
37
+ def balance
38
+ call { @balance.get_balance }
39
+ end
40
+
41
+ def search(query:, max_results: nil, filters: nil)
42
+ request = SearchRequest.new(query: query)
43
+ if max_results.nil?
44
+ request.remove_instance_variable(:@max_results)
45
+ else
46
+ request.max_results = max_results
47
+ end
48
+ request.filters = search_filters(filters) unless filters.nil?
49
+ call { @search.search(request) }
50
+ end
51
+
52
+ def fetch(url:, max_cost_usd:, idempotency_key:, method: nil, body: nil, headers: nil,
53
+ search_id: nil, operation_id: nil, access_method_id: nil)
54
+ raise ArgumentError, 'max_cost_usd is required' if max_cost_usd.to_s.strip.empty?
55
+ raise ArgumentError, 'idempotency_key is required' if idempotency_key.to_s.strip.empty?
56
+ # Weft's limit. Checked here so a bad key never looks like a paid failure.
57
+ unless idempotency_key.to_s.match?(/\A[!-~]{1,255}\z/)
58
+ raise ArgumentError, 'idempotency_key must be 1-255 visible ASCII characters without spaces'
59
+ end
60
+
61
+ fields = {
62
+ url: url,
63
+ max_cost_usd: max_cost_usd,
64
+ method: method.nil? ? nil : method.to_s.upcase
65
+ }
66
+ fields[:body] = fetch_body(body) unless body.nil?
67
+ fields[:headers] = headers.transform_keys(&:to_s) unless headers.nil?
68
+ fields[:search_id] = search_id unless search_id.nil?
69
+ fields[:operation_id] = operation_id unless operation_id.nil?
70
+ fields[:access_method_id] = access_method_id unless access_method_id.nil?
71
+ request = FetchRequest.new(fields)
72
+ response = call(paid: true) { @fetch.fetch(request, idempotency_key: idempotency_key) }
73
+ # A 2xx without a fetch result body: the fetch most likely paid.
74
+ raise decode_error if response.nil?
75
+
76
+ response
77
+ end
78
+
79
+ def purchases(page: nil, per_page: nil)
80
+ call { @purchases.list_purchases(page: page, per_page: per_page) }
81
+ end
82
+
83
+ def purchase(id)
84
+ call { @purchases.get_purchase(id) }
85
+ end
86
+
87
+ private
88
+
89
+ def call(paid: false)
90
+ yield
91
+ rescue ApiError => e
92
+ raise normalize_api_error(e, paid: paid)
93
+ rescue StandardError => e
94
+ raise if !paid || e.is_a?(RequestError)
95
+
96
+ # Weft answered 2xx, so the fetch most likely paid, but the body did not decode.
97
+ raise decode_error
98
+ end
99
+
100
+ # A replay returns the same body; reconcile instead of retrying.
101
+ def decode_error
102
+ RequestError.new(
103
+ status: 0,
104
+ code: 'RESPONSE_DECODE_ERROR',
105
+ message: 'Weft API returned a fetch response that could not be decoded',
106
+ retryable: false,
107
+ charge: 'possible'
108
+ )
109
+ end
110
+
111
+ def credential_error(api_key, access_token)
112
+ return 'api_key is required' unless api_key.nil?
113
+ return 'access_token is required' unless access_token.nil?
114
+
115
+ 'api_key or access_token is required'
116
+ end
117
+
118
+ def apply_base_url(configuration, base_url)
119
+ stripped = trim_trailing_slashes(base_url.to_s)
120
+ uri = URI.parse(stripped)
121
+ configuration.scheme = uri.scheme || 'https'
122
+ configuration.host = uri.host || trim_trailing_slashes(stripped)
123
+ path = collapse_slashes(uri.path.to_s)
124
+ path = trim_trailing_slashes(path)
125
+ path = strip_leading_slashes(path)
126
+ configuration.base_path = path
127
+ end
128
+
129
+ def trim_trailing_slashes(value)
130
+ text = value.dup
131
+ text.chomp!('/') while text.end_with?('/')
132
+ text
133
+ end
134
+
135
+ def strip_leading_slashes(value)
136
+ index = 0
137
+ index += 1 while index < value.length && value[index] == '/'
138
+ index.zero? ? value : value[index..]
139
+ end
140
+
141
+ def collapse_slashes(value)
142
+ out = +''
143
+ previous_slash = false
144
+ value.each_char do |char|
145
+ if char == '/'
146
+ out << '/' unless previous_slash
147
+ previous_slash = true
148
+ else
149
+ out << char
150
+ previous_slash = false
151
+ end
152
+ end
153
+ out
154
+ end
155
+
156
+ def search_filters(value)
157
+ mapped = map_filters(value)
158
+ spec = SearchFilterSpec.new(mapped)
159
+ spec.include_unknown_prices = nil unless mapped.key?(:include_unknown_prices)
160
+ spec
161
+ end
162
+
163
+ def map_filters(value)
164
+ table = {
165
+ 'price' => :price,
166
+ 'priceAtomic' => :price_atomic,
167
+ 'type' => :type,
168
+ 'protocol' => :protocol,
169
+ 'category' => :category,
170
+ 'method' => :method,
171
+ 'executionMode' => :execution_mode,
172
+ 'weftFetchCompatible' => :weft_fetch_compatible,
173
+ 'includeUnknownPrices' => :include_unknown_prices
174
+ }
175
+ nested = %i[price price_atomic type protocol category method execution_mode]
176
+ operators = {
177
+ 'lte' => :lte,
178
+ 'gte' => :gte,
179
+ 'eq' => :eq,
180
+ 'in' => :in,
181
+ 'rangeGte' => :range_gte,
182
+ 'rangeLte' => :range_lte
183
+ }
184
+ mapped = map_keys(value, table)
185
+ nested.each do |name|
186
+ child = mapped[name]
187
+ next unless child.is_a?(Hash)
188
+
189
+ mapped[name] = map_keys(child, operators)
190
+ end
191
+ mapped
192
+ end
193
+
194
+ def map_keys(source, table)
195
+ source.each_with_object({}) do |(key, item), out|
196
+ mapped = table[key.to_s] || table[key.to_sym]
197
+ raise ArgumentError, "unmapped field #{key}" if mapped.nil?
198
+
199
+ out[mapped] = item
200
+ end
201
+ end
202
+
203
+ def fetch_body(value)
204
+ return value if value.is_a?(String)
205
+
206
+ JSON.generate(json_null_non_finite(value))
207
+ end
208
+
209
+ def json_null_non_finite(value)
210
+ case value
211
+ when Float
212
+ value.finite? ? value : nil
213
+ when Hash
214
+ value.each_with_object({}) { |(key, item), out| out[key] = json_null_non_finite(item) }
215
+ when Array
216
+ value.map { |item| json_null_non_finite(item) }
217
+ else
218
+ value
219
+ end
220
+ end
221
+
222
+ def normalize_api_error(error, paid:)
223
+ if error.code.to_i.zero? && !error.response_body
224
+ cause = error.instance_variable_get(:@message).to_s
225
+ cause = 'connection reset' if cause.empty?
226
+ return RequestError.new(
227
+ status: 0,
228
+ code: 'NETWORK_ERROR',
229
+ message: "Network failure before a Weft API response: #{cause}",
230
+ request_id: nil,
231
+ retryable: true,
232
+ details: nil,
233
+ charge: paid ? 'possible' : 'none'
234
+ )
235
+ end
236
+
237
+ details = parse_details(error.response_body)
238
+ body = details.is_a?(Hash) ? details : nil
239
+ nested = body && body['error'].is_a?(Hash) ? body['error'] : nil
240
+ status = error.code.to_i
241
+ code = nested&.[]('code') || body&.[]('code') || (body && body['error'].is_a?(String) ? body['error'] : "HTTP_#{status}")
242
+ RequestError.new(
243
+ status: status,
244
+ code: code,
245
+ message: nested&.[]('message') || body&.[]('message') || "Weft API returned HTTP #{status}",
246
+ request_id: nested&.[]('request_id') || body&.[]('request_id') || header_request_id(error),
247
+ retryable: status == 429 || status >= 500,
248
+ details: details,
249
+ charge: paid ? RequestError.fetch_charge(status, code) : 'none'
250
+ )
251
+ end
252
+
253
+ def parse_details(body)
254
+ return nil if body.nil? || body.empty?
255
+
256
+ parsed = JSON.parse(body)
257
+ parsed.is_a?(Hash) || parsed.is_a?(Array) ? parsed : nil
258
+ rescue JSON::ParserError
259
+ nil
260
+ end
261
+
262
+ def header_request_id(error)
263
+ headers = error.response_headers
264
+ return nil unless headers.respond_to?(:each)
265
+
266
+ pair = headers.find { |name, _| name.to_s.casecmp?('x-request-id') }
267
+ value = pair&.last
268
+ value.is_a?(Array) ? value.first : value
269
+ end
270
+ end
271
+ end