postalmethods 1.1.3 → 1.1.4
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/Manifest.txt +4 -0
- data/lib/postalmethods.rb +1 -1
- data/lib/postalmethods.wsdl +1739 -0
- data/lib/postalmethods/send_postcard.rb +95 -0
- data/postalmethods.gemspec +9 -2
- data/spec/doc/sample_image.jpg +0 -0
- data/spec/send_postcard_spec.rb +126 -0
- metadata +7 -3
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
module PostalMethods
|
|
2
|
+
|
|
3
|
+
module SendPostcard
|
|
4
|
+
|
|
5
|
+
def send_postcard_and_address_advanced(opts)
|
|
6
|
+
raise PostalMethods::NoPreparationException unless self.prepared
|
|
7
|
+
#Add in any default settings
|
|
8
|
+
opts = get_settings().merge(opts)
|
|
9
|
+
rv = @rpc_driver.sendPostcardAndAddress(opts)
|
|
10
|
+
|
|
11
|
+
#Handle the return value
|
|
12
|
+
status_code = rv.sendPostcardAndAddressResult.to_i
|
|
13
|
+
if status_code > 0
|
|
14
|
+
return status_code
|
|
15
|
+
elsif API_STATUS_CODES.has_key?(status_code)
|
|
16
|
+
instance_eval("raise APIStatusCode#{status_code.to_s.gsub(/( |\-)/,'')}Exception")
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def send_postcard_and_address(image_side_filename, address_side_filename, address, description="Sent at #{Time.now()}", work_mode = "Default")
|
|
21
|
+
raise PostalMethods::NoPreparationException unless self.prepared
|
|
22
|
+
|
|
23
|
+
if( image_side_filename.index("MyFile:") )
|
|
24
|
+
is_name = image_side_filename
|
|
25
|
+
else
|
|
26
|
+
is_name = upload_file(image_side_filename)
|
|
27
|
+
end
|
|
28
|
+
if(address_side_filename.index("MyFile:") )
|
|
29
|
+
as_name = address_side_filename
|
|
30
|
+
else
|
|
31
|
+
as_name = upload_file(address_side_filename)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
## push a postcard over the api
|
|
35
|
+
opts = {
|
|
36
|
+
:MyDescription => description,
|
|
37
|
+
:ImageSideFileType => is_name,
|
|
38
|
+
:AddressSideFileType => as_name
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
opts.merge!(address)
|
|
42
|
+
return send_postcard_and_address_advanced(opts)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def get_settings
|
|
46
|
+
return {
|
|
47
|
+
:APIKey=> self.api_key,
|
|
48
|
+
:WorkMode => self.work_mode,
|
|
49
|
+
:ImageSideScaling => self.imageSideScaling,
|
|
50
|
+
:PrintColor=>self.printColor,
|
|
51
|
+
:PostcardSize=>self.postcardSize,
|
|
52
|
+
:MailingPriority=>self.mailingPriority
|
|
53
|
+
}
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def upload_file(doc, description="", overwrite=true, work_mode="")
|
|
57
|
+
if doc.class == String
|
|
58
|
+
opts = upload_file_options_with_strings(doc, description, overwrite, work_mode)
|
|
59
|
+
else
|
|
60
|
+
opts = upload_file_options_with_hash(doc)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
status_code = self.rpc_driver.uploadFile(opts).uploadFileResult
|
|
64
|
+
|
|
65
|
+
if status_code == "-3000"
|
|
66
|
+
return "MyFile:#{opts[:MyFileName]}"
|
|
67
|
+
elsif API_STATUS_CODES.has_key?(status_code)
|
|
68
|
+
instance_eval("raise APIStatusCode#{status_code.to_s.gsub(/( |\-)/,'')}Exception")
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def upload_file_options_with_strings(doc_name, description="", overwrite=true, work_mode="")
|
|
73
|
+
file_name=File.basename(doc_name)
|
|
74
|
+
file_data = open(doc_name, "rb") {|io| io.read }
|
|
75
|
+
opts = {
|
|
76
|
+
:APIKey => self.api_key,
|
|
77
|
+
:MyFileName => file_name,
|
|
78
|
+
:FileBinaryData => file_data,
|
|
79
|
+
:Permissions => self.permissions,
|
|
80
|
+
:MyDescription => description,
|
|
81
|
+
:Overwrite => overwrite
|
|
82
|
+
}
|
|
83
|
+
return opts
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def upload_file_options_with_hash(user_opts)
|
|
87
|
+
#Add in the api key
|
|
88
|
+
user_opts.merge!({:APIKey=> self.api_key})
|
|
89
|
+
return user_opts
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
end
|
data/postalmethods.gemspec
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Gem::Specification.new do |s|
|
|
2
2
|
s.name = %q{postalmethods}
|
|
3
|
-
s.version = "1.1.
|
|
3
|
+
s.version = "1.1.4"
|
|
4
4
|
|
|
5
5
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
6
6
|
s.authors = ["James Cox", "Joe Fair"]
|
|
@@ -8,7 +8,14 @@ Gem::Specification.new do |s|
|
|
|
8
8
|
s.description = %q{API wrapper library for the postal methods api.}
|
|
9
9
|
s.email = ["joe@bodkinconsulting.com"]
|
|
10
10
|
s.extra_rdoc_files = ["History.txt", "License.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "README.txt"]
|
|
11
|
-
s.files = ["History.txt", "License.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "README.txt", "Rakefile", "config/hoe.rb", "config/requirements.rb", "lib/postalmethods.rb", "lib/postalmethods/document_processor.rb", "lib/postalmethods/exceptions.rb", "lib/postalmethods/get_letter_status.rb", "lib/postalmethods/send_letter.rb", "lib/postalmethods/utility.rb", "postalmethods.gemspec", "script/console", "script/destroy", "script/generate", "setup.rb", "spec/doc/WSDL-Output", "spec/doc/default.rb", "spec/doc/defaultMappingRegistry.rb", "spec/doc/sample.pdf", "spec/document_processor_spec.rb", "spec/get_letter_status_spec.rb", "spec/postalmethods_spec.rb", "spec/rcov.opts", "spec/send_letter_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "spec/utility_spec.rb", "tasks/rspec.rake", "spec/doc/postcard_address_side_with_return_address.html", "spec/doc/postcard_image_side_with_return_address.html"
|
|
11
|
+
s.files = ["History.txt", "License.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "README.txt", "Rakefile", "config/hoe.rb", "config/requirements.rb", "lib/postalmethods.wsdl", "lib/postalmethods.rb", "lib/postalmethods/document_processor.rb", "lib/postalmethods/exceptions.rb", "lib/postalmethods/get_letter_status.rb", "lib/postalmethods/send_letter.rb", "lib/postalmethods/send_postcard.rb", "lib/postalmethods/utility.rb", "postalmethods.gemspec", "script/console", "script/destroy", "script/generate", "setup.rb", "spec/doc/sample_image.jpg", "spec/doc/WSDL-Output", "spec/doc/default.rb", "spec/doc/defaultMappingRegistry.rb", "spec/doc/sample.pdf", "spec/document_processor_spec.rb", "spec/get_letter_status_spec.rb", "spec/postalmethods_spec.rb", "spec/rcov.opts", "spec/send_letter_spec.rb", "spec/send_postcard_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "spec/utility_spec.rb", "tasks/rspec.rake", "spec/doc/postcard_address_side_with_return_address.html", "spec/doc/postcard_image_side_with_return_address.html",
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
]
|
|
12
19
|
s.has_rdoc = true
|
|
13
20
|
s.homepage = 'http://www.postalmethods.com/resources/quickstart'
|
|
14
21
|
s.post_install_message = %q{PostInstall.txt}
|
|
Binary file
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
|
2
|
+
|
|
3
|
+
describe "Send Postcard" do
|
|
4
|
+
|
|
5
|
+
before :each do
|
|
6
|
+
#Unique id - miliseconds
|
|
7
|
+
@time_id = (Time.now.to_f * 1000).to_i
|
|
8
|
+
|
|
9
|
+
@sample_image_name = "spec/doc/sample_image.jpg"
|
|
10
|
+
@doc = open(File.dirname(__FILE__) + '/doc/sample.pdf', 'rb'){|io| io.read}
|
|
11
|
+
@client = PostalMethods::Client.new(PM_OPTS)
|
|
12
|
+
|
|
13
|
+
@address_details = {
|
|
14
|
+
:AttentionLine1 => "The White House",
|
|
15
|
+
:Address1 => "1600 Pennsylvania Avenue NW",
|
|
16
|
+
:City => "Washington",
|
|
17
|
+
:State => "DC",
|
|
18
|
+
:PostalCode => "20500",
|
|
19
|
+
:Country => "USA"
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "should upload a file" do
|
|
25
|
+
@client.prepare!
|
|
26
|
+
@client.upload_file(@sample_image_name).should == "MyFile:#{File.basename(@sample_image_name)}"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "should upload a file from local binary data" do
|
|
30
|
+
@client.prepare!
|
|
31
|
+
@sample_data = open(@sample_image_name, "rb") {|io| io.read }
|
|
32
|
+
@upload_details = {
|
|
33
|
+
:MyFileName => "sample_image_file.jpg",
|
|
34
|
+
:FileBinaryData => @sample_data,
|
|
35
|
+
:Permissions => "Account",
|
|
36
|
+
:Description => "Sample File #{@time_id}",
|
|
37
|
+
:Overwrite => true
|
|
38
|
+
}
|
|
39
|
+
filename = @client.upload_file(@upload_details)
|
|
40
|
+
filename.should == "MyFile:sample_image_file.jpg"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "should upload a file from local binary data THEN send a postcard" do
|
|
44
|
+
@client.prepare!
|
|
45
|
+
@sample_data = IO.read(@sample_image_name)
|
|
46
|
+
@upload_details = {
|
|
47
|
+
:MyFileName => "sample_image_file.jpg",
|
|
48
|
+
:FileBinaryData => @sample_data,
|
|
49
|
+
:Permissions => "Account",
|
|
50
|
+
:Description => "Sample File #{@time_id}",
|
|
51
|
+
:Overwrite => true
|
|
52
|
+
}
|
|
53
|
+
filename = @client.upload_file(@upload_details)
|
|
54
|
+
filename.should == "MyFile:sample_image_file.jpg"
|
|
55
|
+
@client.send_postcard_and_address(filename, filename, @address_details).should > 0
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "should instantiate and send a postcard" do
|
|
59
|
+
@client.prepare!
|
|
60
|
+
@client.send_postcard_and_address(@sample_image_name, @sample_image_name, @address_details, "Sample Postcard at #{Time.now()}").should > 0
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "should upload a file THEN send a postcard" do
|
|
64
|
+
@client.prepare!
|
|
65
|
+
filename = @client.upload_file(@sample_image_name)
|
|
66
|
+
filename.should == "MyFile:#{File.basename(@sample_image_name)}"
|
|
67
|
+
@client.send_postcard_and_address(filename, filename, @address_details).should > 0
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "should refuse to send a postcard before prepare" do
|
|
71
|
+
lambda {@client.send_letter(@doc, "the long goodbye")}.should raise_error(PostalMethods::NoPreparationException)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "should raise the proper exception when trying to send a missing file" do
|
|
75
|
+
@client.prepare!
|
|
76
|
+
lambda {@client.send_postcard_and_address("missing.jpg", "missing.jpg", @address_details)}.should raise_error(Errno::ENOENT)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "should upload a template" do
|
|
80
|
+
@addr_template_filename = File.dirname(__FILE__) + '/../spec/doc/postcard_address_side_with_return_address.html'
|
|
81
|
+
@addr_template = open(@addr_template_filename, 'rb'){|io| io.read }
|
|
82
|
+
@client.prepare!
|
|
83
|
+
@client.upload_file(@addr_template_filename).should == "MyFile:#{File.basename(@addr_template_filename)}"
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it "should send a postcard with two templates" do
|
|
87
|
+
@img_template_filename = File.dirname(__FILE__) + '/../spec/doc/postcard_image_side_with_return_address.html'
|
|
88
|
+
@img_template = open(@img_template_filename, 'rb'){|io| io.read }
|
|
89
|
+
@addr_template_filename = File.dirname(__FILE__) + '/../spec/doc/postcard_address_side_with_return_address.html'
|
|
90
|
+
@addr_template = open(@addr_template_filename, 'rb'){|io| io.read }
|
|
91
|
+
opts={}
|
|
92
|
+
|
|
93
|
+
#Prepare address side
|
|
94
|
+
opts[:AddressSideFileType]="HTML"
|
|
95
|
+
opts[:MyDescription]="Sending Two Template Postcard #{Time.now}"
|
|
96
|
+
opts[:AddressSideBinaryData]=@addr_template
|
|
97
|
+
|
|
98
|
+
#Prepare image side
|
|
99
|
+
opts[:ImageSideFileType]="HTML"
|
|
100
|
+
opts[:ImageSideBinaryData]=@img_template
|
|
101
|
+
|
|
102
|
+
opts.merge!@address_details
|
|
103
|
+
@client.prepare!
|
|
104
|
+
@client.send_postcard_and_address_advanced(opts).should > 0
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it "should send a postcard with an image and template" do
|
|
108
|
+
@addr_template_filename = File.dirname(__FILE__) + '/../spec/doc/postcard_address_side_with_return_address.html'
|
|
109
|
+
@addr_template = open(@addr_template_filename, 'rb'){|io| io.read }
|
|
110
|
+
opts={}
|
|
111
|
+
|
|
112
|
+
#Prepare address side
|
|
113
|
+
opts[:AddressSideFileType]="HTML"
|
|
114
|
+
opts[:MyDescription]="Sending Template Postcard #{Time.now}"
|
|
115
|
+
opts[:AddressSideBinaryData]=@addr_template
|
|
116
|
+
|
|
117
|
+
#Prepare image side
|
|
118
|
+
opts[:ImageSideFileType]="jpg"
|
|
119
|
+
opts[:ImageSideBinaryData]=open(@sample_image_name){|io| io.read}
|
|
120
|
+
|
|
121
|
+
opts.merge!@address_details
|
|
122
|
+
@client.prepare!
|
|
123
|
+
@client.send_postcard_and_address_advanced(opts).should > 0
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: postalmethods
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 27
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 1
|
|
8
8
|
- 1
|
|
9
|
-
-
|
|
10
|
-
version: 1.1.
|
|
9
|
+
- 4
|
|
10
|
+
version: 1.1.4
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- James Cox
|
|
@@ -75,17 +75,20 @@ files:
|
|
|
75
75
|
- Rakefile
|
|
76
76
|
- config/hoe.rb
|
|
77
77
|
- config/requirements.rb
|
|
78
|
+
- lib/postalmethods.wsdl
|
|
78
79
|
- lib/postalmethods.rb
|
|
79
80
|
- lib/postalmethods/document_processor.rb
|
|
80
81
|
- lib/postalmethods/exceptions.rb
|
|
81
82
|
- lib/postalmethods/get_letter_status.rb
|
|
82
83
|
- lib/postalmethods/send_letter.rb
|
|
84
|
+
- lib/postalmethods/send_postcard.rb
|
|
83
85
|
- lib/postalmethods/utility.rb
|
|
84
86
|
- postalmethods.gemspec
|
|
85
87
|
- script/console
|
|
86
88
|
- script/destroy
|
|
87
89
|
- script/generate
|
|
88
90
|
- setup.rb
|
|
91
|
+
- spec/doc/sample_image.jpg
|
|
89
92
|
- spec/doc/WSDL-Output
|
|
90
93
|
- spec/doc/default.rb
|
|
91
94
|
- spec/doc/defaultMappingRegistry.rb
|
|
@@ -95,6 +98,7 @@ files:
|
|
|
95
98
|
- spec/postalmethods_spec.rb
|
|
96
99
|
- spec/rcov.opts
|
|
97
100
|
- spec/send_letter_spec.rb
|
|
101
|
+
- spec/send_postcard_spec.rb
|
|
98
102
|
- spec/spec.opts
|
|
99
103
|
- spec/spec_helper.rb
|
|
100
104
|
- spec/utility_spec.rb
|