click_and_send 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/click_and_send/version.rb +1 -1
- data/lib/click_and_send.rb +30 -15
- data/spec/acceptance_spec.rb +19 -6
- data/spec/click_and_send_spec.rb +63 -36
- metadata +3 -3
data/lib/click_and_send.rb
CHANGED
@@ -72,6 +72,22 @@ module ClickAndSend
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
+
def item_pdf_url(ref)
|
76
|
+
ref = ref.to_s
|
77
|
+
tracking_numbers = find_tracking_numbers([ref])[ref] || {}
|
78
|
+
case tracking_numbers.length
|
79
|
+
when 0 then raise(Errors::APIError, "Not found: '#{ref}'")
|
80
|
+
when 1 then tracking_number = tracking_numbers.first
|
81
|
+
else
|
82
|
+
raise(Errors::APIError, "Expected 1 but found #{tracking_numbers.length} tracking numbers for '#{ref}': #{tracking_numbers.join(', ')}")
|
83
|
+
end
|
84
|
+
hash = ActiveSupport::OrderedHash.new
|
85
|
+
hash['PrintFormat' ] = 'LINK'
|
86
|
+
hash['CustTransactionID'] = ref
|
87
|
+
hash['TrackingNumber' ] = tracking_number
|
88
|
+
Request::PrintItem.new(hash).result
|
89
|
+
end
|
90
|
+
|
75
91
|
def item_summary
|
76
92
|
Request::ItemSummary.new.result.fetch(:item_summary_transaction)
|
77
93
|
end
|
@@ -91,23 +107,22 @@ module ClickAndSend
|
|
91
107
|
ClickAndSend::Request::ManifestItems.new(options).result
|
92
108
|
end
|
93
109
|
|
94
|
-
def
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
Request::PrintItem.new(hash).result
|
110
|
+
def manifest_items_by_refs(refs)
|
111
|
+
tracking_numbers = find_tracking_numbers(refs)
|
112
|
+
options = {
|
113
|
+
'ManifestItems' => refs.collect do |ref|
|
114
|
+
{
|
115
|
+
'ManifestItem' => ActiveSupport::OrderedHash.new.tap do |hash|
|
116
|
+
hash['CustTransactionID'] = ref.to_s
|
117
|
+
hash['TrackingNumber' ] = tracking_numbers[ref.to_s].first
|
118
|
+
end
|
119
|
+
}
|
120
|
+
end
|
121
|
+
}
|
122
|
+
manifest_items(options)
|
108
123
|
end
|
109
124
|
|
110
|
-
def
|
125
|
+
def manifest_pdf_url(options)
|
111
126
|
ensure_keys_present(options, %w(PrintFormat PrintDetails ManifestNumber))
|
112
127
|
ClickAndSend::Request::PrintManifest.new(options).result.fetch(:manifest_http_link)
|
113
128
|
end
|
data/spec/acceptance_spec.rb
CHANGED
@@ -36,8 +36,8 @@ describe ClickAndSend, :acceptance do
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
describe '.
|
40
|
-
subject { ClickAndSend.
|
39
|
+
describe '.item_pdf_url' do
|
40
|
+
subject { ClickAndSend.item_pdf_url(ref) }
|
41
41
|
it "returns URL for PDF" do
|
42
42
|
subject.should be_a(String)
|
43
43
|
open(subject).content_type.should eq('application/pdf')
|
@@ -119,8 +119,8 @@ describe ClickAndSend, :acceptance do
|
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
|
-
describe '.
|
123
|
-
let(:
|
122
|
+
describe '.manifest_pdf_url' do
|
123
|
+
let(:manifest_pdf_url) { ClickAndSend.manifest_pdf_url(options) }
|
124
124
|
let(:options) do
|
125
125
|
ActiveSupport::OrderedHash.new.tap do |hash|
|
126
126
|
hash['PrintFormat'] = 'LINK'
|
@@ -130,9 +130,22 @@ describe ClickAndSend, :acceptance do
|
|
130
130
|
end
|
131
131
|
|
132
132
|
it "returns URL for PDF" do
|
133
|
-
|
134
|
-
open(
|
133
|
+
manifest_pdf_url.should be_a(String)
|
134
|
+
open(manifest_pdf_url).content_type.should eq('application/pdf')
|
135
135
|
end
|
136
136
|
end
|
137
137
|
end
|
138
|
+
|
139
|
+
describe '.manifest_items_by_refs' do
|
140
|
+
subject { ClickAndSend.manifest_items_by_refs(refs) }
|
141
|
+
let(:items_created) { ClickAndSend.create_items('Transactions' => attributes_for('Transaction')) }
|
142
|
+
let(:ref) { items_created.fetch(:cust_transaction_id) }
|
143
|
+
let(:refs) { [ref] }
|
144
|
+
|
145
|
+
it "returns manifest number and total charges/taxes" do
|
146
|
+
expect { subject }.not_to raise_error
|
147
|
+
subject.should be_a(Hash)
|
148
|
+
subject.keys.should =~ [:manifest_number, :total_charge, :total_taxes]
|
149
|
+
end
|
150
|
+
end
|
138
151
|
end
|
data/spec/click_and_send_spec.rb
CHANGED
@@ -143,34 +143,8 @@ describe ClickAndSend do
|
|
143
143
|
end
|
144
144
|
end
|
145
145
|
|
146
|
-
describe '.
|
147
|
-
subject { ClickAndSend.
|
148
|
-
it "fetches :item_summary_transaction from ItemSummary result" do
|
149
|
-
ClickAndSend::Request::ItemSummary.should_receive(:new) do
|
150
|
-
stub(:result => {:item_summary_transaction => 'items'})
|
151
|
-
end
|
152
|
-
subject.should eq('items')
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
describe '.manifest_items' do
|
157
|
-
subject { ClickAndSend.manifest_items(options) }
|
158
|
-
let(:required_inputs) { %w(ManifestItems) }
|
159
|
-
it_behaves_like "data required"
|
160
|
-
|
161
|
-
context "when input has valid keys" do
|
162
|
-
it "calls ManifestItems result" do
|
163
|
-
manifest_items = stub
|
164
|
-
options = {'ManifestItems' => stub}
|
165
|
-
ClickAndSend::Request::ManifestItems.should_receive(:new).with(options) { manifest_items }
|
166
|
-
manifest_items.should_receive(:result)
|
167
|
-
ClickAndSend.manifest_items(options)
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
describe '.pdf_url' do
|
173
|
-
subject { ClickAndSend.pdf_url('REF') }
|
146
|
+
describe '.item_pdf_url' do
|
147
|
+
subject { ClickAndSend.item_pdf_url('REF') }
|
174
148
|
let(:options) do
|
175
149
|
{
|
176
150
|
'PrintFormat' => 'LINK',
|
@@ -178,7 +152,7 @@ describe ClickAndSend do
|
|
178
152
|
'TrackingNumber' => tracking_numbers.first
|
179
153
|
}
|
180
154
|
end
|
181
|
-
let(:
|
155
|
+
let(:item_pdf_url) { 'http://example.com/paperwork.pdf' }
|
182
156
|
before do
|
183
157
|
ClickAndSend.stub(:find_tracking_numbers).with(['REF']) do
|
184
158
|
{'REF' => tracking_numbers}
|
@@ -189,9 +163,9 @@ describe ClickAndSend do
|
|
189
163
|
let(:tracking_numbers) { ['xyz'] }
|
190
164
|
specify "requests URL from PrintItem" do
|
191
165
|
ClickAndSend::Request::PrintItem.should_receive(:new).with(options) do
|
192
|
-
stub(:result =>
|
166
|
+
stub(:result => item_pdf_url)
|
193
167
|
end
|
194
|
-
subject.should eq(
|
168
|
+
subject.should eq(item_pdf_url)
|
195
169
|
end
|
196
170
|
end
|
197
171
|
|
@@ -210,23 +184,76 @@ describe ClickAndSend do
|
|
210
184
|
end
|
211
185
|
end
|
212
186
|
|
213
|
-
describe '.
|
214
|
-
subject { ClickAndSend.
|
187
|
+
describe '.item_summary' do
|
188
|
+
subject { ClickAndSend.item_summary }
|
189
|
+
it "fetches :item_summary_transaction from ItemSummary result" do
|
190
|
+
ClickAndSend::Request::ItemSummary.should_receive(:new) do
|
191
|
+
stub(:result => {:item_summary_transaction => 'items'})
|
192
|
+
end
|
193
|
+
subject.should eq('items')
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
describe '.manifest_items' do
|
198
|
+
subject { ClickAndSend.manifest_items(options) }
|
199
|
+
let(:required_inputs) { %w(ManifestItems) }
|
200
|
+
it_behaves_like "data required"
|
201
|
+
|
202
|
+
context "when input has valid keys" do
|
203
|
+
it "calls ManifestItems result" do
|
204
|
+
manifest_items = stub
|
205
|
+
options = {'ManifestItems' => stub}
|
206
|
+
ClickAndSend::Request::ManifestItems.should_receive(:new).with(options) { manifest_items }
|
207
|
+
manifest_items.should_receive(:result)
|
208
|
+
ClickAndSend.manifest_items(options)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
describe '.manifest_items_by_refs' do
|
214
|
+
subject { ClickAndSend.manifest_items_by_refs(refs, options) }
|
215
|
+
let(:manifest_items) do
|
216
|
+
{
|
217
|
+
'ManifestItems' => [
|
218
|
+
{
|
219
|
+
'ManifestItem' => ActiveSupport::OrderedHash.new.tap do |hash|
|
220
|
+
hash['CustTransactionID'] = ref
|
221
|
+
hash['TrackingNumber' ] = tracking_number
|
222
|
+
end
|
223
|
+
}
|
224
|
+
]
|
225
|
+
}
|
226
|
+
end
|
227
|
+
let(:options) { stub }
|
228
|
+
let(:print_manifest) { stub }
|
229
|
+
let(:ref) { stub.tap { |ref| ref.stub(:to_s) { ref } } }
|
230
|
+
let(:refs) { [ref] }
|
231
|
+
let(:tracking_number) { stub }
|
232
|
+
|
233
|
+
it "retrieves tracking numbers and calls manifest_items" do
|
234
|
+
ClickAndSend.should_receive(:find_tracking_numbers).with(refs) { {ref => [tracking_number]} }
|
235
|
+
ClickAndSend.should_receive(:manifest_items).with(manifest_items) { print_manifest }
|
236
|
+
ClickAndSend.manifest_items_by_refs(refs).should eq(print_manifest)
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
describe '.manifest_pdf_url' do
|
241
|
+
subject { ClickAndSend.manifest_pdf_url(options) }
|
215
242
|
let(:required_inputs) { %w(PrintFormat PrintDetails ManifestNumber) }
|
216
243
|
it_behaves_like "data required"
|
217
244
|
|
218
245
|
context "when input has valid keys" do
|
219
246
|
it "calls PrintManifest result" do
|
220
247
|
result = stub
|
221
|
-
|
248
|
+
manifest_pdf_url = stub(:result => result)
|
222
249
|
result.stub(:fetch).with(:manifest_http_link) { 'the link' }
|
223
250
|
options = ActiveSupport::OrderedHash.new.tap do |hash|
|
224
251
|
required_inputs.each do |required_input|
|
225
252
|
hash[required_input] = stub
|
226
253
|
end
|
227
254
|
end
|
228
|
-
ClickAndSend::Request::PrintManifest.should_receive(:new).with(options) {
|
229
|
-
ClickAndSend.
|
255
|
+
ClickAndSend::Request::PrintManifest.should_receive(:new).with(options) { manifest_pdf_url }
|
256
|
+
ClickAndSend.manifest_pdf_url(options).should eq('the link')
|
230
257
|
end
|
231
258
|
end
|
232
259
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: click_and_send
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -178,7 +178,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
178
178
|
version: '0'
|
179
179
|
segments:
|
180
180
|
- 0
|
181
|
-
hash: -
|
181
|
+
hash: -2505933282695818565
|
182
182
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
183
183
|
none: false
|
184
184
|
requirements:
|
@@ -187,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
187
187
|
version: '0'
|
188
188
|
segments:
|
189
189
|
- 0
|
190
|
-
hash: -
|
190
|
+
hash: -2505933282695818565
|
191
191
|
requirements: []
|
192
192
|
rubyforge_project:
|
193
193
|
rubygems_version: 1.8.24
|