-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
executable file
·63 lines (55 loc) · 1.64 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env ruby
require 'dotenv'
require 'net/http'
require 'fileutils'
require 'createsend'
Dotenv.load
# Configuration
api_key = ENV['CAMPAIGN_MONITOR_API_KEY']
client_id = ENV['CAMPAIGN_MONITOR_CLIENT_ID']
baseurl = 'https://github.com/utmsigep/utmsigep-email-templates/blob/main'
basepath = Dir.pwd
task default: %w[build]
desc 'Build zip files for template assets'
task :build do
templates = get_templates(api_key, client_id)
templates.each do |t|
puts "Packaging #{t[:name]} ..."
Dir.chdir("#{basepath}/#{t[:path]}")
system("zip -q -r #{t[:path]}-assets.zip images/* style.css")
end
puts "Done!"
end
desc 'Update templates in Campaign Monitor'
task :update do
auth = { api_key: api_key }
cs = CreateSend::CreateSend.new(auth)
templates = get_templates(api_key, client_id)
templates.each do |t|
template = CreateSend::Template.new auth, t[:id]
puts "Updating #{t[:name]} ..."
begin
template.update(t[:name], "#{baseurl}/#{t[:path]}/index.html?raw=1", "#{baseurl}/#{t[:path]}/#{t[:path]}-assets.zip?raw=1")
rescue => error
puts error
puts "Index file: #{baseurl}/#{t[:path]}/index.html?raw=1"
puts "Zip file: #{baseurl}/#{t[:path]}/#{t[:path]}-assets.zip?raw=1"
end
end
puts "Done!"
end
private
def get_templates(api_key, client_id)
auth = { api_key: api_key }
cs = CreateSend::CreateSend.new(auth)
client = CreateSend::Client.new auth, client_id
templates = []
client.templates.each do |t|
templates.push({
name: t[:Name],
id: t[:TemplateID],
path: t[:Name].downcase.gsub(' ', '-').gsub(/[^0-9a-z\- ]/i, '')
})
end
return templates
end