click_and_send 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,16 @@
1
+ module ClickAndSend
2
+ module Request
3
+ class ManifestItems
4
+ include ClickAndSend::Request
5
+
6
+ private
7
+
8
+ def keys
9
+ { :answer => :ws_manifest_items_answer,
10
+ :request => 'WSManifestItems',
11
+ :response => :ws_manifest_items_response,
12
+ :result => nil }
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module ClickAndSend
2
+ module Request
3
+ class PrintManifest
4
+ include ClickAndSend::Request
5
+
6
+ private
7
+
8
+ def keys
9
+ { :answer => :ws_print_manifest_answer,
10
+ :request => 'WSPrintManifest',
11
+ :response => :ws_print_manifest_response,
12
+ :result => nil }
13
+ end
14
+ end
15
+ end
16
+ end
@@ -11,7 +11,11 @@ module ClickAndSend
11
11
 
12
12
  def result
13
13
  raise_on_error
14
- response.fetch(key(:result))
14
+ if key(:result)
15
+ response.fetch(key(:result))
16
+ else
17
+ response
18
+ end
15
19
  end
16
20
 
17
21
  private
@@ -95,7 +99,6 @@ module ClickAndSend
95
99
  result = Nori.parse(raw)
96
100
  result.fetch(key(:answer))
97
101
  rescue IndexError => e
98
- # binding.pry
99
102
  raise
100
103
  end
101
104
  end
@@ -1,3 +1,3 @@
1
1
  module ClickAndSend
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -8,7 +8,9 @@ require 'click_and_send/request/check_services'
8
8
  require 'click_and_send/request/create_items'
9
9
  require 'click_and_send/request/delete_items'
10
10
  require 'click_and_send/request/item_summary'
11
+ require 'click_and_send/request/manifest_items'
11
12
  require 'click_and_send/request/print_item'
13
+ require 'click_and_send/request/print_manifest'
12
14
  require 'click_and_send/xml'
13
15
 
14
16
  module ClickAndSend
@@ -84,6 +86,11 @@ module ClickAndSend
84
86
  end
85
87
  end
86
88
 
89
+ def manifest_items(options)
90
+ ensure_keys_present(options, %w(ManifestItems))
91
+ ClickAndSend::Request::ManifestItems.new(options).result
92
+ end
93
+
87
94
  def pdf_url(ref)
88
95
  ref = ref.to_s
89
96
  tracking_numbers = find_tracking_numbers([ref])[ref] || {}
@@ -91,7 +98,7 @@ module ClickAndSend
91
98
  when 0 then raise(Errors::APIError, "Not found: '#{ref}'")
92
99
  when 1 then tracking_number = tracking_numbers.first
93
100
  else
94
- raise(Errors::APIError, "Expected 1 but found #{tracking_numbers.length} tracking numbers for 'REF': #{tracking_numbers.join(', ')}")
101
+ raise(Errors::APIError, "Expected 1 but found #{tracking_numbers.length} tracking numbers for '#{ref}': #{tracking_numbers.join(', ')}")
95
102
  end
96
103
  hash = ActiveSupport::OrderedHash.new
97
104
  hash['PrintFormat' ] = 'LINK'
@@ -100,6 +107,11 @@ module ClickAndSend
100
107
  Request::PrintItem.new(hash).result
101
108
  end
102
109
 
110
+ def print_manifest(options)
111
+ ensure_keys_present(options, %w(PrintFormat PrintDetails ManifestNumber))
112
+ ClickAndSend::Request::PrintManifest.new(options).result.fetch(:manifest_http_link)
113
+ end
114
+
103
115
  private
104
116
 
105
117
  def configured_logfile
@@ -32,20 +32,20 @@ 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.to_s]
35
+ subject.keys.should eq([ref.to_s])
36
36
  end
37
37
  end
38
38
 
39
39
  describe '.pdf_url' do
40
40
  subject { ClickAndSend.pdf_url(ref) }
41
- specify do
41
+ it "returns URL for PDF" do
42
42
  subject.should be_a(String)
43
- open(subject).content_type.should == 'application/pdf'
43
+ open(subject).content_type.should eq('application/pdf')
44
44
  end
45
45
  end
46
46
 
47
47
  describe '.delete_items_by_ref' do
48
- specify do
48
+ it "deletes item" do
49
49
  expect do
50
50
  ClickAndSend.delete_items_by_ref([ref])
51
51
  end.to change { ClickAndSend.find_tracking_numbers([ref]).empty? }.to(true)
@@ -62,10 +62,12 @@ describe ClickAndSend, :acceptance do
62
62
  describe '.delete_items' do
63
63
  let(:items) do
64
64
  tracking_numbers.collect do |tracking_number|
