Class: MailFakk2

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/mailfakk2.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

#log

Constructor Details

#initialize(source) ⇒ MailFakk2

Returns a new instance of MailFakk2.



10
11
12
# File 'lib/mailfakk2.rb', line 10

def initialize(source)
  @fax = Facsimile.new(source)
end

Instance Attribute Details

#faxObject (readonly)

Returns the value of attribute fax.



8
9
10
# File 'lib/mailfakk2.rb', line 8

def fax
  @fax
end

Class Method Details

.deliver!(source) ⇒ Object



4
5
6
# File 'lib/mailfakk2.rb', line 4

def self.deliver!(source)
  new(source).deliver!
end

Instance Method Details

#archive_pathObject



21
22
23
# File 'lib/mailfakk2.rb', line 21

def archive_path
  File.expand_path File.join( config.archive_path, @fax.filename)
end

#callfile_contentsObject



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/mailfakk2.rb', line 44

def callfile_contents
  <<-EOCALL
Channel: DAHDI/g0/#{@fax.number}
MaxRetries: 5
WaitTime: 20
Context: incoming-fax
Application: SendFax
Data:#{archive_path}
Archive: yes
  EOCALL
end

#callfile_pathObject



25
26
27
# File 'lib/mailfakk2.rb', line 25

def callfile_path
  File.join( config.outgoing_call_dir, @fax.callfile_name)
end

#configObject



29
30
31
# File 'lib/mailfakk2.rb', line 29

def config
  @config ||= Configuration.load
end

#deliver!Object



14
15
16
17
18
19
# File 'lib/mailfakk2.rb', line 14

def deliver!
  log("sending fax to #{@fax.number}")
  @fax.write( archive_path )
  write_callfile
  self
end

#write_callfileObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/mailfakk2.rb', line 33

def write_callfile
  tmp = Tempfile.new('call')
  log("write tmp callfile to #{tmp.path}")
  tmp.puts callfile_contents
  tmp.close
  log("mv callfile to asterisk spool: #{callfile_path}")
  FileUtils.mkdir_p config.outgoing_call_dir
  FileUtils.mv tmp.path, callfile_path
  FileUtils.chmod 0666, callfile_path
end