shipping 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'rake/rdoctask'
5
5
  require 'rake/gempackagetask'
6
6
  require 'rake/contrib/rubyforgepublisher'
7
7
 
8
- PKG_VERSION = "1.2.0"
8
+ PKG_VERSION = "1.2.1"
9
9
 
10
10
  PKG_FILES = FileList[
11
11
  "lib/**/*", "bin/*", "test/**/*", "[A-Z]*", "Rakefile", "doc/**/*"
@@ -32,7 +32,7 @@ end
32
32
  desc "Create documentation"
33
33
  Rake::RDocTask.new("doc") { |rdoc|
34
34
  rdoc.title = "Ruby Shipping - UPS, FedEx, USPS"
35
- rdoc.rdoc_dir = 'doc'
35
+ rdoc.rdoc_dir = 'html'
36
36
  rdoc.rdoc_files.include('README')
37
37
  rdoc.rdoc_files.include('lib/**/*.rb')
38
38
  }
data/lib/extensions.rb ADDED
@@ -0,0 +1,11 @@
1
+ class Object
2
+ def blank?
3
+ if respond_to? :empty?
4
+ empty?
5
+ elsif respond_to? :zero?
6
+ zero?
7
+ else
8
+ !self
9
+ end
10
+ end
11
+ end
data/lib/shipping.rb CHANGED
@@ -26,15 +26,17 @@
26
26
 
27
27
  begin
28
28
  require 'rubygems'
29
- require_gem 'builder', '~> 1.2'
30
29
  rescue LoadError
31
- require 'builder'
30
+ nil
32
31
  end
33
32
 
33
+ require 'builder'
34
34
  require 'yaml'
35
35
  require 'rexml/document'
36
36
  require 'net/http'
37
37
  require 'net/https'
38
+
39
+ require 'extensions'
38
40
  require 'shipping/base'
39
41
  require 'shipping/fedex'
40
42
  require 'shipping/ups'
@@ -10,17 +10,17 @@ module Shipping
10
10
  # Gets the total price of the shipping
11
11
  def price
12
12
  get_price
13
- p = REXML::XPath.first(@response, "//FDXRateReply/EstimatedCharges/DiscountedCharges/NetCharge").text.to_f rescue nil
14
- raise ShippingError, get_error if p.nil?
15
- return p
13
+ return REXML::XPath.first(@response, "//FDXRateReply/EstimatedCharges/DiscountedCharges/NetCharge").text.to_f
14
+ rescue
15
+ raise ShippingError, get_error
16
16
  end
17
17
 
18
18
  # Gets the base price of the shipping (with discounts taken into consideration)
19
19
  def base_price
20
20
  get_price
21
- p = REXML::XPath.first(@response, "//FDXRateReply/EstimatedCharges/DiscountedCharges/BaseCharge").text.to_f rescue nil
22
- raise ShippingError, get_error if p.nil?
23
- return p
21
+ return REXML::XPath.first(@response, "//FDXRateReply/EstimatedCharges/DiscountedCharges/BaseCharge").text.to_f
22
+ rescue
23
+ raise ShippingError, get_error
24
24
  end
25
25
 
26
26
  # still not sure what the best way to handle this transaction's return data would be. Possibly a hash of the form {service => delivery_estimate}?
@@ -42,7 +42,7 @@ module Shipping
42
42
  b.PostalCode @zip
43
43
  b.CountryCode @country || "US"
44
44
  }
45
- b.ShipDate @ship_date unless @ship_date.nil?
45
+ b.ShipDate @ship_date unless @ship_date.blank?
46
46
  b.PackageCount @package_total || '1'
47
47
  }
48
48
 
@@ -53,7 +53,7 @@ module Shipping
53
53
  @required = [:name, :company, :phone, :email, :address, :city, :state, :zip]
54
54
  @required += [:fedex_account, :fedex_url]
55
55
 
