efax 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -0
- data/README.rdoc +35 -0
- data/Rakefile +45 -0
- data/TODO +2 -0
- data/VERSION +1 -0
- data/lib/efax.rb +224 -0
- data/ruby-efax.gemspec +54 -0
- data/test/efax_test.rb +357 -0
- data/test/test_helper.rb +20 -0
- metadata +84 -0
data/.gitignore
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
= 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, 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,45 @@
|
|
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 = "efax"
|
13
|
+
gem.summary = 'Ruby library for accessing the eFax Developer service'
|
14
|
+
gem.authors = ["Szymon Nowak", "Pawel Kozlowski"]
|
15
|
+
gem.email = "szimek@gmail.com"
|
16
|
+
gem.homepage = "http://github.com/szimek/efax"
|
17
|
+
gem.rubyforge_project = "efax"
|
18
|
+
|
19
|
+
gem.add_dependency('hpricot', '>= 0.8.1')
|
20
|
+
gem.add_development_dependency('mocha', '>= 0.9')
|
21
|
+
end
|
22
|
+
|
23
|
+
Jeweler::RubyforgeTasks.new do |rubyforge|
|
24
|
+
rubyforge.doc_task = "rdoc"
|
25
|
+
end
|
26
|
+
rescue LoadError
|
27
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
28
|
+
end
|
29
|
+
|
30
|
+
Rake::RDocTask.new do |rdoc|
|
31
|
+
files =['README.rdoc', 'lib/**/*.rb']
|
32
|
+
rdoc.rdoc_files.add(files)
|
33
|
+
rdoc.main = "README.rdoc" # page to start on
|
34
|
+
rdoc.title = 'eFax: Ruby library for accessing the eFax Developer service'
|
35
|
+
rdoc.rdoc_dir = 'rdoc' # rdoc output folder
|
36
|
+
rdoc.options << '--line-numbers'
|
37
|
+
end
|
38
|
+
|
39
|
+
Rake::TestTask.new do |t|
|
40
|
+
t.test_files = FileList['test/**/*.rb']
|
41
|
+
end
|
42
|
+
|
43
|
+
Spec::Rake::SpecTask.new do |t|
|
44
|
+
t.spec_files = FileList['spec/**/*.rb']
|
45
|
+
end
|
data/TODO
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.1.1
|
data/lib/efax.rb
ADDED
@@ -0,0 +1,224 @@
|
|
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 'net/http'
|
27
|
+
require 'net/https'
|
28
|
+
require 'builder'
|
29
|
+
require 'hpricot'
|
30
|
+
require 'base64'
|
31
|
+
|
32
|
+
module Net #:nodoc:
|
33
|
+
# Helper class for making HTTPS requests
|
34
|
+
class HTTPS < HTTP
|
35
|
+
def self.start(address, port = nil, p_addr = nil, p_port = nil, p_user = nil, p_pass = nil, &block) #:nodoc:
|
36
|
+
https = new(address, port, p_addr, p_port, p_user, p_pass)
|
37
|
+
https.use_ssl = true
|
38
|
+
https.start(&block)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
module EFax
|
44
|
+
# URL of eFax web service
|
45
|
+
Url = "https://secure.efaxdeveloper.com/EFax_WebFax.serv"
|
46
|
+
# URI of eFax web service
|
47
|
+
Uri = URI.parse(Url)
|
48
|
+
# Prefered content type
|
49
|
+
HEADERS = {'Content-Type' => 'text/xml'}
|
50
|
+
|
51
|
+
# Base class for OutboundRequest and OutboundStatus classes
|
52
|
+
class Request
|
53
|
+
def self.user
|
54
|
+
@@user
|
55
|
+
end
|
56
|
+
def self.user=(name)
|
57
|
+
@@user = name
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.password
|
61
|
+
@@password
|
62
|
+
end
|
63
|
+
def self.password=(password)
|
64
|
+
@@password = password
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.account_id
|
68
|
+
@@account_id
|
69
|
+
end
|
70
|
+
def self.account_id=(id)
|
71
|
+
@@account_id = id
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.params(content)
|
75
|
+
escaped_xml = ::URI.escape(content, Regexp.new("[^#{::URI::PATTERN::UNRESERVED}]"))
|
76
|
+
"id=#{account_id}&xml=#{escaped_xml}&respond=XML"
|
77
|
+
end
|
78
|
+
|
79
|
+
private_class_method :params
|
80
|
+
end
|
81
|
+
|
82
|
+
class OutboundRequest < Request
|
83
|
+
def self.post(name, company, fax_number, subject, content, content_type = :html)
|
84
|
+
xml_request = xml(name, company, fax_number, subject, content, content_type)
|
85
|
+
response = Net::HTTPS.start(EFax::Uri.host, EFax::Uri.port) do |https|
|
86
|
+
https.post(EFax::Uri.path, params(xml_request), EFax::HEADERS)
|
87
|
+
end
|
88
|
+
OutboundResponse.new(response)
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.xml(name, company, fax_number, subject, content, content_type = :html)
|
92
|
+
xml_request = ""
|
93
|
+
xml = Builder::XmlMarkup.new(:target => xml_request, :indent => 2 )
|
94
|
+
xml.instruct! :xml, :version => '1.0'
|
95
|
+
xml.OutboundRequest do
|
96
|
+
xml.AccessControl do
|
97
|
+
xml.UserName(self.user)
|
98
|
+
xml.Password(self.password)
|
99
|
+
end
|
100
|
+
xml.Transmission do
|
101
|
+
xml.TransmissionControl do
|
102
|
+
xml.Resolution("FINE")
|
103
|
+
xml.Priority("NORMAL")
|
104
|
+
xml.SelfBusy("ENABLE")
|
105
|
+
xml.FaxHeader(subject)
|
106
|
+
end
|
107
|
+
xml.DispositionControl do
|
108
|
+
xml.DispositionLevel("NONE")
|
109
|
+
end
|
110
|
+
xml.Recipients do
|
111
|
+
xml.Recipient do
|
112
|
+
xml.RecipientName(name)
|
113
|
+
xml.RecipientCompany(company)
|
114
|
+
xml.RecipientFax(fax_number)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
xml.Files do
|
118
|
+
xml.File do
|
119
|
+
encoded_content = Base64.encode64(content).delete("\n")
|
120
|
+
xml.FileContents(encoded_content)
|
121
|
+
xml.FileType(content_type.to_s)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
xml_request
|
127
|
+
end
|
128
|
+
|
129
|
+
private_class_method :xml
|
130
|
+
end
|
131
|
+
|
132
|
+
class RequestStatus
|
133
|
+
HTTP_FAILURE = 0
|
134
|
+
SUCCESS = 1
|
135
|
+
FAILURE = 2
|
136
|
+
end
|
137
|
+
|
138
|
+
class OutboundResponse
|
139
|
+
attr_reader :status_code
|
140
|
+
attr_reader :error_message
|
141
|
+
attr_reader :error_level
|
142
|
+
attr_reader :doc_id
|
143
|
+
|
144
|
+
def initialize(response) #:nodoc:
|
145
|
+
if response.is_a? Net::HTTPOK
|
146
|
+
doc = Hpricot(response.body)
|
147
|
+
@status_code = doc.at(:statuscode).inner_text.to_i
|
148
|
+
@error_message = doc.at(:errormessage)
|
149
|
+
@error_message = @error_message.inner_text if @error_message
|
150
|
+
@error_level = doc.at(:errorlevel)
|
151
|
+
@error_level = @error_level.inner_text if @error_level
|
152
|
+
@doc_id = doc.at(:docid).inner_text
|
153
|
+
@doc_id = @doc_id.empty? ? nil : @doc_id
|
154
|
+
else
|
155
|
+
@status_code = RequestStatus::HTTP_FAILURE
|
156
|
+
@error_message = "HTTP request failed (#{response.code})"
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
class OutboundStatus < Request
|
162
|
+
def self.post(doc_id)
|
163
|
+
data = params(xml(doc_id))
|
164
|
+
response = Net::HTTPS.start(EFax::Uri.host, EFax::Uri.port) do |https|
|
165
|
+
https.post(EFax::Uri.path, data, EFax::HEADERS)
|
166
|
+
end
|
167
|
+
OutboundStatusResponse.new(response)
|
168
|
+
end
|
169
|
+
|
170
|
+
def self.xml(doc_id)
|
171
|
+
xml_request = ""
|
172
|
+
xml = Builder::XmlMarkup.new(:target => xml_request, :indent => 2 )
|
173
|
+
xml.instruct! :xml, :version => '1.0'
|
174
|
+
xml.OutboundStatus do
|
175
|
+
xml.AccessControl do
|
176
|
+
xml.UserName(self.user)
|
177
|
+
xml.Password(self.password)
|
178
|
+
end
|
179
|
+
xml.Transmission do
|
180
|
+
xml.TransmissionControl do
|
181
|
+
xml.DOCID(doc_id)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
xml_request
|
186
|
+
end
|
187
|
+
|
188
|
+
private_class_method :xml
|
189
|
+
end
|
190
|
+
|
191
|
+
class QueryStatus
|
192
|
+
HTTP_FAILURE = 0
|
193
|
+
PENDING = 3
|
194
|
+
SENT = 4
|
195
|
+
FAILURE = 5
|
196
|
+
end
|
197
|
+
|
198
|
+
class OutboundStatusResponse
|
199
|
+
attr_reader :status_code
|
200
|
+
attr_reader :message
|
201
|
+
attr_reader :classification
|
202
|
+
attr_reader :outcome
|
203
|
+
|
204
|
+
def initialize(response) #:nodoc:
|
205
|
+
if response.is_a? Net::HTTPOK
|
206
|
+
doc = Hpricot(response.body)
|
207
|
+
@message = doc.at(:message).innerText
|
208
|
+
@classification = doc.at(:classification).innerText.delete('"')
|
209
|
+
@outcome = doc.at(:outcome).innerText.delete('"')
|
210
|
+
if @classification.empty? && @outcome.empty?
|
211
|
+
@status_code = QueryStatus::PENDING
|
212
|
+
elsif @classification == "Success" && @outcome == "Success"
|
213
|
+
@status_code = QueryStatus::SENT
|
214
|
+
else
|
215
|
+
@status_code = QueryStatus::FAILURE
|
216
|
+
end
|
217
|
+
else
|
218
|
+
@status_code = QueryStatus::HTTP_FAILURE
|
219
|
+
@message = "HTTP request failed (#{response.code})"
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
end
|
data/ruby-efax.gemspec
ADDED
@@ -0,0 +1,54 @@
|
|
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.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Szymon Nowak", "Pawel Kozlowski"]
|
12
|
+
s.date = %q{2009-09-24}
|
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
|
+
s.add_runtime_dependency(%q<hpricot>, [">= 0.8.1"])
|
45
|
+
s.add_development_dependency(%q<mocha>, [">= 0.9"])
|
46
|
+
else
|
47
|
+
s.add_dependency(%q<hpricot>, [">= 0.8.1"])
|
48
|
+
s.add_dependency(%q<mocha>, [">= 0.9"])
|
49
|
+
end
|
50
|
+
else
|
51
|
+
s.add_dependency(%q<hpricot>, [">= 0.8.1"])
|
52
|
+
s.add_dependency(%q<mocha>, [">= 0.9"])
|
53
|
+
end
|
54
|
+
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
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'mocha'
|
4
|
+
require File.dirname(__FILE__) + '/../lib/efax'
|
5
|
+
|
6
|
+
class Class
|
7
|
+
def publicize_instance_methods
|
8
|
+
saved_private_instance_methods = self.private_instance_methods
|
9
|
+
self.class_eval { public(*saved_private_instance_methods) }
|
10
|
+
yield
|
11
|
+
self.class_eval { private(*saved_private_instance_methods) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def publicize_class_methods
|
15
|
+
saved_private_class_methods = self.private_methods(false)
|
16
|
+
self.class_eval { public_class_method(*saved_private_class_methods) }
|
17
|
+
yield
|
18
|
+
self.class_eval { private_class_method(*saved_private_class_methods) }
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: efax
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Szymon Nowak
|
8
|
+
- Pawel Kozlowski
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-09-28 00:00:00 +02:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: hpricot
|
18
|
+
type: :runtime
|
19
|
+
version_requirement:
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.8.1
|
25
|
+
version:
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: mocha
|
28
|
+
type: :development
|
29
|
+
version_requirement:
|
30
|
+
version_requirements: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0.9"
|
35
|
+
version:
|
36
|
+
description:
|
37
|
+
email: szimek@gmail.com
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files:
|
43
|
+
- README.rdoc
|
44
|
+
files:
|
45
|
+
- .gitignore
|
46
|
+
- README.rdoc
|
47
|
+
- Rakefile
|
48
|
+
- TODO
|
49
|
+
- VERSION
|
50
|
+
- lib/efax.rb
|
51
|
+
- ruby-efax.gemspec
|
52
|
+
- test/efax_test.rb
|
53
|
+
- test/test_helper.rb
|
54
|
+
has_rdoc: true
|
55
|
+
homepage: http://github.com/szimek/efax
|
56
|
+
licenses: []
|
57
|
+
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options:
|
60
|
+
- --charset=UTF-8
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
version:
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: "0"
|
74
|
+
version:
|
75
|
+
requirements: []
|
76
|
+
|
77
|
+
rubyforge_project: efax
|
78
|
+
rubygems_version: 1.3.5
|
79
|
+
signing_key:
|
80
|
+
specification_version: 3
|
81
|
+
summary: Ruby library for accessing the eFax Developer service
|
82
|
+
test_files:
|
83
|
+
- test/test_helper.rb
|
84
|
+
- test/efax_test.rb
|