Class: Courier::AsyncAutomationsClient

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ AsyncAutomationsClient

Parameters:



84
85
86
87
# File 'lib/trycourier/automations/client.rb', line 84

def initialize(request_client:)
  # @type [AsyncRequestClient]
  @request_client = request_client
end

Instance Attribute Details

#request_clientObject (readonly)

Returns the value of attribute request_client.



80
81
82
# File 'lib/trycourier/automations/client.rb', line 80

def request_client
  @request_client
end

Instance Method Details

#invoke_ad_hoc_automation(request:, request_options: nil) ⇒ Automations::AutomationInvokeResponse

Invoke an ad hoc automation run. This endpoint accepts a JSON payload with a series of automation steps. For information about what steps are available, checkout the ad hoc automation guide [here](www.courier.com/docs/automations/steps/).

Parameters:

  • request (Hash)

    Request of type Automations::AutomationAdHocInvokeParams, as a Hash

    • :automation (Hash)

      • :cancelation_token (String)

      • :steps (Array<Automations::AutomationStepOption>)

    • :brand (String)

    • :data (Hash=> String)

    • :profile (Automations::PROFILE)

    • :recipient (String)

    • :template (String)

  • request_options (IdempotencyRequestOptions) (defaults to: nil)

Returns:



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/trycourier/automations/client.rb', line 132

def invoke_ad_hoc_automation(request:, request_options: nil)
  Async do
    response = @request_client.conn.post("/automations/invoke") do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      unless request_options&.authorization_token.nil?
        req.headers["Authorization"] =
          request_options.authorization_token
      end
      req.headers["Idempotency-Key"] = request_options.idempotency_key unless request_options&.idempotency_key.nil?
      unless request_options&.idempotency_expiry.nil?
        req.headers["X-Idempotency-Expiration"] = request_options.idempotency_expiry
      end
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
      req.body = { **(request || {}), **(request_options&.additional_body_parameters || {}) }.compact
    end
    Automations::AutomationInvokeResponse.from_json(json_object: response.body)
  end
end

#invoke_automation_template(template_id:, request:, request_options: nil) ⇒ Automations::AutomationInvokeResponse

Invoke an automation run from an automation template.

Parameters:

  • template_id (String)

    A unique identifier representing the automation template to be invoked. This could be the Automation Template ID or the Automation Template Alias.

  • request (Hash)

    Request of type Automations::AutomationInvokeParams, as a Hash

    • :brand (String)

    • :data (Hash=> String)

    • :profile (Automations::PROFILE)

    • :recipient (String)

    • :template (String)

  • request_options (IdempotencyRequestOptions) (defaults to: nil)

Returns:



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/trycourier/automations/client.rb', line 100

def invoke_automation_template(template_id:, request:, request_options: nil)
  Async do
    response = @request_client.conn.post("/automations/#{template_id}/invoke") do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      unless request_options&.authorization_token.nil?
        req.headers["Authorization"] =
          request_options.authorization_token
      end
      req.headers["Idempotency-Key"] = request_options.idempotency_key unless request_options&.idempotency_key.nil?
      unless request_options&.idempotency_expiry.nil?
        req.headers["X-Idempotency-Expiration"] = request_options.idempotency_expiry
      end
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
      req.body = { **(request || {}), **(request_options&.additional_body_parameters || {}) }.compact
    end
    Automations::AutomationInvokeResponse.from_json(json_object: response.body)
  end
end