56
- state = STATES.has_value?(@state.downcase) ? STATES.index(@state.downcase).upcase : @state.upcase
56
+ state = STATES.has_value?(@state.downcase) ? STATES.index(@state.downcase).upcase : @state.upcase rescue nil
57
57
 
58
58
  @data = String.new
59
59
  b = Builder::XmlMarkup.new :target => @data
@@ -98,13 +98,14 @@ module Shipping
98
98
  def label
99
99
  @required = [:phone, :email, :address, :city, :state, :zip ]
100
100
  @required += [:sender_phone, :sender_email, :sender_address, :sender_city, :sender_state, :sender_zip ]
101
- @required += [:fedex_account, :fedex_url]
101
+ @required += [:fedex_account, :fedex_url, :weight ]
102
102
 
103
103
  @transaction_type ||= 'rate_ground'
104
104
  @weight = (@weight.to_f*10).round/10.0
105
- @declared_value = (@declared_value.to_f*100).round/100.0 unless @declared_value.nil?
106
- state = STATES.has_value?(@state.downcase) ? STATES.index(@state.downcase).upcase : @state.upcase
107
- sender_state = STATES.has_value?(@sender_state.downcase) ? STATES.index(@sender_state.downcase).upcase : @sender_state.upcase
105
+ @declared_value = (@declared_value.to_f*100).round/100.0 unless @declared_value.blank?
106
+
107
+ state = STATES.has_value?(@state.downcase) ? STATES.index(@state.downcase).upcase : @state.upcase rescue nil
108
+ sender_state = STATES.has_value?(@sender_state.downcase) ? STATES.index(@sender_state.downcase).upcase : @sender_state.upcase rescue nil
108
109
 
109
110
  @data = String.new
110
111
 
@@ -127,14 +128,14 @@ module Shipping
127
128
  b.Contact { |b|
128
129
  if @sender_name.to_s.size > 2
129
130
  b.PersonName @sender_name
130
- b.CompanyName @sender_company unless @sender_company.nil?
131
+ b.CompanyName @sender_company unless @sender_company.blank?
131
132
  elsif @sender_company.to_s.size > 2
132
- b.PersonName @sender_name unless @sender_name.nil?
133
+ b.PersonName @sender_name unless @sender_name.blank?
133
134
  b.CompanyName @sender_company
134
135
  else
135
136
  raise ShippingError, "Either the sender_name or the sender_company value must be bigger than 2 characters."
136
137
  end
137
- b.Department @sender_department unless @sender_department.nil?
138
+ b.Department @sender_department unless @sender_department.blank?
138
139
  b.PhoneNumber @sender_phone.gsub(/[^\d]/,"")
139
140
  b.PagerNumber @sender_pager.gsub(/[^\d]/,"") if @sender_pager.class == String
140
141
  b.FaxNumber @sender_fax.gsub(/[^\d]/,"") if @sender_fax.class == String
@@ -142,7 +143,7 @@ module Shipping
142
143
  }
