forked from alphagov/e-petitions
-
Notifications
You must be signed in to change notification settings - Fork 1
/
notify.rake
29 lines (24 loc) · 826 Bytes
/
notify.rake
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
require "notifications/client"
require "fileutils"
namespace :notify do
task fetch_templates: :environment do
template_dir = Rails.root.join("spec", "fixtures", "notify")
client = Notifications::Client.new(ENV.fetch("NOTIFY_API_KEY"))
templates = client.get_all_templates(type: "email")
FileUtils.rm_rf template_dir
FileUtils.mkdir_p template_dir
templates.collection.each do |template|
template_path = template_dir.join("#{template.id}.yml")
yaml = <<~YAML
id: "#{template.id}"
name: "#{template.name}"
subject: "#{template.subject}"
body: |-
#{template.body.split("\r\n").map { |l| " #{l}" }.join("\n")}
YAML
File.write(template_path, yaml)
end
rescue Notifications::Client::RequestError => e
puts e.message
end
end