-
Notifications
You must be signed in to change notification settings - Fork 0
/
faxer.rb
40 lines (33 loc) · 946 Bytes
/
faxer.rb
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
require 'phaxio'
Phaxio.config do |config|
config.api_key = ENV['PHAXIO_API_KEY']
config.api_secret = ENV['PHAXIO_API_SECRET']
end
module Faxer
extend self
def send_fax(phone_number, file_or_files)
if configured_for_sending?
FaxResult.new(Phaxio.send_fax(to: phone_number, filename: file_or_files))
else
FaxResult.new({"success" => false, "message" => "Faxer not configured." })
end
end
def configured_for_sending?
configured = true
['FAX_DESTINATION_NUMBER', 'PHAXIO_API_KEY', 'PHAXIO_API_SECRET'].each do |env_var|
configured = false unless ENV.has_key?(env_var) && ENV[env_var] != ""
end
configured
end
class FaxResult
attr_reader :full_result, :success, :message
def initialize(hash_result)
@full_result = hash_result
@success = hash_result['success']
@message = hash_result['message']
end
def successful?
@success
end
end
end