Class: Telnyx::Resources::EmailBlocks

Inherits:
Object
  • Object
show all
Defined in:
lib/telnyx/resources/email_blocks.rb,
lib/telnyx/resources/email_blocks/import.rb,
sig/telnyx/resources/email_blocks.rbs,
sig/telnyx/resources/email_blocks/import.rbs

Overview

Recipient suppression records (/v2/email_blocks).

Defined Under Namespace

Classes: Import

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ EmailBlocks

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of EmailBlocks.

Parameters:



243
244
245
246
# File 'lib/telnyx/resources/email_blocks.rb', line 243

def initialize(client:)
  @client = client
  @import = Telnyx::Resources::EmailBlocks::Import.new(client: client)
end

Instance Attribute Details

#importTelnyx::Resources::EmailBlocks::Import (readonly)

Async CSV import of competitor suppression lists.



9
10
11
# File 'lib/telnyx/resources/email_blocks.rb', line 9

def import
  @import
end

Instance Method Details

#create(to:, domain_id: nil, expires_at: nil, from: nil, request_options: {}) ⇒ Telnyx::Models::EmailBlockResponse

Creates a suppression with reason: manual_block and source: manual. Caller-supplied reason / source are ignored; scope is derived server-side from domain_id / from and is never trusted. Idempotent: if a matching row already exists (NULL-safe dedupe key: account_id, scope, to, reason, domain_id, from), returns the existing record with 200 (no new audit event).

bounce_category, dsn_code, meta, and group_id are not accepted on the public surface. Use the unsubscribe-group suppression endpoint or the internal create surface for those.

Parameters:

  • to (String)

    Recipient address (normalized: trim + lower-case).

  • domain_id (String, nil)

    null ⇒ account scope.

  • expires_at (Time, nil)
  • from (String, nil)

    Sender address (normalized). null ⇒ account/domain scope.

  • request_options (Telnyx::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



37
38
39
40
41
42
43
44
45
46
# File 'lib/telnyx/resources/email_blocks.rb', line 37

def create(params)
  parsed, options = Telnyx::EmailBlockCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: "email_blocks",
    body: parsed,
    model: Telnyx::EmailBlockResponse,
    options: options
  )
end

#delete(id, request_options: {}) ⇒ Telnyx::Models::EmailBlockResponse

Soft-deletes (status → removed; tombstone retained). A removed audit event is appended unless the block was already removed (idempotent — returns the existing row with 200 and no new event). Mutates updated_at.

