stamps 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/.gitignore +5 -0
  2. data/.rvmrc +1 -0
  3. data/Gemfile +4 -0
  4. data/Gemfile.lock +49 -0
  5. data/README.md +186 -0
  6. data/Rakefile +13 -0
  7. data/lib/stamps.rb +33 -0
  8. data/lib/stamps/api.rb +18 -0
  9. data/lib/stamps/client.rb +12 -0
  10. data/lib/stamps/client/account.rb +36 -0
  11. data/lib/stamps/client/address.rb +16 -0
  12. data/lib/stamps/client/rate.rb +39 -0
  13. data/lib/stamps/client/stamp.rb +62 -0
  14. data/lib/stamps/configuration.rb +69 -0
  15. data/lib/stamps/errors.rb +34 -0
  16. data/lib/stamps/mapping.rb +247 -0
  17. data/lib/stamps/request.rb +55 -0
  18. data/lib/stamps/response.rb +71 -0
  19. data/lib/stamps/trash.rb +29 -0
  20. data/lib/stamps/types.rb +68 -0
  21. data/lib/stamps/version.rb +3 -0
  22. data/stamps.gemspec +33 -0
  23. data/test/client/account_test.rb +64 -0
  24. data/test/client/address_test.rb +36 -0
  25. data/test/client/rate_test.rb +44 -0
  26. data/test/client/stamp_test.rb +89 -0
  27. data/test/fixtures/AuthenticateUser.xml +9 -0
  28. data/test/fixtures/CancelIndicium.xml +8 -0
  29. data/test/fixtures/CarrierPickup.xml +11 -0
  30. data/test/fixtures/CleanseAddress.xml +24 -0
  31. data/test/fixtures/CreateIndicium.xml +32 -0
  32. data/test/fixtures/GetAccountInfo.xml +87 -0
  33. data/test/fixtures/GetRate.xml +163 -0
  34. data/test/fixtures/GetRates.xml +645 -0
  35. data/test/fixtures/InsufficientPostage.xml +14 -0
  36. data/test/fixtures/InvalidSoap.xml +13 -0
  37. data/test/fixtures/PurchasePostage.xml +16 -0
  38. data/test/fixtures/TrackShipment.xml +43 -0
  39. data/test/helper.rb +58 -0
  40. data/test/mapping_test.rb +33 -0
  41. data/test/response_test.rb +66 -0
  42. data/test/stamps_test.rb +26 -0
  43. data/test/types_test.rb +25 -0
  44. metadata +228 -0
