Permalink
Browse files

Misc changes.

  • Loading branch information...
1 parent 81a05f0 commit 23e16914566b5121d05016295b57afa147c1369f @Sutto committed May 7, 2010
Showing with 34 additions and 39 deletions.
  1. +0 −17 README.rdoc
  2. +3 −2 lib/aus_post/drc.rb
  3. +18 −9 lib/aus_post/drc/calculator.rb
  4. +13 −11 lib/aus_post/drc/parcel.rb
View
17 README.rdoc
@@ -1,17 +0,0 @@
-= auspost_drc
-
-Description goes here.
-
-== Note on Patches/Pull Requests
-
-* Fork the project.
-* Make your feature addition or bug fix.
-* Add tests for it. This is important so I don't break it in a
- future version unintentionally.
-* Commit, do not mess with rakefile, version, or history.
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
-* Send me a pull request. Bonus points for topic branches.
-
-== Copyright
-
-Copyright (c) 2010 Darcy Laycock. See LICENSE for details.
View
5 lib/aus_post/drc.rb
@@ -3,8 +3,9 @@ module DRC
Error = Class.new(StandardError)
- autoload :Parcel, 'aus_post/drc/parcel'
- autoload :Calculator, 'aus_post/drc/calculator'
+ autoload :Parcel, 'aus_post/drc/parcel'
+ autoload :Calculator, 'aus_post/drc/calculator'
+ autoload :ServiceType, 'aus_post/drc/service_type'
def self.calculate(params = {})
Calculator.new(Parcel.new(params))
View
27 lib/aus_post/drc/calculator.rb
@@ -8,10 +8,11 @@ class Calculator
DRC_BASE_URI = "http://drc.edeliver.com.au/rateCalc.asp"
def initialize(parcel)
- @parcel = parcel
- @calculated = false
- @charge = nil
- @days = nil
+ @parcel = parcel
+ @calculated = false
+ @charge = nil
+ @charge_as_string = nil
+ @days = nil
end
# Once off thing.
@@ -44,6 +45,11 @@ def days
@days
end
+ def charge_as_string
+ calculate
+ @charge_as_string
+ end
+
def charge!
value_with_exception :charge
end
@@ -52,6 +58,10 @@ def days!
value_with_exception :days
end
+ def charge_as_string!
+ value_with_exception :charge_as_string
+ end
+
protected
def process_response(r)
@@ -64,15 +74,14 @@ def process_response(r)
end
def process_success_body(body)
- @exception = nil
- @charge = body[:charge].to_f
- @days = body[:days].to_i
+ @exception = nil
+ @charge = body[:charge].to_f
+ @days = body[:days].to_i
+ @charge_as_string = body[:charge]
end
def process_error_body(body)
@exception = Error.new(body)
- @charge = nil
- @days = nil
end
def value_with_exception(name)
View
24 lib/aus_post/drc/parcel.rb
@@ -34,18 +34,20 @@ def service_type
@service_type.nil? ? 'STANDARD' : @service_type
end
+ def service_type=(value)
+ @service_type = value.to_s.strip.empty? ? nil : ServiceType[value.to_s]
+ end
+
def to_params_hash
- {
- 'Pickup_Postcode' => self.pickup,
- 'Destination_Postcode' => self.destination,
- 'Country' => self.country,
- 'Service_Type' => self.service_type,
- 'Weight' => self.weight,
- 'Length' => self.length,
- 'Width' => self.width,
- 'Height' => self.height,
- 'Quantity' => self.quantity
- }
+ {'Pickup_Postcode' => self.pickup,
+ 'Destination_Postcode' => self.destination,
+ 'Country' => self.country,
+ 'Service_Type' => self.service_type,
+ 'Weight' => self.weight,
+ 'Length' => self.length,
+ 'Width' => self.width,
+ 'Height' => self.height,
+ 'Quantity' => self.quantity}
end
def to_params

0 comments on commit 23e1691

Please sign in to comment.