endpost 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/endpost.rb +116 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8bf9043d140d78f5f95241d4b089c9556e257d55
|
4
|
+
data.tar.gz: 42399bd50aa7ceca0859b88d6fbd68e3386ade41
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fa4f78634ecf3dc7ee4c3285b6a39feed40a66ab7e4dc5a3cbec6826dd1958033123e513ca5ffe474e650146c8a10719edabb2ca3ce8a32f9d0e208577a10a6e
|
7
|
+
data.tar.gz: 347f0d9a0ad291b55cf2b17462af43259b375247d5b5d564bb1cda83fb5bd6fd5d6f931f580132667db0abe71c5e91a59a3b40397cd1037196d53fcdbf7f323b
|
data/lib/endpost.rb
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'restclient'
|
3
|
+
require 'nokogiri'
|
4
|
+
|
5
|
+
class Endpost
|
6
|
+
BASE_URL = 'https://elstestserver.endicia.com/LabelService/EwsLabelService.asmx'
|
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
|
71
|
+
|
72
|
+
unless endicia_response_code == '0'
|
73
|
+
error_message_node_xml = response_xml.css('LabelRequestResponse ErrorMessage').first
|
74
|
+
endicia_response_message = error_message_node_xml ? error_message_node_xml.text : 'Unknown error'
|
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
|
116
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: endpost
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alfonso Cora
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.6.7
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.6.7
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.6.6.2
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.6.6.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 5.6.1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 5.6.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: vcr
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.9.3
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.9.3
|
69
|
+
description: Allows to generate shipping labels and to perform some of the Endicia
|
70
|
+
basic operations.
|
71
|
+
email: alfius@protonmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- lib/endpost.rb
|
77
|
+
homepage: https://github.com/alfonsocora/endpost
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.4.6
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: A wrapper around Endicia web services.
|
101
|
+
test_files: []
|