Class: Notisend::Recipient

Inherits:
OpenStruct
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/notisend/recipient.rb

Overview

Class for interaction with list recipients

Class Method Summary collapse

Class Method Details

.create(email:, list_id:, values: []) ⇒ Object

Creates a new recipient for a list


16
17
18
19
20
# File 'lib/notisend/recipient.rb', line 16

def create(email:, list_id:, values: [])
  params = { email: email, values: values }
  response = client.post(path(list_id), params).parsed_body
  new(response)
end

.delete(list_id:, id:) ⇒ Object

Deletes a recipient


40
41
42
# File 'lib/notisend/recipient.rb', line 40

def delete(list_id:, id:)
  client.delete(path(list_id, id)).parsed_body
end

.get_all(list_id:, params: {}) ⇒ Object

Gets all recipients for a list


10
11
12
13
# File 'lib/notisend/recipient.rb', line 10

def get_all(list_id:, params: {})
  response = client.get(path(list_id), params).parsed_body
  Collection.new(response, self)
end

.import(list_id:, recipients:) ⇒ Object

Imports a bunch of recipients


33
34
35
36
37
# File 'lib/notisend/recipient.rb', line 33

def import(list_id:, recipients:)
  params = { recipients: recipients }
  response = client.post(path(list_id, 'imports'), params).parsed_body
  RecipientsImport.new(response)
end

.update(id:, list_id:, email: nil, values: []) ⇒ Object

Updates a recipient


23
24
25
26
27
28
29
30
# File 'lib/notisend/recipient.rb', line 23

def update(id:, list_id:, email: nil, values: [])
  params = {}.tap do |hash|
    hash[:email] = email if email
    hash[:values] = values
  end
  response = client.patch(path(list_id, id), params).parsed_body
  new(response)
end