Class: Sendara::Resources::Contacts

Inherits:
Sendara::Resource show all
Defined in:
lib/sendara/resources/contacts.rb

Instance Method Summary collapse

Methods inherited from Sendara::Resource

#initialize

Constructor Details

This class inherits a constructor from Sendara::Resource

Instance Method Details

#activity(id, limit: nil) ⇒ Object



56
57
58
59
60
61
# File 'lib/sendara/resources/contacts.rb', line 56

def activity(id, limit: nil)
  query = compact_params("limit" => limit)
  response = request(:get, "/v1/contacts/#{encode(id)}/activity", query: query) || {}
  events = response["events"]
  events.is_a?(Array) ? events : []
end

#bulk(ids:, action:, tag: nil, list_id: nil, channel: nil, consent: nil) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/sendara/resources/contacts.rb', line 77

def bulk(ids:, action:, tag: nil, list_id: nil, channel: nil, consent: nil)
  body = compact_params(
    "ids" => ids,
    "action" => action,
    "tag" => tag,
    "list_id" => list_id,
    "channel" => channel,
    "consent" => consent
  )
  response = request(:post, "/v1/contacts/bulk", body: body) || {}
  (response["affected"] || 0).to_i
end

#create(email: nil, phone_number: nil, device_token: nil, first_name: nil, last_name: nil, attributes: nil, tags: nil, email_consent: nil, sms_consent: nil, push_consent: nil, voice_consent: nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/sendara/resources/contacts.rb', line 21

def create(email: nil, phone_number: nil, device_token: nil, first_name: nil,
           last_name: nil, attributes: nil, tags: nil, email_consent: nil,
           sms_consent: nil, push_consent: nil, voice_consent: nil)
  body = contact_body(
    email: email, phone_number: phone_number, device_token: device_token,
    first_name: first_name, last_name: last_name, attributes: attributes,
    tags: tags, email_consent: email_consent, sms_consent: sms_consent,
    push_consent: push_consent, voice_consent: voice_consent
  )
  request(:post, "/v1/contacts", body: body) || {}
end

#delete(id) ⇒ Object



45
46
47
48
# File 'lib/sendara/resources/contacts.rb', line 45

def delete(id)
  request(:delete, "/v1/contacts/#{encode(id)}")
  nil
end

#get(id) ⇒ Object



17
18
19
# File 'lib/sendara/resources/contacts.rb', line 17

def get(id)
  request(:get, "/v1/contacts/#{encode(id)}") || {}
end

#import(s3_key:, format:) ⇒ Object



63
64
65
66
# File 'lib/sendara/resources/contacts.rb', line 63

def import(s3_key:, format:)
  body = { "s3_key" => s3_key, "format" => format }
  request(:post, "/v1/contacts/import", body: body) || {}
end

#import_inline(rows:, list_id: nil, dry_run: nil) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/sendara/resources/contacts.rb', line 68

def import_inline(rows:, list_id: nil, dry_run: nil)
  body = compact_params(
    "rows" => rows,
    "list_id" => list_id,
    "dry_run" => dry_run
  )
  request(:post, "/v1/contacts/import/inline", body: body) || {}
end

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



10
11
12
13
14
15
# File 'lib/sendara/resources/contacts.rb', line 10

def list(limit: nil, offset: nil)
  query = compact_params("limit" => limit, "offset" => offset)
  response = request(:get, "/v1/contacts", query: query) || {}
  contacts = response["contacts"]
  contacts.is_a?(Array) ? contacts : []
end

#listsObject



6
7
8
# File 'lib/sendara/resources/contacts.rb', line 6

def lists
  @lists ||= Lists.new(client)
end

#lists_for(id) ⇒ Object



50
51
52
53
54
# File 'lib/sendara/resources/contacts.rb', line 50

def lists_for(id)
  response = request(:get, "/v1/contacts/#{encode(id)}/lists") || {}
  lists = response["lists"]
  lists.is_a?(Array) ? lists : []
end

#segments_preview(segment_rules) ⇒ Object



90
91
92
93
94
# File 'lib/sendara/resources/contacts.rb', line 90

def segments_preview(segment_rules)
  response = request(:post, "/v1/contacts/segments/preview",
                     body: { "segment_rules" => segment_rules }) || {}
  (response["count"] || 0).to_i
end

#update(id, email: nil, phone_number: nil, device_token: nil, first_name: nil, last_name: nil, attributes: nil, tags: nil, email_consent: nil, sms_consent: nil, push_consent: nil, voice_consent: nil) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/sendara/resources/contacts.rb', line 33

def update(id, email: nil, phone_number: nil, device_token: nil, first_name: nil,
           last_name: nil, attributes: nil, tags: nil, email_consent: nil,
           sms_consent: nil, push_consent: nil, voice_consent: nil)
  body = contact_body(
    email: email, phone_number: phone_number, device_token: device_token,
    first_name: first_name, last_name: last_name, attributes: attributes,
    tags: tags, email_consent: email_consent, sms_consent: sms_consent,
    push_consent: push_consent, voice_consent: voice_consent
  )
  request(:put, "/v1/contacts/#{encode(id)}", body: body) || {}
end

#usageObject



96
97
98
# File 'lib/sendara/resources/contacts.rb', line 96

def usage
  request(:get, "/v1/contacts/usage") || {}
end