@@ -0,0 +1,14 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
3
+ <soap:Body>
4
+ <soap:Fault>
5
+ <faultcode>soap:Server</faultcode>
6
+ <faultstring>Insufficient Postage</faultstring>
7
+ <faultactor>https://swsim.testing.stamps.com/swsim/swsimv12.asmx</faultactor>
8
+ <detail>
9
+ <sdcerror code="80040414" xmlns="http://stamps.com/xml/namespace/2008/01/fault">Insufficient Postage</sdcerror>
10
+ <authenticator xmlns="http://stamps.com/xml/namespace/2008/01/fault">exp=1305501129&amp;uid=2745084&amp;cty=swsim&amp;ctk=c95RLEdT0mD2bvRUvdvrkFegFU0=&amp;iid=J877UP/dP0qTQCRj3F421g==&amp;rsid=0&amp;eac=1820294591&amp;eacx=194559&amp;rrsid=0&amp;raid=0&amp;resellerid=0&amp;mac=rp93YQqG1Kix/+RAhddzSv4M4PM=</authenticator>
11
+ </detail>
12
+ </soap:Fault>
13
+ </soap:Body>
14
+ </soap:Envelope>
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
3
+ <soap:Body>
4
+ <soap:Fault>
5
+ <faultcode>soap:Client</faultcode>
6
+ <faultstring>Invalid SOAP message due to XML Schema validation failure. The 'http://stamps.com/xml/namespace/2010/11/swsim/swsimv12:ServiceType' element is invalid - The value 'US-KI' is invalid according to its datatype 'http://stamps.com/xml/namespace/2010/11/swsim/swsimv12:ServiceType' - The Enumeration constraint failed.</faultstring>
7
+ <faultactor>https://swsim.testing.stamps.com/swsim/swsimv12.asmx</faultactor>
8
+ <detail>
9
+ <stamps_exception code="00490102" xmlns="http://stamps.com/xml/namespace/2008/02/stamps/fault" />
10
+ </detail>
11
+ </soap:Fault>
12
+ </soap:Body>
13
+ </soap:Envelope>
@@ -0,0 +1,16 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
3
+ <soap:Body>
4
+ <PurchasePostageResponse xmlns="http://stamps.com/xml/namespace/2010/11/swsim/swsimv12">
5
+ <Authenticator>AlLpXHensVNYPEHFaG8OS+kNd/4=</Authenticator>
6
+ <PurchaseStatus>Pending</PurchaseStatus>
7
+ <TransactionID>66919357</TransactionID>
8
+ <PostageBalance>
9
+ <AvailablePostage>23.4300</AvailablePostage>
10
+ <ControlTotal>60.00</ControlTotal>
11
+ </PostageBalance>
12
+ <RejectionReason>order being processed</RejectionReason>
13
+ <MIRequired>false</MIRequired>
14
+ </PurchasePostageResponse>
15
+ </soap:Body>
16
+ </soap:Envelope>
@@ -0,0 +1,43 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
3
+ <soap:Body>
4
+ <TrackShipmentResponse xmlns="http://stamps.com/xml/namespace/2010/11/swsim/swsimv12">
5
+ <Authenticator>***authenticator***</Authenticator>
6
+ <TrackingEvents>
7
+ <TrackingEvent>
8
+ <Timestamp>2008-02-19T10:32:00</Timestamp>
9
+ <Event>DELIVERED</Event>
10
+ <TrackingEventType>Delivered</TrackingEventType>
11
+ <City>FORT WAYNE</City>
12
+ <State>IN</State>
13
+ <Zip>46809</Zip>
14
+ <Country>US</Country>
15
+ <SignedBy />
16
+ <AuthorizedAgent>true</AuthorizedAgent>
17
+ </TrackingEvent>
18
+ <TrackingEvent>
19
+ <Timestamp>2008-02-15T16:58:00</Timestamp>
20
+ <Event>PROCESSED</Event>
21
+ <TrackingEventType>Enroute</TrackingEventType>
22
+ <City>INDIANAPOLIS</City>
23
+ <State>IN</State>
24
+ <Zip>46206</Zip>
25
+ <Country>US</Country>
26
+ <SignedBy />
27
+ <AuthorizedAgent>true</AuthorizedAgent>
28
+ </TrackingEvent>
29
+ <TrackingEvent>
30
+ <Timestamp>2008-02-13T16:09:00</Timestamp>
31
+ <Event>Electronic Notification</Event>
32
+ <TrackingEventType>ElectronicNotification</TrackingEventType>
33
+ <City />
34
+ <State />
35
+ <Zip>90066</Zip>
36
+ <Country>US</Country>
37
+ <SignedBy />
38
+ <AuthorizedAgent>true</AuthorizedAgent>
39
+ </TrackingEvent>
40
+ </TrackingEvents>
41
+ </TrackShipmentResponse>
42
+ </soap:Body>
43
+ </soap:Envelope>
@@ -0,0 +1,58 @@
1
+ require "bundler"
2
+ Bundler.setup
3
+
4
+ require 'simplecov'
5
+ SimpleCov.merge_timeout 3600
6
+ SimpleCov.start do
7
+ add_group 'Stamps', 'lib/stamps'
8
+ end
9
+
10
+ require 'mocha'
11
+ require 'test/unit'
12
+ require 'stamps'
13
+ require 'shoulda'
14
+ require 'webmock/test_unit'
15
+ require 'json'
16
+ require 'multi_json'
17
+ require 'awesome_print'
18
+
19
+ Stamps.configure do |config|
20
+ config.integration_id = 'XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
21
+ config.username = 'USERNAME'
22
+ config.password = 'PASSXXXX'
23
+ config.endpoint = 'https://stamps.example.com/swsim/swsimv12.asmx'
24
+ config.return_address = {
25
+ :full_name => 'Big E-commerce Company',
26
+ :address1 => '500 Wall Street',
27
+ :address2 => 'Suite 234',
28
+ :city => 'New York',
29
+ :state => 'NY',
30
+ :zip_code => '10004',
31
+ :phone_number => '9375551234'
32
+ }
33
+ end
34
+
35
+ # Stub requests
36
+ def stub_post(web_method, soap_action = nil)
37
+ soap_action = web_method if soap_action.nil?
38
+ stub_request(:post, Stamps.endpoint).
39
+ with(:headers => {"SoapAction" => "#{Stamps.namespace}/#{soap_action}"}).
40
+ to_return(:body => fixture("#{web_method}.xml"))
41
+ end
42
+
43
+ def stub_response(web_method, code = 200)
44
+ http_response = HTTPI::Response.new(code, {}, fixture("#{web_method}.xml").read)
45
+ Stamps::Response.new(Savon::SOAP::Response.new(http_response))
46
+ end
47
+
48
+ def fixture_path
49
+ File.expand_path("../fixtures", __FILE__)
50
+ end
51
+
52
+ def fixture(file)
53
+ File.new(fixture_path + '/' + file)
54
+ end
55
+
56
+ Savon.configure do |config|
57
+ config.log = false # disable logging
58
+ end
@@ -0,0 +1,33 @@
1
+ $:.unshift File.dirname(__FILE__) # allows command line to execute tests
2
+ require 'helper'
3
+
4
+ class MappingTest < Test::Unit::TestCase
5
+
6
+ context 'a new instance' do
7
+
8
+ setup do
9
+ @rate = Stamps::Mapping::Rate.new({
10
+ :from_zip_code => '45440',
11
+ :to_zip_code => '45458',
12
+ :weight_oz => '7.8',
13
+ :package_type => 'Package',
14
+ :service_type => 'US-PM',
15
+ :add_ons => {
16
+ :add_on => [
17
+ { :amount => '2.30', :type => 'US-A-RR' },
18
+ { :amount => '0.19', :type => 'US-A-DC' }
19
+ ]
20
+ }
21
+ })
22
+ end
23
+
24
+ should 'map :to property fields' do
25
+ assert_equal @rate.to_hash['FromZIPCode'], '45440'
26
+ assert_equal @rate.to_hash['ToZIPCode'], '45458'
27
+ assert_equal @rate.to_hash['WeightOz'], '7.8'
28
+ assert_equal @rate.to_hash['PackageType'], 'Package'
29
+ assert_equal @rate.to_hash['ServiceType'], 'US-PM'
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,66 @@
1
+ $:.unshift File.dirname(__FILE__) # allows command line to execute tests
2
+ require 'helper'
3
+
4
+ class ResponseTest < Test::Unit::TestCase
5
+
6
+ context "with valid response" do
7
+ setup do
8
+ @response = stub_response("GetRates")
9
+ end
10
+
11
+ should 'be valid' do
12
+ assert @response.valid?
13
+ end
14
+
15
+ should 'have no errors' do
16
+ assert @response.errors.empty?
17
+ end
18
+ end
19
+
20
+ context 'with non-success responses' do
21
+
22
+ should 'raise BadRequest' do
23
+ assert_raise(Stamps::BadRequest) { stub_response('GetRates', 400)}
24
+ end
25
+
26
+ should 'raise Unauthorized' do
27
+ assert_raise(Stamps::Unauthorized) { stub_response('GetRates', 401)}
28
+ end
29
+
30
+ should 'raise Forbidden' do
31
+ assert_raise(Stamps::Forbidden) { stub_response('GetRates', 403)}
32
+ end
33
+
34
+ should 'raise NotFound' do
35
+ assert_raise(Stamps::NotFound) { stub_response('GetRates', 404)}
36
+ end
37
+
38
+ should 'raise NotAcceptable' do
39
+ assert_raise(Stamps::NotAcceptable) { stub_response('GetRates', 406)}
40
+ end
41
+
42
+ should 'raise InternalServerError' do
43
+ assert_raise(Stamps::InternalServerError) { stub_response('GetRates', 500)}
44
+ end
45
+
46
+ should 'raise ServiceUnavailable' do
47
+ assert_raise(Stamps::ServiceUnavailable) { stub_response('GetRates', 502) }
48
+ end
49
+
50
+ end
51
+
52
+ context "with invalid soap response" do
53
+ setup do
54
+ @response = stub_response("InvalidSoap")
55
+ end
56
+
57
+ should 'return not valid' do
58
+ assert_equal false, @response.valid?
59
+ end
60
+
61
+ should 'contain error messages' do
62
+ assert @response.errors.any?
63
+ end
64
+ end
65
+
66
+ end
@@ -0,0 +1,26 @@
1
+ $:.unshift File.dirname(__FILE__) # allows command line to execute tests
2
+ require 'helper'
3
+
4
+ class StampsTest < Test::Unit::TestCase
5
+
6
+ context "when delegating to a client" do
7
+
8
+ setup do
9
+ stub_post("AuthenticateUser")
10
+ @client = Stamps::Client.new
11
+ end
12
+
13
+ should 'respond to client methods' do
14
+ Stamps.respond_to?(:cleanse_address)
15
+ Stamps.respond_to?(:account)
16
+ end
17
+
18
+ should 'have a default configuration settings' do
19
+ assert @client.endpoint
20
+ assert @client.integration_id
21
+ assert @client.username
22
+ assert @client.password
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1,25 @@
1
+ $:.unshift File.dirname(__FILE__) # allows command line to execute tests
2
+ require 'helper'
3
+
4
+ class TypesTest < Test::Unit::TestCase
5
+
6
+ context "types" do
7
+
8
+ should 'return a hash of service type' do
9
+ assert_equal Hash, Stamps::Types::SERVICE.class
10
+ end
11
+
12
+ should 'return a hash of add ons' do
13
+ assert_equal Hash, Stamps::Types::ADD_ONS.class
14
+ end
15
+
16
+ should 'return a hash of carrier pickup locations' do
17
+ assert_equal Hash, Stamps::Types::CARRIER_PICKUP_LOCATION.class
18
+ end
19
+
20
+ should 'return an array of package types' do
21
+ assert_equal Array, Stamps::Types::PACKAGE.class
22
+ end
23
+ end
24
+
25
+ end
metadata ADDED
@@ -0,0 +1,228 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stamps
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.2.0
6
+ platform: ruby
7
+ authors:
8
+ - Matt Sears
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-05-15 00:00:00 -04:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: simplecov
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: 0.4.0
25
+ type: :development
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: shoulda
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: 2.11.3
36
+ type: :development
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: mocha
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 0.9.11
47
+ type: :development
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: webmock
51
+ prerelease: false
52
+ requirement: &id004 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ version: 1.6.2
58
+ type: :development
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: awesome_print
62
+ prerelease: false
63
+ requirement: &id005 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ type: :development
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: httpi
73
+ prerelease: false
74
+ requirement: &id006 !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - "="
78
+ - !ruby/object:Gem::Version
79
+ version: 0.7.9
80
+ type: :runtime
81
+ version_requirements: *id006
82
+ - !ruby/object:Gem::Dependency
83
+ name: savon
84
+ prerelease: false
85
+ requirement: &id007 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: 0.8.6
91
+ type: :runtime
92
+ version_requirements: *id007
93
+ - !ruby/object:Gem::Dependency
94
+ name: json
95
+ prerelease: false
96
+ requirement: &id008 !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 1.5.1
102
+ type: :runtime
103
+ version_requirements: *id008
104
+ - !ruby/object:Gem::Dependency
105
+ name: multi_json
106
+ prerelease: false
107
+ requirement: &id009 !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ~>
111
+ - !ruby/object:Gem::Version
112
+ version: 0.0.5
113
+ type: :runtime
114
+ version_requirements: *id009
115
+ - !ruby/object:Gem::Dependency
116
+ name: hashie
117
+ prerelease: false
118
+ requirement: &id010 !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ~>
122
+ - !ruby/object:Gem::Version
123
+ version: 1.0.0
124
+ type: :runtime
125
+ version_requirements: *id010
126
+ description: Stamps is Stamps.com backed library for creating postage labels, calculate the shipping cost of packages, standardize domestic addresses via USPS CASS certified Address Matching Software, and track shipments.
127
+ email:
128
+ - matt@mattsears.com
129
+ executables: []
130
+
131
+ extensions: []
132
+
133
+ extra_rdoc_files: []
134
+
135
+ files:
136
+ - .gitignore
137
+ - .rvmrc
138
+ - Gemfile
139
+ - Gemfile.lock
140
+ - README.md
141
+ - Rakefile
142
+ - lib/stamps.rb
143
+ - lib/stamps/api.rb
144
+ - lib/stamps/client.rb
145
+ - lib/stamps/client/account.rb
146
+ - lib/stamps/client/address.rb
147
+ - lib/stamps/client/rate.rb
148
+ - lib/stamps/client/stamp.rb
149
+ - lib/stamps/configuration.rb
150
+ - lib/stamps/errors.rb
151
+ - lib/stamps/mapping.rb
152
+ - lib/stamps/request.rb
153
+ - lib/stamps/response.rb
154
+ - lib/stamps/trash.rb
155
+ - lib/stamps/types.rb
156
+ - lib/stamps/version.rb
157
+ - stamps.gemspec
158
+ - test/client/account_test.rb
159
+ - test/client/address_test.rb
160
+ - test/client/rate_test.rb
161
+ - test/client/stamp_test.rb
162
+ - test/fixtures/AuthenticateUser.xml
163
+ - test/fixtures/CancelIndicium.xml
164
+ - test/fixtures/CarrierPickup.xml
165
+ - test/fixtures/CleanseAddress.xml
166
+ - test/fixtures/CreateIndicium.xml
167
+ - test/fixtures/GetAccountInfo.xml
168
+ - test/fixtures/GetRate.xml
169
+ - test/fixtures/GetRates.xml
170
+ - test/fixtures/InsufficientPostage.xml
171
+ - test/fixtures/InvalidSoap.xml
172
+ - test/fixtures/PurchasePostage.xml
173
+ - test/fixtures/TrackShipment.xml
174
+ - test/helper.rb
175
+ - test/mapping_test.rb
176
+ - test/response_test.rb
177
+ - test/stamps_test.rb
178
+ - test/types_test.rb
179
+ has_rdoc: true
180
+ homepage: http://rubygems.org/gems/stamps
181
+ licenses: []
182
+
183
+ post_install_message:
184
+ rdoc_options: []
185
+
186
+ require_paths:
187
+ - lib
188
+ required_ruby_version: !ruby/object:Gem::Requirement
189
+ none: false
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: "0"
194
+ required_rubygems_version: !ruby/object:Gem::Requirement
195
+ none: false
196
+ requirements:
197
+ - - ">="
198
+ - !ruby/object:Gem::Version
199
+ version: "0"
200
+ requirements: []
201
+
202
+ rubyforge_project: stamps
203
+ rubygems_version: 1.6.2
204
+ signing_key:
205
+ specification_version: 3
206
+ summary: Ruby wrapper for the Stamps.com Web Services API
207
+ test_files:
208
+ - test/client/account_test.rb
209
+ - test/client/address_test.rb
210
+ - test/client/rate_test.rb
211
+ - test/client/stamp_test.rb
212
+ - test/fixtures/AuthenticateUser.xml
213
+ - test/fixtures/CancelIndicium.xml
214
+ - test/fixtures/CarrierPickup.xml
215
+ - test/fixtures/CleanseAddress.xml
216
+ - test/fixtures/CreateIndicium.xml
217
+ - test/fixtures/GetAccountInfo.xml
218
+ - test/fixtures/GetRate.xml
219
+ - test/fixtures/GetRates.xml
220
+ - test/fixtures/InsufficientPostage.xml
221
+ - test/fixtures/InvalidSoap.xml
222
+ - test/fixtures/PurchasePostage.xml
223
+ - test/fixtures/TrackShipment.xml
224
+ - test/helper.rb
225
+ - test/mapping_test.rb
226
+ - test/response_test.rb
227
+ - test/stamps_test.rb
228
+ - test/types_test.rb