shipping 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/shipping/ups.rb CHANGED
@@ -24,6 +24,8 @@ module Shipping
24
24
 
25
25
  API_VERSION = "1.0001"
26
26
 
27
+ # For current implementation docs, see http://www.ec.ups.com/ecommerce/techdocs/pdf/RatesandServiceHTML.pdf
28
+ # For upcoming XML implementation docs, see http://www.ups.com/gec/techdocs/pdf/dtk_RateXML_V1.zip
27
29
  def price
28
30
  @required = [:zip, :country, :sender_zip, :weight]
29
31
 
@@ -42,38 +44,41 @@ module Shipping
42
44
  return price.to_f
43
45
  end
44
46
 
47
+ # See http://www.ups.com/gec/techdocs/pdf/dtk_AddrValidateXML_V1.zip for API info
48
+
45
49
  def valid_address?( delta = 1.0 )
46
50
  @required = [:ups_account, :ups_user, :ups_password]
47
51
 
48
52
  state = STATES.has_value?(@state.downcase) ? STATES.index(@state.downcase) : @state
49
53
 
50
- @data = "<?xml version=\"1.0\"?>
51
- <AccessRequest>
52
- <AccessLicenseNumber>#{@ups_account}</AccessLicenseNumber>
53
- <UserId>#{@ups_user}</UserId>
54
- <Password>#{@ups_password}</Password>
55
- </AccessRequest>
56
- <?xml version=\"1.0\"?>
57
- <AddressValidationRequest xml:lang=\"en-US\">
58
- <Request>
59
- <TransactionReference>
60
- <CustomerContext>#{@city}, #{state} #{@zip}</CustomerContext>
61
- <XpciVersion>#{API_VERSION}</XpciVersion>
62
- </TransactionReference>
63
- <RequestAction>AV</RequestAction>
64
- </Request>
65
- <Address>
66
- <City>#{@city}</City>
67
- <StateProvinceCode>#{state}</StateProvinceCode>
68
- <PostalCode>#{@zip}</PostalCode>
69
- </Address>
70
- </AddressValidationRequest>"
71
-
54
+ @data = String.new
55
+ b = Builder::XmlMarkup.new :target => @data
56
+
57
+ b.instruct!
58
+ b.AccessRequest {|b|
59
+ b.AccessLicenseNumber @ups_account
60
+ b.UserId @ups_user
61
+ b.Password @ups_password
62
+ }
63
+ b.instruct!
64
+ b.AddressValidationRequest {|b|
65
+ b.Request {|b|
66
+ b.RequestAction "AV"
67
+ b.TransactionReference {|b|
68
+ b.CustomerContext "#{@city}, #{state} #{@zip}"
69
+ b.XpciVersion API_VERSION
70
+ }
71
+ }
72
+ b.Address {|b|
73
+ b.City @city
74
+ b.StateProvinceCode state
75
+ b.PostalCode @zip
76
+ }
77
+ }
78
+
72
79
  get_response "https://wwwcie.ups.com/ups.app/xml/AV"
73
-
74
- doc = REXML::Document.new(@response)
75
-
76
- if doc.root.elements["Response"].elements["ResponseStatusCode"].text == "1" && doc.root.elements["AddressValidationResult"].elements["Quality"].text.to_f >= delta
80
+
81
+ if REXML::XPath.first(@response, "//AddressValidationResponse/Response/ResponseStatusCode").text == "1" && REXML::XPath.first(@response, "//AddressValidationResponse/AddressValidationResult/Quality").text.to_f >= delta
77
82
  return true
78
83
  else
79
84
  return false
data/lib/shipping.rb CHANGED
@@ -24,6 +24,13 @@
24
24
  # Copyright:: Copyright (c) 2005 Lucas Carlson
25
25
  # License:: LGPL
26
26
 
27
+ begin
28
+ require 'rubygems'
29
+ require_gem 'builder', '~> 1.2'
30
+ rescue LoadError
31
+ require 'builder'
32
+ end
33
+
27
34
  require 'yaml'
28
35
  require 'rexml/document'
29
36
  require 'net/http'
