Class: SuperSendTX::EmailsResource

Inherits:
Object
  • Object
show all
Defined in:
lib/supersendtx/resources.rb

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ EmailsResource

Returns a new instance of EmailsResource.



5
6
7
# File 'lib/supersendtx/resources.rb', line 5

def initialize(http)
  @http = http
end

Instance Method Details

#batch(emails) ⇒ Object



30
31
32
33
# File 'lib/supersendtx/resources.rb', line 30

def batch(emails)
  serialized = emails.map { |email| serialize_send_params(email) }
  @http.request("POST", "/emails/batch", body: { "emails" => serialized })
end

#cancel(email_id) ⇒ Object



35
36
37
# File 'lib/supersendtx/resources.rb', line 35

def cancel(email_id)
  @http.request("PATCH", "/emails/#{URI.encode_www_form_component(email_id)}", body: { "cancel" => true })
end

#get(email_id) ⇒ Object



13
14
15
# File 'lib/supersendtx/resources.rb', line 13

def get(email_id)
  @http.request("GET", "/emails/#{URI.encode_www_form_component(email_id)}")
end

#insights(window: "30d") ⇒ Object



47
48
49
# File 'lib/supersendtx/resources.rb', line 47

def insights(window: "30d")
  @http.request("GET", "/deliverability#{@http.query({ "window" => window })}")
end

#list(limit: nil, cursor: nil) ⇒ Object



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

def list(limit: nil, cursor: nil)
  @http.request("GET", "/emails#{@http.query({ "limit" => limit, "cursor" => cursor })}")
end

#resend(email_id) ⇒ Object



39
40
41
# File 'lib/supersendtx/resources.rb', line 39

def resend(email_id)
  @http.request("POST", "/emails/#{URI.encode_www_form_component(email_id)}/resend")
end

#send(from: nil, to: nil, **params) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/supersendtx/resources.rb', line 17

def send(from: nil, to: nil, **params)
  params["from"] = from if from
  params["to"] = to if to
  body = serialize_send_params(params)
  headers = {}
  idempotency_key =
    params["idempotency_key"] || params[:idempotency_key] ||
    params["idempotencyKey"] || params[:idempotencyKey]
  headers["Idempotency-Key"] = idempotency_key.to_s if idempotency_key

  @http.request("POST", "/emails", body: body, headers: headers)
end

#test_webhook(**params) ⇒ Object



43
44
45
# File 'lib/supersendtx/resources.rb', line 43

def test_webhook(**params)
  @http.request("POST", "/emails/test", body: params)
end