Parameters:

  • id (String)

    Resource UUID. Malformed UUIDs are treated as not-found (not 400).

  • request_options (Telnyx::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



143
144
145
146
147
148
149
150
# File 'lib/telnyx/resources/email_blocks.rb', line 143

def delete(id, params = {})
  @client.request(
    method: :delete,
    path: ["email_blocks/%1$s", id],
    model: Telnyx::EmailBlockResponse,
    options: params[:request_options]
  )
end

#list(filter_created_after: nil, filter_created_before: nil, filter_domain_id: nil, filter_reason: nil, page_after: nil, page_before: nil, page_number: nil, page_size: nil, sort: nil, request_options: {}) ⇒ Telnyx::Internal::DefaultFlatPagination<Telnyx::Models::EmailBlock>

Some parameter documentations has been truncated, see Models::EmailBlockListParams for more details.

Account-scoped list. Two mutually exclusive pagination modes:

  • Offset: page[number] (default 1) + page[size] (default 25, max 100). meta contains total_pages.
  • Cursor: page[after] and/or page[before] (opaque Base.url_encode64 of {"created_at","id"}). Cannot combine with page[number]; after+before together is an error. meta contains next_cursor / previous_cursor (omitted when their flag is false).

Sort defaults to -created_at (desc); only created_at is sortable. A -- prefix is an error. nil/empty filter values are silently dropped.

Parameters:

  • filter_created_after (Time)

    created_at > value (ISO 8601).

  • filter_created_before (Time)

    created_at < value (ISO 8601).

  • filter_domain_id (String)

    Exact-match filter on domain_id (UUID).

  • filter_reason (Symbol, Telnyx::Models::EmailBlockListParams::FilterReason)

    Exact-match filter on reason.

  • page_after (String)

    Opaque cursor (Base.url_encode64 of {"created_at","id"}). Cursor mode; mutua

  • page_before (String)

    Opaque cursor (see page[after]). Mutually exclusive with page[after] and `pa

  • page_number (Integer)

    Offset page number (≥1, default 1).

  • page_size (Integer)

    Page size (1–100, default 25).

  • sort (Symbol, Telnyx::Models::EmailBlockListParams::Sort)

    Sort field. Leading - = desc; only created_at is sortable. Default `-created

  • request_options (Telnyx::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/telnyx/resources/email_blocks.rb', line 108

def list(params = {})
  parsed, options = Telnyx::EmailBlockListParams.dump_request(params)
  query = Telnyx::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "email_blocks",
    query: query.transform_keys(
      filter_created_after: "filter[created_after]",
      filter_created_before: "filter[created_before]",
      filter_domain_id: "filter[domain_id]",
      filter_reason: "filter[reason]",
      page_after: "page[after]",
      page_before: "page[before]",
      page_number: "page[number]",
      page_size: "page[size]"
    ),
    page: Telnyx::Internal::DefaultFlatPagination,
    model: Telnyx::EmailBlock,
    options: options
  )
end

#retrieve(id, request_options: {}) ⇒ Telnyx::Models::EmailBlockResponse

Retrieve a suppression

Parameters:

  • id (String)

    Resource UUID. Malformed UUIDs are treated as not-found (not 400).

  • request_options (Telnyx::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



59
60
61
62
63
64
65
66
# File 'lib/telnyx/resources/email_blocks.rb', line 59

def retrieve(id, params = {})
  @client.request(
    method: :get,
    path: ["email_blocks/%1$s", id],
    model: Telnyx::EmailBlockResponse,
    options: params[:request_options]
  )
end

#retrieve_events(id, page_number: nil, page_size: nil, request_options: {}) ⇒ Telnyx::Models::EmailBlockRetrieveEventsResponse

Offset pagination only (page[number] default 1, page[size] default 50, max 100). No sort, no filter, no cursor — ordering is fixed desc occurred_at, desc id. Verifies the block belongs to the account first (cross-account → 404).

Parameters:

  • id (String)

    Resource UUID. Malformed UUIDs are treated as not-found (not 400).

  • page_number (Integer)

    Offset page number (≥1, default 1).

  • page_size (Integer)

    Page size (default 50, max 100).

  • request_options (Telnyx::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



170
171
172
173
174
175
176
177
178
179
180
# File 'lib/telnyx/resources/email_blocks.rb', line 170

def retrieve_events(id, params = {})
  parsed, options = Telnyx::EmailBlockRetrieveEventsParams.dump_request(params)
  query = Telnyx::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["email_blocks/%1$s/events", id],
    query: query.transform_keys(page_number: "page[number]", page_size: "page[size]"),
    model: Telnyx::Models::EmailBlockRetrieveEventsResponse,
    options: options
  )
end

#retrieve_export(filter_created_after: nil, filter_created_before: nil, filter_domain_id: nil, filter_reason: nil, page_number: nil, page_size: nil, sort: nil, request_options: {}) ⇒ String

Some parameter documentations has been truncated, see Models::EmailBlockRetrieveExportParams for more details.

Streams the account's suppressions as a chunked CSV (server-side cursor; never materialized). Content-type text/csv, header Content-Disposition: attachment; filename="email_blocks_export.csv".

Filters (filter[reason], filter[domain_id], filter[created_after], filter[created_before]) are the only params that affect output. sort and page[*] are parsed (bad values still produce 400) but ignored — rows stream ORDER BY created_at ASC, id ASC with no pagination.

CSV columns: id,to,from,reason,source,scope,status,domain_id, created_at,updated_at,expires_at,group_id. The CSV carries the group_id column so group-scoped suppressions' group link survives the export (empty for account-scope rows).

Parameters:

Returns:

  • (String)

See Also:



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/telnyx/resources/email_blocks.rb', line 220

def retrieve_export(params = {})
  parsed, options = Telnyx::EmailBlockRetrieveExportParams.dump_request(params)
  query = Telnyx::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "email_blocks/export",
    query: query.transform_keys(
      filter_created_after: "filter[created_after]",
      filter_created_before: "filter[created_before]",
      filter_domain_id: "filter[domain_id]",
      filter_reason: "filter[reason]",
      page_number: "page[number]",
      page_size: "page[size]"
    ),
    headers: {"accept" => "text/csv"},
    model: String,
    options: options
  )
end