click_and_send 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/click_and_send.rb +1 -3
- data/lib/click_and_send/request.rb +2 -2
- data/lib/click_and_send/request/delete_items.rb +2 -1
- data/lib/click_and_send/request/manifest_items.rb +2 -1
- data/lib/click_and_send/version.rb +1 -1
- data/lib/click_and_send/xml.rb +7 -2
- data/spec/acceptance_spec.rb +15 -3
- data/spec/click_and_send/request_spec.rb +3 -1
- data/spec/click_and_send/xml_spec.rb +17 -2
- data/spec/click_and_send_spec.rb +0 -2
- metadata +4 -4
data/lib/click_and_send.rb
CHANGED
@@ -56,9 +56,7 @@ module ClickAndSend
|
|
56
56
|
|
57
57
|
def delete_items(options)
|
58
58
|
ensure_keys_present(options, %w(DeleteItems))
|
59
|
-
|
60
|
-
# Then, replace next line with: Request::DeleteItems.new(options).result
|
61
|
-
options['DeleteItems'].each { |item| Request::DeleteItems.new('DeleteItems' => item).result }
|
59
|
+
Request::DeleteItems.new(options).result
|
62
60
|
end
|
63
61
|
|
64
62
|
def find_tracking_numbers(refs)
|
@@ -45,11 +45,11 @@ module ClickAndSend
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def default_keys
|
48
|
-
{ :errors => [:item_errors, :errors_found] }
|
48
|
+
{ :errors => [:item_errors, :errors_found], :strip_inner_tags => [] }
|
49
49
|
end
|
50
50
|
|
51
51
|
def extra_request_xml
|
52
|
-
ClickAndSend::XML.new(data).to_xml if data
|
52
|
+
ClickAndSend::XML.new(data, :strip_inner_tags => key(:strip_inner_tags)).to_xml if data
|
53
53
|
end
|
54
54
|
|
55
55
|
def header
|
data/lib/click_and_send/xml.rb
CHANGED
@@ -1,11 +1,16 @@
|
|
1
1
|
module ClickAndSend
|
2
2
|
class XML
|
3
|
-
def initialize(input)
|
3
|
+
def initialize(input, options = {})
|
4
4
|
@input = input
|
5
|
+
@options = options
|
5
6
|
end
|
6
7
|
|
7
8
|
def to_xml
|
8
|
-
Gyoku.xml(@input)
|
9
|
+
xml = Gyoku.xml(@input)
|
10
|
+
if @options[:strip_inner_tags]
|
11
|
+
@options[:strip_inner_tags].each { |tag| xml.gsub!("</#{tag}><#{tag}>", '') }
|
12
|
+
end
|
13
|
+
xml
|
9
14
|
end
|
10
15
|
end
|
11
16
|
end
|
data/spec/acceptance_spec.rb
CHANGED
@@ -138,14 +138,26 @@ describe ClickAndSend, :acceptance do
|
|
138
138
|
|
139
139
|
describe '.manifest_items_by_refs' do
|
140
140
|
subject { ClickAndSend.manifest_items_by_refs(refs) }
|
141
|
-
let(:
|
142
|
-
let(:
|
143
|
-
let(:refs) { [
|
141
|
+
let(:item1) { ClickAndSend.create_items('Transactions' => attributes_for('Transaction')) }
|
142
|
+
let(:ref1) { item1.fetch(:cust_transaction_id) }
|
143
|
+
let(:refs) { [ref1] }
|
144
144
|
|
145
145
|
it "returns manifest number and total charges/taxes" do
|
146
146
|
expect { subject }.not_to raise_error
|
147
147
|
subject.should be_a(Hash)
|
148
148
|
subject.keys.should =~ [:manifest_number, :total_charge, :total_taxes]
|
149
149
|
end
|
150
|
+
|
151
|
+
context "with 2 items" do
|
152
|
+
let(:item2) { ClickAndSend.create_items('Transactions' => attributes_for('Transaction')) }
|
153
|
+
let(:ref2) { item1.fetch(:cust_transaction_id) }
|
154
|
+
let(:refs) { [ref1, ref2] }
|
155
|
+
|
156
|
+
it "returns manifest number and total charges/taxes" do
|
157
|
+
expect { subject }.not_to raise_error
|
158
|
+
subject.should be_a(Hash)
|
159
|
+
subject.keys.should =~ [:manifest_number, :total_charge, :total_taxes]
|
160
|
+
end
|
161
|
+
end
|
150
162
|
end
|
151
163
|
end
|
@@ -46,7 +46,9 @@ describe ClickAndSend::Request do
|
|
46
46
|
end
|
47
47
|
Savon.stub(:client) { client }
|
48
48
|
ClickAndSend::Encryption.stub(:new) { |arg| stub(:to_s => "encrypted_#{arg}") }
|
49
|
-
ClickAndSend::XML.stub(:new).with(data
|
49
|
+
ClickAndSend::XML.stub(:new).with(data, :strip_inner_tags => []) do
|
50
|
+
stub(:to_xml => "<ExtraRequestXml></ExtraRequestXml>")
|
51
|
+
end
|
50
52
|
client.stub(:request) { request }
|
51
53
|
Nori.stub(:parse).with(request.to_hash[:ws_something_response][:ws_something_response]) do
|
52
54
|
parsed_response
|
@@ -5,6 +5,7 @@ describe ClickAndSend::XML do
|
|
5
5
|
subject { ClickAndSend::XML.new(input).to_xml }
|
6
6
|
context "hash" do
|
7
7
|
let(:input) { {:a => 1, "b" => 2} }
|
8
|
+
|
8
9
|
it "generates XML" do
|
9
10
|
["<a>1</a><b>2</b>", "<b>2</b><a>1</a>"].should include(subject)
|
10
11
|
end
|
@@ -12,6 +13,7 @@ describe ClickAndSend::XML do
|
|
12
13
|
|
13
14
|
context "nested hash" do
|
14
15
|
let(:input) { {:a => {:b => 2}} }
|
16
|
+
|
15
17
|
it { should eq("<a><b>2</b></a>") }
|
16
18
|
end
|
17
19
|
|
@@ -22,14 +24,27 @@ describe ClickAndSend::XML do
|
|
22
24
|
{'DeleteItem' => {'CustTransactionID' => 2, 'TrackingNumber' => 'B'}},
|
23
25
|
]}
|
24
26
|
end
|
25
|
-
|
26
|
-
|
27
|
+
|
28
|
+
it "encapsulates each value with key" do
|
27
29
|
expected_xml = '<DeleteItems>'+
|
28
30
|
'<DeleteItem><CustTransactionID>1</CustTransactionID><TrackingNumber>A</TrackingNumber></DeleteItem>'+
|
31
|
+
'</DeleteItems><DeleteItems>'+
|
29
32
|
'<DeleteItem><CustTransactionID>2</CustTransactionID><TrackingNumber>B</TrackingNumber></DeleteItem>'+
|
30
33
|
'</DeleteItems>'
|
31
34
|
should eq(expected_xml)
|
32
35
|
end
|
36
|
+
|
37
|
+
context "with :strip_inner_tags option for 'DeleteItems'" do
|
38
|
+
subject { ClickAndSend::XML.new(input, :strip_inner_tags => ['DeleteItems']).to_xml }
|
39
|
+
|
40
|
+
it "encapsulates all values with key" do
|
41
|
+
expected_xml = '<DeleteItems>'+
|
42
|
+
'<DeleteItem><CustTransactionID>1</CustTransactionID><TrackingNumber>A</TrackingNumber></DeleteItem>'+
|
43
|
+
'<DeleteItem><CustTransactionID>2</CustTransactionID><TrackingNumber>B</TrackingNumber></DeleteItem>'+
|
44
|
+
'</DeleteItems>'
|
45
|
+
should eq(expected_xml)
|
46
|
+
end
|
47
|
+
end
|
33
48
|
end
|
34
49
|
end
|
35
50
|
end
|
data/spec/click_and_send_spec.rb
CHANGED
@@ -118,7 +118,6 @@ 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."
|
122
121
|
ClickAndSend::Request::DeleteItems.should_receive(:new).with(options) { stub(:result => 'deleted') }
|
123
122
|
subject.should eq('deleted')
|
124
123
|
end
|
@@ -211,7 +210,6 @@ describe ClickAndSend do
|
|
211
210
|
end
|
212
211
|
|
213
212
|
describe '.manifest_items_by_refs' do
|
214
|
-
subject { ClickAndSend.manifest_items_by_refs(refs, options) }
|
215
213
|
let(:manifest_items) do
|
216
214
|
{
|
217
215
|
'ManifestItems' => [
|
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.2.
|
4
|
+
version: 0.2.1
|
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-12-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -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: 2996821537768733287
|
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: 2996821537768733287
|
191
191
|
requirements: []
|
192
192
|
rubyforge_project:
|
193
193
|
rubygems_version: 1.8.24
|