Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* Added state code mapping so that we can pass full state names and h…

…ave it convert it to a FedEx friendly code behind the scenes.
  • Loading branch information...
commit 92e38190dc586cfb2f11f5efeda5202bb681d69e 1 parent 1f83f79
Ben Johnson authored
4 CHANGELOG.rdoc
View
@@ -1,3 +1,7 @@
+== 1.0.4 released 2009-07-08
+
+* Added state code mapping so that we can pass full state names and have it convert it to a FedEx friendly code behind the scenes.
+
== 1.0.3 released 2009-07-08
* Rails uses United States not United State of America
61 lib/shippinglogic/fedex/enumerations.rb
View
@@ -264,6 +264,67 @@ module Enumerations
RAILS_COUNTRY_CODES = {
"United States" => "US"
}
+
+ STATE_CODES = {
+ "Alabama" => "AL",
+ "Alaska" => "AK",
+ "America Samoa" => "AS",
+ "Arizona" => "AZ",
+ "Arkansas" => "AR",
+ "California" => "CA",
+ "Colorado" => "CO",
+ "Connecticut" => "CT",
+ "Delaware" => "DE",
+ "District of Columbia" => "DC",
+ "Florida" => "FL",
+ "Georgia" => "GA",
+ "Guam" => "GU",
+ "Hawaii" => "HI",
+ "Idaho" => "ID",
+ "Illinois" => "IL",
+ "Indiana" => "IN",
+ "Iowa" => "IA",
+ "Islands1" => "MH",
+ "Kansas" => "KS",
+ "Kentucky" => "KY",
+ "Louisiana" => "LA",
+ "Maine" => "ME",
+ "Maryland" => "MD",
+ "Massachusetts" => "MA",
+ "Michigan" => "MI",
+ "Micronesia1" => "FM",
+ "Minnesota" => "MN",
+ "Mississippi" => "MS",
+ "Missouri" => "MO",
+ "Montana" => "MT",
+ "Nebraska" => "NE",
+ "Nevada" => "NV",
+ "New Hampshire" => "NH",
+ "New Jersey" => "NJ",
+ "New Mexico" => "NM",
+ "New York" => "NY",
+ "North Carolina" => "NC",
+ "North Dakota" => "ND",
+ "Ohio" => "OH",
+ "Oklahoma" => "OK",
+ "Oregon" => "OR",
+ "Palau" => "PW",
+ "Pennsylvania" => "PA",
+ "Puerto Rico" => "PR",
+ "Rhode Island" => "RI",
+ "South Carolina" => "SC",
+ "South Dakota" => "SD",
+ "Tennessee" => "TN",
+ "Texas" => "TX",
+ "Utah" => "UT",
+ "Vermont" => "VT",
+ "Virgin Island" => "VI",
+ "Virginia" => "VA",
+ "Washington" => "WA",
+ "West Virginia" => "WV",
+ "Wisconsin" => "WI",
+ "Wyoming" => "WY",
+ }
end
end
end
6 lib/shippinglogic/fedex/request.rb
View
@@ -57,7 +57,7 @@ def build_address(b, type)
b.Address do
b.StreetLines send("#{type}_streets") if send("#{type}_streets")
b.City send("#{type}_city") if send("#{type}_city")
- b.StateOrProvinceCode send("#{type}_state") if send("#{type}_state")
+ b.StateOrProvinceCode state_code(send("#{type}_state")) if send("#{type}_state")
b.PostalCode send("#{type}_postal_code") if send("#{type}_postal_code")
b.CountryCode country_code(send("#{type}_country")) if send("#{type}_country")
b.Residential send("#{type}_residential")
@@ -94,6 +94,10 @@ def custom_packaging?
def country_code(value)
Enumerations::FEDEX_COUNTRY_CODES[value.to_s] || Enumerations::RAILS_COUNTRY_CODES[value.to_s] || value.to_s
end
+
+ def state_code(value)
+ Enumerations::STATE_CODES[value.to_s] || value.to_s
+ end
end
end
end
6 spec/fedex/request_spec.rb
View
@@ -6,4 +6,10 @@
rates = fedex.rate
rates.send(:country_code, "United States").should == "US"
end
+
+ it "should convert full state names to state codes" do
+ fedex = new_fedex
+ rates = fedex.rate
+ rates.send(:state_code, "Texas").should == "TX"
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.