Class: Weft::FetchApi
- Inherits:
-
Object
- Object
- Weft::FetchApi
- Defined in:
- lib/weft/generated/api/fetch_api.rb
Instance Attribute Summary collapse
-
#api_client ⇒ Object
Returns the value of attribute api_client.
Instance Method Summary collapse
-
#fetch(fetch_request, opts = {}) ⇒ FetchResponse
Pay-and-fetch any URL (x402 proxy) Universal x402 fetch proxy.
-
#fetch_with_http_info(fetch_request, opts = {}) ⇒ Array<(FetchResponse, Integer, Hash)>
Pay-and-fetch any URL (x402 proxy) Universal x402 fetch proxy.
-
#initialize(api_client = ApiClient.default) ⇒ FetchApi
constructor
A new instance of FetchApi.
Constructor Details
Instance Attribute Details
#api_client ⇒ Object
Returns the value of attribute api_client.
17 18 19 |
# File 'lib/weft/generated/api/fetch_api.rb', line 17 def api_client @api_client end |
Instance Method Details
#fetch(fetch_request, opts = {}) ⇒ FetchResponse
Pay-and-fetch any URL (x402 proxy) Universal x402 fetch proxy. The caller provides a target ‘url`, a hard `max_cost_usd` ceiling, and optional `method` / `body` / `headers`. Weft: 1. Issues the request. 2. On `402 Payment Required`, parses the merchant’s challenge. 3. Compares the asking price to ‘max_cost_usd` and the buyer’s policy (‘max_tx_usd`, daily/weekly limits). 4. Signs an EIP-3009 transfer from the buyer’s wallet. 5. Replays the request with the ‘X-Payment` header. 6. Streams the upstream artifact back, base64-encoded under `body_base64`, with `paid_usd`, `tx_hash`, and the merchant’s reputation snapshot. Errors are structured with a stable ‘error` code, and each error response carries the buyer’s ‘policy`, `balance`, and a `dashboard_url` so a CLI can render an actionable message without a second round-trip. Account-scoped: the bearer must be a buyer-scoped API key. **Forwarded headers:** the caller’s ‘headers` are passed through to the upstream, except a denylist of hop-by-hop and Weft-internal headers (`host`, `authorization`, `cookie`, `proxy-authorization`, `x-forwarded-*`, `x-real-ip`, `x-payment`, `connection`, `upgrade`). Up to 32 headers, 4 KB of combined value bytes.
27 28 29 30 |
# File 'lib/weft/generated/api/fetch_api.rb', line 27 def fetch(fetch_request, opts = {}) data, _status_code, _headers = fetch_with_http_info(fetch_request, opts) data end |
#fetch_with_http_info(fetch_request, opts = {}) ⇒ Array<(FetchResponse, Integer, Hash)>
Pay-and-fetch any URL (x402 proxy) Universal x402 fetch proxy. The caller provides a target `url`, a hard `max_cost_usd` ceiling, and optional `method` / `body` / `headers`. Weft: 1. Issues the request. 2. On `402 Payment Required`, parses the merchant's challenge. 3. Compares the asking price to `max_cost_usd` and the buyer's policy (`max_tx_usd`, daily/weekly limits). 4. Signs an EIP-3009 transfer from the buyer's wallet. 5. Replays the request with the `X-Payment` header. 6. Streams the upstream artifact back, base64-encoded under `body_base64`, with `paid_usd`, `tx_hash`, and the merchant's reputation snapshot. Errors are structured with a stable `error` code, and each error response carries the buyer's `policy`, `balance`, and a `dashboard_url` so a CLI can render an actionable message without a second round-trip. Account-scoped: the bearer must be a buyer-scoped API key. **Forwarded headers:** the caller's `headers` are passed through to the upstream, except a denylist of hop-by-hop and Weft-internal headers (`host`, `authorization`, `cookie`, `proxy-authorization`, `x-forwarded-*`, `x-real-ip`, `x-payment`, `connection`, `upgrade`). Up to 32 headers, 4 KB of combined value bytes.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/weft/generated/api/fetch_api.rb', line 37 def fetch_with_http_info(fetch_request, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: FetchApi.fetch ...' end # verify the required parameter 'fetch_request' is set if @api_client.config.client_side_validation && fetch_request.nil? fail ArgumentError, "Missing the required parameter 'fetch_request' when calling FetchApi.fetch" end # resource path local_var_path = '/api/v1/fetch' # query parameters query_params = opts[:query_params] || {} # header parameters header_params = opts[:header_params] || {} # HTTP header 'Accept' (if needed) header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept'] # HTTP header 'Content-Type' content_type = @api_client.select_header_content_type(['application/json']) if !content_type.nil? header_params['Content-Type'] = content_type end # form parameters form_params = opts[:form_params] || {} # http body (model) post_body = opts[:debug_body] || @api_client.object_to_http_body(fetch_request) # return_type return_type = opts[:debug_return_type] || 'FetchResponse' # auth_names auth_names = opts[:debug_auth_names] || ['bearerAuth'] = opts.merge( :operation => :"FetchApi.fetch", :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, :auth_names => auth_names, :return_type => return_type ) data, status_code, headers = @api_client.call_api(:POST, local_var_path, ) if @api_client.config.debugging @api_client.config.logger.debug "API called: FetchApi#fetch\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end |