Class: ADSMedia::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/adsmedia.rb

Constant Summary collapse

BASE_URL =
'https://api.adsmedia.live/v1'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ Client

Returns a new instance of Client.



8
9
10
11
12
13
14
15
# File 'lib/adsmedia.rb', line 8

def initialize(api_key)
  @api_key = api_key
  @conn = Faraday.new(url: BASE_URL) do |f|
    f.request :json
    f.response :json
    f.adapter Faraday.default_adapter
  end
end

Instance Method Details

#add_contacts(list_id:, contacts:) ⇒ Object

Add contacts to list



78
79
80
# File 'lib/adsmedia.rb', line 78

def add_contacts(list_id:, contacts:)
  post("/lists/contacts/add?id=#{list_id}", contacts: contacts)
end

#check_suppression(email) ⇒ Object

Check suppression



107
108
109
# File 'lib/adsmedia.rb', line 107

def check_suppression(email)
  get('/suppressions/check', email: email)
end

#create_campaign(name:, subject:, html:, text: nil, preheader: nil, type: 1) ⇒ Object

Create campaign



59
60
61
62
63
64
65
# File 'lib/adsmedia.rb', line 59

def create_campaign(name:, subject:, html:, text: nil, preheader: nil, type: 1)
  payload = { name: name, subject: subject, html: html, type: type }
  payload[:text] = text if text
  payload[:preheader] = preheader if preheader
  
  post('/campaigns/create', payload)
end

#create_list(name:, type: 1) ⇒ Object

Create list



73
74
75
# File 'lib/adsmedia.rb', line 73

def create_list(name:, type: 1)
  post('/lists/create', name: name, type: type)
end

#create_schedule(campaign_id:, list_id:, server_id:, sender_name: nil, schedule: nil) ⇒ Object

Create schedule



88
89
90
91
92
93
94
# File 'lib/adsmedia.rb', line 88

def create_schedule(campaign_id:, list_id:, server_id:, sender_name: nil, schedule: nil)
  payload = { campaign_id: campaign_id, list_id: list_id, server_id: server_id }
  payload[:sender_name] = sender_name if sender_name
  payload[:schedule] = schedule if schedule
  
  post('/schedules/create', payload)
end

#get_accountObject

Get account info



112
113
114
# File 'lib/adsmedia.rb', line 112

def 
  get('/account')
end

#get_campaign(id) ⇒ Object

Get campaign



54
55
56
# File 'lib/adsmedia.rb', line 54

def get_campaign(id)
  get('/campaigns/get', id: id)
end

#get_campaigns(limit: 50, offset: 0) ⇒ Object

List campaigns



49
50
51
# File 'lib/adsmedia.rb', line 49

def get_campaigns(limit: 50, offset: 0)
  get('/campaigns', limit: limit, offset: offset)
end

#get_listsObject

List contact lists



68
69
70
# File 'lib/adsmedia.rb', line 68

def get_lists
  get('/lists')
end

#get_schedules(status: 'queue') ⇒ Object

List schedules



83
84
85
# File 'lib/adsmedia.rb', line 83

def get_schedules(status: 'queue')
  get('/schedules', status: status)
end

#get_serversObject

List servers



97
98
99
# File 'lib/adsmedia.rb', line 97

def get_servers
  get('/servers')
end

#get_status(message_id) ⇒ Object

Check email status



44
45
46
# File 'lib/adsmedia.rb', line 44

def get_status(message_id)
  get('/send/status', message_id: message_id)
end

#get_usageObject

Get usage



117
118
119
# File 'lib/adsmedia.rb', line 117

def get_usage
  get('/account/usage')
end

#pingObject

Test connection



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

def ping
  get('/ping')
end

#send_batch(recipients:, subject:, html:, text: nil, preheader: nil, from_name: nil) ⇒ Object

Send batch emails



34
35
36
37
38
39
40
41
# File 'lib/adsmedia.rb', line 34

def send_batch(recipients:, subject:, html:, text: nil, preheader: nil, from_name: nil)
  payload = { recipients: recipients, subject: subject, html: html }
  payload[:text] = text if text
  payload[:preheader] = preheader if preheader
  payload[:from_name] = from_name if from_name
  
  post('/send/batch', payload)
end

#send_email(to:, subject:, html:, to_name: nil, from_name: nil, text: nil, reply_to: nil) ⇒ Object

Send single email



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

def send_email(to:, subject:, html:, to_name: nil, from_name: nil, text: nil, reply_to: nil)
  payload = { to: to, subject: subject, html: html }
  payload[:to_name] = to_name if to_name
  payload[:from_name] = from_name if from_name
  payload[:text] = text if text
  payload[:reply_to] = reply_to if reply_to
  
  post('/send', payload)
end

#verify_domain(server_id) ⇒ Object

Verify domain



102
103
104
# File 'lib/adsmedia.rb', line 102

def verify_domain(server_id)
  get('/domains/verify', server_id: server_id)
end