|
1
|
|
|
#!ruby |
|
2
|
|
|
|
|
3
|
|
|
require 'handlebars' |
|
4
|
|
|
require 'ringcentral_sdk' |
|
5
|
|
|
require 'pp' |
|
6
|
|
|
require 'mime_builder' |
|
7
|
|
|
|
|
8
|
|
|
# Set your credentials in the .env file |
|
9
|
|
|
# Use the rc_config_sample.env.txt file as a scaffold |
|
10
|
|
|
config = RingCentralSdk::REST::Config.new.load_dotenv |
|
11
|
|
|
client = RingCentralSdk::REST::Client.new |
|
12
|
|
|
client.set_app_config config.app |
|
13
|
|
|
client.authorize_user config.user |
|
14
|
|
|
|
|
15
|
|
|
def get_coverpage |
|
16
|
|
|
hbs = ENV['RC_DEMO_FAX_COVERPAGE_TEMPLATE'] |
|
17
|
|
|
unless File.exists? hbs |
|
18
|
|
|
raise "Coverpage Template Does Not Exist: " + hbs |
|
19
|
|
|
end |
|
20
|
|
|
|
|
21
|
|
|
handlebars = Handlebars::Context.new |
|
22
|
|
|
template = handlebars.compile IO.read(hbs) |
|
23
|
|
|
|
|
24
|
|
|
html = template.call( |
|
25
|
|
|
fax_date: DateTime.now().to_s, |
|
26
|
|
|
fax_pages: ENV['RC_DEMO_FAX_PAGES'], |
|
27
|
|
|
fax_to_name: ENV['RC_DEMO_FAX_TO_NAME'], |
|
28
|
|
|
fax_to_phone: ENV['RC_DEMO_FAX_TO'], |
|
29
|
|
|
fax_to_fax: ENV['RC_DEMO_FAX_TO'], |
|
30
|
|
|
fax_from_name: ENV['RC_DEMO_FAX_FROM_NAME'], |
|
31
|
|
|
fax_from_phone: ENV['RC_DEMO_FAX_FROM'], |
|
32
|
|
|
fax_from_fax: ENV['RC_DEMO_FAX_FROM'], |
|
33
|
|
|
fax_coverpage_text: ENV['RC_DEMO_FAX_COVERPAGE_TEXT'] |
|
34
|
|
|
) |
|
35
|
|
|
|
|
36
|
|
|
builder = MIMEBuilder::Text.new html, |
|
37
|
|
|
content_type: 'text/html', |
|
38
|
|
|
content_id_disable: true, |
|
39
|
|
|
is_attachment: true |
|
40
|
|
|
|
|
41
|
|
|
return builder.mime |
|
42
|
|
|
end |
|
43
|
|
|
|
|
44
|
|
|
# Get the coverpage as a MIME::Media object to pass into |
|
45
|
|
|
# Fax method as an file part |
|
46
|
|
|
cover = get_coverpage() |
|
47
|
|
|
|
|
48
|
|
|
# Set coverIndex to 0 to remove standard template |
|
49
|
|
|
# add MIME::Media object as first file attachment |
|
50
|
|
|
res = client.messages.fax.create( |
|
51
|
|
|
to: config.env.data['RC_DEMO_FAX_TO'], |
|
52
|
|
|
coverIndex: 0, |
|
53
|
|
|
files: [cover, config.env.data['RC_DEMO_FAX_FILE']] |
|
54
|
|
|
) |
|
55
|
|
|
pp res.body |
|
56
|
|
|
|
|
57
|
|
|
puts "DONE" |
|
58
|
|
|
|