Class: Shipping::Base

Inherits:
Object show all
Defined in:
lib/shipping/base.rb

Direct Known Subclasses

FedEx, UPS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/shipping/base.rb', line 24

def initialize(options = {})
   prefs = File.expand_path(options[:prefs] || "~/.shipping.yml")
   YAML.load(File.open(prefs)).each {|pref, value| eval("@#{pref} = #{value.inspect}")} if File.exists?(prefs)
   
   @required = Array.new

	# include all provided data
	options.each do |method, value| 
	  instance_variable_set("@#{method}", value)
	end
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



16
17
18
# File 'lib/shipping/base.rb', line 16

def address
  @address
end

#address2Object

Returns the value of attribute address2.



16
17
18
# File 'lib/shipping/base.rb', line 16

def address2
  @address2
end

#cityObject

Returns the value of attribute city.



16
17
18
# File 'lib/shipping/base.rb', line 16

def city
  @city
end

#companyObject

Returns the value of attribute company.



16
17
18
# File 'lib/shipping/base.rb', line 16

def company
  @company
end

#countryObject

Returns the value of attribute country.



16
17
18
# File 'lib/shipping/base.rb', line 16

def country
  @country
end

#currency_codeObject

Returns the value of attribute currency_code.



22
23
24
# File 'lib/shipping/base.rb', line 22

def currency_code
  @currency_code
end

#dataObject (readonly)

Returns the value of attribute data.



11
12
13
# File 'lib/shipping/base.rb', line 11

def data
  @data
end

#declared_valueObject

Returns the value of attribute declared_value.



19
20
21
# File 'lib/shipping/base.rb', line 19

def declared_value
  @declared_value
end

#descriptionObject

Returns the value of attribute description.



19
20
21
# File 'lib/shipping/base.rb', line 19

def description
  @description
end

#dropoff_typeObject

Returns the value of attribute dropoff_type.



22
23
24
# File 'lib/shipping/base.rb', line 22

def dropoff_type
  @dropoff_type
end

#emailObject

Returns the value of attribute email.



16
17
18
# File 'lib/shipping/base.rb', line 16

def email
  @email
end

#fedex_account=(value) ⇒ Object (writeonly)

Sets the attribute fedex_account

Parameters:

  • value

    the value to set the attribute fedex_account to.



14
15
16
# File 'lib/shipping/base.rb', line 14

def fedex_account=(value)
  @fedex_account = value
end

#fedex_meter=(value) ⇒ Object (writeonly)

Sets the attribute fedex_meter

Parameters:

  • value

    the value to set the attribute fedex_meter to.



14
15
16
# File 'lib/shipping/base.rb', line 14

def fedex_meter=(value)
  @fedex_meter = value
end

#fedex_url=(value) ⇒ Object (writeonly)

Sets the attribute fedex_url

Parameters:

  • value

    the value to set the attribute fedex_url to.



14
15
16
# File 'lib/shipping/base.rb', line 14

def fedex_url=(value)
  @fedex_url = value
end

#image_typeObject

Returns the value of attribute image_type.



22
23
24
# File 'lib/shipping/base.rb', line 22

def image_type
  @image_type
end

#insured_valueObject

Returns the value of attribute insured_value.



19
20
21
# File 'lib/shipping/base.rb', line 19

def insured_value
  @insured_value
end

#label_typeObject

Returns the value of attribute label_type.



22
23
24
# File 'lib/shipping/base.rb', line 22

def label_type
  @label_type
end

#nameObject

Returns the value of attribute name.



16
17
18
# File 'lib/shipping/base.rb', line 16

def name
  @name
end

#package_totalObject

Returns the value of attribute package_total.



20
21
22
# File 'lib/shipping/base.rb', line 20

def package_total
  @package_total
end

#packaging_typeObject

Returns the value of attribute packaging_type.



20
21
22
# File 'lib/shipping/base.rb', line 20

def packaging_type
  @packaging_type
end

#pay_typeObject

Returns the value of attribute pay_type.



22
23
24
# File 'lib/shipping/base.rb', line 22

def pay_type
  @pay_type
end

#phoneObject

Returns the value of attribute phone.



16
17
18
# File 'lib/shipping/base.rb', line 16

def phone
  @phone
end

#plain_responseObject (readonly)

Returns the value of attribute plain_response.



11
12
13
# File 'lib/shipping/base.rb', line 11

def plain_response
  @plain_response
end

#requiredObject (readonly)

Returns the value of attribute required.



11
12
13
# File 'lib/shipping/base.rb', line 11

def required
  @required
end

#responseObject (readonly)

Returns the value of attribute response.



11
12
13
# File 'lib/shipping/base.rb', line 11

def response
  @response
end

#sender_addressObject

Returns the value of attribute sender_address.



17
18
19
# File 'lib/shipping/base.rb', line 17

def sender_address
  @sender_address
end

#sender_cityObject

Returns the value of attribute sender_city.



17
18
19
# File 'lib/shipping/base.rb', line 17

def sender_city
  @sender_city
end

#sender_countryObject

Returns the value of attribute sender_country.



17
18
19
# File 'lib/shipping/base.rb', line 17

def sender_country
  @sender_country
end

#sender_emailObject

Returns the value of attribute sender_email.



17
18
19
# File 'lib/shipping/base.rb', line 17

def sender_email
  @sender_email
end

#sender_nameObject

Returns the value of attribute sender_name.



17
18
19
# File 'lib/shipping/base.rb', line 17

def sender_name
  @sender_name
end

#sender_phoneObject

Returns the value of attribute sender_phone.



17
18
19
# File 'lib/shipping/base.rb', line 17

def sender_phone
  @sender_phone
end

#sender_stateObject

Returns the value of attribute sender_state.