@@ -5,6 +5,33 @@ class FedExTest < Test::Unit::TestCase
5
5
  end
6
6
 
7
7
  def test_price
8
- assert_equal 5.17, @ship.price
8
+ assert_equal 4.67, @ship.price
9
+ end
10
+
11
+ def test_base_price
12
+ assert_equal 5.07, @ship.base_price
13
+ end
14
+
15
+ def test_fails
16
+ ship = Shipping::FedEx.new :zip => 97202, :weight => 2
17
+ assert_raise(Shipping::ShippingError) { ship.price }
18
+ end
19
+
20
+ def test_label
21
+ @ship.name = "Package Receiver"
22
+ @ship.phone = "555-555-5555"
23
+ @ship.email = "lucas@rufy.com"
24
+ @ship.address = "Some address"
25
+ @ship.city = "Portland"
26
+
27
+ @ship.sender_name = "Package Sender"
28
+ @ship.sender_phone = "333-333-3333"
29
+ @ship.sender_email = "john@doe.com"
30
+ @ship.sender_address = "Ok old address"
31
+ @ship.sender_city = "New York"
32
+
33
+ response = nil
34
+ # assert_nothing_raised { response = @ship.label }
35
+ # assert_equal 'PackageSen', response.image_userid
9
36
  end
10
37
  end
data/test/ups/ups_test.rb CHANGED
@@ -5,7 +5,7 @@ class UpsTest < Test::Unit::TestCase
5
5
  end
6
6
 
7
7
  def test_price
8
- assert_equal 8.77, @ship.price
8
+ assert_equal 8.82, @ship.price
9
9
  end
10
10
 
11
11
  def test_valid_address
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.6
2
+ rubygems_version: 0.8.10
3
3
  specification_version: 1
4
4
  name: shipping
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.0
7
- date: 2005-04-27
6
+ version: 1.1.0
7
+ date: 2005-06-02
8
8
  summary: A general shipping module to find out the shipping prices via UPS or FedEx.
9
9
  require_paths:
10
10
  - lib
@@ -39,6 +39,7 @@ files:
39
39
  - test/base/base_test.rb
40
40
  - test/fedex/fedex_test.rb
41
41
  - test/ups/ups_test.rb
42
+ - LICENSE
42
43
  - Rakefile
43
44
  - README
44
45
  - doc/classes
@@ -58,11 +59,14 @@ files:
58
59
  - doc/classes/Shipping/ShippingError.html
59
60
  - doc/classes/Shipping/UPS.html
60
61
  - doc/classes/Shipping/UPS.src
61
- - doc/classes/Shipping/Base.src/M000005.html
62
- - doc/classes/Shipping/Base.src/M000006.html
63
- - doc/classes/Shipping/Base.src/M000007.html
62
+ - doc/classes/Shipping/Base.src/M000008.html
63
+ - doc/classes/Shipping/Base.src/M000009.html
64
+ - doc/classes/Shipping/Base.src/M000010.html
64
65
  - doc/classes/Shipping/FedEx.src/M000003.html
65
66
  - doc/classes/Shipping/FedEx.src/M000004.html
67
+ - doc/classes/Shipping/FedEx.src/M000005.html
68
+ - doc/classes/Shipping/FedEx.src/M000006.html
69
+ - doc/classes/Shipping/FedEx.src/M000007.html
66
70
  - doc/classes/Shipping/UPS.src/M000001.html
67
71
  - doc/classes/Shipping/UPS.src/M000002.html
68
72
  - doc/files/lib
@@ -77,5 +81,16 @@ rdoc_options: []
77
81
  extra_rdoc_files: []
78
82
  executables: []
79
83
  extensions: []
80
- requirements: []
81
- dependencies: []
84
+ requirements:
85
+ - An xml-builder library.
86
+ dependencies:
87
+ - !ruby/object:Gem::Dependency
88
+ name: builder
89
+ version_requirement:
90
+ version_requirements: !ruby/object:Gem::Version::Requirement
91
+ requirements:
92
+ -
93
+ - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: 1.2.0
96
+ version: