endicia_ruby 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/endicia_ruby/label_response.rb +39 -1
- data/lib/endicia_ruby/version.rb +1 -1
- data/spec/label_response_spec.rb +65 -0
- data/spec/spec_helper.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 069bc5090abdcefa20260fd618036ac0f9438a03
|
4
|
+
data.tar.gz: fa9e5f2e9957c1f2712a04f2b033859b75553185
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6940cb6f90dbdf668bab142075a394c54eef47a63ee3546fee998883c54e6ffdfcac2a9865837b85922de36123d23c4cc1b68ee86117b0236cbdede7146ef4de
|
7
|
+
data.tar.gz: fba952cd0c7e4dbd5d8f2ec8d2b6d11d9998c99dde58ee0f5d88af2c9993a729b1e991639b2ead1cb8461292cfd8a682ae0b166aaea6c135024f80aa3275f86d
|
@@ -37,7 +37,45 @@ module Endicia
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
|
40
|
+
# True if this result represents a successful label response
|
41
|
+
def success?
|
42
|
+
status && status.to_i == 0
|
43
|
+
end
|
44
|
+
|
45
|
+
# True if this is an error and it's a "critical" one, meaning the ability
|
46
|
+
# to generate further labels could be impeded by the information received back
|
47
|
+
def critical_error?
|
48
|
+
CRITICAL_ERROR_CODES.include?(status.to_i)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
CRITICAL_ERROR_CODES = [
|
54
|
+
1101,
|
55
|
+
2011,
|
56
|
+
2012,
|
57
|
+
2013,
|
58
|
+
2014,
|
59
|
+
2015,
|
60
|
+
2020,
|
61
|
+
2021,
|
62
|
+
12101,
|
63
|
+
12103,
|
64
|
+
12104,
|
65
|
+
12115,
|
66
|
+
12116,
|
67
|
+
12117,
|
68
|
+
12120,
|
69
|
+
12130,
|
70
|
+
12133,
|
71
|
+
12503,
|
72
|
+
12505,
|
73
|
+
12507,
|
74
|
+
12515,
|
75
|
+
12525,
|
76
|
+
100201,
|
77
|
+
].freeze
|
78
|
+
|
41
79
|
def filter_response_body(string)
|
42
80
|
# Strip image data for readability:
|
43
81
|
string.sub(/<.*Image>.+<\/.*Image>/, "<Image>[data]</Image>")
|
data/lib/endicia_ruby/version.rb
CHANGED
data/spec/label_response_spec.rb
CHANGED
@@ -81,4 +81,69 @@ describe Endicia::LabelResponse do
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|
84
|
+
describe "#success?" do
|
85
|
+
let(:status) { nil }
|
86
|
+
subject(:label_response) { described_class.new(OpenStruct.new(body: "<foo></foo>", LabelRequestResponse: {"Status" => status})) }
|
87
|
+
|
88
|
+
context "when '0'" do
|
89
|
+
let(:status) { "0" }
|
90
|
+
specify { expect(label_response.success?).to eq(true) }
|
91
|
+
end
|
92
|
+
|
93
|
+
context "when 0" do
|
94
|
+
let(:status) { 0 }
|
95
|
+
specify { expect(label_response.success?).to eq(true) }
|
96
|
+
end
|
97
|
+
|
98
|
+
context "when not 0" do
|
99
|
+
let(:status) { "1234" }
|
100
|
+
specify { expect(label_response.success?).to eq(false) }
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "#critical_error?" do
|
105
|
+
let(:status) { nil }
|
106
|
+
subject(:label_response) { described_class.new(OpenStruct.new(body: "<foo></foo>", LabelRequestResponse: {"Status" => status})) }
|
107
|
+
|
108
|
+
context "when 0" do
|
109
|
+
let(:status) { 0 }
|
110
|
+
specify { expect(label_response.critical_error?).to eq(false) }
|
111
|
+
end
|
112
|
+
|
113
|
+
context "when not 1234" do
|
114
|
+
let(:status) { "1234" }
|
115
|
+
specify { expect(label_response.critical_error?).to eq(false) }
|
116
|
+
end
|
117
|
+
[
|
118
|
+
1101,
|
119
|
+
2011,
|
120
|
+
2012,
|
121
|
+
2013,
|
122
|
+
2014,
|
123
|
+
2015,
|
124
|
+
2020,
|
125
|
+
2021,
|
126
|
+
12101,
|
127
|
+
12103,
|
128
|
+
12104,
|
129
|
+
12115,
|
130
|
+
12116,
|
131
|
+
12117,
|
132
|
+
12120,
|
133
|
+
12130,
|
134
|
+
12133,
|
135
|
+
12503,
|
136
|
+
12505,
|
137
|
+
12507,
|
138
|
+
12515,
|
139
|
+
12525,
|
140
|
+
100201,
|
141
|
+
].each do |code|
|
142
|
+
context "when #{code}" do
|
143
|
+
let(:status) { code.to_s }
|
144
|
+
specify { expect(label_response.critical_error?).to eq(true) }
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
84
149
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: endicia_ruby
|
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
|
- Jon Dean
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-10-
|
12
|
+
date: 2014-10-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|