Module: Mailblastr::Segments

Defined in:
lib/mailblastr/segments.rb

Overview

Segments are DOMAIN-FIRST: domain is required on create and list. Names are unique within a domain (reusable across domains); every domain also carries an auto-created "General" (all contacts) segment.

Class Method Summary collapse

Class Method Details

.contacts(segment_id, params = {}) ⇒ Object

Preview the contacts a segment currently resolves to (filter matches plus explicit memberships). With no pagination params every contact is returned. GET /segments/:id/contacts



31
32
33
34
35
36
37
# File 'lib/mailblastr/segments.rb', line 31

def contacts(segment_id, params = {})
  Client.request(
    :get,
    "/segments/#{Client.path_escape(segment_id)}/contacts",
    query: Client.pagination(params)
  )
end

.create(params) ⇒ Object

POST /segments Mailblastr::Segments.create({ domain: "yourdomain.com", name: "VIP", filter: { status: "subscribed" } })



12
13
14
15
# File 'lib/mailblastr/segments.rb', line 12

def create(params)
  Client.require_domain!(params, "Segments.create")
  Client.request(:post, "/segments", body: params)
end

.delete(segment_id) ⇒ Object

DELETE /segments/:id



45
46
47
# File 'lib/mailblastr/segments.rb', line 45

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

.get(segment_id) ⇒ Object

GET /segments/:id



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

def get(segment_id)
  Client.request(:get, "/segments/#{Client.path_escape(segment_id)}")
end

.list(params) ⇒ Object

List a domain's segments (domain required). GET /segments?domain=



23
24
25
26
# File 'lib/mailblastr/segments.rb', line 23

def list(params)
  domain = Client.require_domain!(params, "Segments.list")
  Client.request(:get, "/segments", query: { domain: domain }.merge(Client.pagination(params)))
end

.update(segment_id, params) ⇒ Object

PATCH /segments/:id



40
41
42
# File 'lib/mailblastr/segments.rb', line 40

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