Class: Leash::CustomIntegration

Inherits:
Object
  • Object
show all
Defined in:
lib/leash/custom_integration.rb

Overview

Untyped client for a custom integration.

Obtained via Integrations#integration. Proxies requests through the Leash platform at /api/integrations/custom/{name}.

Examples:

stripe = client.integration("stripe")
charges = stripe.call("/v1/charges", method: "GET")

Instance Method Summary collapse

Constructor Details

#initialize(name, call_fn) ⇒ CustomIntegration

Returns a new instance of CustomIntegration.

Parameters:

  • name (String)

    the custom integration name

  • call_fn (Method)

    internal callable that performs the HTTP request



15
16
17
18
# File 'lib/leash/custom_integration.rb', line 15

def initialize(name, call_fn)
  @name = name
  @call_fn = call_fn
end

Instance Method Details

#call(path, method: "GET", body: nil, headers: nil) ⇒ Object

Invoke the custom integration proxy.

Parameters:

  • path (String)

    the endpoint path to forward (e.g. “/users”)

  • method (String) (defaults to: "GET")

    HTTP method (default “GET”)

  • body (Hash, nil) (defaults to: nil)

    optional JSON body to forward

  • headers (Hash, nil) (defaults to: nil)

    optional extra headers to forward

Returns:

  • (Object)

    the “data” field from the platform response

Raises:

  • (Leash::Error)

    if the platform returns a non-success response



28
29
30
# File 'lib/leash/custom_integration.rb', line 28

def call(path, method: "GET", body: nil, headers: nil)
  @call_fn.call(@name, path, method, body, headers)
end