endpost 0.0.1 → 0.1.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.
- checksums.yaml +4 -4
- data/lib/dial_a_zip.rb +58 -0
- data/lib/endpost.rb +5 -110
- data/lib/label_server.rb +110 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2241801ca3404c9fe209a75b33760c2596c8558
|
4
|
+
data.tar.gz: 031a92ae2a9af8bb29d642a042bf9d8f8dbc47bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c9b7a452b9b5aec71edb8106d709f9768ead2b2d5b01f982aa381d8fd7e83d0076cb400957f04413e88d05c343dd71cdb940be605598c938f910d185df501a6
|
7
|
+
data.tar.gz: d28b38da6f4538e39542a387a56972a73011ccba23e85c8d1373304a4f4691aa5cf278b9e29d3ce26aea47e95cff005c79617283a9b911ba0f4087085a331a2d
|
data/lib/dial_a_zip.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
module DialAZip
|
2
|
+
DIAL_A_ZIP_BASE_URL = 'http://www.dial-a-zip.com/XML-Dial-A-ZIP/DAZService.asmx'
|
3
|
+
|
4
|
+
DIAL_A_ZIP_RESPONSE_MESSAGES = {
|
5
|
+
'10' => 'More than one delivery address was detected',
|
6
|
+
'11' => 'ZIP Code could not be found',
|
7
|
+
'12' => 'The State code is invalid',
|
8
|
+
'13' => 'The City is invalid',
|
9
|
+
'21' => 'The address as submitted could not be found',
|
10
|
+
'22' => 'More than one ZIP code was found',
|
11
|
+
'25' => 'The Street address is invalid',
|
12
|
+
'31' => 'Exact Match',
|
13
|
+
'32' => 'More information, such as an apartment or suite number, may give a more specific address.',
|
14
|
+
}
|
15
|
+
|
16
|
+
attr_accessor :dial_a_zip_user, :dial_a_zip_password
|
17
|
+
|
18
|
+
def verify_address(address)
|
19
|
+
xml = %!
|
20
|
+
<VERIFYADDRESS>
|
21
|
+
<COMMAND>ZIP1</COMMAND>
|
22
|
+
<SERIALNO>#{dial_a_zip_user}</SERIALNO>
|
23
|
+
<USER>#{dial_a_zip_user}</USER>
|
24
|
+
<PASSWORD>#{dial_a_zip_password}</PASSWORD>
|
25
|
+
<ADDRESS0></ADDRESS0>
|
26
|
+
<ADDRESS1>#{address[:full_name]}</ADDRESS1>
|
27
|
+
<ADDRESS2>#{address[:address]}</ADDRESS2>
|
28
|
+
<ADDRESS3>#{address[:city]}, #{address[:state]} #{address[:zipcode]}</ADDRESS3>
|
29
|
+
</VERIFYADDRESS>!
|
30
|
+
|
31
|
+
begin
|
32
|
+
response = RestClient.post "#{DIAL_A_ZIP_BASE_URL}/MethodZIPValidate", :input => xml
|
33
|
+
|
34
|
+
response_xml = Nokogiri::XML(response.body)
|
35
|
+
|
36
|
+
return_code_node_xml = response_xml.css('Dial-A-ZIP_Response ReturnCode').first
|
37
|
+
return_code = return_code_node_xml ? return_code_node_xml.text : nil
|
38
|
+
|
39
|
+
addr_exists_node_xml = response_xml.css('Dial-A-ZIP_Response AddrExists').first
|
40
|
+
addr_exists = addr_exists_node_xml ? addr_exists_node_xml.text : nil
|
41
|
+
|
42
|
+
if return_code == '31' && addr_exists == 'TRUE'
|
43
|
+
return {
|
44
|
+
:full_name => response_xml.css('Dial-A-ZIP_Response AddrLine2').first.text,
|
45
|
+
:address => response_xml.css('Dial-A-ZIP_Response AddrLine1').first.text,
|
46
|
+
:city => response_xml.css('Dial-A-ZIP_Response City').first.text,
|
47
|
+
:state => response_xml.css('Dial-A-ZIP_Response State').first.text,
|
48
|
+
:zipcode => [response_xml.css('Dial-A-ZIP_Response ZIP5').first.text, response_xml.css('Dial-A-ZIP_Response Plus4').first.text].join('-'),
|
49
|
+
}
|
50
|
+
else
|
51
|
+
fail DIAL_A_ZIP_RESPONSE_MESSAGES[return_code]
|
52
|
+
end
|
53
|
+
|
54
|
+
rescue => e
|
55
|
+
fail e.to_s
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/endpost.rb
CHANGED
@@ -2,115 +2,10 @@ require 'base64'
|
|
2
2
|
require 'restclient'
|
3
3
|
require 'nokogiri'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
class << self
|
9
|
-
attr_accessor :test, :requester_id, :account_id, :password
|
10
|
-
|
11
|
-
def change_pass_phrase(old_password, new_password)
|
12
|
-
xml = %!
|
13
|
-
<ChangePassPhraseRequest>
|
14
|
-
<RequesterID>#{requester_id}</RequesterID>
|
15
|
-
<RequestID>0</RequestID>
|
16
|
-
<CertifiedIntermediary>
|
17
|
-
<AccountID>#{account_id}</AccountID>
|
18
|
-
<PassPhrase>#{old_password}</PassPhrase>
|
19
|
-
</CertifiedIntermediary>
|
20
|
-
<NewPassPhrase>#{new_password}</NewPassPhrase>
|
21
|
-
</ChangePassPhraseRequest>!
|
22
|
-
|
23
|
-
response = RestClient.post "#{BASE_URL}/ChangePassPhraseXML", :changePassPhraseRequestXML => xml
|
24
|
-
|
25
|
-
response_xml = Nokogiri::XML(response.body)
|
26
|
-
status_node_xml = response_xml.css('ChangePassPhraseRequestResponse Status').first
|
27
|
-
endicia_response_code = status_node_xml ? status_node_xml.text : nil
|
28
|
-
|
29
|
-
unless endicia_response_code == '0'
|
30
|
-
error_message_node_xml = response_xml.css('ChangePassPhraseRequestResponse ErrorMessage').first
|
31
|
-
endicia_response_message = error_message_node_xml ? error_message_node_xml.text : 'Unknown error'
|
32
|
-
fail endicia_response_message
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def get_postage_label(args)
|
37
|
-
xml = %!
|
38
|
-
<LabelRequest Test="#{test ? 'YES' : 'NO'}" LabelType="Default" ImageFormat="PDF" LabelSize="4x6">
|
39
|
-
<RequesterID>#{requester_id}</RequesterID>
|
40
|
-
<AccountID>#{account_id}</AccountID>
|
41
|
-
<PassPhrase>#{password}</PassPhrase>
|
42
|
-
<MailClass>#{args[:mail_class]}</MailClass>
|
43
|
-
<MailpieceShape>#{args[:mailpiece_shape]}</MailpieceShape>
|
44
|
-
<SortType>#{args[:sort_type]}</SortType>
|
45
|
-
<DateAdvance>0</DateAdvance>
|
46
|
-
<WeightOz>#{args[:weight]}</WeightOz>
|
47
|
-
<Services DeliveryConfirmation="ON" SignatureConfirmation="OFF"/>
|
48
|
-
<ReferenceID>#{args[:order_number]}</ReferenceID>
|
49
|
-
<PartnerCustomerID>1</PartnerCustomerID>
|
50
|
-
<PartnerTransactionID>1</PartnerTransactionID>
|
51
|
-
<ToName>#{args[:to][:full_name]}</ToName>
|
52
|
-
<ToCompany>#{args[:to][:company]}</ToCompany>
|
53
|
-
<ToAddress1>#{args[:to][:address]}</ToAddress1>
|
54
|
-
<ToCity>#{args[:to][:city]}</ToCity>
|
55
|
-
<ToState>#{args[:to][:state]}</ToState>
|
56
|
-
<ToPostalCode>#{args[:to][:zip]}</ToPostalCode>
|
57
|
-
<ToPhone>#{args[:to][:phone]}</ToPhone>
|
58
|
-
<FromName>#{args[:from][:full_name]}</FromName>
|
59
|
-
<ReturnAddress1>#{args[:from][:address]}</ReturnAddress1>
|
60
|
-
<FromCity>#{args[:from][:city]}</FromCity>
|
61
|
-
<FromState>#{args[:from][:state]}</FromState>
|
62
|
-
<FromPostalCode>#{args[:from][:zip]}</FromPostalCode>
|
63
|
-
</LabelRequest>!
|
64
|
-
|
65
|
-
begin
|
66
|
-
response = RestClient.post "#{BASE_URL}/GetPostageLabelXML", :labelRequestXML => xml
|
67
|
-
|
68
|
-
response_xml = Nokogiri::XML(response.body)
|
69
|
-
status_node_xml = response_xml.css('LabelRequestResponse Status').first
|
70
|
-
endicia_response_code = status_node_xml ? status_node_xml.text : nil
|
5
|
+
require_relative './label_server.rb'
|
6
|
+
require_relative './dial_a_zip.rb'
|
71
7
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
fail endicia_response_message
|
76
|
-
end
|
77
|
-
|
78
|
-
label_node_xml = response_xml.css('LabelRequestResponse Base64LabelImage').first
|
79
|
-
return label_node_xml.text
|
80
|
-
|
81
|
-
rescue => e
|
82
|
-
fail e.to_s
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def buy_postage(amount)
|
87
|
-
xml = %!
|
88
|
-
<RecreditRequest>
|
89
|
-
<RequesterID>#{requester_id}</RequesterID>
|
90
|
-
<RequestID>0</RequestID>
|
91
|
-
<CertifiedIntermediary>
|
92
|
-
<AccountID>#{account_id}</AccountID>
|
93
|
-
<PassPhrase>#{password}</PassPhrase>
|
94
|
-
</CertifiedIntermediary>
|
95
|
-
<RecreditAmount>#{amount}</RecreditAmount>
|
96
|
-
</RecreditRequest>!
|
97
|
-
|
98
|
-
begin
|
99
|
-
response = RestClient.post "#{BASE_URL}/BuyPostageXML", :recreditRequestXML => xml
|
100
|
-
|
101
|
-
response_xml = Nokogiri::XML(response.body)
|
102
|
-
status_node_xml = response_xml.css('RecreditRequestResponse Status').first
|
103
|
-
endicia_response_code = status_node_xml ? status_node_xml.text : nil
|
104
|
-
|
105
|
-
unless endicia_response_code == '0'
|
106
|
-
error_message_node_xml = response_xml.css('RecreditRequestResponse ErrorMessage').first
|
107
|
-
endicia_response_message = error_message_node_xml ? error_message_node_xml.text : 'Unknown error'
|
108
|
-
fail endicia_response_message
|
109
|
-
end
|
110
|
-
|
111
|
-
rescue => e
|
112
|
-
fail e.to_s
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
8
|
+
class Endpost
|
9
|
+
extend LabelServer
|
10
|
+
extend DialAZip
|
116
11
|
end
|
data/lib/label_server.rb
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
module LabelServer
|
2
|
+
LABEL_SERVER_BASE_URL = 'https://elstestserver.endicia.com/LabelService/EwsLabelService.asmx'
|
3
|
+
|
4
|
+
attr_accessor :test, :requester_id, :account_id, :password
|
5
|
+
|
6
|
+
def change_pass_phrase(old_password, new_password)
|
7
|
+
xml = %!
|
8
|
+
<ChangePassPhraseRequest>
|
9
|
+
<RequesterID>#{requester_id}</RequesterID>
|
10
|
+
<RequestID>0</RequestID>
|
11
|
+
<CertifiedIntermediary>
|
12
|
+
<AccountID>#{account_id}</AccountID>
|
13
|
+
<PassPhrase>#{old_password}</PassPhrase>
|
14
|
+
</CertifiedIntermediary>
|
15
|
+
<NewPassPhrase>#{new_password}</NewPassPhrase>
|
16
|
+
</ChangePassPhraseRequest>!
|
17
|
+
|
18
|
+
response = RestClient.post "#{LABEL_SERVER_BASE_URL}/ChangePassPhraseXML", :changePassPhraseRequestXML => xml
|
19
|
+
|
20
|
+
response_xml = Nokogiri::XML(response.body)
|
21
|
+
status_node_xml = response_xml.css('ChangePassPhraseRequestResponse Status').first
|
22
|
+
endicia_response_code = status_node_xml ? status_node_xml.text : nil
|
23
|
+
|
24
|
+
unless endicia_response_code == '0'
|
25
|
+
error_message_node_xml = response_xml.css('ChangePassPhraseRequestResponse ErrorMessage').first
|
26
|
+
endicia_response_message = error_message_node_xml ? error_message_node_xml.text : 'Unknown error'
|
27
|
+
fail endicia_response_message
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def get_postage_label(args)
|
32
|
+
xml = %!
|
33
|
+
<LabelRequest Test="#{test ? 'YES' : 'NO'}" LabelType="Default" ImageFormat="PDF" LabelSize="4x6">
|
34
|
+
<RequesterID>#{requester_id}</RequesterID>
|
35
|
+
<AccountID>#{account_id}</AccountID>
|
36
|
+
<PassPhrase>#{password}</PassPhrase>
|
37
|
+
<MailClass>#{args[:mail_class]}</MailClass>
|
38
|
+
<MailpieceShape>#{args[:mailpiece_shape]}</MailpieceShape>
|
39
|
+
<SortType>#{args[:sort_type]}</SortType>
|
40
|
+
<DateAdvance>0</DateAdvance>
|
41
|
+
<WeightOz>#{args[:weight]}</WeightOz>
|
42
|
+
<Services DeliveryConfirmation="ON" SignatureConfirmation="OFF"/>
|
43
|
+
<ReferenceID>#{args[:order_number]}</ReferenceID>
|
44
|
+
<PartnerCustomerID>1</PartnerCustomerID>
|
45
|
+
<PartnerTransactionID>1</PartnerTransactionID>
|
46
|
+
<ToName>#{args[:to][:full_name]}</ToName>
|
47
|
+
<ToCompany>#{args[:to][:company]}</ToCompany>
|
48
|
+
<ToAddress1>#{args[:to][:address]}</ToAddress1>
|
49
|
+
<ToCity>#{args[:to][:city]}</ToCity>
|
50
|
+
<ToState>#{args[:to][:state]}</ToState>
|
51
|
+
<ToPostalCode>#{args[:to][:zipcode]}</ToPostalCode>
|
52
|
+
<ToPhone>#{args[:to][:phone]}</ToPhone>
|
53
|
+
<FromName>#{args[:from][:full_name]}</FromName>
|
54
|
+
<ReturnAddress1>#{args[:from][:address]}</ReturnAddress1>
|
55
|
+
<FromCity>#{args[:from][:city]}</FromCity>
|
56
|
+
<FromState>#{args[:from][:state]}</FromState>
|
57
|
+
<FromPostalCode>#{args[:from][:zipcode]}</FromPostalCode>
|
58
|
+
</LabelRequest>!
|
59
|
+
|
60
|
+
begin
|
61
|
+
response = RestClient.post "#{LABEL_SERVER_BASE_URL}/GetPostageLabelXML", :labelRequestXML => xml
|
62
|
+
|
63
|
+
response_xml = Nokogiri::XML(response.body)
|
64
|
+
status_node_xml = response_xml.css('LabelRequestResponse Status').first
|
65
|
+
endicia_response_code = status_node_xml ? status_node_xml.text : nil
|
66
|
+
|
67
|
+
unless endicia_response_code == '0'
|
68
|
+
error_message_node_xml = response_xml.css('LabelRequestResponse ErrorMessage').first
|
69
|
+
endicia_response_message = error_message_node_xml ? error_message_node_xml.text : 'Unknown error'
|
70
|
+
fail endicia_response_message
|
71
|
+
end
|
72
|
+
|
73
|
+
label_node_xml = response_xml.css('LabelRequestResponse Base64LabelImage').first
|
74
|
+
return label_node_xml.text
|
75
|
+
|
76
|
+
rescue => e
|
77
|
+
fail e.to_s
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def buy_postage(amount)
|
82
|
+
xml = %!
|
83
|
+
<RecreditRequest>
|
84
|
+
<RequesterID>#{requester_id}</RequesterID>
|
85
|
+
<RequestID>0</RequestID>
|
86
|
+
<CertifiedIntermediary>
|
87
|
+
<AccountID>#{account_id}</AccountID>
|
88
|
+
<PassPhrase>#{password}</PassPhrase>
|
89
|
+
</CertifiedIntermediary>
|
90
|
+
<RecreditAmount>#{amount}</RecreditAmount>
|
91
|
+
</RecreditRequest>!
|
92
|
+
|
93
|
+
begin
|
94
|
+
response = RestClient.post "#{LABEL_SERVER_BASE_URL}/BuyPostageXML", :recreditRequestXML => xml
|
95
|
+
|
96
|
+
response_xml = Nokogiri::XML(response.body)
|
97
|
+
status_node_xml = response_xml.css('RecreditRequestResponse Status').first
|
98
|
+
endicia_response_code = status_node_xml ? status_node_xml.text : nil
|
99
|
+
|
100
|
+
unless endicia_response_code == '0'
|
101
|
+
error_message_node_xml = response_xml.css('RecreditRequestResponse ErrorMessage').first
|
102
|
+
endicia_response_message = error_message_node_xml ? error_message_node_xml.text : 'Unknown error'
|
103
|
+
fail endicia_response_message
|
104
|
+
end
|
105
|
+
|
106
|
+
rescue => e
|
107
|
+
fail e.to_s
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: endpost
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alfonso Cora
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -73,7 +73,9 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
+
- lib/dial_a_zip.rb
|
76
77
|
- lib/endpost.rb
|
78
|
+
- lib/label_server.rb
|
77
79
|
homepage: https://github.com/alfonsocora/endpost
|
78
80
|
licenses:
|
79
81
|
- MIT
|