Class: SimpleConnect::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_connect/client.rb

Overview

Entry point for the SimpleWaConnect integration client. Assembles the signed-request transport once, then exposes two resource objects:

SIMPLECONNECT.events.deliver(event_key, fields, event_id: ...)
SIMPLECONNECT.events.detail(event_id)
SIMPLECONNECT.integrations.verify

See README.md for usage, envelope format, and signing scheme.

Constant Summary collapse

DEFAULT_TIMEOUT =
10

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint_url:, key_id:, secret:, timeout: DEFAULT_TIMEOUT, logger: nil, event_keys: nil, max_attempts: nil, retryable: nil, user_agent: nil) ⇒ Client

Returns a new instance of Client.

Parameters:

  • endpoint_url (String)

    the integration events URL, e.g. “app.simplewaconnect.com/api/v1/integrations/purepani/events”.

  • key_id (String)

    signing-secret prefix shown on the integration Security card (the ‘wa_sec_…` string, NOT the raw secret).

  • secret (String)

    raw signing secret shown once at connect / rotation.

  • timeout (Integer) (defaults to: DEFAULT_TIMEOUT)

    HTTP read/open timeout in seconds.

  • logger (#info, #warn, nil) (defaults to: nil)

    optional logger for transport events.

  • event_keys (Array<String>, nil) (defaults to: nil)

    optional client-side whitelist of event_keys. When nil (default), ‘events.deliver` accepts any non-empty event_key and the server is the source of truth.

  • max_attempts (Integer) (defaults to: nil)

    total HTTP attempts (including the first). Default 3. Pass ‘1` to disable library-level retries (appropriate when wrapping in a job queue that has its own retry layer). Mutually exclusive with `retryable:`.

  • retryable (SimpleConnect::Retryable, nil) (defaults to: nil)

    power-user escape hatch for custom retry policy (exponential backoff, jitter, etc.). Mutually exclusive with ‘max_attempts:`.

  • user_agent (String, nil) (defaults to: nil)

    override the default User-Agent header (‘simple_connect-client/<version> ruby/<version>`).

Raises:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/simple_connect/client.rb', line 37

def initialize(endpoint_url:, key_id:, secret:,
               timeout: DEFAULT_TIMEOUT, logger: nil, event_keys: nil,
               max_attempts: nil, retryable: nil, user_agent: nil)
  raise ConfigurationError, "endpoint_url is required" if endpoint_url.to_s.strip.empty?
  raise ConfigurationError, "key_id is required"       if key_id.to_s.strip.empty?
  raise ConfigurationError, "secret is required"       if secret.to_s.strip.empty?

  if max_attempts && retryable
    raise ConfigurationError,
          "pass either `max_attempts:` or `retryable:`, not both"
  end

  endpoint_uri = URI.parse(endpoint_url)
  request = Request.new(
    headers: Headers.new(key_id: key_id, secret: secret, user_agent: user_agent),
    timeout: timeout,
    logger: logger,
    retryable: retryable || Retryable.new(max_attempts: max_attempts || Retryable::DEFAULT_MAX_ATTEMPTS)
  )
  @events       = Api::Events.new(request: request, endpoint_uri: endpoint_uri, event_keys: event_keys)
  @integrations = Api::Integrations.new(request: request, endpoint_uri: endpoint_uri)
end

Instance Attribute Details

#eventsObject (readonly)

Returns the value of attribute events.



15
16
17
# File 'lib/simple_connect/client.rb', line 15

def events
  @events
end

#integrationsObject (readonly)

Returns the value of attribute integrations.



15
16
17
# File 'lib/simple_connect/client.rb', line 15

def integrations
  @integrations
end