efax 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/{ruby-efax.gemspec → efax.gemspec} +14 -10
- data/lib/efax.rb +4 -199
- data/lib/efax/inbound.rb +68 -0
- data/lib/efax/outbound.rb +198 -0
- data/test/efax_inbound_test.rb +70 -0
- data/test/{efax_test.rb → efax_outbound_test.rb} +2 -1
- data/test/test_helper.rb +0 -1
- metadata +9 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
@@ -4,35 +4,39 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{
|
8
|
-
s.version = "1.
|
7
|
+
s.name = %q{efax}
|
8
|
+
s.version = "1.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Szymon Nowak", "Pawel Kozlowski"]
|
12
|
-
s.date = %q{2009-09-
|
12
|
+
s.date = %q{2009-09-30}
|
13
13
|
s.email = %q{szimek@gmail.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
|
-
"README"
|
15
|
+
"README.rdoc"
|
16
16
|
]
|
17
17
|
s.files = [
|
18
18
|
".gitignore",
|
19
|
-
"README",
|
19
|
+
"README.rdoc",
|
20
20
|
"Rakefile",
|
21
21
|
"TODO",
|
22
22
|
"VERSION",
|
23
|
+
"efax.gemspec",
|
23
24
|
"lib/efax.rb",
|
24
|
-
"
|
25
|
-
"
|
25
|
+
"lib/efax/inbound.rb",
|
26
|
+
"lib/efax/outbound.rb",
|
27
|
+
"test/efax_inbound_test.rb",
|
28
|
+
"test/efax_outbound_test.rb",
|
26
29
|
"test/test_helper.rb"
|
27
30
|
]
|
28
|
-
s.homepage = %q{http://github.com/szimek/
|
31
|
+
s.homepage = %q{http://github.com/szimek/efax}
|
29
32
|
s.rdoc_options = ["--charset=UTF-8"]
|
30
33
|
s.require_paths = ["lib"]
|
31
|
-
s.rubyforge_project = %q{
|
34
|
+
s.rubyforge_project = %q{efax}
|
32
35
|
s.rubygems_version = %q{1.3.5}
|
33
36
|
s.summary = %q{Ruby library for accessing the eFax Developer service}
|
34
37
|
s.test_files = [
|
35
|
-
"test/
|
38
|
+
"test/efax_inbound_test.rb",
|
39
|
+
"test/efax_outbound_test.rb",
|
36
40
|
"test/test_helper.rb"
|
37
41
|
]
|
38
42
|
|
data/lib/efax.rb
CHANGED
@@ -22,203 +22,8 @@
|
|
22
22
|
# IN THE SOFTWARE.
|
23
23
|
#++
|
24
24
|
#
|
25
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
26
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
25
27
|
|
26
|
-
require '
|
27
|
-
require '
|
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
|
28
|
+
require 'efax/outbound'
|
29
|
+
require 'efax/inbound'
|
data/lib/efax/inbound.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'hpricot'
|
2
|
+
require 'base64'
|
3
|
+
require 'tempfile'
|
4
|
+
require 'time'
|
5
|
+
|
6
|
+
module EFax
|
7
|
+
class InboundPostStatus
|
8
|
+
SUCCESS = 1
|
9
|
+
end
|
10
|
+
|
11
|
+
class InboundPostRequest
|
12
|
+
attr_reader :encoded_file_contents,
|
13
|
+
:file_type,
|
14
|
+
:ani,
|
15
|
+
:account_id,
|
16
|
+
:fax_name,
|
17
|
+
:csid,
|
18
|
+
:status,
|
19
|
+
:mcfid,
|
20
|
+
:page_count,
|
21
|
+
:request_type,
|
22
|
+
:date_received,
|
23
|
+
:request_date
|
24
|
+
|
25
|
+
alias_method :sender_fax_number, :ani
|
26
|
+
|
27
|
+
def initialize(xml)
|
28
|
+
doc = Hpricot(xml)
|
29
|
+
@encoded_file_contents = doc.at(:filecontents).inner_text
|
30
|
+
@file_type = doc.at(:filetype).inner_text.to_sym
|
31
|
+
@ani = doc.at(:ani).inner_text
|
32
|
+
@account_id = doc.at(:accountid).inner_text
|
33
|
+
@fax_name = doc.at(:faxname).inner_text
|
34
|
+
@csid = doc.at(:csid).inner_text
|
35
|
+
@status = doc.at(:status).inner_text.to_i
|
36
|
+
@mcfid = doc.at(:mcfid).inner_text.to_i
|
37
|
+
@page_count = doc.at(:pagecount).inner_text.to_i
|
38
|
+
@request_type = doc.at(:requesttype).inner_text
|
39
|
+
@date_received = Time.parse("#{doc.at(:datereceived).inner_text} -08:00")
|
40
|
+
@request_date = Time.parse("#{doc.at(:requestdate).inner_text} -08:00")
|
41
|
+
end
|
42
|
+
|
43
|
+
def file_contents
|
44
|
+
@file_contents ||= Base64.decode64(encoded_file_contents)
|
45
|
+
end
|
46
|
+
|
47
|
+
def file
|
48
|
+
@file ||= begin
|
49
|
+
file = Tempfile.new(fax_name)
|
50
|
+
file << file_contents
|
51
|
+
file.rewind
|
52
|
+
file
|
53
|
+
end
|
54
|
+
end
|
55
|
+
def post_successful_message
|
56
|
+
"Post Successful"
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.receive_by_params(params)
|
60
|
+
receive_by_xml(params[:xml] || params["xml"])
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.receive_by_xml(xml)
|
64
|
+
new(xml)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
@@ -0,0 +1,198 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'net/https'
|
3
|
+
require 'builder'
|
4
|
+
require 'hpricot'
|
5
|
+
require 'base64'
|
6
|
+
|
7
|
+
module Net #:nodoc:
|
8
|
+
# Helper class for making HTTPS requests
|
9
|
+
class HTTPS < HTTP
|
10
|
+
def self.start(address, port = nil, p_addr = nil, p_port = nil, p_user = nil, p_pass = nil, &block) #:nodoc:
|
11
|
+
https = new(address, port, p_addr, p_port, p_user, p_pass)
|
12
|
+
https.use_ssl = true
|
13
|
+
https.start(&block)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module EFax
|
19
|
+
# URL of eFax web service
|
20
|
+
Url = "https://secure.efaxdeveloper.com/EFax_WebFax.serv"
|
21
|
+
# URI of eFax web service
|
22
|
+
Uri = URI.parse(Url)
|
23
|
+
# Prefered content type
|
24
|
+
HEADERS = {'Content-Type' => 'text/xml'}
|
25
|
+
|
26
|
+
# Base class for OutboundRequest and OutboundStatus classes
|
27
|
+
class Request
|
28
|
+
def self.user
|
29
|
+
@@user
|
30
|
+
end
|
31
|
+
def self.user=(name)
|
32
|
+
@@user = name
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.password
|
36
|
+
@@password
|
37
|
+
end
|
38
|
+
def self.password=(password)
|
39
|
+
@@password = password
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.account_id
|
43
|
+
@@account_id
|
44
|
+
end
|
45
|
+
def self.account_id=(id)
|
46
|
+
@@account_id = id
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.params(content)
|
50
|
+
escaped_xml = ::URI.escape(content, Regexp.new("[^#{::URI::PATTERN::UNRESERVED}]"))
|
51
|
+
"id=#{account_id}&xml=#{escaped_xml}&respond=XML"
|
52
|
+
end
|
53
|
+
|
54
|
+
private_class_method :params
|
55
|
+
end
|
56
|
+
|
57
|
+
class OutboundRequest < Request
|
58
|
+
def self.post(name, company, fax_number, subject, content, content_type = :html)
|
59
|
+
xml_request = xml(name, company, fax_number, subject, content, content_type)
|
60
|
+
response = Net::HTTPS.start(EFax::Uri.host, EFax::Uri.port) do |https|
|
61
|
+
https.post(EFax::Uri.path, params(xml_request), EFax::HEADERS)
|
62
|
+
end
|
63
|
+
OutboundResponse.new(response)
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.xml(name, company, fax_number, subject, content, content_type = :html)
|
67
|
+
xml_request = ""
|
68
|
+
xml = Builder::XmlMarkup.new(:target => xml_request, :indent => 2 )
|
69
|
+
xml.instruct! :xml, :version => '1.0'
|
70
|
+
xml.OutboundRequest do
|
71
|
+
xml.AccessControl do
|
72
|
+
xml.UserName(self.user)
|
73
|
+
xml.Password(self.password)
|
74
|
+
end
|
75
|
+
xml.Transmission do
|
76
|
+
xml.TransmissionControl do
|
77
|
+
xml.Resolution("FINE")
|
78
|
+
xml.Priority("NORMAL")
|
79
|
+
xml.SelfBusy("ENABLE")
|
80
|
+
xml.FaxHeader(subject)
|
81
|
+
end
|
82
|
+
xml.DispositionControl do
|
83
|
+
xml.DispositionLevel("NONE")
|
84
|
+
end
|
85
|
+
xml.Recipients do
|
86
|
+
xml.Recipient do
|
87
|
+
xml.RecipientName(name)
|
88
|
+
xml.RecipientCompany(company)
|
89
|
+
xml.RecipientFax(fax_number)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
xml.Files do
|
93
|
+
xml.File do
|
94
|
+
encoded_content = Base64.encode64(content).delete("\n")
|
95
|
+
xml.FileContents(encoded_content)
|
96
|
+
xml.FileType(content_type.to_s)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
xml_request
|
102
|
+
end
|
103
|
+
|
104
|
+
private_class_method :xml
|
105
|
+
end
|
106
|
+
|
107
|
+
class RequestStatus
|
108
|
+
HTTP_FAILURE = 0
|
109
|
+
SUCCESS = 1
|
110
|
+
FAILURE = 2
|
111
|
+
end
|
112
|
+
|
113
|
+
class OutboundResponse
|
114
|
+
attr_reader :status_code
|
115
|
+
attr_reader :error_message
|
116
|
+
attr_reader :error_level
|
117
|
+
attr_reader :doc_id
|
118
|
+
|
119
|
+
def initialize(response) #:nodoc:
|
120
|
+
if response.is_a? Net::HTTPOK
|
121
|
+
doc = Hpricot(response.body)
|
122
|
+
@status_code = doc.at(:statuscode).inner_text.to_i
|
123
|
+
@error_message = doc.at(:errormessage)
|
124
|
+
@error_message = @error_message.inner_text if @error_message
|
125
|
+
@error_level = doc.at(:errorlevel)
|
126
|
+
@error_level = @error_level.inner_text if @error_level
|
127
|
+
@doc_id = doc.at(:docid).inner_text
|
128
|
+
@doc_id = @doc_id.empty? ? nil : @doc_id
|
129
|
+
else
|
130
|
+
@status_code = RequestStatus::HTTP_FAILURE
|
131
|
+
@error_message = "HTTP request failed (#{response.code})"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
class OutboundStatus < Request
|
137
|
+
def self.post(doc_id)
|
138
|
+
data = params(xml(doc_id))
|
139
|
+
response = Net::HTTPS.start(EFax::Uri.host, EFax::Uri.port) do |https|
|
140
|
+
https.post(EFax::Uri.path, data, EFax::HEADERS)
|
141
|
+
end
|
142
|
+
OutboundStatusResponse.new(response)
|
143
|
+
end
|
144
|
+
|
145
|
+
def self.xml(doc_id)
|
146
|
+
xml_request = ""
|
147
|
+
xml = Builder::XmlMarkup.new(:target => xml_request, :indent => 2 )
|
148
|
+
xml.instruct! :xml, :version => '1.0'
|
149
|
+
xml.OutboundStatus do
|
150
|
+
xml.AccessControl do
|
151
|
+
xml.UserName(self.user)
|
152
|
+
xml.Password(self.password)
|
153
|
+
end
|
154
|
+
xml.Transmission do
|
155
|
+
xml.TransmissionControl do
|
156
|
+
xml.DOCID(doc_id)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
xml_request
|
161
|
+
end
|
162
|
+
|
163
|
+
private_class_method :xml
|
164
|
+
end
|
165
|
+
|
166
|
+
class QueryStatus
|
167
|
+
HTTP_FAILURE = 0
|
168
|
+
PENDING = 3
|
169
|
+
SENT = 4
|
170
|
+
FAILURE = 5
|
171
|
+
end
|
172
|
+
|
173
|
+
class OutboundStatusResponse
|
174
|
+
attr_reader :status_code
|
175
|
+
attr_reader :message
|
176
|
+
attr_reader :classification
|
177
|
+
attr_reader :outcome
|
178
|
+
|
179
|
+
def initialize(response) #:nodoc:
|
180
|
+
if response.is_a? Net::HTTPOK
|
181
|
+
doc = Hpricot(response.body)
|
182
|
+
@message = doc.at(:message).innerText
|
183
|
+
@classification = doc.at(:classification).innerText.delete('"')
|
184
|
+
@outcome = doc.at(:outcome).innerText.delete('"')
|
185
|
+
if @classification.empty? && @outcome.empty?
|
186
|
+
@status_code = QueryStatus::PENDING
|
187
|
+
elsif @classification == "Success" && @outcome == "Success"
|
188
|
+
@status_code = QueryStatus::SENT
|
189
|
+
else
|
190
|
+
@status_code = QueryStatus::FAILURE
|
191
|
+
end
|
192
|
+
else
|
193
|
+
@status_code = QueryStatus::HTTP_FAILURE
|
194
|
+
@message = "HTTP request failed (#{response.code})"
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
require File.dirname(__FILE__) + '/../lib/efax/inbound'
|
3
|
+
|
4
|
+
module EFaxInboundTest
|
5
|
+
class InboundPostRequestTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_receive_by_params
|
8
|
+
EFax::InboundPostRequest.expects(:receive_by_xml).with(xml).returns(response = mock)
|
9
|
+
assert_equal(EFax::InboundPostRequest.receive_by_params({:xml => xml}), response)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_receive_by_xml
|
13
|
+
response = EFax::InboundPostRequest.receive_by_xml(xml)
|
14
|
+
|
15
|
+
assert_equal file_contents, response.encoded_file_contents
|
16
|
+
assert_equal :pdf, response.file_type
|
17
|
+
assert_equal '098-765-4321', response.sender_fax_number
|
18
|
+
assert_equal '098-765-4321', response.ani
|
19
|
+
assert_equal '1234567890', response.account_id
|
20
|
+
assert_equal '48794686', response.fax_name
|
21
|
+
assert_equal '1234567890', response.csid
|
22
|
+
assert_equal 0, response.status
|
23
|
+
assert_equal 59985697, response.mcfid
|
24
|
+
assert_equal 1, response.page_count
|
25
|
+
assert_equal 'New Inbound', response.request_type
|
26
|
+
assert_not_nil response.file_contents
|
27
|
+
assert_not_nil response.file
|
28
|
+
assert_respond_to response.file, :read
|
29
|
+
assert_equal response.file_contents, response.file.read
|
30
|
+
|
31
|
+
# According to docs these will always be "Pacific Time Zone" (sometimes -8, sometimes -7 -- using -8)
|
32
|
+
assert_equal Time.utc(2009,9,29,23,56,35), response.date_received
|
33
|
+
assert_equal Time.utc(2009,9,30, 0, 1,11), response.request_date
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
def xml
|
38
|
+
%Q{
|
39
|
+
<?xml version="1.0"?>
|
40
|
+
<InboundPostRequest>
|
41
|
+
<AccessControl>
|
42
|
+
<UserName></UserName>
|
43
|
+
<Password></Password>
|
44
|
+
</AccessControl>
|
45
|
+
<RequestControl>
|
46
|
+
<RequestDate>09/29/2009 16:01:11</RequestDate>
|
47
|
+
<RequestType>New Inbound</RequestType>
|
48
|
+
</RequestControl>
|
49
|
+
<FaxControl>
|
50
|
+
<AccountID>1234567890</AccountID>
|
51
|
+
<DateReceived>09/29/2009 15:56:35</DateReceived>
|
52
|
+
<FaxName>48794686</FaxName>
|
53
|
+
<FileType>pdf</FileType>
|
54
|
+
<PageCount>1</PageCount>
|
55
|
+
<CSID>1234567890</CSID>
|
56
|
+
<ANI>098-765-4321</ANI>
|
57
|
+
<Status>0</Status>
|
58
|
+
<MCFID>59985697</MCFID>
|
59
|
+
<FileContents>#{file_contents}</FileContents>
|
60
|
+
</FaxControl>
|
61
|
+
</InboundPostRequest>
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
def file_contents
|
66
|
+
%Q| JVBERi0xLjYKJeTjz9IKMSAwIG9iagpbL1BERi9JbWFnZUIvSW1hZ2VDL0ltYWdlSS9UZXh0XQplbmRvYmoKMyAwIG9iago8PC9TdWJ0eXBlL0ltYWdlCi9XaWR0aCAxNzI4Ci9IZWlnaHQgMjIwMAovQml0c1BlckNvbXBvbmVudCAxCi9Db2xvclNwYWNlL0RldmljZUdyYXkKL0ZpbHRlci9DQ0lUVEZheERlY29kZQovRGVjb2RlUGFybXM8PC9LIC0xL0VuZE9mQmxvY2sgZmFsc2U+PgovTGVuZ3RoIDQgMCBSCj4+CnN0cmVhbQrI4OaClTMigMHY4pFc7GxDtWKRdEDDBJSJJf///4ZvDKGHms1zvGoMEdjbTDNMMH//////w25DGaGRx5s/zwU5kciORwyOTkMedQuSA5zI5EcjMZDCunhswMuM+FygjMUuKJDCf/////////////pYRcBhieA9Aq3CL8NidxO7YlQHhFwGaAgRfh6NNsTuJ3YRcBhF+HoER7wdGhhF+GZhARdgwwgwj4oRfB//////////////////xWIbYQb0hxQQbppthBvENkiQQb8aabENoIN6TfsUKCDYRd0EG3okNBBv///////////////mmHnQT9Lj/286CcZUBjZC/8+JHpN4ShRoJ0m20nx//////////////8N4Rd/iHzV//CLvzbESXf4Rd5lFC4hVMnX7aX///////////////hBfzWH5O/9LCC/J3lGH/CC8nejUcwjk7vbSYrye////////////////8JJ0EyP/hvYYQX8MJJ0EyP2YbDCC7C/0EyPsMIJNJvTYYQTDCsMJNJsMJf////////////////+EIRmCMTuKCDCDCDCDBAwxCTTThEcicEYncUGIQYhAgbEJNNNidxQYhGgIgwmEDBAwxCDEodgxBNEMEDEL/////////////xERERERERURERERERERERERERER9B+P/////////5kFhTvgpWI6xGwIOzOJEZBDO0R2SRW7ByGAQrP+QRL/uwv/hV/zTc1H+Sm/m3r/hvfx///t7////ckIp0al2UI6rzaJNZqRQinR1RFEULyNrJCNaIhGtEQskIlazaIkiMRJFkhETWSEa0U6NS+ZilAh6CD8+KCIvA8EDPxyBA8nggzgpQICIvmmazDhnBfORnHIEDCBnBTOCDOgpnBBnQUEDOCHGfiHBBl4zsEDPRpAgZHjMU/FyNjBA8zFPRpHhczFPwIGUCn4IP2mE4+kGnxD4vjTCafxp/8XpxoONPCbrH8Q/CGnFqENPpPQcQ04+6Lxzc4Ij/ou6NjDBSeeTx8ER9F45uaNj+CI+i8f/J4wwSLxwRH0XeCI+i8YMFNzbSgiP/J5bSl3ReOTsSrc2UXj1RePRd5PKLxwRH/pNpPCHVIN0/TfT8IUm0np/hCk3H9PpNwhSDcIUm9J7qEP036CdJumnSdJtvSb0g3TaTcIf1/4JVe1//9f7X9f/9fV9f7r//W9f+9elX1f1/9seopJ7Hpvr62x7H62/6/bpJ628diq+m21S9uq0vbf29J6b26+lr18H//6WsH+lzEf/S/9L1r//9L/9LvS//S/8ZmE5k/YP//4zMIwf8f//H/x5oEa//S+P/49KP/4/rgv+wf//4Kwf/////4L/+3///t////mrJZ/zQf//zVksk4/5kn/+av/Mnolm///5qv/Mn1NV/5qvrgv/B///4LB//////4LT/90v//9f//6tpf+bT//+2lnE/7f/+3/t6Wix//33t/+23t/+3+szf+2kF+0v/zN+F/8zf//mb20vM3+k3/aXTrmb/b8zfWZvbStLM38LdWv33+v/3Vrfa919r/dd/ddrV9rqx33X9rdMd13/deKbVwvthJtKwRTtL/21cK2k2F219sL9gioa7YS213CpPthbS2GFbX9tW1212wlYSbXNLTFR+xTHHFf+xUbHHsV8fxsVsVsVxq3xxVMTj2K/Y2KpitiopivwTCZFh+0wnmHX/sJkWGwgyT9heGSf7sLa2Fsiw6vDJPmHThrYX7Ix7CdhbUzphfERERERERERERERERERER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//+0lX9tL//bS///1X99pdraV//7I6sEU7CR6/9sJNruFPTathL/8ccV/+xTFcexTFf/d5nWq/tNbIsPaa/iIjiIiIiIiIiIiI///x/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////+ACACCmVuZHN0cmVhbQplbmRvYmoKNCAwIG9iago0MTY1CmVuZG9iago2IDAgb2JqCjw8L0xlbmd0aCA3IDAgUgovRmlsdGVyL0ZsYXRlRGVjb2RlCj4+CnN0cmVhbQp4nCvkMjOw1LOwMDJRMABCCwMLPUMzY2MwJzmXS9/TQMElnyuQCwCiLAf0CmVuZHN0cmVhbQplbmRvYmoKNyAwIG9iago0MwplbmRvYmoKOCAwIG9iago8PC9Qcm9jU2V0IDEgMCBSCi9YT2JqZWN0PDwvSTAgMyAwIFIKPj4KPj4KZW5kb2JqCjkgMCBvYmoKPDwvQ3JlYXRpb25EYXRlIChEOjIwMDkwOTI5MTYwOTI0LTA3JzAwJykKL1Byb2R1Y2VyIChQREZsaWIgNy4wLjMgXChKREsgMS42L1dpbjMyXCkpCj4+CmVuZG9iago1IDAgb2JqCjw8L1R5cGUvUGFnZQovUGFyZW50IDIgMCBSCi9Db250ZW50cyA2IDAgUgovUmVzb3VyY2VzIDggMCBSCi9NZWRpYUJveFswIDAgNjA5Ljg4MjQgODA4LjE2MzNdCj4+CmVuZG9iagoyIDAgb2JqCjw8L1R5cGUvUGFnZXMKL0NvdW50IDEKL0tpZHNbIDUgMCBSXT4+CmVuZG9iagoxMCAwIG9iago8PC9UeXBlL0NhdGFsb2cKL1BhZ2VzIDIgMCBSCj4+CmVuZG9iagp4cmVmCjAgMTEKMDAwMDAwMDAwMCA2NTUzNSBmIAowMDAwMDAwMDE1IDAwMDAwIG4gCjAwMDAwMDQ4NTAgMDAwMDAgbiAKMDAwMDAwMDA2MyAwMDAwMCBuIAowMDAwMDA0NDI1IDAwMDAwIG4gCjAwMDAwMDQ3MzkgMDAwMDAgbiAKMDAwMDAwNDQ0NSAwMDAwMCBuIAowMDAwMDA0NTYwIDAwMDAwIG4gCjAwMDAwMDQ1NzggMDAwMDAgbiAKMDAwMDAwNDYzNiAwMDAwMCBuIAowMDAwMDA0OTA0IDAwMDAwIG4gCnRyYWlsZXIKPDwvU2l6ZSAxMQovUm9vdCAxMCAwIFIKL0luZm8gOSAwIFIKL0lEWzw1NUMzQUY5Rjk3QzNBQjMwN0I2OTIzNTcxM0Q1RUVFND48NTVDM0FGOUY5N0MzQUIzMDdCNjkyMzU3MTNENUVFRTQ+XQo+PgpzdGFydHhyZWYKNDk1MgolJUVPRgo=|
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: efax
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Szymon Nowak
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-09-
|
13
|
+
date: 2009-09-30 00:00:00 +10:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -47,9 +47,12 @@ files:
|
|
47
47
|
- Rakefile
|
48
48
|
- TODO
|
49
49
|
- VERSION
|
50
|
+
- efax.gemspec
|
50
51
|
- lib/efax.rb
|
51
|
-
-
|
52
|
-
-
|
52
|
+
- lib/efax/inbound.rb
|
53
|
+
- lib/efax/outbound.rb
|
54
|
+
- test/efax_inbound_test.rb
|
55
|
+
- test/efax_outbound_test.rb
|
53
56
|
- test/test_helper.rb
|
54
57
|
has_rdoc: true
|
55
58
|
homepage: http://github.com/szimek/efax
|
@@ -80,5 +83,6 @@ signing_key:
|
|
80
83
|
specification_version: 3
|
81
84
|
summary: Ruby library for accessing the eFax Developer service
|
82
85
|
test_files:
|
86
|
+
- test/efax_inbound_test.rb
|
87
|
+
- test/efax_outbound_test.rb
|
83
88
|
- test/test_helper.rb
|
84
|
-
- test/efax_test.rb
|