fax_finder 0.1.0 → 0.2.0
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/VERSION +1 -1
- data/fax_finder.gemspec +4 -2
- data/lib/fax_finder/request.rb +1 -0
- data/lib/fax_finder/send.rb +34 -10
- data/lib/fax_finder.rb +1 -2
- data/pkg/fax_finder-0.1.0.gem +0 -0
- data/test/fixtures/test.pdf +0 -0
- data/test/send_test.rb +69 -7
- metadata +6 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/fax_finder.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{fax_finder}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.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 = ["Erich L. Timkar"]
|
12
|
-
s.date = %q{2011-05-
|
12
|
+
s.date = %q{2011-05-10}
|
13
13
|
s.email = %q{erich@hordesoftware.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE",
|
@@ -29,9 +29,11 @@ Gem::Specification.new do |s|
|
|
29
29
|
"lib/fax_finder/request.rb",
|
30
30
|
"lib/fax_finder/response.rb",
|
31
31
|
"lib/fax_finder/send.rb",
|
32
|
+
"pkg/fax_finder-0.1.0.gem",
|
32
33
|
"test/fixtures/send_request_external.xml",
|
33
34
|
"test/fixtures/send_request_inline.xml",
|
34
35
|
"test/fixtures/send_response_success.xml",
|
36
|
+
"test/fixtures/test.pdf",
|
35
37
|
"test/query_test.rb",
|
36
38
|
"test/request_test.rb",
|
37
39
|
"test/response_test.rb",
|
data/lib/fax_finder/request.rb
CHANGED
data/lib/fax_finder/send.rb
CHANGED
@@ -4,13 +4,13 @@ require 'builder'
|
|
4
4
|
module FaxFinder
|
5
5
|
module SendClassMethods
|
6
6
|
|
7
|
-
def post(recipient_fax,
|
7
|
+
def post(recipient_fax, options={})
|
8
8
|
super(){
|
9
|
-
construct_http_request(recipient_fax,
|
9
|
+
construct_http_request(recipient_fax, options)
|
10
10
|
}
|
11
11
|
end
|
12
12
|
|
13
|
-
def construct_xml(recipient_fax,
|
13
|
+
def construct_xml(recipient_fax, options={})
|
14
14
|
xml = ""
|
15
15
|
builder = Builder::XmlMarkup.new(:target => xml, :indent => 2 )
|
16
16
|
builder.instruct!(:xml, :version=>'1.0', :encoding=>'UTF-8')
|
@@ -19,10 +19,24 @@ module FaxFinder
|
|
19
19
|
time=time.utc if time && !time.utc?
|
20
20
|
formatted_time=time ? time.strftime(Request::TIME_FORMAT) : nil
|
21
21
|
|
22
|
+
external_url=options[:external_url]
|
23
|
+
if external_url.nil? && _content=options[:content]
|
24
|
+
if _content.is_a?(String)
|
25
|
+
content=_content
|
26
|
+
else
|
27
|
+
_content.rewind
|
28
|
+
_content.binmode
|
29
|
+
attachment_name = options[:attachment_name] || File.basename(_content.path)
|
30
|
+
content=Base64.encode64(_content.read).gsub(/\n/, '')
|
31
|
+
end
|
32
|
+
else
|
33
|
+
content=nil
|
34
|
+
end
|
35
|
+
|
22
36
|
builder.schedule_fax {
|
23
37
|
builder.cover_page do
|
24
|
-
|
25
|
-
|
38
|
+
builder.subject(options[:subject])
|
39
|
+
builder.comment(options[:comment])
|
26
40
|
builder.enabled('false')
|
27
41
|
end
|
28
42
|
|
@@ -40,18 +54,28 @@ module FaxFinder
|
|
40
54
|
builder.name(options[:sender_name])
|
41
55
|
end
|
42
56
|
|
43
|
-
|
44
|
-
|
45
|
-
|
57
|
+
builder.attachment do
|
58
|
+
if external_url
|
59
|
+
builder.location('external')
|
60
|
+
builder.url(external_url)
|
61
|
+
elsif content
|
62
|
+
builder.content(content)
|
63
|
+
builder.name(options[:filename])
|
64
|
+
builder.attachment_name(attachment_name)
|
65
|
+
builder.content_transfer_encoding('base64')
|
66
|
+
builder.location('inline')
|
67
|
+
builder.name(attachment_name)
|
68
|
+
builder.content_type(options[:content_type])
|
69
|
+
end
|
46
70
|
end
|
47
71
|
builder.schedule_all_at(formatted_fax_finder_time(options[:schedule_all_at]))
|
48
72
|
}
|
49
73
|
xml
|
50
74
|
end
|
51
75
|
|
52
|
-
def construct_http_request(recipient_fax,
|
76
|
+
def construct_http_request(recipient_fax, options={})
|
53
77
|
request = Net::HTTP::Post.new(Request::BASE_PATH)
|
54
|
-
request.body=construct_xml(recipient_fax,
|
78
|
+
request.body=construct_xml(recipient_fax, options)
|
55
79
|
request
|
56
80
|
end
|
57
81
|
|
data/lib/fax_finder.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#--
|
2
2
|
# (The MIT License)
|
3
3
|
#
|
4
|
-
# Copyright (c)
|
4
|
+
# Copyright (c) 2011 Horde Software, LLC (U2I)
|
5
5
|
#
|
6
6
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
7
|
# of this software and associated documentation files (the "Software"), to
|
@@ -25,7 +25,6 @@
|
|
25
25
|
$:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
26
26
|
require 'net/http'
|
27
27
|
require 'net/https'
|
28
|
-
|
29
28
|
require 'fax_finder/response.rb'
|
30
29
|
require 'fax_finder/request.rb'
|
31
30
|
require 'fax_finder/send.rb'
|
Binary file
|
Binary file
|
data/test/send_test.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper'
|
2
|
-
|
2
|
+
require "base64"
|
3
3
|
module FaxFinder
|
4
4
|
OPTIONS={:subject=>'Something',
|
5
5
|
:comment=>'Comment',
|
@@ -23,17 +23,17 @@ module FaxFinder
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_posts_returns_response
|
26
|
-
assert_instance_of(FaxFinder::Response, Send.post(nil
|
26
|
+
assert_instance_of(FaxFinder::Response, Send.post(nil))
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
class SendConstructXMLTest<Test::Unit::TestCase
|
31
31
|
def setup
|
32
|
-
@doc=Nokogiri::XML(Send.construct_xml('1234567890', 'https://localhost/something'
|
32
|
+
@doc=Nokogiri::XML(Send.construct_xml('1234567890', OPTIONS.merge(:external_url=>'https://localhost/something')))
|
33
33
|
end
|
34
34
|
|
35
35
|
def test_returns_string_and_doesnt_blow_up
|
36
|
-
assert_nothing_thrown { assert_instance_of(String, Send.construct_xml(nil
|
36
|
+
assert_nothing_thrown { assert_instance_of(String, Send.construct_xml(nil)) }
|
37
37
|
end
|
38
38
|
|
39
39
|
def test_includes_subject
|
@@ -89,16 +89,78 @@ module FaxFinder
|
|
89
89
|
end
|
90
90
|
|
91
91
|
def test_converts_to_utc
|
92
|
-
@doc=Nokogiri::XML(Send.construct_xml('1234567890',
|
92
|
+
@doc=Nokogiri::XML(Send.construct_xml('1234567890', OPTIONS.merge(:schedule_all_at=>Time.now, :external_url=>'https://localhost/something')))
|
93
93
|
assert_equal(Time.now.utc.strftime(Request::TIME_FORMAT), @doc.xpath('//schedule_fax/schedule_all_at').text)
|
94
94
|
end
|
95
95
|
|
96
96
|
end
|
97
97
|
|
98
|
+
class SendConstructXMLTestEmbedDocument<Test::Unit::TestCase
|
99
|
+
def setup
|
100
|
+
@file=File.open(File.join('test', 'fixtures', 'test.pdf'))
|
101
|
+
@options=OPTIONS.merge(
|
102
|
+
:content=>@file,
|
103
|
+
:content_type=>'application/pdf'
|
104
|
+
)
|
105
|
+
@doc=Nokogiri::XML(Send.construct_xml('1234567890', @options))
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_encodes_files
|
109
|
+
@file.rewind
|
110
|
+
@file.binmode
|
111
|
+
encoded=Base64.encode64(@file.read).gsub(/\n/, '')
|
112
|
+
assert_equal(encoded, @doc.xpath('//schedule_fax/attachment/content').text)
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_should_call_rewind_on_the_file
|
116
|
+
@file.rewind
|
117
|
+
@file.binmode
|
118
|
+
encoded=Base64.encode64(@file.read).gsub(/\n/, '')
|
119
|
+
@doc=Nokogiri::XML(Send.construct_xml('1234567890', @options.merge(:content=>@file)))
|
120
|
+
assert_equal(encoded, @doc.xpath('//schedule_fax/attachment/content').text)
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_including_an_external_url_will_override_embedded_document
|
124
|
+
@doc=Nokogiri::XML(Send.construct_xml('1234567890', @options.merge(:external_url=>'https://localhost/something')))
|
125
|
+
assert_empty(@doc.xpath('//schedule_fax/attachment/content'))
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_supports_passing_in_a_base64_string_directly
|
129
|
+
@file.rewind
|
130
|
+
@file.binmode
|
131
|
+
encoded=Base64.encode64(@file.read).gsub(/\n/, '')
|
132
|
+
|
133
|
+
@doc=Nokogiri::XML(Send.construct_xml('1234567890', @options.merge(:content=>encoded)))
|
134
|
+
assert_equal(encoded, @doc.xpath('//schedule_fax/attachment/content').text)
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_sets_the_content_type
|
138
|
+
assert_equal('application/pdf', @doc.xpath('//schedule_fax/attachment/content_type').text)
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_sets_location_as_inline
|
142
|
+
assert_equal('inline', @doc.xpath('//schedule_fax/attachment/location').text)
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_sets_the_filename_from_the_file_path
|
146
|
+
assert_equal(File.basename(@file.path), @doc.xpath('//schedule_fax/attachment/name').text)
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_sets_the_content_transfer_encoding
|
150
|
+
assert_equal('base64', @doc.xpath('//schedule_fax/attachment/content_transfer_encoding').text)
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_supports_overrding_filename
|
154
|
+
@doc=Nokogiri::XML(Send.construct_xml('1234567890', @options.merge(:attachment_name=>'attachment.name')))
|
155
|
+
assert_equal('attachment.name', @doc.xpath('//schedule_fax/attachment/name').text)
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
|
98
160
|
class SendConstructHttpRequestTest<Test::Unit::TestCase
|
99
161
|
def setup
|
100
162
|
Request.configure('example.com', 'user', 'password')
|
101
|
-
@http_request=Send.construct_http_request('1234567890', 'https://localhost/something'
|
163
|
+
@http_request=Send.construct_http_request('1234567890', OPTIONS.merge(:external_url=>'https://localhost/something'))
|
102
164
|
end
|
103
165
|
|
104
166
|
def test_returns_a_post
|
@@ -106,7 +168,7 @@ module FaxFinder
|
|
106
168
|
end
|
107
169
|
|
108
170
|
def test_sets_body
|
109
|
-
assert_equal(Send.construct_xml('1234567890', 'https://localhost/something'
|
171
|
+
assert_equal(Send.construct_xml('1234567890', OPTIONS.merge(:external_url=>'https://localhost/something')), @http_request.body)
|
110
172
|
end
|
111
173
|
|
112
174
|
def test_sets_path
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fax_finder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Erich L. Timkar
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-05-
|
18
|
+
date: 2011-05-10 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: nokogiri
|
@@ -101,9 +101,11 @@ files:
|
|
101
101
|
- lib/fax_finder/request.rb
|
102
102
|
- lib/fax_finder/response.rb
|
103
103
|
- lib/fax_finder/send.rb
|
104
|
+
- pkg/fax_finder-0.1.0.gem
|
104
105
|
- test/fixtures/send_request_external.xml
|
105
106
|
- test/fixtures/send_request_inline.xml
|
106
107
|
- test/fixtures/send_response_success.xml
|
108
|
+
- test/fixtures/test.pdf
|
107
109
|
- test/query_test.rb
|
108
110
|
- test/request_test.rb
|
109
111
|
- test/response_test.rb
|