17
18
19
# File 'lib/shipping/base.rb', line 17

def sender_state
  @sender_state
end

#sender_zipObject

Returns the value of attribute sender_zip.



17
18
19
# File 'lib/shipping/base.rb', line 17

def sender_zip
  @sender_zip
end

#service_typeObject

Returns the value of attribute service_type.



20
21
22
# File 'lib/shipping/base.rb', line 20

def service_type
  @service_type
end

#ship_dateObject

Returns the value of attribute ship_date.



22
23
24
# File 'lib/shipping/base.rb', line 22

def ship_date
  @ship_date
end

#stateObject

Returns the value of attribute state.



16
17
18
# File 'lib/shipping/base.rb', line 16

def state
  @state
end

#transaction_typeObject

Returns the value of attribute transaction_type.



19
20
21
# File 'lib/shipping/base.rb', line 19

def transaction_type
  @transaction_type
end

#ups_account=(value) ⇒ Object (writeonly)

Sets the attribute ups_account

Parameters:

  • value

    the value to set the attribute ups_account to.



13
14
15
# File 'lib/shipping/base.rb', line 13

def ups_account=(value)
  @ups_account = value
end

#ups_password=(value) ⇒ Object (writeonly)

Sets the attribute ups_password

Parameters:

  • value

    the value to set the attribute ups_password to.



13
14
15
# File 'lib/shipping/base.rb', line 13

def ups_password=(value)
  @ups_password = value
end

#ups_user=(value) ⇒ Object (writeonly)

Sets the attribute ups_user

Parameters:

  • value

    the value to set the attribute ups_user to.



13
14
15
# File 'lib/shipping/base.rb', line 13

def ups_user=(value)
  @ups_user = value
end

#weightObject

Returns the value of attribute weight.



19
20
21
# File 'lib/shipping/base.rb', line 19

def weight
  @weight
end

#weight_unitsObject

Returns the value of attribute weight_units.



19
20
21
# File 'lib/shipping/base.rb', line 19

def weight_units
  @weight_units
end

#zipObject

Returns the value of attribute zip.



16
17
18
# File 'lib/shipping/base.rb', line 16

def zip
  @zip
end

Class Method Details

.plainObject



149
# File 'lib/shipping/base.rb', line 149

def @response.plain; @response_plain; end

.state_from_zip(zip) ⇒ Object

Raises:



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/shipping/base.rb', line 46

def self.state_from_zip(zip)
  zip = zip.to_i
  {
    (99500...99929) => "AK", 
    (35000...36999) => "AL", 
    (71600...72999) => "AR", 
		(75502...75505) => "AR", 
    (85000...86599) => "AZ", 
    (90000...96199) => "CA", 
    (80000...81699) => "CO", 
    (6000...6999) => "CT", 
    (20000...20099) => "DC", 
		(20200...20599) => "DC", 
    (19700...19999) => "DE", 
    (32000...33999) => "FL", 
		(34100...34999) => "FL", 
    (30000...31999) => "GA", 
    (96700...96798) => "HI", 
		(96800...96899) => "HI", 
    (50000...52999) => "IA", 
    (83200...83899) => "ID", 
    (60000...62999) => "IL", 
    (46000...47999) => "IN", 
    (66000...67999) => "KS", 
    (40000...42799) => "KY", 
		(45275...45275) => "KY", 
    (70000...71499) => "LA", 
		(71749...71749) => "LA", 
    (1000...2799) => "MA", 
    (20331...20331) => "MD", 
		(20600...21999) => "MD", 
    (3801...3801) => "ME", 
		(3804...3804) => "ME", 
		(3900...4999) => "ME", 
    (48000...49999) => "MI", 
    (55000...56799) => "MN", 
    (63000...65899) => "MO", 
    (38600...39799) => "MS", 
    (59000...59999) => "MT", 
    (27000...28999) => "NC", 
    (58000...58899) => "ND", 
    (68000...69399) => "NE", 
    (3000...3803) => "NH", 
		(3809...3899) => "NH", 
    (7000...8999) => "NJ", 
    (87000...88499) => "NM", 
    (89000...89899) => "NV", 
    (400...599) => "NY", 
		(6390...6390) => "NY", 
		(9000...14999) => "NY", 
    (43000...45999) => "OH", 
    (73000...73199) => "OK", 
		(73400...74999) => "OK", 
    (97000...97999) => "OR", 
    (15000...19699) => "PA", 
    (2800...2999) => "RI", 
		(6379...6379) => "RI", 
    (29000...29999) => "SC", 
    (57000...57799) => "SD", 
    (37000...38599) => "TN", 
		(72395...72395) => "TN", 
    (73300...73399) => "TX", 
		(73949...73949) => "TX", 
		(75000...79999) => "TX", 
		(88501...88599) => "TX", 
    (84000...84799) => "UT", 
    (20105...20199) => "VA", 
		(20301...20301) => "VA", 
		(20370...20370) => "VA", 
		(22000...24699) => "VA", 
    (5000...5999) => "VT", 
    (98000...99499) => "WA", 
    (49936...49936) => "WI", 
		(53000...54999) => "WI", 
    (24700...26899) => "WV", 
    (82000...83199) => "WY"
  }.each do |range, state|
    return state if range.include? zip
  end

  raise ShippingError, "Invalid zip code"
end

Instance Method Details

#fedexObject

Initializes an instance of Shipping::FedEx with the same instance variables as the base object



37
38
39
# File 'lib/shipping/base.rb', line 37

def fedex
   Shipping::FedEx.new prepare_vars
end

#upsObject

Initializes an instance of Shipping::UPS with the same instance variables as the base object



42
43
44
# File 'lib/shipping/base.rb', line 42

def ups
   Shipping::UPS.new prepare_vars
end