Skip to content

Commit

Permalink
Add missing service_type file, readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Sutto committed May 7, 2010
1 parent 23e1691 commit 6e358af
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
49 changes: 49 additions & 0 deletions README.md
@@ -0,0 +1,49 @@
# auspost-drc #

A rubygem for accessing the Australia Post Delivery Rate Calculator.

Please note that in order to use this service, you must agree to the [Australia Post DRC terms and conditions](http://www.edeliver.com.au/Templates/ifs/IFS_DRC_Terms.htm) - I take no responsibility for
how you use this library, it is simply a wrapper around the DRC api.

## Usage ##

require 'aus_post/drc'

result = AusPost::DRC.calculate(:length => 100, :height => 100, :width => 100,
:destination => 'XXXX', :pickup => 'YYYY', :country => 'AU', :service_type => :express,
:weight => 1, :quantity => 1)
The following are optional with the following defaults:

* `:quantity` - defaults to `1`
* `:service_type` - defaults to `:standard`
* `:country` - defaults to `'AU'`. As a 2 character country code

The calculator has the following methods:

- `result.charge` - charge as a float, nil on error
- `result.days` - days as integer, nil on error
- `result.charge_as_string` - charge as string, nil on error

With exception-throwing variants:

- `result.charge!` - charge as a float, throwing an error otherwise.
- `result.days!` - days as integer, throwing an error otherwise.
- `result.charge_as_string!` - charge as string, throwing an error otherwise.

## Note on Patches/Pull Requests ##

1. Fork the project.
2. Make your feature addition or bug fix.
3. Add tests for it. This is important so I don't break it in a future version unintentionally.
4. 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)
5. Send me a pull request. Bonus points for topic branches.

## Copyright ##

Copyright (c) 2010 Darcy Laycock. See LICENSE for details.

Australia Post and other assorted trademarks are copyright Australia Post.



49 changes: 49 additions & 0 deletions lib/aus_post/drc/service_type.rb
@@ -0,0 +1,49 @@
module AusPost
module DRC
class ServiceType

def self.mapping
@mapping ||= []
end

def self.add_mapping(short_name, code, description)
mapping << ServiceType.new(short_name, code, description)
end

def self.[](code)
item = mapping.detect { |st| st.matches?(code) }
item && item.code
end

def self.for_select
mapping.map { |st| [st.description, st.short_name.to_s] }
end

attr_accessor :code, :short_name, :description

def initialize(short_name, code, description)
@short_name = short_name.to_s
@code = code.to_s
@description = description.to_s
end

def to_s
@code
end

def matches?(text)
text = text.to_s.strip
!text.empty? && [short_name, code, description].any? { |v| v == text }
end

add_mapping :standard, 'Standard', 'Regular'
add_mapping :express, 'Express', 'Express'
add_mapping :express_platinum, 'Exp_Plt', 'Express Platinum'
add_mapping :express_courier_international_document, 'ECI_D', 'Express Courier International Document'
add_mapping :express_courier_international_merchandise, 'ECI_M', 'Express Courier International Merchandise'
add_mapping :international_air, 'Air', 'International Air'
add_mapping :international_sea, 'Sea', 'International Sea'

end
end
end

0 comments on commit 6e358af

Please sign in to comment.