click_and_send 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.travis.yml +0 -2
- data/README.md +6 -0
- data/click_and_send.gemspec +1 -0
- data/lib/click_and_send.rb +12 -7
- data/lib/click_and_send/version.rb +1 -1
- data/spec/acceptance_spec.rb +4 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/support/factories.rb +60 -56
- metadata +38 -22
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -34,6 +34,12 @@ Note that the WSDL URL above is for ClickAndSend's staging environment.
|
|
34
34
|
You should only need to call methods on the `ClickAndSend` class.
|
35
35
|
Refer to the docs and acceptance tests for usage examples.
|
36
36
|
|
37
|
+
## Gotchas
|
38
|
+
|
39
|
+
Order is important for ClickAndSend API data structures. Therefore, under ruby 1.8, use
|
40
|
+
[`ActiveSupport::OrderedHash`](http://rdoc.info/gems/activesupport/ActiveSupport/OrderedHash.html) instead of a regular
|
41
|
+
hash.
|
42
|
+
|
37
43
|
## Contributing
|
38
44
|
|
39
45
|
1. Fork it
|
data/click_and_send.gemspec
CHANGED
data/lib/click_and_send.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'active_support/ordered_hash'
|
1
2
|
require 'click_and_send/version'
|
2
3
|
require 'click_and_send/configuration'
|
3
4
|
require 'click_and_send/encryption'
|
@@ -39,7 +40,12 @@ module ClickAndSend
|
|
39
40
|
|
40
41
|
def delete_items_by_ref(refs)
|
41
42
|
items = find_tracking_numbers(refs).inject([]) do |carrier, (ref, tracking_numbers)|
|
42
|
-
tracking_numbers.each
|
43
|
+
tracking_numbers.each do |tracking_number|
|
44
|
+
hash = ActiveSupport::OrderedHash.new
|
45
|
+
hash['CustTransactionID'] = ref
|
46
|
+
hash['TrackingNumber' ] = tracking_number
|
47
|
+
carrier << {'DeleteItem' => hash}
|
48
|
+
end
|
43
49
|
carrier
|
44
50
|
end
|
45
51
|
delete_items('DeleteItems' => items)
|
@@ -72,12 +78,11 @@ module ClickAndSend
|
|
72
78
|
else
|
73
79
|
raise(Errors::APIError, "Expected 1 but found #{tracking_numbers.length} tracking numbers for 'REF': #{tracking_numbers.join(', ')}")
|
74
80
|
end
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
Request::PrintItem.new(options).result
|
81
|
+
hash = ActiveSupport::OrderedHash.new
|
82
|
+
hash['PrintFormat' ] = 'LINK'
|
83
|
+
hash['CustTransactionID'] = ref
|
84
|
+
hash['TrackingNumber' ] = tracking_number
|
85
|
+
Request::PrintItem.new(hash).result
|
81
86
|
end
|
82
87
|
|
83
88
|
private
|
data/spec/acceptance_spec.rb
CHANGED
@@ -55,7 +55,10 @@ describe ClickAndSend, :acceptance do
|
|
55
55
|
describe '.delete_items' do
|
56
56
|
let(:items) do
|
57
57
|
tracking_numbers.collect do |tracking_number|
|
58
|
-
|
58
|
+
hash = ActiveSupport::OrderedHash.new
|
59
|
+
hash['CustTransactionID'] = ref
|
60
|
+
hash['TrackingNumber' ] = tracking_number
|
61
|
+
{'DeleteItem' => hash}
|
59
62
|
end
|
60
63
|
end
|
61
64
|
let(:tracking_numbers) { ClickAndSend.find_tracking_numbers([ref]).fetch(ref) }
|
data/spec/spec_helper.rb
CHANGED
data/spec/support/factories.rb
CHANGED
@@ -4,50 +4,50 @@ module ClickAndSend
|
|
4
4
|
module Test
|
5
5
|
module Factories
|
6
6
|
def attributes_for(*keys)
|
7
|
-
keys.flatten.inject(
|
7
|
+
keys.flatten.inject(ActiveSupport::OrderedHash.new) do |hash, key|
|
8
8
|
value = case key
|
9
|
-
when 'ItemDetails'
|
10
|
-
when 'Receiver'
|
11
|
-
when 'Sender'
|
12
|
-
when 'Transaction'
|
13
|
-
when 'Transactions'
|
14
|
-
[{'Transaction' => [transaction_attributes, transaction_attributes]}]
|
9
|
+
when 'ItemDetails' then item_details_attributes
|
10
|
+
when 'Receiver' then us_address_attributes
|
11
|
+
when 'Sender' then au_address_attributes
|
12
|
+
when 'Transaction' then transaction_attributes
|
13
|
+
when 'Transactions' then {'Transaction' => [transaction_attributes, transaction_attributes]}
|
15
14
|
else raise UnknownDataKey, key
|
16
15
|
end
|
17
|
-
hash
|
16
|
+
hash[key] = value
|
17
|
+
hash
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
private
|
22
22
|
|
23
23
|
def address_attributes
|
24
|
-
|
25
|
-
'CompanyName'
|
26
|
-
'ContactName'
|
27
|
-
'Telephone'
|
28
|
-
'Email'
|
29
|
-
'AddressLine1'
|
30
|
-
'AddressLine2'
|
31
|
-
'AddressLine3'
|
32
|
-
|
24
|
+
ActiveSupport::OrderedHash.new.tap do |hash|
|
25
|
+
hash['CompanyName' ] = ''
|
26
|
+
hash['ContactName' ] = name
|
27
|
+
hash['Telephone' ] = phone_number
|
28
|
+
hash['Email' ] = email
|
29
|
+
hash['AddressLine1'] = street_address
|
30
|
+
hash['AddressLine2'] = ''
|
31
|
+
hash['AddressLine3'] = ''
|
32
|
+
end
|
33
33
|
end
|
34
34
|
|
35
35
|
def au_address_attributes
|
36
|
-
address_attributes.
|
37
|
-
'Town'
|
38
|
-
'StateCode'
|
39
|
-
'PostCode'
|
40
|
-
'CountryCode'
|
41
|
-
|
36
|
+
address_attributes.tap do |hash|
|
37
|
+
hash['Town' ] = "Sydney"
|
38
|
+
hash['StateCode' ] = "NSW"
|
39
|
+
hash['PostCode' ] = "2000"
|
40
|
+
hash['CountryCode'] = "AU"
|
41
|
+
end
|
42
42
|
end
|
43
43
|
|
44
44
|
def us_address_attributes
|
45
|
-
address_attributes.
|
46
|
-
'Town'
|
47
|
-
'StateCode'
|
48
|
-
'PostCode'
|
49
|
-
'CountryCode'
|
50
|
-
|
45
|
+
address_attributes.tap do |hash|
|
46
|
+
hash['Town' ] = city
|
47
|
+
hash['StateCode' ] = "NY"
|
48
|
+
hash['PostCode' ] = "10001"
|
49
|
+
hash['CountryCode'] = "US"
|
50
|
+
end
|
51
51
|
end
|
52
52
|
|
53
53
|
def city
|
@@ -55,23 +55,27 @@ module ClickAndSend
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def customs_data_attributes
|
58
|
-
|
59
|
-
'CustomsData'
|
58
|
+
ActiveSupport::OrderedHash.new.tap do |hash|
|
59
|
+
hash['CustomsData'] = ActiveSupport::OrderedHash.new.tap do |hash|
|
60
60
|
# 'CustomsItemType' => '',
|
61
61
|
# 'CustomsQuantity' => '',
|
62
62
|
# 'ExportDeclarationNumber' => '',
|
63
63
|
# 'ReasonForExport' => '',
|
64
|
-
'NameOfPersonLodging'
|
64
|
+
hash['NameOfPersonLodging'] = name
|
65
65
|
# 'HSTariffNumber' => '',
|
66
66
|
# 'CountryOfOrigin' => '',
|
67
67
|
# 'NonDeliverySenderInstructions' => '',
|
68
68
|
# 'ReturnFollowingAddress' => '',
|
69
|
-
|
70
|
-
|
69
|
+
end
|
70
|
+
end
|
71
71
|
end
|
72
72
|
|
73
73
|
def dimensions
|
74
|
-
|
74
|
+
ActiveSupport::OrderedHash.new.tap do |hash|
|
75
|
+
hash['Length'] = '12.00'
|
76
|
+
hash['Width' ] = '12.00'
|
77
|
+
hash['Height'] = '5.00'
|
78
|
+
end
|
75
79
|
end
|
76
80
|
|
77
81
|
def email
|
@@ -79,15 +83,15 @@ module ClickAndSend
|
|
79
83
|
end
|
80
84
|
|
81
85
|
def item_details_attributes
|
82
|
-
|
83
|
-
'PackagingType'
|
84
|
-
'Dimensions'
|
85
|
-
'ItemWeight'
|
86
|
-
'ExtraCover'
|
87
|
-
'ExtraCoverAmountOrDeclaredValue'
|
88
|
-
'ItemDescriptionOrDescriptionOfGoods'
|
89
|
-
'InternationalItemDetails'
|
90
|
-
|
86
|
+
ActiveSupport::OrderedHash.new.tap do |hash|
|
87
|
+
hash['PackagingType' ] = 'M' # Merchandise
|
88
|
+
hash['Dimensions' ] = dimensions
|
89
|
+
hash['ItemWeight' ] = '0.500' # Float Format 999.999 Kg
|
90
|
+
hash['ExtraCover' ] = 0 # Boolean
|
91
|
+
hash['ExtraCoverAmountOrDeclaredValue' ] = '100.00'
|
92
|
+
hash['ItemDescriptionOrDescriptionOfGoods'] = "stuff"
|
93
|
+
hash['InternationalItemDetails' ] = customs_data_attributes
|
94
|
+
end
|
91
95
|
end
|
92
96
|
|
93
97
|
def name
|
@@ -95,10 +99,10 @@ module ClickAndSend
|
|
95
99
|
end
|
96
100
|
|
97
101
|
def payment_details_attributes
|
98
|
-
|
99
|
-
'PaymentType'
|
100
|
-
'PaymentData'
|
101
|
-
|
102
|
+
ActiveSupport::OrderedHash.new.tap do |hash|
|
103
|
+
hash['PaymentType'] = '01'
|
104
|
+
hash['PaymentData'] = ClickAndSend.configuration.account_number
|
105
|
+
end
|
102
106
|
end
|
103
107
|
|
104
108
|
def phone_number
|
@@ -110,14 +114,14 @@ module ClickAndSend
|
|
110
114
|
end
|
111
115
|
|
112
116
|
def transaction_attributes
|
113
|
-
|
114
|
-
'CustTransactionID'
|
115
|
-
'Sender'
|
116
|
-
'Receiver'
|
117
|
-
'ItemDetails'
|
118
|
-
'ProductCode'
|
119
|
-
'PaymentDetails'
|
120
|
-
|
117
|
+
ActiveSupport::OrderedHash.new.tap do |hash|
|
118
|
+
hash['CustTransactionID'] = rand(10**10).to_s
|
119
|
+
hash['Sender' ] = au_address_attributes
|
120
|
+
hash['Receiver' ] = us_address_attributes
|
121
|
+
hash['ItemDetails' ] = item_details_attributes
|
122
|
+
hash['ProductCode' ] = '1'
|
123
|
+
hash['PaymentDetails' ] = payment_details_attributes
|
124
|
+
end
|
121
125
|
end
|
122
126
|
|
123
127
|
class UnknownDataKey < StandardError; end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: click_and_send
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Zubin Henner
|
@@ -15,10 +15,26 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-09-10 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
22
|
+
none: false
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
hash: 31
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 2
|
30
|
+
- 0
|
31
|
+
version: 1.2.0
|
32
|
+
type: :runtime
|
33
|
+
requirement: *id001
|
34
|
+
prerelease: false
|
35
|
+
name: activesupport
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
22
38
|
none: false
|
23
39
|
requirements:
|
24
40
|
- - ">="
|
@@ -27,12 +43,12 @@ dependencies:
|
|
27
43
|
segments:
|
28
44
|
- 0
|
29
45
|
version: "0"
|
30
|
-
prerelease: false
|
31
|
-
requirement: *id001
|
32
46
|
type: :runtime
|
47
|
+
requirement: *id002
|
48
|
+
prerelease: false
|
33
49
|
name: nori
|
34
50
|
- !ruby/object:Gem::Dependency
|
35
|
-
version_requirements: &
|
51
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
36
52
|
none: false
|
37
53
|
requirements:
|
38
54
|
- - ">="
|
@@ -41,12 +57,12 @@ dependencies:
|
|
41
57
|
segments:
|
42
58
|
- 0
|
43
59
|
version: "0"
|
44
|
-
prerelease: false
|
45
|
-
requirement: *id002
|
46
60
|
type: :runtime
|
61
|
+
requirement: *id003
|
62
|
+
prerelease: false
|
47
63
|
name: savon
|
48
64
|
- !ruby/object:Gem::Dependency
|
49
|
-
version_requirements: &
|
65
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
50
66
|
none: false
|
51
67
|
requirements:
|
52
68
|
- - ">="
|
@@ -55,12 +71,12 @@ dependencies:
|
|
55
71
|
segments:
|
56
72
|
- 0
|
57
73
|
version: "0"
|
58
|
-
prerelease: false
|
59
|
-
requirement: *id003
|
60
74
|
type: :development
|
75
|
+
requirement: *id004
|
76
|
+
prerelease: false
|
61
77
|
name: rake
|
62
78
|
- !ruby/object:Gem::Dependency
|
63
|
-
version_requirements: &
|
79
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
64
80
|
none: false
|
65
81
|
requirements:
|
66
82
|
- - ">="
|
@@ -69,12 +85,12 @@ dependencies:
|
|
69
85
|
segments:
|
70
86
|
- 0
|
71
87
|
version: "0"
|
72
|
-
prerelease: false
|
73
|
-
requirement: *id004
|
74
88
|
type: :development
|
89
|
+
requirement: *id005
|
90
|
+
prerelease: false
|
75
91
|
name: rspec
|
76
92
|
- !ruby/object:Gem::Dependency
|
77
|
-
version_requirements: &
|
93
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
78
94
|
none: false
|
79
95
|
requirements:
|
80
96
|
- - ">="
|
@@ -83,12 +99,12 @@ dependencies:
|
|
83
99
|
segments:
|
84
100
|
- 0
|
85
101
|
version: "0"
|
86
|
-
prerelease: false
|
87
|
-
requirement: *id005
|
88
102
|
type: :development
|
103
|
+
requirement: *id006
|
104
|
+
prerelease: false
|
89
105
|
name: faker
|
90
106
|
- !ruby/object:Gem::Dependency
|
91
|
-
version_requirements: &
|
107
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
92
108
|
none: false
|
93
109
|
requirements:
|
94
110
|
- - ">="
|
@@ -97,9 +113,9 @@ dependencies:
|
|
97
113
|
segments:
|
98
114
|
- 0
|
99
115
|
version: "0"
|
100
|
-
prerelease: false
|
101
|
-
requirement: *id006
|
102
116
|
type: :development
|
117
|
+
requirement: *id007
|
118
|
+
prerelease: false
|
103
119
|
name: pry
|
104
120
|
description: Ruby adapter for Australia Post's ClickAndSend API
|
105
121
|
email:
|
@@ -170,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
170
186
|
requirements: []
|
171
187
|
|
172
188
|
rubyforge_project:
|
173
|
-
rubygems_version: 1.8.
|
189
|
+
rubygems_version: 1.8.24
|
174
190
|
signing_key:
|
175
191
|
specification_version: 3
|
176
192
|
summary: Ruby adapter for Australia Post's ClickAndSend API
|