Module: Mailblastr::Events

Defined in:
lib/mailblastr/events.rb

Overview

Custom events that automations trigger on. Events are DOMAIN-FIRST: domain is required on send, and only that domain's automations fire.

Class Method Summary collapse

Class Method Details

.create(params, options = {}) ⇒ Object

Create a custom-event definition (name + optional payload schema). Schema values are one of "string", "number", "boolean", "date". POST /events Mailblastr::Events.create({ name: "signup.completed", schema: { plan: "string" } })

NOTE: options[:idempotency_key] carries no guarantee here — see send. A duplicate event name is already a 422 validation_error.



30
31
32
# File 'lib/mailblastr/events.rb', line 30

def create(params, options = {})
  Client.request(:post, "/events", body: params, options: options)
end

.delete(event_id) ⇒ Object

Delete a custom-event definition. DELETE /events/:id



48
49
50
# File 'lib/mailblastr/events.rb', line 48

def delete(event_id)
  Client.request(:delete, "/events/#{Client.path_escape(event_id)}")
end

.list(params = {}) ⇒ Object

List custom-event definitions. GET /events



43
44
45
# File 'lib/mailblastr/events.rb', line 43

def list(params = {})
  Client.request(:get, "/events", query: Client.pagination(params))
end

.send(params, options = {}) ⇒ Object

Send a custom event. POST /events/send Mailblastr::Events.send({ event: "signup.completed", domain: "yourdomain.com", email: "user@example.com", payload: { plan: "pro" } }) Identify the contact by contact_id OR email. Event names cannot start with the reserved "mailblastr:" prefix.

NOTE: only POST /emails and POST /emails/batch honour Idempotency-Key. An idempotency_key passed here is still forwarded, but the server ignores it, so a retry ingests a SECOND event and can enroll the contact twice — de-duplicate on your side instead.



18
19
20
21
# File 'lib/mailblastr/events.rb', line 18

def send(params, options = {})
  Client.require_domain!(params, "Events.send")
  Client.request(:post, "/events/send", body: params, options: options)
end

.update(event_id, params) ⇒ Object

Update a definition's payload schema. PATCH /events/:id The event NAME is immutable (automations reference it) — passing name is a 422; pass schema: nil to clear the schema. Mailblastr::Events.update("evt_1", { schema: { plan: "string" } })



38
39
40
# File 'lib/mailblastr/events.rb', line 38

def update(event_id, params)
  Client.request(:patch, "/events/#{Client.path_escape(event_id)}", body: params)
end