Class: AxHub::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/axhub_sdk/data.rb,
lib/axhub_sdk.rb,
lib/axhub_sdk/operations.rb

Overview

— Ergonomic data layer fluent surface (mirrors node client.tenant().app().data) — ‘client.data` stays the operation-id route-table OperationClient (the conformance vectors + e2e tests depend on it). The ergonomic data layer is reached only through the tenant/app fluent chain, exactly as in node/python.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, **kwargs) ⇒ Client

Returns a new instance of Client.



274
275
276
# File 'lib/axhub_sdk.rb', line 274

def initialize(base_url: DEFAULT_BASE_URL, token: nil, token_type: nil, default_tenant_id: nil, default_tenant_slug: nil, timeout_seconds: 10)
  @base_url = base_url.sub(%r{/$}, ''); @token = token; @token_type = token_type&.to_sym; @default_tenant_id = default_tenant_id; @default_tenant_slug = default_tenant_slug; @timeout_seconds = timeout_seconds; @apps = AppsClient.new(self)
end

Instance Attribute Details

#appsObject (readonly)

Returns the value of attribute apps.



273
274
275
# File 'lib/axhub_sdk.rb', line 273

def apps
  @apps
end

#auditObject (readonly)

Returns the value of attribute audit.



19
20
21
# File 'lib/axhub_sdk/operations.rb', line 19

def audit
  @audit
end

#authzObject (readonly)

Returns the value of attribute authz.



19
20
21
# File 'lib/axhub_sdk/operations.rb', line 19

def authz
  @authz
end

#base_urlObject (readonly)

Returns the value of attribute base_url.



273
274
275
# File 'lib/axhub_sdk.rb', line 273

def base_url
  @base_url
end

#costObject (readonly)

Returns the value of attribute cost.



19
20
21
# File 'lib/axhub_sdk/operations.rb', line 19

def cost
  @cost
end

#dataObject (readonly)

Returns the value of attribute data.



19
20
21
# File 'lib/axhub_sdk/operations.rb', line 19

def data
  @data
end

#deploymentsObject (readonly)

Returns the value of attribute deployments.



19
20
21
# File 'lib/axhub_sdk/operations.rb', line 19

def deployments
  @deployments
end

#gatewayObject (readonly)

Returns the value of attribute gateway.



19
20
21
# File 'lib/axhub_sdk/operations.rb', line 19

def gateway
  @gateway
end

#identityObject (readonly)

Returns the value of attribute identity.



19
20
21
# File 'lib/axhub_sdk/operations.rb', line 19

def identity
  @identity
end

#tenantsObject (readonly)

Returns the value of attribute tenants.



19
20
21
# File 'lib/axhub_sdk/operations.rb', line 19

def tenants
  @tenants
end

Instance Method Details

#__axhub_original_initializeClient

Returns a new instance of Client.

Returns:

  • (Client)

    a new instance of Client



20
21
22
# File 'lib/axhub_sdk/operations.rb', line 20

def initialize(base_url: DEFAULT_BASE_URL, token: nil, token_type: nil, default_tenant_id: nil, default_tenant_slug: nil, timeout_seconds: 10)
  @base_url = base_url.sub(%r{/$}, ''); @token = token; @token_type = token_type&.to_sym; @default_tenant_id = default_tenant_id; @default_tenant_slug = default_tenant_slug; @timeout_seconds = timeout_seconds; @apps = AppsClient.new(self)
end

#ergo_dataObject

The single per-client ergonomic DataClient, lazily memoized so the schema cache (TTL/negative-TTL/LRU) survives across tenant().app() chains (mirrors node, where ‘data` is one per-SDK DataClient).



59
60
61
# File 'lib/axhub_sdk/data.rb', line 59

def ergo_data
  @ergo_data ||= AxHub::Data::DataClient.new(self, schema_cache: @schema_cache_opt)
end

#redacted_tokenObject



277
278
279
# File 'lib/axhub_sdk.rb', line 277

def redacted_token
  @token.nil? || @token.empty? ? '' : '***REDACTED***'
end

#request(operation_id, path_params: {}, query: {}, body: nil) ⇒ Object

Raises:



280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
# File 'lib/axhub_sdk.rb', line 280

def request(operation_id, path_params: {}, query: {}, body: nil)
  route = ROUTE_BY_OP.fetch(operation_id); path = route['path'].dup; path_params.each { |k, v| path.gsub!("{#{k}}", URI.encode_www_form_component(v.to_s)) }; raise Error.new(category: 'validation', code: 'required', message: 'missing path parameter') if path.include?(123.chr) || path.include?(125.chr)
  uri = URI(@base_url + path); uri.query = URI.encode_www_form(query) unless query.empty?
  req_class = Net::HTTP.const_get(route['method'].capitalize); req = req_class.new(uri); req['X-Request-ID'] = request_id
  if body
    if FORM_ENCODED_OPERATIONS.include?(operation_id)
      req['Content-Type'] = 'application/x-www-form-urlencoded'
      req.body = URI.encode_www_form(body.transform_keys(&:to_s).transform_values { |v| v.nil? ? '' : v.to_s })
    else
      req['Content-Type'] = 'application/json'
      req.body = JSON.generate(body)
    end
  end
  _send(req, uri, camelize: true)
end

#request_raw(method, path, query: {}, body: nil, camelize: false) ⇒ Object

Raw-path transport for endpoints with no generated operation-id facade (the ergonomic data ring: dynamic CRUD + runtime schema discover). ‘path` is already fully substituted; `query` keys may be array-valued so repeated filter params (e.g. `tag=eq.a&tag=eq.b`) serialize via URI.encode_www_form. Defaults to `camelize: false` to mirror the node data transport: row bodies and list envelopes (`has_more`/`per_page`) are returned verbatim.



302
303
304
305
306
307
308
309
# File 'lib/axhub_sdk.rb', line 302

def request_raw(method, path, query: {}, body: nil, camelize: false)
  uri = URI(@base_url + path); uri.query = URI.encode_www_form(query) unless query.nil? || query.empty?
  req_class = Net::HTTP.const_get(method.to_s.capitalize); req = req_class.new(uri); req['X-Request-ID'] = request_id
  unless body.nil?
    req['Content-Type'] = 'application/json'; req.body = JSON.generate(body)
  end
  _send(req, uri, camelize: camelize)
end

#tenant(tenant_slug) ⇒ Object



63
64
65
# File 'lib/axhub_sdk/data.rb', line 63

def tenant(tenant_slug)
  AxHub::Data::TenantScope.new(ergo_data, tenant_slug)
end