65
- hash = ActiveSupport::OrderedHash.new
66
- hash['CustTransactionID'] = ref
67
- hash['TrackingNumber' ] = tracking_number
68
- {'DeleteItem' => hash}
65
+ {
66
+ 'DeleteItem' => ActiveSupport::OrderedHash.new.tap do |hash|
67
+ hash['CustTransactionID'] = ref
68
+ hash['TrackingNumber' ] = tracking_number
69
+ end
70
+ }
69
71
  end
70
72
  end
71
73
  let(:tracking_numbers) { ClickAndSend.find_tracking_numbers([ref]).fetch(ref.to_s) }
@@ -90,4 +92,47 @@ describe ClickAndSend, :acceptance do
90
92
  subject { ClickAndSend.item_summary }
91
93
  specify { should be_a(Array) }
92
94
  end
95
+
96
+ context "manifest when item uploaded" do
97
+ let(:manifest) { ClickAndSend.manifest_items(manifest_items) }
98
+ let(:items_created) { ClickAndSend.create_items('Transactions' => attributes_for('Transaction')) }
99
+ let(:manifest_items) do
100
+ {
101
+ 'ManifestItems' => [
102
+ {
103
+ 'ManifestItem' => ActiveSupport::OrderedHash.new.tap do |hash|
104
+ hash['CustTransactionID'] = ref
105
+ hash['TrackingNumber' ] = tracking_number
106
+ end
107
+ }
108
+ ]
109
+ }
110
+ end
111
+ let(:ref) { items_created.fetch(:cust_transaction_id) }
112
+ let(:tracking_number) { items_created.fetch(:tracking_number) }
113
+
114
+ describe '.manifest_items' do
115
+ it "returns manifest number and total charges/taxes" do
116
+ expect { manifest }.not_to raise_error
117
+ manifest.should be_a(Hash)
118
+ manifest.keys.should =~ [:manifest_number, :total_charge, :total_taxes]
119
+ end
120
+ end
121
+
122
+ describe '.print_manifest' do
123
+ let(:print_manifest) { ClickAndSend.print_manifest(options) }
124
+ let(:options) do
125
+ ActiveSupport::OrderedHash.new.tap do |hash|
126
+ hash['PrintFormat'] = 'LINK'
127
+ hash['PrintDetails'] = 'ALL'
128
+ hash['ManifestNumber'] = manifest[:manifest_number]
129
+ end
130
+ end
131
+
132
+ it "returns URL for PDF" do
133
+ print_manifest.should be_a(String)
134
+ open(print_manifest).content_type.should eq('application/pdf')
135
+ end
136
+ end
137
+ end
93
138
  end
@@ -6,11 +6,11 @@ describe ClickAndSend::Request do
6
6
 
7
7
  describe '.new' do
8
8
  it "defaults data to an empty hash" do
9
- subject.data.should == {}
9
+ subject.data.should eq({})
10
10
  end
11
11
 
12
12
  it "sets data" do
13
- klass.new('foo').data.should == 'foo'
13
+ klass.new('foo').data.should eq('foo')
14
14
  end
15
15
  end
16
16
 
@@ -67,7 +67,7 @@ describe ClickAndSend::Request do
67
67
  request = stub.as_null_object
68
68
  client.should_receive(:request) { request }
69
69
  Nori.should_receive(:parse).with(request.to_hash[:ws_something_response][:ws_something_response])
70
- subject.should == 'the result'
70
+ subject.should eq('the result')
71
71
  end
72
72
 
73
73
  context "when error key present in response" do
@@ -12,7 +12,7 @@ describe ClickAndSend::XML do
12
12
 
13
13
  context "nested hash" do
14
14
  let(:input) { {:a => {:b => 2}} }
15
- it { should == "<a><b>2</b></a>" }
15
+ it { should eq("<a><b>2</b></a>") }
16
16
  end
17
17
 
18
18
  context "hash/array combo" do
@@ -13,7 +13,7 @@ describe ClickAndSend do
13
13
  context "configured" do
14
14
  before { ClickAndSend.configure {} }
15
15
  it { should be_a(ClickAndSend::Configuration) }
16
- its(:api_version) { should == 10 }
16
+ its(:api_version) { should eq(10) }
17
17
  end
18
18
  end
19
19
 
@@ -84,7 +84,7 @@ describe ClickAndSend do
84
84
  let(:options) { {'Sender' => stub, 'Receiver' => stub, 'ItemDetails' => stub} }
85
85
  it "fetches :product_found from CheckServices result" do
86
86
  ClickAndSend::Request::CheckServices.should_receive(:new) { stub(:result => {:product_found => 'services'}) }
87
- subject.should == 'services'
87
+ subject.should eq('services')
88
88
  end
89
89
  end
90
90
  end
@@ -96,7 +96,7 @@ describe ClickAndSend do
96
96
  it_behaves_like "data required"
97
97
  it "fetches :item_created from CreateItems result" do
98
98
  ClickAndSend::Request::CreateItems.should_receive(:new) { stub(:result => {:item_created => 'created'}) }
99
- subject.should == 'created'
99
+ subject.should eq('created')
100
100
  end
