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
-
#response ⇒ Object
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
- #currency ⇒ Object
- #dimension_unit ⇒ Object
- #make_request ⇒ Object
- #parsed_response ⇒ Object
- #request_xml ⇒ Object
- #valid_response? ⇒ Boolean
- #weight_unit ⇒ Object
Instance Attribute Details
#response ⇒ Object
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
.carriers ⇒ Object
24 25 26 |
# File 'lib/auction_inc/shipping/base.rb', line 24 def self.carriers @carriers ||= load_carriers end |
.entry_points ⇒ Object
39 40 41 |
# File 'lib/auction_inc/shipping/base.rb', line 39 def self.entry_points self.carriers.collect { |carrier| carrier.entry_point } end |
.load_carriers ⇒ Object
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 |
.services ⇒ Object
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
#currency ⇒ Object
103 104 105 |
# File 'lib/auction_inc/shipping/base.rb', line 103 def currency AuctionInc::Shipping::Base.currency.to_s.upcase end |
#dimension_unit ⇒ Object
99 100 101 |
# File 'lib/auction_inc/shipping/base.rb', line 99 def dimension_unit AuctionInc::Shipping::Base.dimension_unit.to_s.upcase end |
#make_request ⇒ Object
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 |
#parsed_response ⇒ Object
47 48 49 |
# File 'lib/auction_inc/shipping/base.rb', line 47 def parsed_response self.response end |
#request_xml ⇒ Object
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 "<?xml version=\"1.0 encoding=iso-8859-1\" utf-8 ?>\n<Envelope>\n <Header>\n <AccountId>\#{license_key}</AccountId>\n </Header>\n <Body>\n <GetTime version=\"2.0\">\n </GetTime>\n </Body>\n</Envelope>\n HERE\nend\n" |
#valid_response? ⇒ Boolean
91 92 93 |
# File 'lib/auction_inc/shipping/base.rb', line 91 def valid_response? !self.response.blank? end |
#weight_unit ⇒ Object
95 96 97 |
# File 'lib/auction_inc/shipping/base.rb', line 95 def weight_unit AuctionInc::Shipping::Base.weight_unit.to_s.upcase end |