143
144
  b.Address { |b|
144
145
  b.Line1 @sender_address
145
- b.Line2 @sender_address2 unless @sender_address2.nil?
146
+ b.Line2 @sender_address2 unless @sender_address2.blank?
146
147
  b.City @sender_city
147
148
  b.StateOrProvinceCode sender_state
148
149
  b.PostalCode @sender_zip
@@ -153,14 +154,14 @@ module Shipping
153
154
  b.Contact { |b|
154
155
  if @name.to_s.size > 2
155
156
  b.PersonName @name
156
- b.CompanyName @company unless @company.nil?
157
+ b.CompanyName @company unless @company.blank?
157
158
  elsif @company.to_s.size > 2
158
- b.PersonName @name unless @name.nil?
159
+ b.PersonName @name unless @name.blank?
159
160
  b.CompanyName @company
160
161
  else
161
162
  raise ShippingError, "Either the name or the company value must be bigger than 2 characters."
162
163
  end
163
- b.Department @department unless @department.nil?
164
+ b.Department @department unless @department.blank?
164
165
  b.PhoneNumber @phone.gsub(/[^\d]/,"")
165
166
  b.PagerNumber @pager.gsub(/[^\d]/,"") if @pager.class == String
166
167
  b.FaxNumber @fax.gsub(/[^\d]/,"") if @fax.class == String
@@ -168,7 +169,7 @@ module Shipping
168
169
  }
169
170
  b.Address { |b|
170
171
  b.Line1 @address
171
- b.Line2 @address2 unless @address2.nil?
172
+ b.Line2 @address2 unless @address2.blank?
172
173
  b.City @city
173
174
  b.StateOrProvinceCode state
174
175
  b.PostalCode @zip
@@ -179,18 +180,18 @@ module Shipping
179
180
  b.PayorType PaymentTypes[@pay_type] || 'SENDER'
180
181
  b.Payor { |b|
181
182
  b.AccountNumber @payor_account_number
182
- b.CountryCode @payor_country_code unless @payor_country_code.nil?
183
- } unless @payor_account_number.nil?
183
+ b.CountryCode @payor_country_code unless @payor_country_code.blank?
184
+ } unless @payor_account_number.blank?
184
185
  }
185
186
  b.RMA { |b|
186
187
  b.Number @rma_number
187
- } unless @rma_number.nil?
188
+ } unless @rma_number.blank?
188
189
  b.Package { |b|
189
190
  b.Weight @weight
190
191
  b.DeclaredValue @declared_value || '99.00'
191
192
  b.ReferenceInfo { |b|
192
193
  b.CustomerReference @customer_reference
193
- } unless @customer_reference.nil?
194
+ } unless @customer_reference.blank?
194
195
  b.ItemDescription @description || "Shipment"
195
196
  }
196
197
  b.SpecialServices { |b|
@@ -208,9 +209,9 @@ module Shipping
208
209
  b.tag! :"E-MailAddress", @other_email
209
210
  b.ShipAlert @other_ship_alert ? 'true' : 'false'
210
211
  b.LanguageCode @other_language || 'EN' # FR also available
211
- } unless @other_email.nil?
212
+ } unless @other_email.blank?
212
213
  }
213
- } unless @message.nil?
214
+ } unless @message.blank?
214
215
  }
215
216
 
216
217
  get_response @fedex_url
@@ -250,7 +251,7 @@ module Shipping
250
251
  =end
251
252
 
252
253
  # don't allow people to edit the response
253
- response.freeze
254
+ return response.freeze
254
255
  end
255
256
 
256
257
  private
@@ -271,7 +272,7 @@ module Shipping
271
272
  b.MeterNumber @fedex_meter
272
273
  b.CarrierCode TransactionTypes[@transaction_type][1]
273
274
  }
274
- b.ShipDate @ship_date unless @ship_date.nil?
275
+ b.ShipDate @ship_date unless @ship_date.blank?
275
276
  b.DropoffType @dropoff_type || 'REGULARPICKUP'
276
277
  b.Service ServiceTypes[@service_type] || ServiceTypes['ground_service'] # default to ground service
277
278
  b.Packaging PackageTypes[@packaging_type] || 'YOURPACKAGING'
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.10
3
3
  specification_version: 1
4
4
  name: shipping
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.2.0
7
- date: 2005-08-02
6
+ version: 1.2.1
7
+ date: 2005-09-15
8
8
  summary: A general shipping module to find out the shipping prices via UPS or FedEx.
9
9
  require_paths:
10
10
  - lib
@@ -27,6 +27,7 @@ platform: ruby
27
27
  authors:
28
28
  - Lucas Carlson
29
29
  files:
30
+ - lib/extensions.rb
30
31
  - lib/shipping
31
32
  - lib/shipping.rb
32
33
  - lib/shipping/base.rb