Class: Sendly::CampaignsResource

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ CampaignsResource

Returns a new instance of CampaignsResource.



101
102
103
# File 'lib/sendly/campaigns_resource.rb', line 101

def initialize(client)
  @client = client
end

Instance Method Details

#cancel(id) ⇒ Object



171
172
173
174
# File 'lib/sendly/campaigns_resource.rb', line 171

def cancel(id)
  response = @client.post("/campaigns/#{id}/cancel")
  Campaign.new(response)
end

#clone(id) ⇒ Object



176
177
178
179
# File 'lib/sendly/campaigns_resource.rb', line 176

def clone(id)
  response = @client.post("/campaigns/#{id}/clone")
  Campaign.new(response)
end

#create(name:, text:, contact_list_ids:, template_id: nil) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
# File 'lib/sendly/campaigns_resource.rb', line 105

def create(name:, text:, contact_list_ids:, template_id: nil)
  body = {
    name: name,
    text: text,
    contactListIds: contact_list_ids
  }
  body[:templateId] = template_id if template_id

  response = @client.post("/campaigns", body)
  Campaign.new(response)
end

#delete(id) ⇒ Object



149
150
151
# File 'lib/sendly/campaigns_resource.rb', line 149

def delete(id)
  @client.delete("/campaigns/#{id}")
end

#get(id) ⇒ Object



133
134
135
136
# File 'lib/sendly/campaigns_resource.rb', line 133

def get(id)
  response = @client.get("/campaigns/#{id}")
  Campaign.new(response)
end

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



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/sendly/campaigns_resource.rb', line 117

def list(limit: nil, offset: nil, status: nil)
  params = {}
  params[:limit] = limit if limit
  params[:offset] = offset if offset
  params[:status] = status if status

  response = @client.get("/campaigns", params)
  campaigns = (response["campaigns"] || []).map { |c| Campaign.new(c) }
  {
    campaigns: campaigns,
    total: response["total"],
    limit: response["limit"],
    offset: response["offset"]
  }
end

#preview(id) ⇒ Object



153
154
155
156
# File 'lib/sendly/campaigns_resource.rb', line 153

def preview(id)
  response = @client.get("/campaigns/#{id}/preview")
  CampaignPreview.new(response)
end

#schedule(id, scheduled_at:, timezone: nil) ⇒ Object



163
164
165
166
167
168
169
# File 'lib/sendly/campaigns_resource.rb', line 163

def schedule(id, scheduled_at:, timezone: nil)
  body = { scheduledAt: scheduled_at }
  body[:timezone] = timezone if timezone

  response = @client.post("/campaigns/#{id}/schedule", body)
  Campaign.new(response)
end

#send_campaign(id) ⇒ Object



158
159
160
161
# File 'lib/sendly/campaigns_resource.rb', line 158

def send_campaign(id)
  response = @client.post("/campaigns/#{id}/send")
  Campaign.new(response)
end

#update(id, name: nil, text: nil, template_id: nil, contact_list_ids: nil) ⇒ Object



138
139
140
141
142
143
144
145
146
147
# File 'lib/sendly/campaigns_resource.rb', line 138

def update(id, name: nil, text: nil, template_id: nil, contact_list_ids: nil)
  body = {}
  body[:name] = name if name
  body[:text] = text if text
  body[:templateId] = template_id unless template_id.nil?
  body[:contactListIds] = contact_list_ids if contact_list_ids

  response = @client.patch("/campaigns/#{id}", body)
  Campaign.new(response)
end