Module: Resend::Broadcasts

Defined in:
lib/resend/broadcasts.rb

Overview

broadcasts api wrapper

Class Method Summary collapse

Class Method Details

.cancel(broadcast_id = "") ⇒ Object



50
51
52
53
# File 'lib/resend/broadcasts.rb', line 50

def cancel(broadcast_id = "")
  path = "broadcasts/#{broadcast_id}/cancel"
  Resend::Request.new(path, {}, "post").perform
end


45
46
47
48
# File 'lib/resend/broadcasts.rb', line 45

def clicked_links(broadcast_id = "", params = {})
  path = Resend::PaginationHelper.build_paginated_path("broadcasts/#{broadcast_id}/clicked-links", params)
  Resend::Request.new(path, {}, "get").perform
end

.create(params = {}) ⇒ Object

Note:

Supports both segment_id and audience_id. At least one is required. audience_id is deprecated - use segment_id instead.

Note:

When send: true is passed, the broadcast is sent immediately instead of creating a draft. When using send: true, you can also include scheduled_at to schedule the broadcast. Passing scheduled_at without send: true is an error.

https://resend.com/docs/api-reference/broadcasts/create-broadcast



13
14
15
16
17
18
19
# File 'lib/resend/broadcasts.rb', line 13

def create(params = {})
  if params[:audience_id] && !params[:segment_id]
    warn "[DEPRECATION] Using audience_id in broadcasts is deprecated. Use segment_id instead."
  end
  path = "broadcasts"
  Resend::Request.new(path, params, "post").perform
end

.get(broadcast_id = "") ⇒ Object



62
63
64
65
# File 'lib/resend/broadcasts.rb', line 62

def get(broadcast_id = "")
  path = "broadcasts/#{broadcast_id}"
  Resend::Request.new(path, {}, "get").perform
end

.list(params = {}) ⇒ Object



39
40
41
42
# File 'lib/resend/broadcasts.rb', line 39

def list(params = {})
  path = Resend::PaginationHelper.build_paginated_path("broadcasts", params)
  Resend::Request.new(path, {}, "get").perform
end

.recipients(broadcast_id = "", params = {}) ⇒ Object

Parameters:

  • broadcast_id (String) (defaults to: "")

    the broadcast id

  • params (Hash) (defaults to: {})

    the parameters

Options Hash (params):

  • :type (String)

    the recipient event type to filter by (required): sent, delivered, opened, clicked, bounced, complained, unsubscribed, suppressed

  • :email (String)

    filter recipients by email address (optional)

  • :bounce_type (String)

    filter bounced recipients by bounce type (optional, only valid when type is bounced): permanent, transient, undetermined

  • :limit (Integer)

    the maximum number of results to return (optional)

  • :after (String)

    the cursor for pagination (optional)

  • :before (String)

    the cursor for pagination (optional)

Raises:

  • (ArgumentError)


78
79
80
81
82
83
84
# File 'lib/resend/broadcasts.rb', line 78

def recipients(broadcast_id = "", params = {})
  raise ArgumentError, "type is required" if params[:type].nil?

  base_path = "broadcasts/#{broadcast_id}/recipients"
  path = Resend::PaginationHelper.build_paginated_path(base_path, params)
  Resend::Request.new(path, {}, "get").perform
end

.remove(broadcast_id = "") ⇒ Object



56
57
58
59
# File 'lib/resend/broadcasts.rb', line 56

def remove(broadcast_id = "")
  path = "broadcasts/#{broadcast_id}"
  Resend::Request.new(path, {}, "delete").perform
end

.send(params = {}) ⇒ Object



33
34
35
36
# File 'lib/resend/broadcasts.rb', line 33

def send(params = {})
  path = "broadcasts/#{params[:broadcast_id]}/send"
  Resend::Request.new(path, params, "post").perform
end

.update(params = {}) ⇒ Object

Note:

Supports both segment_id and audience_id. At least one may be required. audience_id is deprecated - use segment_id instead.

https://resend.com/docs/api-reference/broadcasts/update-broadcast



24
25
26
27
28
29
30
# File 'lib/resend/broadcasts.rb', line 24

def update(params = {})
  if params[:audience_id] && !params[:segment_id]
    warn "[DEPRECATION] Using audience_id in broadcasts is deprecated. Use segment_id instead."
  end
  path = "broadcasts/#{params[:broadcast_id]}"
  Resend::Request.new(path, params, "patch").perform
end