Class: AuctionInc::Shipping::Base

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

Direct Known Subclasses

Xs

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#responseObject

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

.carriersObject



24
25
26
# File 'lib/auction_inc/shipping/base.rb', line 24

def self.carriers
  @carriers ||= load_carriers
end

.entry_pointsObject



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_carriersObject



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

.servicesObject



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

#currencyObject



103
104
105
# File 'lib/auction_inc/shipping/base.rb', line 103

def currency
  AuctionInc::Shipping::Base.currency.to_s.upcase
end

#dimension_unitObject



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_requestObject



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_responseObject



47
48
49
# File 'lib/auction_inc/shipping/base.rb', line 47

def parsed_response
  self.response
end

#request_xmlObject



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

Returns:

  • (Boolean)


91
92
93
# File 'lib/auction_inc/shipping/base.rb', line 91

def valid_response?
  !self.response.blank?
end

#weight_unitObject



95
96
97
# File 'lib/auction_inc/shipping/base.rb', line 95

def weight_unit
  AuctionInc::Shipping::Base.weight_unit.to_s.upcase
end