endicia_ruby 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/.gitignore +18 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +23 -0
- data/Rakefile +6 -0
- data/config/endicia.yml +10 -0
- data/endicia_ruby.gemspec +30 -0
- data/lib/endicia_ruby/label.rb +53 -0
- data/lib/endicia_ruby/label_response.rb +46 -0
- data/lib/endicia_ruby/refund.rb +53 -0
- data/lib/endicia_ruby/refund_response.rb +39 -0
- data/lib/endicia_ruby/request.rb +168 -0
- data/lib/endicia_ruby/version.rb +3 -0
- data/lib/endicia_ruby.rb +7 -0
- data/spec/label_response_spec.rb +84 -0
- data/spec/label_spec.rb +64 -0
- data/spec/refund_spec.rb +63 -0
- data/spec/spec_helper.rb +55 -0
- data/spec/vcr-cassettes/Endicia_Label/_request_label/handles_a_nonsense_request.yml +124 -0
- data/spec/vcr-cassettes/Endicia_Label/_request_label/makes_a_request_and_properly_parses_the_result.yml +164 -0
- data/spec/vcr-cassettes/Endicia_Refund/_request_refund/returns_info_about_each_tracking_number.yml +217 -0
- metadata +202 -0
data/spec/refund_spec.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe Endicia::Refund, vcr: { record: :none } do # XXX: Hand-crafted, artisanal, small-batch VCR file
|
4
|
+
subject(:refund) { described_class.new }
|
5
|
+
|
6
|
+
describe "#request_refund" do
|
7
|
+
let(:values) {
|
8
|
+
{
|
9
|
+
ToName: Faker::Name.name,
|
10
|
+
ToCompany: Faker::Company.name,
|
11
|
+
ToPostalCode: "90210",
|
12
|
+
ToAddress1: Faker::Address.street_address,
|
13
|
+
ToAddress2: Faker::Address.secondary_address,
|
14
|
+
ToCity: Faker::Address.city,
|
15
|
+
ToState: "CA",
|
16
|
+
PartnerTransactionID: 12345,
|
17
|
+
PartnerCustomerID: 45678,
|
18
|
+
MailClass: "Priority",
|
19
|
+
MailpieceShape: "Parcel",
|
20
|
+
ToZIP4: '1234',
|
21
|
+
WeightOz: "32", # 2 pounds
|
22
|
+
MailpieceDimensions: {
|
23
|
+
Length: "12",
|
24
|
+
Width: "16",
|
25
|
+
Height: "18",
|
26
|
+
},
|
27
|
+
FromCompany: Faker::Company.name,
|
28
|
+
ReturnAddress1: Faker::Address.street_address,
|
29
|
+
ReturnAddress2: Faker::Address.secondary_address,
|
30
|
+
FromCity: Faker::Address.city,
|
31
|
+
FromState: "DC",
|
32
|
+
FromPostalCode: "20005",
|
33
|
+
FromZIP4: "1234",
|
34
|
+
FromPhone: "2025551212",
|
35
|
+
}
|
36
|
+
}
|
37
|
+
before do
|
38
|
+
# get a couple real tracking number
|
39
|
+
@tracking_numbers = []
|
40
|
+
label = Endicia::Label.new
|
41
|
+
2.times {
|
42
|
+
create_label_response = label.request_label({ nodes: values, attrs: {} }, { log_requests: true, log_responses: true })
|
43
|
+
@tracking_numbers << create_label_response.tracking_number
|
44
|
+
}
|
45
|
+
@response = refund.request_refund(@tracking_numbers)
|
46
|
+
end
|
47
|
+
it "returns info about each tracking number" do # XXX: Do not rename this test as we had to hand-craft
|
48
|
+
# the VCR file, since the test server doesn't support
|
49
|
+
# refund requests
|
50
|
+
expect(@response.success).to eq(true)
|
51
|
+
expect(@response.form_number).to_not be_nil
|
52
|
+
expect(@response.raw_response).to_not be_nil
|
53
|
+
expect(@response.parsed_response).to_not be_nil
|
54
|
+
expect(@response.tracking_numbers.size).to eq(@tracking_numbers.size)
|
55
|
+
@tracking_numbers.each do |tracking_number|
|
56
|
+
expect(@response.tracking_numbers[0].pic_number).to eq(tracking_number)
|
57
|
+
expect(@response.tracking_numbers[0].approved).to eq(true)
|
58
|
+
expect(@response.tracking_numbers[0].message).to_not be_nil
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
require 'webmock'
|
4
|
+
require 'vcr'
|
5
|
+
require 'faker'
|
6
|
+
|
7
|
+
require 'endicia_ruby'
|
8
|
+
|
9
|
+
WebMock.disable_net_connect!
|
10
|
+
VCR.configure do |c|
|
11
|
+
c.cassette_library_dir = 'spec/vcr-cassettes'
|
12
|
+
c.hook_into :webmock
|
13
|
+
c.default_cassette_options = { :record => :new_episodes }
|
14
|
+
c.allow_http_connections_when_no_cassette = false
|
15
|
+
c.ignore_localhost = true
|
16
|
+
c.ignore_hosts 'localhost', 'amazonaws.com', 's3.amazonaws.com', 'stitchfix-dev.s3.amazonaws.com'
|
17
|
+
c.configure_rspec_metadata!
|
18
|
+
c.preserve_exact_body_bytes do |http_message|
|
19
|
+
http_message.body.encoding.name == 'ASCII-8BIT' ||
|
20
|
+
!http_message.body.valid_encoding?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
RSpec.configure do |config|
|
25
|
+
config.order = "random"
|
26
|
+
config.expect_with :rspec do |c|
|
27
|
+
c.syntax = [:should, :expect]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
module Kernel
|
32
|
+
alias :original_warn :warn
|
33
|
+
def warn(*args)
|
34
|
+
if args.length == 1 && args[0] == 'Digest::Digest is deprecated; use Digest'
|
35
|
+
else
|
36
|
+
original_warn(*args)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
module Rails
|
42
|
+
def self.root
|
43
|
+
File.expand_path(File.join(File.dirname(__FILE__),'..'))
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.env
|
47
|
+
'test'
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.logger
|
51
|
+
@logger ||= Logger.new(STDERR).tap { |_|
|
52
|
+
_.level = Logger::ERROR
|
53
|
+
}
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://elstestserver.endicia.com/LabelService/EwsLabelService.asmx/GetPostageLabelXML
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: |
|
9
|
+
labelRequestXML=<?xml version="1.0"?>
|
10
|
+
<LabelRequest Test="YES" LabelType="Default">
|
11
|
+
<AccountID>2500334</AccountID>
|
12
|
+
<RequesterID>lxxx</RequesterID>
|
13
|
+
<PassPhrase>endicia.com</PassPhrase>
|
14
|
+
</LabelRequest>
|
15
|
+
headers: {}
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK500 Internal Server Error
|
20
|
+
headers:
|
21
|
+
Connection:
|
22
|
+
- close
|
23
|
+
Date:
|
24
|
+
- Wed, 22 Oct 2014 20:50:28 GMT
|
25
|
+
Server:
|
26
|
+
- Microsoft-IIS/6.0
|
27
|
+
X-Powered-By:
|
28
|
+
- ASP.NET
|
29
|
+
X-Aspnet-Version:
|
30
|
+
- 4.0.30319
|
31
|
+
Endicia-Label-Format:
|
32
|
+
- 'Cache-Control: private'
|
33
|
+
Content-Type:
|
34
|
+
- text/html; charset=utf-8
|
35
|
+
Content-Length:
|
36
|
+
- '3042'
|
37
|
+
body:
|
38
|
+
encoding: UTF-8
|
39
|
+
string: "<html>\r\n <head>\r\n <title>Runtime Error</title>\r\n <style>\r\n
|
40
|
+
\ body {font-family:\"Verdana\";font-weight:normal;font-size: .7em;color:black;}
|
41
|
+
\r\n p {font-family:\"Verdana\";font-weight:normal;color:black;margin-top:
|
42
|
+
-5px}\r\n b {font-family:\"Verdana\";font-weight:bold;color:black;margin-top:
|
43
|
+
-5px}\r\n H1 { font-family:\"Verdana\";font-weight:normal;font-size:18pt;color:red
|
44
|
+
}\r\n H2 { font-family:\"Verdana\";font-weight:normal;font-size:14pt;color:maroon
|
45
|
+
}\r\n pre {font-family:\"Lucida Console\";font-size: .9em}\r\n .marker
|
46
|
+
{font-weight: bold; color: black;text-decoration: none;}\r\n .version
|
47
|
+
{color: gray;}\r\n .error {margin-bottom: 10px;}\r\n .expandable
|
48
|
+
{ text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }\r\n
|
49
|
+
\ </style>\r\n </head>\r\n\r\n <body bgcolor=\"white\">\r\n\r\n
|
50
|
+
\ <span><H1>Server Error in '/LabelService' Application.<hr width=100%
|
51
|
+
size=1 color=silver></H1>\r\n\r\n <h2> <i>Runtime Error</i> </h2></span>\r\n\r\n
|
52
|
+
\ <font face=\"Arial, Helvetica, Geneva, SunSans-Regular, sans-serif
|
53
|
+
\">\r\n\r\n <b> Description: </b>An application error occurred
|
54
|
+
on the server. The current custom error settings for this application prevent
|
55
|
+
the details of the application error from being viewed remotely (for security
|
56
|
+
reasons). It could, however, be viewed by browsers running on the local server
|
57
|
+
machine.\r\n <br><br>\r\n\r\n <b>Details:</b> To enable
|
58
|
+
the details of this specific error message to be viewable on remote machines,
|
59
|
+
please create a <customErrors> tag within a "web.config" configuration
|
60
|
+
file located in the root directory of the current web application. This <customErrors>
|
61
|
+
tag should then have its "mode" attribute set to "Off".<br><br>\r\n\r\n
|
62
|
+
\ <table width=100% bgcolor=\"#ffffcc\">\r\n <tr>\r\n
|
63
|
+
\ <td>\r\n <code><pre>\r\n\r\n<!--
|
64
|
+
Web.Config Configuration File -->\r\n\r\n<configuration>\r\n <system.web>\r\n
|
65
|
+
\ <customErrors mode="Off"/>\r\n </system.web>\r\n</configuration></pre></code>\r\n\r\n
|
66
|
+
\ </td>\r\n </tr>\r\n </table>\r\n\r\n
|
67
|
+
\ <br>\r\n\r\n <b>Notes:</b> The current error page you
|
68
|
+
are seeing can be replaced by a custom error page by modifying the "defaultRedirect"
|
69
|
+
attribute of the application's <customErrors> configuration tag
|
70
|
+
to point to a custom error page URL.<br><br>\r\n\r\n <table width=100%
|
71
|
+
bgcolor=\"#ffffcc\">\r\n <tr>\r\n <td>\r\n
|
72
|
+
\ <code><pre>\r\n\r\n<!-- Web.Config Configuration
|
73
|
+
File -->\r\n\r\n<configuration>\r\n <system.web>\r\n <customErrors
|
74
|
+
mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>\r\n
|
75
|
+
\ </system.web>\r\n</configuration></pre></code>\r\n\r\n </td>\r\n
|
76
|
+
\ </tr>\r\n </table>\r\n\r\n <br>\r\n\r\n
|
77
|
+
\ </body>\r\n</html>\r\n"
|
78
|
+
http_version:
|
79
|
+
recorded_at: Wed, 22 Oct 2014 20:50:26 GMT
|
80
|
+
- request:
|
81
|
+
method: post
|
82
|
+
uri: https://www.envmgr.com/LabelService/EwsLabelService.asmx/GetPostageLabelXML
|
83
|
+
body:
|
84
|
+
encoding: UTF-8
|
85
|
+
string: |
|
86
|
+
labelRequestXML=<?xml version="1.0"?>
|
87
|
+
<LabelRequest Test="YES" LabelType="Default">
|
88
|
+
<AccountID>2500334</AccountID>
|
89
|
+
<RequesterID>lxxx</RequesterID>
|
90
|
+
<PassPhrase>endicia.com</PassPhrase>
|
91
|
+
</LabelRequest>
|
92
|
+
headers: {}
|
93
|
+
response:
|
94
|
+
status:
|
95
|
+
code: 200
|
96
|
+
message: OK
|
97
|
+
headers:
|
98
|
+
Cache-Control:
|
99
|
+
- private, max-age=0
|
100
|
+
Content-Type:
|
101
|
+
- text/xml; charset=utf-8
|
102
|
+
X-Aspnet-Version:
|
103
|
+
- 4.0.30319
|
104
|
+
X-Powered-By:
|
105
|
+
- ASP.NET
|
106
|
+
Date:
|
107
|
+
- Mon, 27 Oct 2014 16:25:54 GMT
|
108
|
+
Content-Length:
|
109
|
+
- '572'
|
110
|
+
Set-Cookie:
|
111
|
+
- TS01f3408d=017b1809615f96bb14189a5af4bc475ddcf412dbb1637c14e6b5ae7d00beae8ac6f59c48c7;
|
112
|
+
Path=/
|
113
|
+
body:
|
114
|
+
encoding: UTF-8
|
115
|
+
string: "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<LabelRequestResponse
|
116
|
+
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
|
117
|
+
xmlns=\"www.envmgr.com/LabelService\">\r\n <Status>1001</Status>\r\n <ErrorMessage>Missing
|
118
|
+
or invalid data element: MailClassLabelRequest. Error encountered (Log ID:
|
119
|
+
34422)</ErrorMessage>\r\n <FinalPostage>0.0</FinalPostage>\r\n <TransactionID>0</TransactionID>\r\n
|
120
|
+
\ <PostageBalance>0.00</PostageBalance>\r\n <CostCenter>0</CostCenter>\r\n
|
121
|
+
\ <ReferenceID2 />\r\n <ReferenceID3 />\r\n <ReferenceID4 />\r\n</LabelRequestResponse>"
|
122
|
+
http_version:
|
123
|
+
recorded_at: Mon, 27 Oct 2014 16:26:02 GMT
|
124
|
+
recorded_with: VCR 2.9.3
|