Class: Interfax::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/interfax/base.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type = "HTML", content = nil) ⇒ Base

Instance methods



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/interfax/base.rb', line 53

def initialize(type="HTML",content=nil)
  @username = self.class.username
  @password = self.class.password
  @type = type.to_s.upcase
  @content = content
  @at = Time.now
  @recipients = nil
  @subject = "Change me"
  @retries = "0"

  @orientation = self.class.orientation || 'Portrait'
  @high_res = self.class.high_res || 'false'
  @fine_rendering = self.class.fine_rendering || 'true'
  @page_size = self.class.page_size || 'Letter'
end

Class Attribute Details

.fine_renderingObject

Returns the value of attribute fine_rendering.



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

def fine_rendering
  @fine_rendering
end

.high_resObject

Returns the value of attribute high_res.



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

def high_res
  @high_res
end

.orientationObject

Returns the value of attribute orientation.



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

def orientation
  @orientation
end

.page_sizeObject

Returns the value of attribute page_size.



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

def page_size
  @page_size
end

.passwordObject

Returns the value of attribute password.



9
10
11
# File 'lib/interfax/base.rb', line 9

def password
  @password
end

.usernameObject

Returns the value of attribute username.



9
10
11
# File 'lib/interfax/base.rb', line 9

def username
  @username
end

Class Method Details

.allObject



45
46
47
# File 'lib/interfax/base.rb', line 45

def all()
  query("LE","999999999")
end

.find(*args) ⇒ Object



37
38
39
# File 'lib/interfax/base.rb', line 37

def find(*args)
  query("IN", args.join(','))
end

.last(limit = 1) ⇒ Object



41
42
43
# File 'lib/interfax/base.rb', line 41

def last(limit=1)
  query("LE","999999999",limit)
end

.query(verb, verbdata, limit = -1)) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/interfax/base.rb', line 12

def query(verb,verbdata,limit=-1)
  result = SOAP::WSDLDriverFactory.new("https://ws.interfax.net/dfs.asmx?WSDL").create_rpc_driver.FaxQuery(
    :Username => self.username,
    :Password => self.password,
    :Verb => verb,
    :VerbData => verbdata,
    :MaxItems => limit,
    :ResultCode => 0
  )
  return [] if result.nil? || !defined?(result.faxQueryResult)
  [*result.faxQueryResult.faxItemEx].map do |f| 
    FaxItem.new(
      f.transactionID,
      Time.parse(f.submitTime),
      Time.parse(f.postponeTime),
      f.destinationFax,
      f.duration,
      f.remoteCSID,
      f.pagesSent,
      f.status,
      f.subject,
      f.pagesSubmitted)
  end  
end

Instance Method Details

#at(time) ⇒ Object



89
90
91
92
# File 'lib/interfax/base.rb', line 89

def at(time)
  @at = time
  self
end

#contains(content) ⇒ Object



69
70
71
72
# File 'lib/interfax/base.rb', line 69

def contains(content)
  @content = content
  self
end

#deliverObject



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/interfax/base.rb', line 128

def deliver
  driver = SOAP::WSDLDriverFactory.new("https://ws.interfax.net/dfs.asmx?WSDL").create_rpc_driver
  
  result = driver.SendfaxEx_2(
    :Username => @username,
    :Password => @password,
    :FileTypes => @type,
    :Postpone => @at,
    :RetriesToPerform => @retries,
    :FaxNumbers=> @recipients,
    :FileSizes => @content.bytesize,
    :FilesData => @content,
    :Subject => @subject,
    :PageSize => @page_size,
    :PageOrientation => @orientation,
    :IsHighResolution => @high_res,
    :IsFineRendering => @fine_rendering
  )
  result ? result.sendfaxEx_2Result : nil
end

#fine_rendering(boolstring) ⇒ Object



94
95
96
97
# File 'lib/interfax/base.rb', line 94

def fine_rendering(boolstring)
  @fine_rendering = boolstring
  self
end

#high_res(boolstring) ⇒ Object



104
105
106
107
# File 'lib/interfax/base.rb', line 104

def high_res(boolstring)
  @high_res = boolstring
  self
end

#orientation(orientation) ⇒ Object



99
100
101
102
# File 'lib/interfax/base.rb', line 99

def orientation(orientation)
  @orientation = orientation
  self
end

#page_size(size) ⇒ Object



109
110
111
112
# File 'lib/interfax/base.rb', line 109

def page_size(size)
  @page_size = size
  self
end

#retries(count) ⇒ Object



84
85
86
87
# File 'lib/interfax/base.rb', line 84

def retries(count)
  @retries = count.to_s
  self
end

#subject(subject) ⇒ Object



79
80
81
82
# File 'lib/interfax/base.rb', line 79

def subject(subject)
  @subject = subject
  self
end

#summaryObject



115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/interfax/base.rb', line 115

def summary
  { 
    :fax_numbers => @recipients, 
    :content => @content,
    :at => @at,
    :retries => @retries,
    :subject => @subject,
    :username => @username,
    :orientation => @orientation,
    :page_size => @page_size
  }
end

#to(recipients) ⇒ Object



74
75
76
77
# File 'lib/interfax/base.rb', line 74

def to(recipients)
  @recipients = [*recipients].join(";")
  self
end