drnic-ruby-efax 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ pkg
2
+ tmp
data/README ADDED
@@ -0,0 +1,35 @@
1
+ = ruby-efax
2
+
3
+ Ruby library for accessing the eFax Developer service (http://www.efaxdeveloper.com).
4
+
5
+ Strange class names and their attribute names come from "eFax Developer Universal User Guide for Outbound Processing" document.
6
+ You can get it on eFax Developer pages or on Scribd (http://www.scribd.com/doc/5382394/eFax-Developer-Universal-User-Guide-Outbound).
7
+
8
+ == Usage
9
+
10
+ First you need to provide your account id and credentials:
11
+ EFax::Request.account_id = <your account id>
12
+ EFax::Request.user = <your login>
13
+ EFax::Request.password = <your password>
14
+
15
+
16
+ Sending an HTML page using eFax service is pretty simple:
17
+ response = EFax::OutboundRequest.post(recipient_name, company_name, fax_number, subject, html_content)
18
+
19
+ The response object has the following attributes:
20
+ response.status_code
21
+ response.doc_id # unique identifier of your request
22
+ response.error_level
23
+ response.error_message
24
+
25
+ See EFax::RequestStatus class for details on status codes.
26
+
27
+
28
+ Having ID of your request, you can get its current status:
29
+ response = OutboundRequestStatus.post(doc_id)
30
+
31
+ The status response has the following attributes:
32
+ response.status_code
33
+ response.message # "user friendly" status message
34
+
35
+ See EFax::QueryStatus class for details on status codes.
data/Rakefile ADDED
@@ -0,0 +1,42 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/clean'
4
+ require 'rake/gempackagetask'
5
+ require 'rake/rdoctask'
6
+ require 'rake/testtask'
7
+ require 'spec/rake/spectask'
8
+
9
+ begin
10
+ require 'jeweler'
11
+ Jeweler::Tasks.new do |gem|
12
+ gem.name = "ruby-efax"
13
+ gem.summary = 'Ruby library for accessing the eFax Developer service'
14
+ gem.authors = ["Szymon Nowak"]
15
+ gem.email = "szimek@gmail.com"
16
+ gem.homepage = "http://github.com/szimek/ruby-efax"
17
+ gem.rubyforge_project = "ruby-efax"
18
+ end
19
+
20
+ Jeweler::RubyforgeTasks.new do |rubyforge|
21
+ rubyforge.doc_task = "rdoc"
22
+ end
23
+ rescue LoadError
24
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
25
+ end
26
+
27
+ Rake::RDocTask.new do |rdoc|
28
+ files =['README', 'lib/**/*.rb']
29
+ rdoc.rdoc_files.add(files)
30
+ rdoc.main = "README" # page to start on
31
+ rdoc.title = 'ruby-efax: Ruby library for accessing the eFax Developer service'
32
+ rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder
33
+ rdoc.options << '--line-numbers'
34
+ end
35
+
36
+ Rake::TestTask.new do |t|
37
+ t.test_files = FileList['test/**/*.rb']
38
+ end
39
+
40
+ Spec::Rake::SpecTask.new do |t|
41
+ t.spec_files = FileList['spec/**/*.rb']
42
+ end
data/TODO ADDED
@@ -0,0 +1,2 @@
1
+ - provide simpler interface like EFax#send_request and EFax#query_status
2
+ - raise exception if account info or credentials are not set
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
data/lib/efax.rb ADDED
@@ -0,0 +1,225 @@
1
+ #--
2
+ # (The MIT License)
3
+ #
4
+ # Copyright (c) 2008 Szymon Nowak & Pawel Kozlowski (U2I)
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to
8
+ # deal in the Software without restriction, including without limitation the
9
+ # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10
+ # sell copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22
+ # IN THE SOFTWARE.
23
+ #++
24
+ #
25
+
26
+ require 'rubygems'
27
+ require 'net/http'
28
+ require 'net/https'
29
+ require 'builder'
30
+ require 'hpricot'
31
+ require 'base64'
32
+
33
+ module Net #:nodoc:
34
+ # Helper class for making HTTPS requests
35
+ class HTTPS < HTTP
36
+ def self.start(address, port = nil, p_addr = nil, p_port = nil, p_user = nil, p_pass = nil, &block) #:nodoc:
37
+ https = new(address, port, p_addr, p_port, p_user, p_pass)
38
+ https.use_ssl = true
39
+ https.start(&block)
40
+ end
41
+ end
42
+ end
43
+
44
+ module EFax
45
+ # URL of eFax web service
46
+ URL = "https://secure.efaxdeveloper.com/EFax_WebFax.serv"
47
+ # URI of eFax web service
48
+ URI = URI.parse(URL)
49
+ # Prefered content type
50
+ HEADERS = {'Content-Type' => 'text/xml'}
51
+
52
+ # Base class for OutboundRequest and OutboundStatus classes
53
+ class Request
54
+ def self.user
55
+ @@user
56
+ end
57
+ def self.user=(name)
58
+ @@user = name
59
+ end
60
+
61
+ def self.password
62
+ @@password
63
+ end
64
+ def self.password=(password)
65
+ @@password = password
66
+ end
67
+
68
+ def self.account_id
69
+ @@account_id
70
+ end
71
+ def self.account_id=(id)
72
+ @@account_id = id
73
+ end
74
+
75
+ def self.params(content)
76
+ escaped_xml = ::URI.escape(content, Regexp.new("[^#{::URI::PATTERN::UNRESERVED}]"))
77
+ "id=#{account_id}&xml=#{escaped_xml}&respond=XML"
78
+ end
79
+
80
+ private_class_method :params
81
+ end
82
+
83
+ class OutboundRequest < Request
84
+ def self.post(name, company, fax_number, subject, html_content)
85
+ xml_request = xml(name, company, fax_number, subject, html_content)
86
+ response = Net::HTTPS.start(EFax::URI.host, EFax::URI.port) do |https|
87
+ https.post(EFax::URI.path, params(xml_request), EFax::HEADERS)
88
+ end
89
+ OutboundResponse.new(response)
90
+ end
91
+
92
+ def self.xml(name, company, fax_number, subject, html_content)
93
+ xml_request = ""
94
+ xml = Builder::XmlMarkup.new(:target => xml_request, :indent => 2 )
95
+ xml.instruct! :xml, :version => '1.0'
96
+ xml.OutboundRequest do
97
+ xml.AccessControl do
98
+ xml.UserName(self.user)
99
+ xml.Password(self.password)
100
+ end
101
+ xml.Transmission do
102
+ xml.TransmissionControl do
103
+ xml.Resolution("FINE")
104
+ xml.Priority("NORMAL")
105
+ xml.SelfBusy("ENABLE")
106
+ xml.FaxHeader(subject)
107
+ end
108
+ xml.DispositionControl do
109
+ xml.DispositionLevel("NONE")
110
+ end
111
+ xml.Recipients do
112
+ xml.Recipient do
113
+ xml.RecipientName(name)
114
+ xml.RecipientCompany(company)
115
+ xml.RecipientFax(fax_number)
116
+ end
117
+ end
118
+ xml.Files do
119
+ xml.File do
120
+ encoded_html = Base64.encode64(html_content).delete("\n")
121
+ xml.FileContents(encoded_html)
122
+ xml.FileType("html")
123
+ end
124
+ end
125
+ end
126
+ end
127
+ xml_request
128
+ end
129
+
130
+ private_class_method :xml
131
+ end
132
+
133
+ class RequestStatus
134
+ HTTP_FAILURE = 0
135
+ SUCCESS = 1
136
+ FAILURE = 2
137
+ end
138
+
139
+ class OutboundResponse
140
+ attr_reader :status_code
141
+ attr_reader :error_message
142
+ attr_reader :error_level
143
+ attr_reader :doc_id
144
+
145
+ def initialize(response) #:nodoc:
146
+ if response.is_a? Net::HTTPOK
147
+ doc = Hpricot(response.body)
148
+ @status_code = doc.at(:statuscode).inner_text.to_i
149
+ @error_message = doc.at(:errormessage)
150
+ @error_message = @error_message.inner_text if @error_message
151
+ @error_level = doc.at(:errorlevel)
152
+ @error_level = @error_level.inner_text if @error_level
153
+ @doc_id = doc.at(:docid).inner_text
154
+ @doc_id = @doc_id.empty? ? nil : @doc_id
155
+ else
156
+ @status_code = RequestStatus::HTTP_FAILURE
157
+ @error_message = "HTTP request failed (#{response.code})"
158
+ end
159
+ end
160
+ end
161
+
162
+ class OutboundStatus < Request
163
+ def self.post(doc_id)
164
+ data = params(xml(doc_id))
165
+ response = Net::HTTPS.start(EFax::URI.host, EFax::URI.port) do |https|
166
+ https.post(EFax::URI.path, data, EFax::HEADERS)
167
+ end
168
+ OutboundStatusResponse.new(response)
169
+ end
170
+
171
+ def self.xml(doc_id)
172
+ xml_request = ""
173
+ xml = Builder::XmlMarkup.new(:target => xml_request, :indent => 2 )
174
+ xml.instruct! :xml, :version => '1.0'
175
+ xml.OutboundStatus do
176
+ xml.AccessControl do
177
+ xml.UserName(self.user)
178
+ xml.Password(self.password)
179
+ end
180
+ xml.Transmission do
181
+ xml.TransmissionControl do
182
+ xml.DOCID(doc_id)
183
+ end
184
+ end
185
+ end
186
+ xml_request
187
+ end
188
+
189
+ private_class_method :xml
190
+ end
191
+
192
+ class QueryStatus
193
+ HTTP_FAILURE = 0
194
+ PENDING = 3
195
+ SENT = 4
196
+ FAILURE = 5
197
+ end
198
+
199
+ class OutboundStatusResponse
200
+ attr_reader :status_code
201
+ attr_reader :message
202
+ attr_reader :classification
203
+ attr_reader :outcome
204
+
205
+ def initialize(response) #:nodoc:
206
+ if response.is_a? Net::HTTPOK
207
+ doc = Hpricot(response.body)
208
+ @message = doc.at(:message).innerText
209
+ @classification = doc.at(:classification).innerText.delete('"')
210
+ @outcome = doc.at(:outcome).innerText.delete('"')
211
+ if @classification.empty? && @outcome.empty?
212
+ @status_code = QueryStatus::PENDING
213
+ elsif @classification == "Success" && @outcome == "Success"
214
+ @status_code = QueryStatus::SENT
215
+ else
216
+ @status_code = QueryStatus::FAILURE
217
+ end
218
+ else
219
+ @status_code = QueryStatus::HTTP_FAILURE
220
+ @message = "HTTP request failed (#{response.code})"
221
+ end
222
+ end
223
+ end
224
+
225
+ end
data/ruby-efax.gemspec ADDED
@@ -0,0 +1,48 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{ruby-efax}
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Szymon Nowak"]
12
+ s.date = %q{2009-09-21}
13
+ s.email = %q{szimek@gmail.com}
14
+ s.extra_rdoc_files = [
15
+ "README"
16
+ ]
17
+ s.files = [
18
+ ".gitignore",
19
+ "README",
20
+ "Rakefile",
21
+ "TODO",
22
+ "VERSION",
23
+ "lib/efax.rb",
24
+ "ruby-efax.gemspec",
25
+ "test/efax_test.rb",
26
+ "test/test_helper.rb"
27
+ ]
28
+ s.homepage = %q{http://github.com/szimek/ruby-efax}
29
+ s.rdoc_options = ["--charset=UTF-8"]
30
+ s.require_paths = ["lib"]
31
+ s.rubyforge_project = %q{ruby-efax}
32
+ s.rubygems_version = %q{1.3.5}
33
+ s.summary = %q{Ruby library for accessing the eFax Developer service}
34
+ s.test_files = [
35
+ "test/efax_test.rb",
36
+ "test/test_helper.rb"
37
+ ]
38
+
39
+ if s.respond_to? :specification_version then
40
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
44
+ else
45
+ end
46
+ else
47
+ end
48
+ end
data/test/efax_test.rb ADDED
@@ -0,0 +1,357 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ module EFaxTest
4
+
5
+ class RequestTest < Test::Unit::TestCase
6
+ def test_should_encode_data
7
+ EFax::Request.account_id = 1234567890
8
+ EFax::Request.publicize_class_methods do
9
+ assert_equal "id=1234567890&xml=%40abc%23&respond=XML", EFax::Request.params('@abc#')
10
+ end
11
+ end
12
+ end
13
+
14
+ class OutboundResponseTest < Test::Unit::TestCase
15
+ def test_successful_response
16
+ xml = <<-XML
17
+ <?xml version="1.0"?>
18
+ <OutboundResponse>
19
+ <Transmission>
20
+ <TransmissionControl>
21
+ <TransmissionID></TransmissionID>
22
+ <DOCID>12345678</DOCID>
23
+ </TransmissionControl>
24
+ <Response>
25
+ <StatusCode>1</StatusCode>
26
+ <StatusDescription>Success</StatusDescription>
27
+ </Response>
28
+ </Transmission>
29
+ </OutboundResponse>
30
+ XML
31
+ http_response = mock
32
+ http_response.expects(:is_a?).with(Net::HTTPOK).returns(true)
33
+ http_response.expects(:body).returns(xml)
34
+ response = EFax::OutboundResponse.new(http_response)
35
+
36
+ assert_equal EFax::RequestStatus::SUCCESS, response.status_code
37
+ assert_equal "12345678", response.doc_id
38
+ assert_nil response.error_message
39
+ assert_nil response.error_level
40
+ end
41
+
42
+ def test_system_level_failed_response
43
+ xml = <<-XML
44
+ <?xml version="1.0"?>
45
+ <OutboundResponse>
46
+ <Transmission>
47
+ <TransmissionControl>
48
+ <TransmissionID></TransmissionID>
49
+ <DOCID></DOCID>
50
+ </TransmissionControl>
51
+ <Response>
52
+ <StatusCode>2</StatusCode>
53
+ <StatusDescription>Failure</StatusDescription>
54
+ <ErrorLevel>System</ErrorLevel>
55
+ <ErrorMessage>We FAIL</ErrorMessage>
56
+ </Response>
57
+ </Transmission>
58
+ </OutboundResponse>
59
+ XML
60
+ http_response = mock()
61
+ http_response.expects(:is_a?).with(Net::HTTPOK).returns(true)
62
+ http_response.expects(:body).returns(xml)
63
+ response = EFax::OutboundResponse.new(http_response)
64
+ assert_equal EFax::RequestStatus::FAILURE, response.status_code
65
+ assert_nil response.doc_id
66
+ assert_equal "We FAIL", response.error_message
67
+ assert_equal "System", response.error_level
68
+ end
69
+
70
+ def test_user_level_failed_response
71
+ xml = <<-XML
72
+ <?xml version="1.0"?>
73
+ <OutboundResponse>
74
+ <Transmission>
75
+ <TransmissionControl>
76
+ <TransmissionID></TransmissionID>
77
+ <DOCID></DOCID>
78
+ </TransmissionControl>
79
+ <Response>
80
+ <StatusCode>2</StatusCode>
81
+ <StatusDescription>Failure</StatusDescription>
82
+ <ErrorLevel>User</ErrorLevel>
83
+ <ErrorMessage>"QWE RTY" does not satisfy the "base64Binary" type</ErrorMessage>
84
+ </Response>
85
+ </Transmission>
86
+ </OutboundResponse>
87
+ XML
88
+ http_response = mock()
89
+ http_response.expects(:is_a?).with(Net::HTTPOK).returns(true)
90
+ http_response.expects(:body).returns(xml)
91
+ response = EFax::OutboundResponse.new(http_response)
92
+ assert_equal EFax::RequestStatus::FAILURE, response.status_code
93
+ assert_nil response.doc_id
94
+ assert_equal '"QWE RTY" does not satisfy the "base64Binary" type', response.error_message
95
+ assert_equal "User", response.error_level
96
+ end
97
+
98
+ def test_http_failed_response
99
+ http_response = mock()
100
+ http_response.expects(:is_a?).with(Net::HTTPOK).returns(false)
101
+ http_response.expects(:code).returns(500)
102
+ response = EFax::OutboundResponse.new(http_response)
103
+ assert_equal EFax::RequestStatus::HTTP_FAILURE, response.status_code
104
+ assert_nil response.doc_id
105
+ assert_equal "HTTP request failed (500)", response.error_message
106
+ assert_nil response.error_level
107
+ end
108
+ end
109
+
110
+ class OutboundStatusResponseTest < Test::Unit::TestCase
111
+ def test_successful_response
112
+ xml = <<-XML
113
+ <?xml version="1.0"?>
114
+ <OutboundStatusResponse>
115
+ <Transmission>
116
+ <TransmissionControl>
117
+ <TransmissionID></TransmissionID>
118
+ </TransmissionControl>
119
+ <Recipients>
120
+ <Recipient>
121
+ <DOCID>12345678</DOCID>
122
+ <Name>Mike Rotch</Name>
123
+ <Company>Moe's</Company>
124
+ <Fax>12345678901</Fax>
125
+ <Status>
126
+ <Message>Your transmission has completed.</Message>
127
+ <Classification>"Success"</Classification>
128
+ <Outcome>"Success"</Outcome>
129
+ </Status>
130
+ <LastAttempt>
131
+ <LastDate>08/06/2008</LastDate>
132
+ <LastTime>05:49:05</LastTime>
133
+ </LastAttempt>
134
+ <NextAttempt>
135
+ <NextDate></NextDate>
136
+ <NextTime></NextTime>
137
+ </NextAttempt>
138
+ <Pages>
139
+ <Scheduled>1</Scheduled>
140
+ <Sent>1</Sent>
141
+ </Pages>
142
+ <BaudRate>14400</BaudRate>
143
+ <Duration>0.4</Duration>
144
+ <Retries>1</Retries>
145
+ <RemoteCSID>"-"</RemoteCSID>
146
+ </Recipient>
147
+ </Recipients>
148
+ </Transmission>
149
+ </OutboundStatusResponse>
150
+ XML
151
+ http_response = mock()
152
+ http_response.expects(:is_a?).with(Net::HTTPOK).returns(true)
153
+ http_response.expects(:body).returns(xml)
154
+ response = EFax::OutboundStatusResponse.new(http_response)
155
+ assert_equal "Your transmission has completed.", response.message
156
+ assert_equal "Success", response.outcome
157
+ assert_equal "Success", response.classification
158
+ assert_equal EFax::QueryStatus::SENT, response.status_code
159
+ end
160
+
161
+ def test_pending_response
162
+ xml = <<-XML
163
+ <?xml version="1.0"?>
164
+ <OutboundStatusResponse>
165
+ <Transmission>
166
+ <TransmissionControl>
167
+ <TransmissionID></TransmissionID>
168
+ </TransmissionControl>
169
+ <Recipients>
170
+ <Recipient>
171
+ <DOCID>12345678</DOCID>
172
+ <Name>Mike Rotch</Name>
173
+ <Company>Moe's</Company>
174
+ <Fax>12345678901</Fax>
175
+ <Status>
176
+ <Message>Your fax is waiting to be send</Message>
177
+ <Classification></Classification>
178
+ <Outcome></Outcome>
179
+ </Status>
180
+ <LastAttempt>
181
+ <LastDate></LastDate>
182
+ <LastTime></LastTime>
183
+ </LastAttempt>
184
+ <NextAttempt>
185
+ <NextDate></NextDate>
186
+ <NextTime></NextTime>
187
+ </NextAttempt>
188
+ <Pages>
189
+ <Scheduled>1</Scheduled>
190
+ <Sent>1</Sent>
191
+ </Pages>
192
+ <BaudRate>14400</BaudRate>
193
+ <Duration>0.4</Duration>
194
+ <Retries>1</Retries>
195
+ <RemoteCSID>"-"</RemoteCSID>
196
+ </Recipient>
197
+ </Recipients>
198
+ </Transmission>
199
+ </OutboundStatusResponse>
200
+ XML
201
+
202
+ http_response = mock()
203
+ http_response.expects(:is_a?).with(Net::HTTPOK).returns(true)
204
+ http_response.expects(:body).returns(xml)
205
+ response = EFax::OutboundStatusResponse.new(http_response)
206
+
207
+ assert_equal "", response.outcome
208
+ assert_equal "", response.classification
209
+ assert_equal EFax::QueryStatus::PENDING, response.status_code
210
+ end
211
+
212
+ def test_failed_response
213
+ xml = <<-XML
214
+ <?xml version="1.0"?>
215
+ <OutboundStatusResponse>
216
+ <Transmission>
217
+ <TransmissionControl>
218
+ <TransmissionID></TransmissionID>
219
+ </TransmissionControl>
220
+ <Recipients>
221
+ <Recipient>
222
+ <DOCID>12345678</DOCID>
223
+ <Name>Mike Rotch</Name>
224
+ <Company>Moe's</Company>
225
+ <Fax>12345678901</Fax>
226
+ <Status>
227
+ <Message>Your fax caused the world to end</Message>
228
+ <Classification>Apocalyptic failure</Classification>
229
+ <Outcome>End of days</Outcome>
230
+ </Status>
231
+ <LastAttempt>
232
+ <LastDate></LastDate>
233
+ <LastTime></LastTime>
234
+ </LastAttempt>
235
+ <NextAttempt>
236
+ <NextDate></NextDate>
237
+ <NextTime></NextTime>
238
+ </NextAttempt>
239
+ <Pages>
240
+ <Scheduled>1</Scheduled>
241
+ <Sent>0</Sent>
242
+ </Pages>
243
+ <BaudRate></BaudRate>
244
+ <Duration></Duration>
245
+ <Retries>1</Retries>
246
+ <RemoteCSID>"-"</RemoteCSID>
247
+ </Recipient>
248
+ </Recipients>
249
+ </Transmission>
250
+ </OutboundStatusResponse>
251
+ XML
252
+
253
+ http_response = mock()
254
+ http_response.expects(:is_a?).with(Net::HTTPOK).returns(true)
255
+ http_response.expects(:body).returns(xml)
256
+ response = EFax::OutboundStatusResponse.new(http_response)
257
+
258
+ assert_equal "Your fax caused the world to end", response.message
259
+ assert_equal "End of days", response.outcome
260
+ assert_equal "Apocalyptic failure", response.classification
261
+ assert_equal EFax::QueryStatus::FAILURE, response.status_code
262
+ end
263
+
264
+ end
265
+
266
+ class OutboundRequestTest < Test::Unit::TestCase
267
+ def test_generate_xml
268
+ expected_xml = <<-XML
269
+ <?xml version="1.0" encoding="UTF-8"?>
270
+ <OutboundRequest>
271
+ <AccessControl>
272
+ <UserName>Mike Rotch</UserName>
273
+ <Password>moes</Password>
274
+ </AccessControl>
275
+ <Transmission>
276
+ <TransmissionControl>
277
+ <Resolution>FINE</Resolution>
278
+ <Priority>NORMAL</Priority>
279
+ <SelfBusy>ENABLE</SelfBusy>
280
+ <FaxHeader>Subject</FaxHeader>
281
+ </TransmissionControl>
282
+ <DispositionControl>
283
+ <DispositionLevel>NONE</DispositionLevel>
284
+ </DispositionControl>
285
+ <Recipients>
286
+ <Recipient>
287
+ <RecipientName>I. P. Freely</RecipientName>
288
+ <RecipientCompany>Moe's</RecipientCompany>
289
+ <RecipientFax>12345678901</RecipientFax>
290
+ </Recipient>
291
+ </Recipients>
292
+ <Files>
293
+ <File>
294
+ <FileContents>PGh0bWw+PGJvZHk+PGgxPlRlc3Q8L2gxPjwvYm9keT48L2h0bWw+</FileContents>
295
+ <FileType>html</FileType>
296
+ </File>
297
+ </Files>
298
+ </Transmission>
299
+ </OutboundRequest>
300
+ XML
301
+ EFax::Request.user = "Mike Rotch"
302
+ EFax::Request.password = "moes"
303
+ EFax::OutboundRequest.publicize_class_methods do
304
+ assert_equal expected_xml.delete(" "), EFax::OutboundRequest.xml("I. P. Freely", "Moe's", "12345678901", "Subject", "<html><body><h1>Test</h1></body></html>").delete(" ")
305
+ end
306
+ end
307
+ end
308
+
309
+ class OutboundStatusTest < Test::Unit::TestCase
310
+ def test_generate_xml
311
+ expected_xml = <<-XML
312
+ <?xml version="1.0" encoding="UTF-8"?>
313
+ <OutboundStatus>
314
+ <AccessControl>
315
+ <UserName>Mike Rotch</UserName>
316
+ <Password>moes</Password>
317
+ </AccessControl>
318
+ <Transmission>
319
+ <TransmissionControl>
320
+ <DOCID>123456</DOCID>
321
+ </TransmissionControl>
322
+ </Transmission>
323
+ </OutboundStatus>
324
+ XML
325
+
326
+ EFax::OutboundStatus.publicize_class_methods do
327
+ assert_equal expected_xml.delete(" "), EFax::OutboundStatus.xml("123456").delete(" ")
328
+ end
329
+ end
330
+ end
331
+
332
+ class OutboundStatusTest < Test::Unit::TestCase
333
+ def test_generate_xml
334
+ expected_xml = <<-XML
335
+ <?xml version="1.0" encoding="UTF-8"?>
336
+ <OutboundStatus>
337
+ <AccessControl>
338
+ <UserName>Mike Rotch</UserName>
339
+ <Password>moes</Password>
340
+ </AccessControl>
341
+ <Transmission>
342
+ <TransmissionControl>
343
+ <DOCID>123456</DOCID>
344
+ </TransmissionControl>
345
+ </Transmission>
346
+ </OutboundStatus>
347
+ XML
348
+
349
+ EFax::Request.user = "Mike Rotch"
350
+ EFax::Request.password = "moes"
351
+ EFax::OutboundStatus.publicize_class_methods do
352
+ assert_equal expected_xml.delete(" "), EFax::OutboundStatus.xml("123456").delete(" ")
353
+ end
354
+ end
355
+ end
356
+
357
+ end
@@ -0,0 +1,19 @@
1
+ require 'test/unit'
2
+ require 'mocha'
3
+ require File.dirname(__FILE__) + '/../lib/efax'
4
+
5
+ class Class
6
+ def publicize_instance_methods
7
+ saved_private_instance_methods = self.private_instance_methods
8
+ self.class_eval { public(*saved_private_instance_methods) }
9
+ yield
10
+ self.class_eval { private(*saved_private_instance_methods) }
11
+ end
12
+
13
+ def publicize_class_methods
14
+ saved_private_class_methods = self.private_methods(false)
15
+ self.class_eval { public_class_method(*saved_private_class_methods) }
16
+ yield
17
+ self.class_eval { private_class_method(*saved_private_class_methods) }
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: drnic-ruby-efax
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Szymon Nowak
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-21 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: szimek@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ files:
25
+ - .gitignore
26
+ - README
27
+ - Rakefile
28
+ - TODO
29
+ - VERSION
30
+ - lib/efax.rb
31
+ - ruby-efax.gemspec
32
+ - test/efax_test.rb
33
+ - test/test_helper.rb
34
+ has_rdoc: false
35
+ homepage: http://github.com/szimek/ruby-efax
36
+ licenses:
37
+ post_install_message:
38
+ rdoc_options:
39
+ - --charset=UTF-8
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ version:
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ version:
54
+ requirements: []
55
+
56
+ rubyforge_project: ruby-efax
57
+ rubygems_version: 1.3.5
58
+ signing_key:
59
+ specification_version: 3
60
+ summary: Ruby library for accessing the eFax Developer service
61
+ test_files:
62
+ - test/efax_test.rb
63
+ - test/test_helper.rb