Class: Axene::Mailer::Resources::Suppressions

Inherits:
Object
  • Object
show all
Defined in:
lib/axene/mailer/resources/suppressions.rb

Overview

The suppressions resource: manage the do-not-send list. Accessed as client.suppressions.

Instance Method Summary collapse

Constructor Details

#initialize(transport) ⇒ Suppressions

Returns a new instance of Suppressions.

Parameters:



10
11
12
# File 'lib/axene/mailer/resources/suppressions.rb', line 10

def initialize(transport)
  @transport = transport
end

Instance Method Details

#add(email:, reason: "manual") ⇒ Hash

Suppress a single address. The email argument maps to the wire field email_address.

Parameters:

  • email (String)
  • reason (String) (defaults to: "manual")

    default “manual”

Returns:

  • (Hash)


30
31
32
# File 'lib/axene/mailer/resources/suppressions.rb', line 30

def add(email:, reason: "manual")
  @transport.request(:post, "/v1/suppressions", body: { email_address: email, reason: reason })
end

#bulk_upload(file, filename: "suppressions.txt") ⇒ Hash

Bulk-import suppressions from a file (one email per line). file may be raw bytes (a String) or a path to a readable file.

Parameters:

  • file (String)

    raw bytes or a file path

  • filename (String) (defaults to: "suppressions.txt")

Returns:

  • (Hash)

    { added:, skipped:, total_processed: }



40
41
42
43
# File 'lib/axene/mailer/resources/suppressions.rb', line 40

def bulk_upload(file, filename: "suppressions.txt")
  bytes = read_file(file)
  @transport.upload("/v1/suppressions/bulk", bytes, filename)
end

#list(page: 0, limit: 50, search: nil) ⇒ Hash

List suppressed addresses (paginated envelope; zero-based page).

Parameters:

  • page (Integer) (defaults to: 0)

    default 0

  • limit (Integer) (defaults to: 50)

    default 50

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

Returns:

  • (Hash)

    { items:, total:, page:, limit: }



20
21
22
# File 'lib/axene/mailer/resources/suppressions.rb', line 20

def list(page: 0, limit: 50, search: nil)
  @transport.request(:get, "/v1/suppressions", query: { page: page, limit: limit, search: search })
end

#remove(id) ⇒ nil

Remove an address from the suppression list.

Parameters:

  • id (String)

Returns:

  • (nil)


49
50
51
# File 'lib/axene/mailer/resources/suppressions.rb', line 49

def remove(id)
  @transport.request(:delete, "/v1/suppressions/#{Util.escape(id)}")
end