postalmethods-ng 0.0.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.
- checksums.yaml +15 -0
- data/.gitignore +19 -0
- data/Gemfile +3 -0
- data/LICENSE +20 -0
- data/README.md +66 -0
- data/Rakefile +1 -0
- data/lib/postalmethods-ng.rb +1 -0
- data/lib/postalmethods.rb +3 -0
- data/lib/postalmethods/client.rb +302 -0
- data/lib/postalmethods/errors.rb +131 -0
- data/lib/postalmethods/version.rb +3 -0
- data/postalmethods-ng.gemspec +24 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
OTE1MzgwN2UxZDM5MmY4ZTJmNTc2MmUxOTRkY2NkNmMzMjYxY2QxMQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YzNiN2ZkNTBkZTFjMDg2ZTNjZGI0MGM5MDlmMTZhYjU0NmUyZjQxZA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OWJiYzQyMjBjNzEzNWQxNGRlN2RmMGU2ZDFmZTA3ODFmYTUxY2Q0MGMzM2Fi
|
10
|
+
N2RjZDM5ZjQ0NmY4MWVjNjhhNDhjZTAwOGEyNTllNWJkYjYwYWRjMzEwZGMw
|
11
|
+
ZThkYzg1OTdkNjY1OTE4OWZjMzFmZjEyY2VmNTNmOTU3NTllMWE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
OGEwOWJmYzNmYjE0Zjc1MTM5ZWQwNWMzODkzMTQ0YjkwNmRiODJmNGY4Nzg2
|
14
|
+
MDE2ZWE3MzdmN2Y1OGFiZDgzMWUyODI5YzhiYWVjMmI3Y2ZiY2U4M2I5Yzhl
|
15
|
+
YzE2YTc1ZjY1ZTI0NWVmMmVkZjg3NTIyYmVmYmZlN2M0NzkxMjE=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Paul Philippov
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
postalmethods-ng
|
2
|
+
================
|
3
|
+
|
4
|
+
A Ruby wrapper for [PostalMethods](http://postalmethods.com/) SOAP API.
|
5
|
+
|
6
|
+
Unlike official postalmethods gem depending on abandoned soap4r library
|
7
|
+
postalmethods-ng built around Savon SOAP Client v2.
|
8
|
+
|
9
|
+
Installation
|
10
|
+
------------
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'postalmethods-ng'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install postalmethods-ng
|
23
|
+
|
24
|
+
Usage
|
25
|
+
-----
|
26
|
+
|
27
|
+
~~~
|
28
|
+
require 'postalmethods'
|
29
|
+
|
30
|
+
pmc = PostalMethods::Client.new(
|
31
|
+
username: "username",
|
32
|
+
password: "password"
|
33
|
+
)
|
34
|
+
|
35
|
+
letter_id = pmc.send_letter_and_address(
|
36
|
+
file: "/path/to/file.pdf",
|
37
|
+
description: "Sample letter",
|
38
|
+
address: {
|
39
|
+
attention_line_1: "John Doe",
|
40
|
+
attention_line_2: "IT Department",
|
41
|
+
company: "ACME Software",
|
42
|
+
address_1: "123 Long Rd",
|
43
|
+
address_2: "Unit 404",
|
44
|
+
city: "Oblivion",
|
45
|
+
state: "KS",
|
46
|
+
postal_code: "55505",
|
47
|
+
country: "United States of America"
|
48
|
+
})
|
49
|
+
|
50
|
+
letter_status = pmc.get_status(letter_id)
|
51
|
+
|
52
|
+
puts letter_status.first[:description]
|
53
|
+
~~~
|
54
|
+
|
55
|
+
Contributing
|
56
|
+
------------
|
57
|
+
|
58
|
+
I've tried my best to make the library compact and simple whilst robust
|
59
|
+
and convenient to use, but you are more than welcomed to hack and patch it,
|
60
|
+
just don't forget to send pull requests to share your improvements.
|
61
|
+
|
62
|
+
1. Fork it
|
63
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
64
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
65
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
66
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1 @@
|
|
1
|
+
require "postalmethods"
|
@@ -0,0 +1,302 @@
|
|
1
|
+
require 'savon'
|
2
|
+
require 'base64'
|
3
|
+
|
4
|
+
module PostalMethods
|
5
|
+
|
6
|
+
API_URI = "https://api.postalmethods.com/2009-02-26/PostalWS.asmx?WSDL"
|
7
|
+
|
8
|
+
API_VALID_IMAGE_SIDE_SCALING = %w{Default FitToPage None}
|
9
|
+
API_VALID_MAILING_PRIORITY = %w{Default FirstClass}
|
10
|
+
API_VALID_OVERWRITE = [true, false]
|
11
|
+
API_VALID_PERMISSIONS = %w{Account User}
|
12
|
+
API_VALID_POSTCARD_SIZE = %w{Default Postcard_4_25X6}
|
13
|
+
API_VALID_PRINT_COLOR = %w{Default Black FullColor}
|
14
|
+
API_VALID_WORK_MODE = %w{Default Production Development}
|
15
|
+
|
16
|
+
class Client
|
17
|
+
extend Savon::Model
|
18
|
+
|
19
|
+
client wsdl: API_URI
|
20
|
+
|
21
|
+
global :log_level, :error
|
22
|
+
global :pretty_print_xml, true
|
23
|
+
global :open_timeout, 30
|
24
|
+
global :convert_request_keys_to, :camelcase
|
25
|
+
|
26
|
+
attr_accessor :username, :password, :api_key
|
27
|
+
|
28
|
+
operations :cancel_delivery,
|
29
|
+
:delete_uploaded_file,
|
30
|
+
:get_details,
|
31
|
+
:get_details_extended,
|
32
|
+
:get_status,
|
33
|
+
:get_pdf,
|
34
|
+
:get_uploaded_file_details,
|
35
|
+
:send_letter,
|
36
|
+
:send_letter_and_address,
|
37
|
+
:send_postcard_and_address,
|
38
|
+
:upload_file
|
39
|
+
|
40
|
+
def initialize(args)
|
41
|
+
self.username = args[:username]
|
42
|
+
self.password = args[:password]
|
43
|
+
self.api_key = args[:api_key]
|
44
|
+
end
|
45
|
+
|
46
|
+
def sign!(data)
|
47
|
+
data.merge!({ username: self.username }) unless self.username.blank?
|
48
|
+
data.merge!({ password: self.password }) unless self.password.blank?
|
49
|
+
data.merge!({ a_p_i_key: self.api_key }) unless self.api_key.blank?
|
50
|
+
|
51
|
+
return data
|
52
|
+
end
|
53
|
+
|
54
|
+
def one_or_many_ids(data)
|
55
|
+
if data.is_a?(Array)
|
56
|
+
data.join(',')
|
57
|
+
elsif data.is_a?(Range)
|
58
|
+
data.to_s.sub('..','-')
|
59
|
+
else
|
60
|
+
data.to_s
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def valid_or_default(data, stack)
|
65
|
+
(data and stack.include?(data)) ? data : stack.first
|
66
|
+
end
|
67
|
+
|
68
|
+
def file_from(data)
|
69
|
+
return data if data.is_a?(File)
|
70
|
+
|
71
|
+
raise "Filename is empty" if data.blank?
|
72
|
+
raise "File does not exist: #{data}" unless File.exist?(data)
|
73
|
+
raise "File is not a regular file: #{data}" unless File.file?(data)
|
74
|
+
|
75
|
+
File.open(data)
|
76
|
+
end
|
77
|
+
|
78
|
+
def report_error(code)
|
79
|
+
if Error::CODES.keys.include?(code)
|
80
|
+
instance_eval("raise APIStatusCode#{code.to_s.strip.sub(/^\-/,'')}Error")
|
81
|
+
else
|
82
|
+
puts "Unknown result code: #{code}"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def get_status(ids)
|
87
|
+
opts = { i_d: one_or_many_ids(ids) }
|
88
|
+
xml = super message: sign!(opts)
|
89
|
+
res = xml.body[:get_status_response][:get_status_result]
|
90
|
+
code = res[:result_code].to_i
|
91
|
+
|
92
|
+
if code == -3000
|
93
|
+
[res[:statuses][:letter_status_and_desc]].flatten
|
94
|
+
else
|
95
|
+
report_error(code)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def get_details(ids)
|
100
|
+
opts = { i_d: one_or_many_ids(ids) }
|
101
|
+
xml = super message: sign!(opts)
|
102
|
+
res = xml.body[:get_details_response][:get_details_result]
|
103
|
+
code = res[:result_code].to_i
|
104
|
+
|
105
|
+
if code == -3000
|
106
|
+
[res[:details][:details]].flatten
|
107
|
+
else
|
108
|
+
report_error(code)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def get_details_extended(ids)
|
113
|
+
opts = { i_d: one_or_many_ids(ids) }
|
114
|
+
xml = super message: sign!(opts)
|
115
|
+
res = xml.body[:get_details_extended_response][:get_details_extended_result]
|
116
|
+
code = res[:result_code].to_i
|
117
|
+
|
118
|
+
if code == -3000
|
119
|
+
[res[:details][:extended_details]].flatten
|
120
|
+
else
|
121
|
+
report_error(code)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def get_pdf(id)
|
126
|
+
opts = { i_d: id }
|
127
|
+
xml = super message: sign!(opts)
|
128
|
+
res = xml.body[:get_pdf_response][:get_pdf_result]
|
129
|
+
code = res[:result_code].to_i
|
130
|
+
|
131
|
+
if code == -3000
|
132
|
+
true
|
133
|
+
else
|
134
|
+
report_error(code)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def get_uploaded_file_details
|
139
|
+
opts = { }
|
140
|
+
xml = super message: sign!(opts)
|
141
|
+
res = xml.body[:get_uploaded_file_details_response][:get_uploaded_file_details_result]
|
142
|
+
code = res[:result_code].to_i
|
143
|
+
|
144
|
+
if code == -3000
|
145
|
+
[res[:uploaded_files][:file_details]].flatten
|
146
|
+
else
|
147
|
+
report_error(code)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def upload_file(args = {})
|
152
|
+
file = file_from(args[:file])
|
153
|
+
description = args[:description]
|
154
|
+
permissions = valid_or_default(args[:permissions], API_VALID_PERMISSIONS)
|
155
|
+
overwrite = valid_or_default(args[:overwrite], API_VALID_OVERWRITE)
|
156
|
+
|
157
|
+
opts = {
|
158
|
+
my_file_name: File.basename(file.path),
|
159
|
+
file_binary_data: Base64.encode64(file.read),
|
160
|
+
description: description,
|
161
|
+
permissions: permissions,
|
162
|
+
overwrite: overwrite,
|
163
|
+
}
|
164
|
+
xml = super message: sign!(opts)
|
165
|
+
res = xml.body[:upload_file_response][:upload_file_result]
|
166
|
+
code = res.to_i
|
167
|
+
|
168
|
+
if code == -3000
|
169
|
+
true
|
170
|
+
else
|
171
|
+
report_error(code)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def delete_uploaded_file(filename)
|
176
|
+
opts = { my_file_name: filename }
|
177
|
+
xml = super message: sign!(opts)
|
178
|
+
res = xml.body[:delete_uploaded_file_response][:delete_uploaded_file_result]
|
179
|
+
code = res.to_i
|
180
|
+
|
181
|
+
if code > 0
|
182
|
+
true
|
183
|
+
else
|
184
|
+
report_error(code)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
def send_letter(args = {})
|
189
|
+
description = args[:description].to_s
|
190
|
+
mode = valid_or_default(args[:mode], API_VALID_WORK_MODE)
|
191
|
+
file = file_from(args[:file])
|
192
|
+
|
193
|
+
opts = {
|
194
|
+
my_description: description,
|
195
|
+
file_extension: File.extname(file.path),
|
196
|
+
file_binary_Data: Base64.encode64(file.read),
|
197
|
+
work_mode: mode
|
198
|
+
}
|
199
|
+
xml = super message: sign!(opts)
|
200
|
+
res = xml.body[:send_letter_response][:send_letter_result]
|
201
|
+
code = res.to_i
|
202
|
+
|
203
|
+
if code > 0
|
204
|
+
code
|
205
|
+
else
|
206
|
+
report_error(code)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
def send_letter_and_address(args = {})
|
211
|
+
description = args[:description].to_s
|
212
|
+
mode = valid_or_default(args[:mode], API_VALID_WORK_MODE)
|
213
|
+
file = file_from(args[:file])
|
214
|
+
|
215
|
+
opts = {
|
216
|
+
my_description: description,
|
217
|
+
file_extension: File.extname(file.path),
|
218
|
+
file_binary_Data: Base64.encode64(file.read),
|
219
|
+
work_mode: mode
|
220
|
+
}
|
221
|
+
opts.merge!(args[:address])
|
222
|
+
xml = super message: sign!(opts)
|
223
|
+
res = xml.body[:send_letter_and_address_response][:send_letter_and_address_result]
|
224
|
+
code = res.to_i
|
225
|
+
|
226
|
+
if code > 0
|
227
|
+
code
|
228
|
+
else
|
229
|
+
report_error(code)
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
def send_postcard_and_address(args = {})
|
234
|
+
description = args[:description].to_s
|
235
|
+
front = args[:front].to_s
|
236
|
+
back = args[:back].to_s
|
237
|
+
size = valid_or_default(args[:size], API_VALID_POSTCARD_SIZE)
|
238
|
+
scaling = valid_or_default(args[:scaling], API_VALID_IMAGE_SIDE_SCALING)
|
239
|
+
color = valid_or_default(args[:color], API_VALID_PRINT_COLOR)
|
240
|
+
priority = valid_or_default(args[:priority], API_VALID_MAILING_PRIORITY)
|
241
|
+
mode = valid_or_default(args[:mode], API_VALID_WORK_MODE)
|
242
|
+
address = parse_address(args[:address])
|
243
|
+
|
244
|
+
opts = {
|
245
|
+
my_description: description,
|
246
|
+
image_side_scaling: scaling,
|
247
|
+
print_color: color,
|
248
|
+
postcard_size: size,
|
249
|
+
mailling_priority: priority,
|
250
|
+
work_mode: mode,
|
251
|
+
}
|
252
|
+
opts.merge!(address)
|
253
|
+
|
254
|
+
if front.is_a?(String) and front.start_with?('MyFile:','MyTemplate:')
|
255
|
+
opts.merge!({
|
256
|
+
image_side_file_type: File.basename(front),
|
257
|
+
})
|
258
|
+
else
|
259
|
+
file = file_from(front)
|
260
|
+
opts.merge!({
|
261
|
+
image_side_file_type: File.extname(file.path),
|
262
|
+
image_side_binary_data: Base64.encode64(file.read),
|
263
|
+
})
|
264
|
+
end
|
265
|
+
|
266
|
+
if back.is_a?(String) and back.start_with?('MyFile:','MyTemplate:')
|
267
|
+
opts.merge!({
|
268
|
+
address_side_file_type: File.basename(back),
|
269
|
+
})
|
270
|
+
else
|
271
|
+
file = file_from(back)
|
272
|
+
opts.merge!({
|
273
|
+
address_side_file_type: File.extname(file.path),
|
274
|
+
address_side_binary_data: Base64.encode64(file.read),
|
275
|
+
})
|
276
|
+
end
|
277
|
+
|
278
|
+
xml = super message: sign!(opts)
|
279
|
+
res = xml.body[:send_postcard_and_address_response][:send_postcard_and_address_result]
|
280
|
+
code = res.to_i
|
281
|
+
|
282
|
+
if code > 0
|
283
|
+
code
|
284
|
+
else
|
285
|
+
report_error(code)
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
def cancel_delivery(id)
|
290
|
+
opts = { i_d: id }
|
291
|
+
xml = super message: sign!(opts)
|
292
|
+
res = xml.body[:cancel_delivery_response][:cancel_delivery_result]
|
293
|
+
code = res.to_i
|
294
|
+
|
295
|
+
if code == -3000
|
296
|
+
return true
|
297
|
+
else
|
298
|
+
report_error(code)
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
module PostalMethods
|
2
|
+
class Error < RuntimeError
|
3
|
+
CODES = {
|
4
|
+
-1000 => "Completed: successfully delivered to the postal agency",
|
5
|
+
-1002 => "Completed: successfully completed in Development work mode",
|
6
|
+
-1005 => "Actively canceled by user",
|
7
|
+
-1010 => "Failed: no funds available to process the letter",
|
8
|
+
-1018 => "Failed: Provided US address cannot be verified",
|
9
|
+
-1021 => "Failed: Invalid page size",
|
10
|
+
-1025 => "Failed: A document could not be processed",
|
11
|
+
-1045 => "Failed: Recipient postal address could not be extracted from the document",
|
12
|
+
-1065 => "Failed: Too many sheets of paper",
|
13
|
+
-1099 => "Failed: Internal Error",
|
14
|
+
-3000 => "OK",
|
15
|
+
-3001 => "This user is not authorized to access the specified item",
|
16
|
+
-3003 => "Not Authenticated",
|
17
|
+
-3004 => "The specified extension is not supported",
|
18
|
+
-3010 => "Rejected: no funds available",
|
19
|
+
-3020 => "The file specified is unavailable (it may still be being processed, please try later)",
|
20
|
+
-3022 => "Cancellation Denied: The letter was physically processed and cannot be cancelled",
|
21
|
+
-3113 => "Rejected: the city field contains more than 30 characters",
|
22
|
+
-3114 => "Rejected: the state field contains more than 30 characters",
|
23
|
+
-3115 => "There was no data returned for your query",
|
24
|
+
-3116 => "The specified letter (ID) does not exist in the system",
|
25
|
+
-3117 => "Rejected: the company field contains more than 45 characters",
|
26
|
+
-3118 => "Rejected: the address1 field contains more than 45 characters",
|
27
|
+
-3119 => "Rejected: the address2 field contains more than 45 characters",
|
28
|
+
-3120 => "Rejected: the AttentionLine1 field contains more than 45 characters",
|
29
|
+
-3121 => "Rejected: the AttentionLine2 field contains more than 45 characters",
|
30
|
+
-3122 => "Rejected: the AttentionLine3 field contains more than 45 characters",
|
31
|
+
-3123 => "Rejected: the PostalCode/ZIP field contains more than 15 characters",
|
32
|
+
-3124 => "Rejected: the Country field contains more than 30 characters",
|
33
|
+
-3125 => "Only account administrators are allowed access to this information",
|
34
|
+
-3126 => "Invalid file name",
|
35
|
+
-3127 => "File name already exists",
|
36
|
+
-3128 => "The ImageSideFileType field is empty or missing",
|
37
|
+
-3129 => "The AddressSideFileType field is empty or missing",
|
38
|
+
-3130 => "Unsupported file extension in ImageSideFileType",
|
39
|
+
-3131 => "Unsupported file extension in AddressSideFileType",
|
40
|
+
-3132 => "The ImageSideBinaryData field is empty or missing",
|
41
|
+
-3133 => "The AddressSideBinaryData field is empty or missing",
|
42
|
+
-3134 => "File name provided in ImageSideFileType does not exist for this user",
|
43
|
+
-3135 => "File name provided in AddressSideFileType does not exist for this user",
|
44
|
+
-3136 => "Image side: One or more of the fields is missing from the template",
|
45
|
+
-3137 => "Address side: One or more of the fields is missing from the template",
|
46
|
+
-3138 => "Image side: The XML merge data is invalid",
|
47
|
+
-3139 => "Address side: The XML merge data is invalid",
|
48
|
+
-3142 => "Image side: This file cannot be used as a template",
|
49
|
+
-3143 => "Address side: This file cannot be used as a template",
|
50
|
+
-3144 => "The XML merge data is invalid",
|
51
|
+
-3145 => "One or more of the fields in the XML merge data is missing from the selected template",
|
52
|
+
-3146 => "Specified pre-uploaded document does not exist",
|
53
|
+
-3147 => "Uploading a file and a template in the same request is not allowed",
|
54
|
+
-3150 => "General System Error: Contact technical support",
|
55
|
+
-3160 => "File does not exist",
|
56
|
+
-3161 => "Insufficient Permissions",
|
57
|
+
-3162 => "Too many uploaded files",
|
58
|
+
-3163 => "No files for the account",
|
59
|
+
-3164 => "Only Administrator can upload file as account",
|
60
|
+
-3165 => "User does not have an API key assigned",
|
61
|
+
-3209 => "No more users allowed",
|
62
|
+
-3210 => "Last administrator for account",
|
63
|
+
-3211 => "User does not exist for this account",
|
64
|
+
-3212 => "One or more of the parameters are invalid",
|
65
|
+
-3213 => "Invalid value: General_Username",
|
66
|
+
-3214 => "Invalid value: General_Description",
|
67
|
+
-3215 => "Invalid value: General_Timezone",
|
68
|
+
-3216 => "Invalid value: General_WordMode",
|
69
|
+
-3217 => "Invalid value: Security_Password",
|
70
|
+
-3218 => "Invalid value: Security_AdministrativeEmail",
|
71
|
+
-3219 => "Invalid value: Security_KeepContentOnServer",
|
72
|
+
-3220 => "Invalid value: Letters_PrintColor",
|
73
|
+
-3221 => "Invalid value: Letters_PrintSides",
|
74
|
+
-3222 => "Invalid value: Postcards_DefaultScaling",
|
75
|
+
-3223 => "Invalid value: Feedback_FeedbackType",
|
76
|
+
-3224 => "Invalid value: Feedback_Email_WhenToSend_EmailReceived",
|
77
|
+
-3225 => "Invalid value: Feedback_Email_WhenToSend_Completed",
|
78
|
+
-3226 => "Invalid value: Feedback_Email_WhenToSend_Error",
|
79
|
+
-3227 => "Invalid value: Feedback_Email_WhenToSend_BatchErrors",
|
80
|
+
-3228 => "Invalid value: Feedback_Email_DefaultFeedbackEmail",
|
81
|
+
-3229 => "Invalid value: Feedback_Email_Authentication",
|
82
|
+
-3230 => "Invalid value: Feedback_Post_WhenToSend_Completed",
|
83
|
+
-3231 => "Invalid value: Feedback_Post_WhenToSend_Error",
|
84
|
+
-3232 => "Invalid value: Feedback_Post_WhenToSend_BatchErrors",
|
85
|
+
-3233 => "Invalid value: Feedback_Post_FeedbackURL",
|
86
|
+
-3234 => "Invalid value: Feedback_Post_Authentication",
|
87
|
+
-3235 => "Invalid value: Feedback_Soap_WhenToSend_Completed",
|
88
|
+
-3236 => "Invalid value: Feedback_Soap_WhenToSend_Error",
|
89
|
+
-3237 => "Invalid value: Feedback_Soap_WhenToSend_BatchErrors",
|
90
|
+
-3238 => "Invalid value: Feedback_Soap_FeedbackURL",
|
91
|
+
-3239 => "Invalid value: Feedback_Soap_Authentication",
|
92
|
+
-3240 => "Invalid parameters array",
|
93
|
+
-3500 => "Warning: too many attempts were made for this method",
|
94
|
+
-4001 => "The username field is empty or missing",
|
95
|
+
-4002 => "The password field is empty or missing",
|
96
|
+
-4003 => "The MyDescription field is empty or missing - please contact support",
|
97
|
+
-4004 => "The FileExtension field is empty or missing - please contact support",
|
98
|
+
-4005 => "The FileBinaryData field is empty or missing - please contact support",
|
99
|
+
-4006 => "The Address1 field is empty or missing",
|
100
|
+
-4007 => "The city field is empty or missing",
|
101
|
+
-4008 => "The Attention1 or Company fields are empty or missing",
|
102
|
+
-4009 => "The ID field is empty or missing.",
|
103
|
+
-4010 => "The MinID field is empty or missing",
|
104
|
+
-4011 => "The MaxID field is empty or missing",
|
105
|
+
-4013 => "Invalid ID or IDs",
|
106
|
+
-4014 => "The MergeData field is empty or missing",
|
107
|
+
-4015 => "Missing field: APIKey"
|
108
|
+
}
|
109
|
+
end
|
110
|
+
|
111
|
+
class APIError < StandardError
|
112
|
+
attr_accessor :code
|
113
|
+
|
114
|
+
def initialize(code, message)
|
115
|
+
@code = code
|
116
|
+
super(message)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
Error::CODES.to_a.each do |http_status|
|
121
|
+
status, message = http_status
|
122
|
+
code = status.to_s.strip.sub(/^\-/,'')
|
123
|
+
class_eval <<-"end;"
|
124
|
+
class APIStatusCode#{code}Error < APIError
|
125
|
+
def initialize(message=nil)
|
126
|
+
super("#{status}", "#{message}")
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end;
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'postalmethods/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "postalmethods-ng"
|
8
|
+
spec.version = PostalMethods::VERSION
|
9
|
+
spec.authors = ["Paul Philippov"]
|
10
|
+
spec.email = ["themactep@gmail.com"]
|
11
|
+
spec.description = %q{PostalMethods SOAP API library}
|
12
|
+
spec.summary = %q{PostalMethods SOAP API library based on Savon SOAP Client v2.}
|
13
|
+
spec.homepage = "http://themactep.com/ruby/postalmethods-ng"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.4"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_dependency "savon", "~> 2.0"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: postalmethods-ng
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paul Philippov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.4'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: savon
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
55
|
+
description: PostalMethods SOAP API library
|
56
|
+
email:
|
57
|
+
- themactep@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/postalmethods-ng.rb
|
68
|
+
- lib/postalmethods.rb
|
69
|
+
- lib/postalmethods/client.rb
|
70
|
+
- lib/postalmethods/errors.rb
|
71
|
+
- lib/postalmethods/version.rb
|
72
|
+
- postalmethods-ng.gemspec
|
73
|
+
homepage: http://themactep.com/ruby/postalmethods-ng
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.1.5
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: PostalMethods SOAP API library based on Savon SOAP Client v2.
|
97
|
+
test_files: []
|