Class: Mailfloss::Resources::Connections

Inherits:
Base
  • Object
show all
Defined in:
lib/mailfloss/resources.rb,
sig/resources.rbs

Overview

/integrations/type/connections/*

Instance Attribute Summary

Attributes inherited from Base

#client

Instance Method Summary collapse

Methods inherited from Base

#encode, #initialize

Constructor Details

This class inherits a constructor from Mailfloss::Resources::Base

Instance Method Details

#create(type, credentials:, name: nil, idempotency_key: nil) ⇒ Hash

POST /integrations/type/connections — connect an ESP account.

Parameters:

  • type (String)

    ESP slug (e.g. "klaviyo")

  • credentials (Hash)

    per-ESP credential shape (e.g. { api_key: "..." })

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

    optional display name

Returns:

  • (Hash)

    the created connection { id:, name:, status:, created_at:, last_synced_at:, settings: }



188
189
190
191
192
193
# File 'lib/mailfloss/resources.rb', line 188

def create(type, credentials:, name: nil, idempotency_key: nil)
  body = { credentials: credentials }
  body[:name] = name if name
  client.request(:post, "/integrations/#{encode(type)}/connections",
                 body: body, idempotency_key: idempotency_key)
end

#delete(type, id) ⇒ Hash

DELETE /integrations/type/connections/id — disconnect (soft-disable).

Parameters:

  • type (String)
  • id (String)

Returns:

  • (Hash)

    { id:, type:, status:, disconnected_at: }



224
225
226
# File 'lib/mailfloss/resources.rb', line 224

def delete(type, id)
  client.request(:delete, "/integrations/#{encode(type)}/connections/#{encode(id)}")
end

#get(type, id) ⇒ Types::connection

GET /integrations/type/connections/id

Parameters:

  • type (String)
  • id (String)

Returns:

  • (Types::connection)


196
197
198
# File 'lib/mailfloss/resources.rb', line 196

def get(type, id)
  client.request(:get, "/integrations/#{encode(type)}/connections/#{encode(id)}")
end

#sync(type, id, idempotency_key: nil) ⇒ Hash

POST /integrations/type/connections/id/sync — trigger a sync.

Parameters:

  • type (String)
  • id (String)
  • idempotency_key: (String, nil) (defaults to: nil)

Returns:

  • (Hash)

    the connection after the sync was queued



231
232
233
234
# File 'lib/mailfloss/resources.rb', line 231

def sync(type, id, idempotency_key: nil)
  client.request(:post, "/integrations/#{encode(type)}/connections/#{encode(id)}/sync",
                 idempotency_key: idempotency_key)
end

#test(type, id, idempotency_key: nil) ⇒ Hash

POST /integrations/type/connections/id/test — test stored credentials.

Parameters:

  • type (String)
  • id (String)
  • idempotency_key: (String, nil) (defaults to: nil)

Returns:

  • (Hash)

    { id:, type:, credential_valid:, tested_at:, reason: }



239
240
241
242
# File 'lib/mailfloss/resources.rb', line 239

def test(type, id, idempotency_key: nil)
  client.request(:post, "/integrations/#{encode(type)}/connections/#{encode(id)}/test",
                 idempotency_key: idempotency_key)
end

#update(type, id, aggressiveness: nil, manual_mode: nil, autofloss: nil, decay_protection: nil, action: nil, checks: nil) ⇒ Hash

PATCH /integrations/type/connections/id — update floss settings.

Parameters:

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

    normal|aggressive|custom

  • manual_mode (Boolean, nil) (defaults to: nil)
  • autofloss (Boolean, nil) (defaults to: nil)
  • decay_protection (Boolean, nil) (defaults to: nil)
  • action (String, nil) (defaults to: nil)

    unsubscribe|delete|update_tags|update_custom_fields|do_nothing

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

    partial map of the 12 check gates

Returns:

  • (Hash)

    the updated connection



209
210
211
212
213
214
215
216
217
218
219
# File 'lib/mailfloss/resources.rb', line 209

def update(type, id, aggressiveness: nil, manual_mode: nil, autofloss: nil,
           decay_protection: nil, action: nil, checks: nil)
  body = {}
  body[:aggressiveness] = aggressiveness unless aggressiveness.nil?
  body[:manual_mode] = manual_mode unless manual_mode.nil?
  body[:autofloss] = autofloss unless autofloss.nil?
  body[:decay_protection] = decay_protection unless decay_protection.nil?
  body[:action] = action unless action.nil?
  body[:checks] = checks unless checks.nil?
  client.request(:patch, "/integrations/#{encode(type)}/connections/#{encode(id)}", body: body)
end