101
101
  end
102
102
 
@@ -120,7 +120,7 @@ describe ClickAndSend do
120
120
  it "calls DeleteItems result" do
121
121
  pending "Won't work this way until TODO completed for ClickAndSend#delete_items."
122
122
  ClickAndSend::Request::DeleteItems.should_receive(:new).with(options) { stub(:result => 'deleted') }
123
- subject.should == 'deleted'
123
+ subject.should eq('deleted')
124
124
  end
125
125
  end
126
126
 
@@ -133,7 +133,7 @@ describe ClickAndSend do
133
133
  end
134
134
  before { ClickAndSend.stub(:item_summary) { item_summary } }
135
135
  it { should be_a(Hash) }
136
- its(:keys) { should == ['REF'] }
136
+ its(:keys) { should eq(['REF']) }
137
137
  it "includes tracking numbers for REF" do
138
138
  subject.values.first.should include('TRACK-REF-1')
139
139
  subject.values.first.should include('TRACK-REF-2')
@@ -149,7 +149,23 @@ describe ClickAndSend do
149
149
  ClickAndSend::Request::ItemSummary.should_receive(:new) do
150
150
  stub(:result => {:item_summary_transaction => 'items'})
151
151
  end
152
- subject.should == 'items'
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
153
169
  end
154
170
  end
155
171
 
@@ -175,7 +191,7 @@ describe ClickAndSend do
175
191
  ClickAndSend::Request::PrintItem.should_receive(:new).with(options) do
176
192
  stub(:result => pdf_url)
177
193
  end
178
- subject.should == pdf_url
194
+ subject.should eq(pdf_url)
179
195
  end
180
196
  end
181
197
 
@@ -193,5 +209,26 @@ describe ClickAndSend do
193
209
  end
194
210
  end
195
211
  end
212
+
213
+ describe '.print_manifest' do
214
+ subject { ClickAndSend.print_manifest(options) }
215
+ let(:required_inputs) { %w(PrintFormat PrintDetails ManifestNumber) }
216
+ it_behaves_like "data required"
217
+
218
+ context "when input has valid keys" do
219
+ it "calls PrintManifest result" do
220
+ result = stub
221
+ print_manifest = stub(:result => result)
222
+ result.stub(:fetch).with(:manifest_http_link) { 'the link' }
223
+ options = ActiveSupport::OrderedHash.new.tap do |hash|
224
+ required_inputs.each do |required_input|
225
+ hash[required_input] = stub
226
+ end
227
+ end
228
+ ClickAndSend::Request::PrintManifest.should_receive(:new).with(options) { print_manifest }
229
+ ClickAndSend.print_manifest(options).should eq('the link')
230
+ end
231
+ end
232
+ end
196
233
  end
197
234
  end
@@ -101,13 +101,6 @@ module ClickAndSend
101
101
  Faker::Name.name
102
102
  end
103
103
 
104
- def payment_details_attributes
105
- ActiveSupport::OrderedHash.new.tap do |hash|
106
- hash['PaymentType'] = '01'
107
- hash['PaymentData'] = ClickAndSend.configuration.account_number
108
- end
109
- end
110
-
111
104
  def phone_number
112
105
  Faker::PhoneNumber.phone_number.gsub(/[^\d]/, '')
113
106
  end
@@ -123,7 +116,6 @@ module ClickAndSend
123
116
  hash['Receiver' ] = us_address_attributes
124
117
  hash['ItemDetails' ] = item_details_attributes
125
118
  hash['ProductCode' ] = '1'
126
- hash['PaymentDetails' ] = payment_details_attributes
127
119
  end
128
120
  end
129
121
 
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.1.0
4
+ version: 0.1.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-10-04 00:00:00.000000000 Z
12
+ date: 2012-10-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -148,7 +148,9 @@ files:
148
148
  - lib/click_and_send/request/create_items.rb
149
149
  - lib/click_and_send/request/delete_items.rb
150
150
  - lib/click_and_send/request/item_summary.rb
151
+ - lib/click_and_send/request/manifest_items.rb
151
152
  - lib/click_and_send/request/print_item.rb
153
+ - lib/click_and_send/request/print_manifest.rb
152
154
  - lib/click_and_send/version.rb
153
155
  - lib/click_and_send/xml.rb
154
156
  - log/.gitkeep
@@ -176,7 +178,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
176
178
  version: '0'
177
179
  segments:
178
180
  - 0
179
- hash: -1546608747268446612
181
+ hash: -2750192198691146344
180
182
  required_rubygems_version: !ruby/object:Gem::Requirement
181
183
  none: false
182
184
  requirements:
@@ -185,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
187
  version: '0'
186
188
  segments:
187
189
  - 0
188
- hash: -1546608747268446612
190
+ hash: -2750192198691146344
189
191
  requirements: []
190
192
  rubyforge_project:
191
193
  rubygems_version: 1.8.24