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



28
29
30
31
# File 'lib/supersendtx/resources.rb', line 28

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

#cancel(email_id) ⇒ Object



33
34
35
# File 'lib/supersendtx/resources.rb', line 33

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



45
46
47
# File 'lib/supersendtx/resources.rb', line 45

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



37
38
39
# File 'lib/supersendtx/resources.rb', line 37

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
# 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["idempotencyKey"]
  headers["Idempotency-Key"] = idempotency_key.to_s if idempotency_key

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

#test_webhook(**params) ⇒ Object



41
42
43
# File 'lib/supersendtx/resources.rb', line 41

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