click_and_send 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +0 -1
- data/doc/click_and_send_api_guide_v8.1.pdf +0 -0
- data/lib/click_and_send/version.rb +1 -1
- data/lib/click_and_send.rb +7 -2
- data/spec/acceptance_spec.rb +18 -4
- data/spec/click_and_send_spec.rb +1 -0
- data/spec/fixtures/config.example.yml +1 -1
- data/spec/support/factories.rb +1 -1
- data/spec/support/helpers.rb +1 -3
- metadata +5 -4
data/.gitignore
CHANGED
Binary file
|
data/lib/click_and_send.rb
CHANGED
@@ -39,6 +39,7 @@ module ClickAndSend
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def delete_items_by_ref(refs)
|
42
|
+
refs = refs.collect(&:to_s)
|
42
43
|
items = find_tracking_numbers(refs).inject([]) do |carrier, (ref, tracking_numbers)|
|
43
44
|
tracking_numbers.each do |tracking_number|
|
44
45
|
hash = ActiveSupport::OrderedHash.new
|
@@ -48,15 +49,18 @@ module ClickAndSend
|
|
48
49
|
end
|
49
50
|
carrier
|
50
51
|
end
|
51
|
-
delete_items('DeleteItems' => items)
|
52
|
+
delete_items('DeleteItems' => items) if items.any?
|
52
53
|
end
|
53
54
|
|
54
55
|
def delete_items(options)
|
55
56
|
ensure_keys_present(options, %w(DeleteItems))
|
56
|
-
|
57
|
+
# TODO: Adjust XML so all DeleteItem objects are nested within one DeleteItems object.
|
58
|
+
# Then, replace next line with: Request::DeleteItems.new(options).result
|
59
|
+
options['DeleteItems'].each { |item| Request::DeleteItems.new('DeleteItems' => item).result }
|
57
60
|
end
|
58
61
|
|
59
62
|
def find_tracking_numbers(refs)
|
63
|
+
refs = refs.collect(&:to_s)
|
60
64
|
item_summary.inject({}) do |hash,item|
|
61
65
|
if item.kind_of?(Hash) && refs.include?(item[:cust_transaction_id])
|
62
66
|
hash[item[:cust_transaction_id]] ||= []
|
@@ -81,6 +85,7 @@ module ClickAndSend
|
|
81
85
|
end
|
82
86
|
|
83
87
|
def pdf_url(ref)
|
88
|
+
ref = ref.to_s
|
84
89
|
tracking_numbers = find_tracking_numbers([ref])[ref] || {}
|
85
90
|
case tracking_numbers.length
|
86
91
|
when 0 then raise(Errors::APIError, "Not found: '#{ref}'")
|
data/spec/acceptance_spec.rb
CHANGED
@@ -32,7 +32,7 @@ describe ClickAndSend, :acceptance do
|
|
32
32
|
subject { ClickAndSend.find_tracking_numbers([ref]) }
|
33
33
|
specify do
|
34
34
|
should be_a(Hash)
|
35
|
-
subject.keys.should == [ref]
|
35
|
+
subject.keys.should == [ref.to_s]
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -50,6 +50,13 @@ describe ClickAndSend, :acceptance do
|
|
50
50
|
ClickAndSend.delete_items_by_ref([ref])
|
51
51
|
end.to change { ClickAndSend.find_tracking_numbers([ref]).empty? }.to(true)
|
52
52
|
end
|
53
|
+
|
54
|
+
context "when item doesn't exist" do
|
55
|
+
let(:ref) { 'MISSING' }
|
56
|
+
specify do
|
57
|
+
expect { ClickAndSend.delete_items_by_ref([ref]) }.not_to raise_error
|
58
|
+
end
|
59
|
+
end
|
53
60
|
end
|
54
61
|
|
55
62
|
describe '.delete_items' do
|
@@ -61,14 +68,21 @@ describe ClickAndSend, :acceptance do
|
|
61
68
|
{'DeleteItem' => hash}
|
62
69
|
end
|
63
70
|
end
|
64
|
-
let(:tracking_numbers) { ClickAndSend.find_tracking_numbers([ref]).fetch(ref) }
|
71
|
+
let(:tracking_numbers) { ClickAndSend.find_tracking_numbers([ref]).fetch(ref.to_s) }
|
65
72
|
specify do
|
66
73
|
expect do
|
67
74
|
ClickAndSend.delete_items('DeleteItems' => items)
|
68
|
-
end.to change { ClickAndSend.find_tracking_numbers(ref).empty? }.to(true)
|
75
|
+
end.to change { ClickAndSend.find_tracking_numbers([ref]).empty? }.to(true)
|
69
76
|
end
|
70
77
|
|
71
|
-
|
78
|
+
context "when duplicate item exists (same ref)" do
|
79
|
+
before { ClickAndSend.create_items('Transactions' => create_item_attributes) }
|
80
|
+
it "deletes both items" do
|
81
|
+
expect do
|
82
|
+
ClickAndSend.delete_items('DeleteItems' => items)
|
83
|
+
end.to change { ClickAndSend.find_tracking_numbers([ref]).empty? }.to(true)
|
84
|
+
end
|
85
|
+
end
|
72
86
|
end
|
73
87
|
end
|
74
88
|
|
data/spec/click_and_send_spec.rb
CHANGED
@@ -118,6 +118,7 @@ describe ClickAndSend do
|
|
118
118
|
let(:required_inputs) { %w(DeleteItems) }
|
119
119
|
it_behaves_like "data required"
|
120
120
|
it "calls DeleteItems result" do
|
121
|
+
pending "Won't work this way until TODO completed for ClickAndSend#delete_items."
|
121
122
|
ClickAndSend::Request::DeleteItems.should_receive(:new).with(options) { stub(:result => 'deleted') }
|
122
123
|
subject.should == 'deleted'
|
123
124
|
end
|
@@ -2,4 +2,4 @@
|
|
2
2
|
:account_number: 1234567
|
3
3
|
:api_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
4
4
|
:user_name: acme
|
5
|
-
:wsdl: https://
|
5
|
+
:wsdl: https://auspost-staging.oss.neopost-id.com/modules/oss/api/ship/wsdl?sz_Client=AustraliaPost
|
data/spec/support/factories.rb
CHANGED
@@ -118,7 +118,7 @@ module ClickAndSend
|
|
118
118
|
|
119
119
|
def transaction_attributes
|
120
120
|
ActiveSupport::OrderedHash.new.tap do |hash|
|
121
|
-
hash['CustTransactionID'] = rand(10**10)
|
121
|
+
hash['CustTransactionID'] = rand(10**10)
|
122
122
|
hash['Sender' ] = au_address_attributes
|
123
123
|
hash['Receiver' ] = us_address_attributes
|
124
124
|
hash['ItemDetails' ] = item_details_attributes
|
data/spec/support/helpers.rb
CHANGED
@@ -6,9 +6,7 @@ module ClickAndSend
|
|
6
6
|
def cleanup
|
7
7
|
puts "--> Cleaning up"
|
8
8
|
refs = ClickAndSend.item_summary.collect { |item| item[:cust_transaction_id] }
|
9
|
-
|
10
|
-
# ClickAndSend.delete_items_by_ref(refs) if refs.any?
|
11
|
-
refs.each { |ref| ClickAndSend.delete_items_by_ref(ref) }
|
9
|
+
ClickAndSend.delete_items_by_ref(refs) if refs.any?
|
12
10
|
end
|
13
11
|
|
14
12
|
def load_config(mode = :test)
|
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.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -138,6 +138,7 @@ files:
|
|
138
138
|
- README.md
|
139
139
|
- Rakefile
|
140
140
|
- click_and_send.gemspec
|
141
|
+
- doc/click_and_send_api_guide_v8.1.pdf
|
141
142
|
- lib/click_and_send.rb
|
142
143
|
- lib/click_and_send/configuration.rb
|
143
144
|
- lib/click_and_send/encryption.rb
|
@@ -175,7 +176,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
175
176
|
version: '0'
|
176
177
|
segments:
|
177
178
|
- 0
|
178
|
-
hash:
|
179
|
+
hash: -1546608747268446612
|
179
180
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
180
181
|
none: false
|
181
182
|
requirements:
|
@@ -184,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
185
|
version: '0'
|
185
186
|
segments:
|
186
187
|
- 0
|
187
|
-
hash:
|
188
|
+
hash: -1546608747268446612
|
188
189
|
requirements: []
|
189
190
|
rubyforge_project:
|
190
191
|
rubygems_version: 1.8.24
|