Class: AuctionInc::Shipping::Base
- Inherits:
-
Object
- Object
- AuctionInc::Shipping::Base
- Defined in:
- lib/auction_inc/shipping/base.rb
Direct Known Subclasses
Instance Attribute Summary (collapse)
-
- (Object) response
Returns the value of attribute response.
Class Method Summary (collapse)
Instance Method Summary (collapse)
- - (Object) currency
- - (Object) dimension_unit
- - (Object) make_request
- - (Object) parsed_response
- - (Object) request_xml
- - (Boolean) valid_response?
- - (Object) weight_unit
Instance Attribute Details
- (Object) response
Returns the value of attribute response
22 23 24 |
# File 'lib/auction_inc/shipping/base.rb', line 22 def response @response end |
Class Method Details
+ (Object) carriers
24 25 26 |
# File 'lib/auction_inc/shipping/base.rb', line 24 def self.carriers @carriers ||= load_carriers end |
+ (Object) entry_points
39 40 41 |
# File 'lib/auction_inc/shipping/base.rb', line 39 def self.entry_points self.carriers.collect { |carrier| carrier.entry_point } end |
+ (Object) load_carriers
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/auction_inc/shipping/base.rb', line 28 def self.load_carriers carrier_data = YAML::load(Pathname.new(carriers_yml).read) result = [] carrier_data.each do |carrier| # TODO allow for PkgMaxWeight and OnDemand values services = carrier['services'].collect { |s| Service.new(:name => s['name'], :code => s['code'], :klass => s['klass']) } result << Carrier.new(:name => carrier['name'], :code => carrier['code'], :entry_point => carrier['entry_point'], :services => services) end result end |
+ (Object) services
43 44 45 |
# File 'lib/auction_inc/shipping/base.rb', line 43 def self.services self.carriers.collect { |carrier| carrier.services }.flatten end |
Instance Method Details
- (Object) currency
103 104 105 |
# File 'lib/auction_inc/shipping/base.rb', line 103 def currency AuctionInc::Shipping::Base.currency.to_s.upcase end |
- (Object) dimension_unit
99 100 101 |
# File 'lib/auction_inc/shipping/base.rb', line 99 def dimension_unit AuctionInc::Shipping::Base.dimension_unit.to_s.upcase end |
- (Object) make_request
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/auction_inc/shipping/base.rb', line 51 def make_request if license_key.nil? raise AuctionInc::Shipping::LicenseError.new("License Key is missing") end uri = URI.parse(base_url) begin http_server = Net::HTTP.new(base_url, 80) http_request = Net::HTTP::Post.new(base_path) http_request.body = self.request_xml response_string = http_server.start { |http| http.request(http_request) }.body self.response = Response.new(response_string) rescue EOFError => e raise ConnectionError, "The remote server dropped the connection" rescue Errno::ECONNRESET => e raise ConnectionError, "The remote server reset the connection" rescue Errno::ECONNREFUSED => e raise ConnectionError, "The remote server refused the connection" rescue Timeout::Error, Errno::ETIMEDOUT => e raise ConnectionError, "The connection to the remote server timed out" end end |
- (Object) parsed_response
47 48 49 |
# File 'lib/auction_inc/shipping/base.rb', line 47 def parsed_response self.response end |
- (Object) request_xml
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/auction_inc/shipping/base.rb', line 76 def request_xml <<-HERE <?xml version="1.0 encoding=iso-8859-1" utf-8 ?> <Envelope> <Header> <AccountId>#{license_key}</AccountId> </Header> <Body> <GetTime version="2.0"> </GetTime> </Body> </Envelope> HERE end |
- (Boolean) valid_response?
91 92 93 |
# File 'lib/auction_inc/shipping/base.rb', line 91 def valid_response? !self.response.blank? end |
- (Object) weight_unit
95 96 97 |
# File 'lib/auction_inc/shipping/base.rb', line 95 def weight_unit AuctionInc::Shipping::Base.weight_unit.to_s.upcase end |