auction_inc 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -19,3 +19,4 @@ rdoc
19
19
  pkg
20
20
 
21
21
  ## PROJECT::SPECIFIC
22
+ *.gem
data/Rakefile CHANGED
@@ -12,7 +12,7 @@ begin
12
12
  gem.authors = ["pjkelly"]
13
13
  gem.add_dependency "roxml", ">= 3.1.5"
14
14
  gem.add_development_dependency "rspec", ">= 1.2.9"
15
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ gem.add_development_dependency "fakeweb", ">=1.2.8"
16
16
  end
17
17
  Jeweler::GemcutterTasks.new
18
18
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -0,0 +1,94 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{auction_inc}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["pjkelly"]
12
+ s.date = %q{2010-08-05}
13
+ s.description = %q{Ruby wrapper around Auction Inc's shipping API.}
14
+ s.email = %q{pj@crushlovely.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "auction_inc.gemspec",
27
+ "lib/auction_inc.rb",
28
+ "lib/auction_inc/shipping/base.rb",
29
+ "lib/auction_inc/shipping/carriers.yml",
30
+ "lib/auction_inc/shipping/node.rb",
31
+ "lib/auction_inc/shipping/node/body.rb",
32
+ "lib/auction_inc/shipping/node/calc_method.rb",
33
+ "lib/auction_inc/shipping/node/carrier.rb",
34
+ "lib/auction_inc/shipping/node/carrier_calc_props.rb",
35
+ "lib/auction_inc/shipping/node/destination_address.rb",
36
+ "lib/auction_inc/shipping/node/envelope.rb",
37
+ "lib/auction_inc/shipping/node/error.rb",
38
+ "lib/auction_inc/shipping/node/get_item_ship_rate_xs.rb",
39
+ "lib/auction_inc/shipping/node/header.rb",
40
+ "lib/auction_inc/shipping/node/item.rb",
41
+ "lib/auction_inc/shipping/node/item_ship_rate.rb",
42
+ "lib/auction_inc/shipping/node/origin_address.rb",
43
+ "lib/auction_inc/shipping/node/package.rb",
44
+ "lib/auction_inc/shipping/node/pkg_item.rb",
45
+ "lib/auction_inc/shipping/node/service.rb",
46
+ "lib/auction_inc/shipping/node/ship_rate.rb",
47
+ "lib/auction_inc/shipping/response.rb",
48
+ "lib/auction_inc/shipping/xs.rb",
49
+ "spec/auction_inc/shipping/base_spec.rb",
50
+ "spec/auction_inc/shipping/error_spec.rb",
51
+ "spec/auction_inc/shipping/item_ship_rate_spec.rb",
52
+ "spec/auction_inc/shipping/response_spec.rb",
53
+ "spec/fixtures/auction_inc_detail_level_1_response.xml",
54
+ "spec/fixtures/auction_inc_detail_level_2_response.xml",
55
+ "spec/fixtures/auction_inc_detail_level_3_response.xml",
56
+ "spec/fixtures/auction_inc_get_time_response.xml",
57
+ "spec/fixtures/auction_inc_type_1_error_response.xml",
58
+ "spec/fixtures/auction_inc_type_2_error_response.xml",
59
+ "spec/spec.opts",
60
+ "spec/spec_helper.rb"
61
+ ]
62
+ s.homepage = %q{http://github.com/pjkelly/auction_inc}
63
+ s.rdoc_options = ["--charset=UTF-8"]
64
+ s.require_paths = ["lib"]
65
+ s.rubygems_version = %q{1.3.7}
66
+ s.summary = %q{Ruby wrapper around Auction Inc's shipping API.}
67
+ s.test_files = [
68
+ "spec/auction_inc/shipping/base_spec.rb",
69
+ "spec/auction_inc/shipping/error_spec.rb",
70
+ "spec/auction_inc/shipping/item_ship_rate_spec.rb",
71
+ "spec/auction_inc/shipping/response_spec.rb",
72
+ "spec/spec_helper.rb"
73
+ ]
74
+
75
+ if s.respond_to? :specification_version then
76
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
77
+ s.specification_version = 3
78
+
79
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
80
+ s.add_runtime_dependency(%q<roxml>, [">= 3.1.5"])
81
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
82
+ s.add_development_dependency(%q<fakeweb>, [">= 1.2.8"])
83
+ else
84
+ s.add_dependency(%q<roxml>, [">= 3.1.5"])
85
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
86
+ s.add_dependency(%q<fakeweb>, [">= 1.2.8"])
87
+ end
88
+ else
89
+ s.add_dependency(%q<roxml>, [">= 3.1.5"])
90
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
91
+ s.add_dependency(%q<fakeweb>, [">= 1.2.8"])
92
+ end
93
+ end
94
+
@@ -31,7 +31,7 @@ module AuctionInc
31
31
  carrier_data.each do |carrier|
32
32
  # TODO allow for PkgMaxWeight and OnDemand values
33
33
  services = carrier['services'].collect { |s| Service.new(:name => s['name'], :code => s['code'], :klass => s['klass']) }
34
- result << Carrier.new(:name => carrier['name'], :code => carrier['code'], :entry_point => carrier['entry_point'], :service_list => services)
34
+ result << Carrier.new(:name => carrier['name'], :code => carrier['code'], :entry_point => carrier['entry_point'], :services => services)
35
35
  end
36
36
  result
37
37
  end
@@ -41,7 +41,7 @@ module AuctionInc
41
41
  end
42
42
 
43
43
  def self.services
44
- self.carriers.collect { |carrier| carrier.service_list }.flatten
44
+ self.carriers.collect { |carrier| carrier.services }.flatten
45
45
  end
46
46
 
47
47
  def parsed_response
@@ -60,7 +60,8 @@ module AuctionInc
60
60
  http_request = Net::HTTP::Post.new(base_path)
61
61
  http_request.body = self.request_xml
62
62
 
63
- self.response = http_server.start { |http| http.request(http_request) }.body
63
+ response_string = http_server.start { |http| http.request(http_request) }.body
64
+ self.response = Response.new(response_string)
64
65
  rescue EOFError => e
65
66
  raise ConnectionError, "The remote server dropped the connection"
66
67
  rescue Errno::ECONNRESET => e
@@ -2,6 +2,8 @@ module AuctionInc
2
2
  module Shipping
3
3
  class Body < Node
4
4
  xml_accessor :get_item_ship_rate_x_s, :as => GetItemShipRateXs
5
+ xml_accessor :item_ship_rate, :as => ItemShipRate
6
+ xml_accessor :error, :as => Error
5
7
  end
6
8
  end
7
9
  end
@@ -1,7 +1,7 @@
1
1
  module AuctionInc
2
2
  module Shipping
3
3
  class CalcMethod < Node
4
- xml_accessor :code, :from => "@Code"
4
+ xml_accessor :code, :from => "@code"
5
5
  xml_accessor :carrier_calc_props, :as => CarrierCalcProps
6
6
  end
7
7
  end
@@ -2,9 +2,9 @@ module AuctionInc
2
2
  module Shipping
3
3
  class Carrier < Node
4
4
  attr_accessor :name
5
- xml_accessor :code, :from => "@Code"
5
+ xml_accessor :code, :from => "@code"
6
6
  xml_accessor :entry_point
7
- xml_accessor :service_list, :as => [Service]
7
+ xml_accessor :services, :as => [Service], :in => "ServiceList"
8
8
  end
9
9
  end
10
10
  end
@@ -5,6 +5,20 @@ module AuctionInc
5
5
  xml_accessor :message
6
6
  xml_accessor :detail, :as => []
7
7
  xml_accessor :severity
8
+
9
+ SEVERITIES = [:NOTICE, :WARNING, :CRITICAL]
10
+
11
+ def notice?
12
+ self.severity.to_sym == :NOTICE
13
+ end
14
+
15
+ def warning?
16
+ self.severity.to_sym == :WARNING
17
+ end
18
+
19
+ def critical?
20
+ self.severity.to_sym == :CRITICAL
21
+ end
8
22
  end
9
23
  end
10
24
  end
@@ -4,10 +4,10 @@ module AuctionInc
4
4
  xml_accessor :version, :from => "@version"
5
5
  xml_accessor :detail_level
6
6
  xml_accessor :currency
7
- xml_accessor :carrier_list, :as => [Carrier]
8
- xml_accessor :origin_address_list, :as => [OriginAddress]
7
+ xml_accessor :carriers, :as => [Carrier], :in => "CarrierList"
8
+ xml_accessor :origin_addresses, :as => [OriginAddress], :in => "OriginAddressList"
9
9
  xml_accessor :destination_address, :as => DestinationAddress
10
- xml_accessor :item_list, :as => [Item]
10
+ xml_accessor :items, :as => [Item], :in => "ItemList"
11
11
  end
12
12
  end
13
13
  end
@@ -2,6 +2,7 @@ module AuctionInc
2
2
  module Shipping
3
3
  class Header < Node
4
4
  xml_accessor :account_id
5
+ xml_accessor :date
5
6
  end
6
7
  end
7
8
  end
@@ -0,0 +1,30 @@
1
+ module AuctionInc
2
+ module Shipping
3
+ class ItemShipRate < Node
4
+ xml_accessor :currency
5
+ xml_accessor :ship_rates, :as => [ShipRate], :in => "ShipRateList"
6
+
7
+ def has_error?
8
+ error = false
9
+ self.ship_rates.each do |ship_rate|
10
+ error = true if ship_rate.errors.present?
11
+ end
12
+ error
13
+ end
14
+ alias_method :has_errors?, :has_error?
15
+
16
+ def error
17
+ self.errors.empty? ? nil : self.errors.first
18
+ end
19
+
20
+ def errors
21
+ @errors = []
22
+ self.ship_rates.each do |ship_rate|
23
+ @errors << ship_rate.errors if ship_rate.errors.present?
24
+ end
25
+ @errors.flatten
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -19,7 +19,7 @@ module AuctionInc
19
19
  xml_accessor :insurance
20
20
  xml_accessor :handling
21
21
  xml_accessor :ship_rate
22
- xml_accessor :pkg_item, :as => [PkgItem]
22
+ xml_accessor :pkg_items, :as => [PkgItem]
23
23
  end
24
24
  end
25
25
  end
@@ -3,7 +3,7 @@ module AuctionInc
3
3
  class Service < Node
4
4
  attr_accessor :name, :klass
5
5
 
6
- xml_accessor :code, :from => "@Code"
6
+ xml_accessor :code, :from => "@code"
7
7
  xml_accessor :pkg_max_weight
8
8
  xml_accessor :on_demand
9
9
  end
@@ -2,14 +2,14 @@ module AuctionInc
2
2
  module Shipping
3
3
  class ShipRate < Node
4
4
  # Detail Level 1
5
- xml_accessor :valid
5
+ xml_accessor :valid?
6
6
  xml_accessor :carrier_code
7
7
  xml_accessor :service_code
8
8
  xml_accessor :service_name
9
9
  xml_accessor :calc_method
10
10
  xml_accessor :rate
11
- xml_accessor :error_list, :as => [Error]
12
- # Detail Level 1
11
+ xml_accessor :errors, :as => [Error], :in => "ErrorList"
12
+ # Detail Level 2
13
13
  xml_accessor :carrier_rate
14
14
  xml_accessor :fixed_rate
15
15
  xml_accessor :surcharges
@@ -21,7 +21,7 @@ module AuctionInc
21
21
  xml_accessor :package_count
22
22
  xml_accessor :flat_rate_code
23
23
  # Detail Level 3
24
- xml_accessor :package_detail, :as => [Package]
24
+ xml_accessor :packages, :as => [Package], :in => "PackageDetail"
25
25
  end
26
26
  end
27
27
  end
@@ -0,0 +1,35 @@
1
+ module AuctionInc
2
+ module Shipping
3
+ class Response
4
+ attr_accessor :raw, :parsed
5
+
6
+ def initialize(xml_string)
7
+ self.raw = xml_string
8
+ self.parsed = Envelope.from_xml(self.raw)
9
+ end
10
+
11
+ def body
12
+ self.parsed.body
13
+ end
14
+
15
+ def has_error?
16
+ self.body.error.present? || (self.body.item_ship_rate.present? && self.body.item_ship_rate.has_errors?)
17
+ end
18
+ alias_method :has_errors?, :has_error?
19
+
20
+ def error
21
+ if self.body.error.present?
22
+ self.body.error
23
+ elsif self.body.item_ship_rate.present? && self.body.item_ship_rate.has_errors?
24
+ self.body.item_ship_rate.error
25
+ else
26
+ nil
27
+ end
28
+ end
29
+
30
+ def ship_rates
31
+ self.parsed.body.item_ship_rate.ship_rates if self.body.item_ship_rate.present?
32
+ end
33
+ end
34
+ end
35
+ end
@@ -6,7 +6,7 @@ module AuctionInc
6
6
  def request_xml
7
7
  doc = Nokogiri::XML::Document.new
8
8
  doc.root = self.envelope.to_xml
9
- doc
9
+ doc.to_s
10
10
  end
11
11
 
12
12
  def envelope
@@ -26,10 +26,10 @@ module AuctionInc
26
26
  content.version = self.class.api_version
27
27
  content.detail_level = self.class.detail_level
28
28
  content.currency = self.currency
29
- content.carrier_list = self.class.carriers
30
- content.origin_address_list = origin_addresses unless origin_addresses.blank?
29
+ content.carriers = self.class.carriers
30
+ content.origin_addresses = origin_addresses unless origin_addresses.blank?
31
31
  content.destination_address = destination_address unless destination_address.blank?
32
- content.item_list = items unless items.blank?
32
+ content.items = items unless items.blank?
33
33
  content
34
34
  end
35
35
  end
data/lib/auction_inc.rb CHANGED
@@ -21,8 +21,10 @@ require 'auction_inc/shipping/node/calc_method'
21
21
  require 'auction_inc/shipping/node/item'
22
22
  require 'auction_inc/shipping/node/carrier'
23
23
  require 'auction_inc/shipping/node/get_item_ship_rate_xs'
24
+ require 'auction_inc/shipping/node/item_ship_rate'
24
25
  require 'auction_inc/shipping/node/body'
25
26
  require 'auction_inc/shipping/node/envelope'
26
27
 
28
+ require 'auction_inc/shipping/response'
27
29
  require 'auction_inc/shipping/base'
28
30
  require 'auction_inc/shipping/xs'
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe AuctionInc::Shipping::Base do
4
-
5
4
  before(:each) do
6
5
  AuctionInc::Shipping::Base.license_key = nil
7
6
  end
@@ -52,11 +51,15 @@ describe AuctionInc::Shipping::Base do
52
51
 
53
52
  describe ".services" do
54
53
  it "should return an array of all services" do
55
- AuctionInc::Shipping::Base.services.should == AuctionInc::Shipping::Base.carriers.collect { |carrier| carrier.service_list }.flatten
54
+ AuctionInc::Shipping::Base.services.should == AuctionInc::Shipping::Base.carriers.collect { |carrier| carrier.services }.flatten
56
55
  end
57
56
  end
58
57
 
59
58
  describe "#make_request" do
59
+ before do
60
+ FakeWeb.register_uri(:post, %r|api\.auctioninc\.com/|, :body => remote_fixture_file('auction_inc_get_time_response.xml'))
61
+ end
62
+
60
63
  context "when no license key is present" do
61
64
  it "should raise a license error" do
62
65
  lambda {
@@ -66,11 +69,20 @@ describe AuctionInc::Shipping::Base do
66
69
  end
67
70
 
68
71
  context "when a license key is present" do
69
- it "return set the response" do
72
+ before do
70
73
  AuctionInc::Shipping::Base.license_key = '123'
71
- service = AuctionInc::Shipping::Base.new
72
- service.make_request
73
- service.response.should_not be_blank
74
+ @service = AuctionInc::Shipping::Base.new
75
+ @response_string = File.read(remote_fixture_file('auction_inc_get_time_response.xml'))
76
+ end
77
+
78
+ it "should pass the response string to Response.new" do
79
+ AuctionInc::Shipping::Response.should_receive(:new).with(@response_string)
80
+ @service.make_request
81
+ end
82
+
83
+ it "should set the response as a Response object" do
84
+ @service.make_request
85
+ @service.response.should be_an(AuctionInc::Shipping::Response)
74
86
  end
75
87
  end
76
88
  end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe AuctionInc::Shipping::Error do
4
+ let(:xml_string) { File.read(remote_fixture_file('auction_inc_type_1_error_response.xml')) }
5
+ let(:error) { AuctionInc::Shipping::Envelope.from_xml(xml_string).body.error }
6
+
7
+ AuctionInc::Shipping::Error::SEVERITIES.each do |severity|
8
+ describe "##{severity.to_s.downcase}?" do
9
+ it "should return true when severity is #{severity.to_s}" do
10
+ error.send("severity=", severity.to_s)
11
+ error.send("#{severity.to_s.downcase}?").should be_true
12
+ end
13
+
14
+ AuctionInc::Shipping::Error::SEVERITIES.reject { |s| s == severity }.each do |other|
15
+ it "should return false when severity is #{other.to_s}" do
16
+ error.send("severity=", other.to_s)
17
+ error.send("#{severity.to_s.downcase}?").should be_false
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe AuctionInc::Shipping::ItemShipRate do
4
+ describe "#has_error?" do
5
+ context "when there are ship_rate errors" do
6
+ let(:xml_string) { File.read(remote_fixture_file('auction_inc_type_2_error_response.xml')) }
7
+ let(:item_ship_rate) { AuctionInc::Shipping::Envelope.from_xml(xml_string).body.item_ship_rate }
8
+
9
+ it "should return true" do
10
+ item_ship_rate.has_error?.should be_true
11
+ end
12
+ end
13
+
14
+ context "when there are not ship_rate errors" do
15
+ let(:xml_string) { File.read(remote_fixture_file('auction_inc_detail_level_1_response.xml')) }
16
+ let(:item_ship_rate) { AuctionInc::Shipping::Envelope.from_xml(xml_string).body.item_ship_rate }
17
+
18
+ it "should return false" do
19
+ item_ship_rate.has_error?.should be_false
20
+ end
21
+ end
22
+ end
23
+
24
+ describe "#errors" do
25
+ context "when there are ship_rate errors" do
26
+ let(:xml_string) { File.read(remote_fixture_file('auction_inc_type_2_error_response.xml')) }
27
+ let(:item_ship_rate) { AuctionInc::Shipping::Envelope.from_xml(xml_string).body.item_ship_rate }
28
+
29
+ it "should include errors from the ship rates" do
30
+ item_ship_rate.errors.should include(item_ship_rate.ship_rates.first.errors.first)
31
+ end
32
+ end
33
+
34
+ context "when there are not ship_rate errors" do
35
+ let(:xml_string) { File.read(remote_fixture_file('auction_inc_detail_level_1_response.xml')) }
36
+ let(:item_ship_rate) { AuctionInc::Shipping::Envelope.from_xml(xml_string).body.item_ship_rate }
37
+
38
+ it "should be empty" do
39
+ item_ship_rate.errors.should be_empty
40
+ end
41
+ end
42
+ end
43
+
44
+ describe "#error" do
45
+ context "when there are ship_rate errors" do
46
+ let(:xml_string) { File.read(remote_fixture_file('auction_inc_type_2_error_response.xml')) }
47
+ let(:item_ship_rate) { AuctionInc::Shipping::Envelope.from_xml(xml_string).body.item_ship_rate }
48
+
49
+ it "should return the first error from the errors array" do
50
+ item_ship_rate.error.should == item_ship_rate.errors.first
51
+ end
52
+ end
53
+
54
+ context "when there are not ship_rate errors" do
55
+ let(:xml_string) { File.read(remote_fixture_file('auction_inc_detail_level_1_response.xml')) }
56
+ let(:item_ship_rate) { AuctionInc::Shipping::Envelope.from_xml(xml_string).body.item_ship_rate }
57
+
58
+ it "should return nil" do
59
+ item_ship_rate.error.should be_nil
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,91 @@
1
+ require 'spec_helper'
2
+
3
+ describe AuctionInc::Shipping::Response do
4
+ let(:xml_string) { File.read(remote_fixture_file('auction_inc_get_time_response.xml')) }
5
+ let(:response) { AuctionInc::Shipping::Response.new(xml_string) }
6
+
7
+ describe "initialization" do
8
+ it "should pass the xml_string to Body.from_xml" do
9
+ AuctionInc::Shipping::Envelope.should_receive(:from_xml).with(xml_string)
10
+ AuctionInc::Shipping::Response.new(xml_string)
11
+ end
12
+
13
+ it "should put the raw XML in #raw" do
14
+ response.raw.should == xml_string
15
+ end
16
+
17
+ it "should set #parsed as an Envelope object" do
18
+ response.parsed.should be_a(AuctionInc::Shipping::Envelope)
19
+ end
20
+ end
21
+
22
+ describe "#body" do
23
+ it "should be a Body object" do
24
+ response.body.should be_an(AuctionInc::Shipping::Body)
25
+ end
26
+ end
27
+
28
+ describe "#has_errors?" do
29
+ [1, 2].each do |type|
30
+ context "when there is a type #{type.to_s} error response" do
31
+ let(:xml_string) { File.read(remote_fixture_file("auction_inc_type_#{type.to_s}_error_response.xml")) }
32
+
33
+ it "should return true" do
34
+ response = AuctionInc::Shipping::Response.new(xml_string)
35
+ response.has_errors?.should be_true
36
+ end
37
+ end
38
+ end
39
+
40
+ [1, 2, 3].each do |level|
41
+ context "when there is a detail level #{level.to_s} response" do
42
+ let(:xml_string) { File.read(remote_fixture_file("auction_inc_detail_level_#{level.to_s}_response.xml")) }
43
+
44
+ it "should return false" do
45
+ response = AuctionInc::Shipping::Response.new(xml_string)
46
+ response.has_errors?.should be_false
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ describe "#error" do
53
+ context "when there is a type 1 error response" do
54
+ let(:xml_string) { File.read(remote_fixture_file("auction_inc_type_1_error_response.xml")) }
55
+
56
+ it "should include be error inside <Body/>" do
57
+ response = AuctionInc::Shipping::Response.new(xml_string)
58
+ response.error.should == response.body.error
59
+ end
60
+ end
61
+
62
+ context "when there is a type 2 error response" do
63
+ let(:xml_string) { File.read(remote_fixture_file("auction_inc_type_2_error_response.xml")) }
64
+
65
+ it "should be the first ship_rate error" do
66
+ response = AuctionInc::Shipping::Response.new(xml_string)
67
+ response.error.should == response.body.item_ship_rate.error
68
+ end
69
+ end
70
+
71
+ [1, 2, 3].each do |level|
72
+ context "when there is a detail level #{level.to_s} response" do
73
+ let(:xml_string) { File.read(remote_fixture_file("auction_inc_detail_level_#{level.to_s}_response.xml")) }
74
+
75
+ it "should be empty" do
76
+ response = AuctionInc::Shipping::Response.new(xml_string)
77
+ response.error.should be_nil
78
+ end
79
+ end
80
+ end
81
+ end
82
+
83
+ describe "#ship_rates" do
84
+ let(:xml_string) { File.read(remote_fixture_file("auction_inc_detail_level_1_response.xml")) }
85
+ it "should be a shortcut to #body.item_ship_rate.ship_rates" do
86
+ response = AuctionInc::Shipping::Response.new(xml_string)
87
+ response.ship_rates.should == response.body.item_ship_rate.ship_rates
88
+ end
89
+ end
90
+
91
+ end
@@ -0,0 +1,29 @@
1
+ <?xml version="2.1" encoding="utf-8" ?>
2
+ <Envelope>
3
+ <Header>
4
+ <Date>2008-10-28 19:53:14 GMT</Date>
5
+ </Header>
6
+ <Body>
7
+ <ItemShipRate>
8
+ <Currency>USD</Currency>
9
+ <ShipRateList>
10
+ <ShipRate>
11
+ <Valid>1</Valid>
12
+ <CarrierCode>USPS</CarrierCode>
13
+ <ServiceCode>USPSPM</ServiceCode>
14
+ <ServiceName>PriorityMail</ServiceName>
15
+ <CalcMethod>C</CalcMethod>
16
+ <Rate>48.26</Rate>
17
+ </ShipRate>
18
+ <ShipRate>
19
+ <Valid>1</Valid>
20
+ <CarrierCode>UPS</CarrierCode>
21
+ <ServiceCode>UPSGND</ServiceCode>
22
+ <ServiceName>Ground</ServiceName>
23
+ <CalcMethod>C</CalcMethod>
24
+ <Rate>31.21</Rate>
25
+ </ShipRate>
26
+ </ShipRateList>
27
+ </ItemShipRate>
28
+ </Body>
29
+ </Envelope>
@@ -0,0 +1,62 @@
1
+ <?xml version="2.1" encoding="utf-8" ?>
2
+ <Envelope>
3
+ <Header>
4
+ <Date>2008-10-28 19:53:14 GMT</Date>
5
+ </Header>
6
+ <Body>
7
+ <ItemShipRate>
8
+ <Currency>USD</Currency>
9
+ <ShipRateList>
10
+ <ShipRate>
11
+ <Valid>true</Valid>
12
+ <CarrierCode>USPS</CarrierCode>
13
+ <ServiceCode>USPPM</ServiceCode>
14
+ <ServiceName>USPS Priority Mail</ServiceName>
15
+ <CalcMethod>C</CalcMethod>
16
+ <Rate>11.50</Rate>
17
+ <CarrierRate>9.80</CarrierRate>
18
+ <Surcharges>0.00</Surcharges>
19
+ <FuelSurcharges>0.00</FuelSurcharges>
20
+ <HandlingFees>0.00</HandlingFees>
21
+ <DeclaredValue>19.95</DeclaredValue>
22
+ <InsuranceCharges>1.70</InsuranceCharges>
23
+ <Weight>10.00</Weight>
24
+ <PackageCount>1</PackageCount>
25
+ <FlatRateCode>FRB1</FlatRateCode>
26
+ </ShipRate>
27
+ <ShipRate>
28
+ <Valid>true</Valid>
29
+ <CarrierCode>UPS</CarrierCode>
30
+ <ServiceCode>UPSGND</ServiceCode>
31
+ <ServiceName>UPS Ground</ServiceName>
32
+ <CalcMethod>C</CalcMethod>
33
+ <Rate>11.30</Rate>
34
+ <CarrierRate>10.81</CarrierRate>
35
+ <Surcharges>0.00</Surcharges>
36
+ <FuelSurcharges>0.49</FuelSurcharges>
37
+ <HandlingFees>0.00</HandlingFees>
38
+ <DeclaredValue>19.95</DeclaredValue>
39
+ <InsuranceCharges>0.00</InsuranceCharges>
40
+ <Weight>10.00</Weight>
41
+ <PackageCount>1</PackageCount>
42
+ </ShipRate>
43
+ <ShipRate>
44
+ <Valid>true</Valid>
45
+ <CarrierCode>UPS</CarrierCode>
46
+ <ServiceCode>UPS2ND</ServiceCode>
47
+ <ServiceName>UPS 2 Day</ServiceName>
48
+ <CalcMethod>C</CalcMethod>
49
+ <Rate>27.47</Rate>
50
+ <CarrierRate>24.20</CarrierRate>
51
+ <Surcharges>0.00</Surcharges>
52
+ <FuelSurcharges>3.27</FuelSurcharges>
53
+ <HandlingFees>0.00</HandlingFees>
54
+ <DeclaredValue>19.95</DeclaredValue>
55
+ <InsuranceCharges>1.70</InsuranceCharges>
56
+ <Weight>10.00</Weight>
57
+ <PackageCount>1</PackageCount>
58
+ </ShipRate>
59
+ </ShipRateList>
60
+ </ItemShipRate>
61
+ </Body>
62
+ </Envelope>
@@ -0,0 +1,83 @@
1
+ <?xml version="2.1" encoding="utf-8" ?>
2
+ <Envelope>
3
+ <Header>
4
+ <Date>2008-10-28 19:53:14 GMT</Date>
5
+ </Header>
6
+ <Body>
7
+ <ItemShipRate>
8
+ <Currency>USD</Currency>
9
+ <ShipRateList>
10
+ <ShipRate>
11
+ <Valid>true</Valid>
12
+ <CarrierCode>USPS</CarrierCode>
13
+ <ServiceCode>USPPM</ServiceCode>
14
+ <ServiceName>USPS Priority Mail</ServiceName>
15
+ <CalcMethod>C</CalcMethod>
16
+ <Rate>39.67</Rate>
17
+ <CarrierRate>30.50</CarrierRate>
18
+ <Surcharges>2.40</Surcharges>
19
+ <FuelSurcharges>1.67</FuelSurcharges>
20
+ <HandlingFees>0.00</HandlingFees>
21
+ <DeclaredValue>19.95</DeclaredValue>
22
+ <InsuranceCharges>5.10</InsuranceCharges>
23
+ <Weight>20.00</Weight>
24
+ <PackageCount>2</PackageCount>
25
+ <FlatRateCode>NONE</FlatRateCode>
26
+ <PackageDetail>
27
+ <Package>
28
+ <Quantity>1</Quantity>
29
+ <PackMethod>T</PackMethod>
30
+ <Origin>01610</Origin>
31
+ <DeclaredValue>19.95</DeclaredValue>
32
+ <Weight>10</Weight>
33
+ <Length>5</Length>
34
+ <Width>3</Width>
35
+ <Height>4</Height>
36
+ <OversizeCode>NONE</OversizeCode>
37
+ <FlatRateCode>NONE</FlatRateCode>
38
+ <CarrierRate>9.80</CarrierRate>
39
+ <Surcharge>2.40</Surcharge>
40
+ <FuelSurcharge>1.67</FuelSurcharge>
41
+ <Insurance>1.70</Insurance>
42
+ <Handling>0</Handling>
43
+ <ShipRate>15.57</ShipRate>
44
+ <PkgItem>
45
+ <RefCode>red-keyboard-101</RefCode>
46
+ <Qty>1</Qty>
47
+ <Weight>5</Weight>
48
+ </PkgItem>
49
+ <PkgItem>
50
+ <RefCode>yellow-keyboard-101-e</RefCode>
51
+ <Qty>1</Qty>
52
+ <Weight>5</Weight>
53
+ </PkgItem>
54
+ </Package>
55
+ <Package>
56
+ <Quantity>2</Quantity>
57
+ <PackMethod>S</PackMethod>
58
+ <Origin>01610</Origin>
59
+ <DeclaredValue>19.95</DeclaredValue>
60
+ <Weight>1</Weight>
61
+ <Length>1</Length>
62
+ <Width>1</Width>
63
+ <Height>1</Height>
64
+ <OversizeCode>NONE</OversizeCode>
65
+ <FlatRateCode>NONE</FlatRateCode>
66
+ <CarrierRate>10.35</CarrierRate>
67
+ <Surcharge>0</Surcharge>
68
+ <FuelSurcharge>0</FuelSurcharge>
69
+ <Insurance>1.70</Insurance>
70
+ <Handling>0</Handling>
71
+ <ShipRate>12.05</ShipRate>
72
+ <PkgItem>
73
+ <RefCode>mouse</RefCode>
74
+ <Qty>1</Qty>
75
+ <Weight>1</Weight>
76
+ </PkgItem>
77
+ </Package>
78
+ </PackageDetail>
79
+ </ShipRate>
80
+ </ShipRateList>
81
+ </ItemShipRate>
82
+ </Body>
83
+ </Envelope>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0"?>
2
+ <Envelope>
3
+ <Header>
4
+ <Date>2010-07-23 19:44:33 GMT.</Date>
5
+ </Header>
6
+ <Body>
7
+ <Time>
8
+ <Value>2010-07-23 15:44:33 EDT</Value>
9
+ </Time>
10
+ </Body>
11
+ </Envelope>
@@ -0,0 +1,14 @@
1
+ <?xml version="2.1 encoding=iso-8859-1" utf-8 ?>
2
+ <Envelope>
3
+ <Header>
4
+ <AccountId>your access key</AccountId>
5
+ </Header>
6
+ <Body>
7
+ <Error>
8
+ <Code>560</Code>
9
+ <Message>Invalid Account Id</Message>
10
+ <Detail>USPPM:Item weight exceeds limit</Detail>
11
+ <Severity>CRITICAL</Severity>
12
+ </Error>
13
+ </Body>
14
+ </Envelope>
@@ -0,0 +1,28 @@
1
+ <?xml version="2.1" encoding="utf-8" ?>
2
+ <Envelope>
3
+ <Header>
4
+ <Date>2008-10-28 19:53:14 GMT</Date>
5
+ </Header>
6
+ <Body>
7
+ <ItemShipRate>
8
+ <Currency>USD</Currency>
9
+ <ShipRateList>
10
+ <ShipRate>
11
+ <Valid>False</Valid>
12
+ <CarrierCode>USPS</CarrierCode>
13
+ <ServiceCode>USPSPM</ServiceCode>
14
+ <ServiceName>PriorityMail</ServiceName>
15
+ <CalcMethod>C</CalcMethod>
16
+ <Rate></Rate>
17
+ <ErrorList>
18
+ <Error>
19
+ <Code>710</Code>
20
+ <Message>Item exceeds maximum weight</Message>
21
+ <Severity>NOTICE</Severity>
22
+ </Error>
23
+ </ErrorList>
24
+ </ShipRate>
25
+ </ShipRateList>
26
+ </ItemShipRate>
27
+ </Body>
28
+ </Envelope>
data/spec/spec_helper.rb CHANGED
@@ -1,8 +1,22 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
3
4
  require 'auction_inc'
4
5
  require 'spec'
5
6
  require 'spec/autorun'
6
7
 
7
8
  Spec::Runner.configure do |config|
8
9
  end
10
+
11
+ require 'fakeweb'
12
+
13
+ FakeWeb.allow_net_connect = false
14
+
15
+ def remote_fixture_file(filename)
16
+ return '' if filename == ''
17
+ File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', filename))
18
+ end
19
+
20
+ # Fake out the call to Auction Inc.
21
+ # e.g. http://api.auctioninc.com
22
+ # FakeWeb.register_uri(:post, %r|api\.auctioninc\.com/|, :body => remote_fixture_file('auction_inc_get_time_response.xml'))
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
7
+ - 2
8
8
  - 0
9
- version: 0.1.0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - pjkelly
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-02 00:00:00 -07:00
17
+ date: 2010-08-05 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -47,6 +47,21 @@ dependencies:
47
47
  version: 1.2.9
48
48
  type: :development
49
49
  version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: fakeweb
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 1
60
+ - 2
61
+ - 8
62
+ version: 1.2.8
63
+ type: :development
64
+ version_requirements: *id003
50
65
  description: Ruby wrapper around Auction Inc's shipping API.
51
66
  email: pj@crushlovely.com
52
67
  executables: []
@@ -63,6 +78,7 @@ files:
63
78
  - README.rdoc
64
79
  - Rakefile
65
80
  - VERSION
81
+ - auction_inc.gemspec
66
82
  - lib/auction_inc.rb
67
83
  - lib/auction_inc/shipping/base.rb
68
84
  - lib/auction_inc/shipping/carriers.yml
@@ -77,13 +93,24 @@ files:
77
93
  - lib/auction_inc/shipping/node/get_item_ship_rate_xs.rb
78
94
  - lib/auction_inc/shipping/node/header.rb
79
95
  - lib/auction_inc/shipping/node/item.rb
96
+ - lib/auction_inc/shipping/node/item_ship_rate.rb
80
97
  - lib/auction_inc/shipping/node/origin_address.rb
81
98
  - lib/auction_inc/shipping/node/package.rb
82
99
  - lib/auction_inc/shipping/node/pkg_item.rb
83
100
  - lib/auction_inc/shipping/node/service.rb
84
101
  - lib/auction_inc/shipping/node/ship_rate.rb
102
+ - lib/auction_inc/shipping/response.rb
85
103
  - lib/auction_inc/shipping/xs.rb
86
104
  - spec/auction_inc/shipping/base_spec.rb
105
+ - spec/auction_inc/shipping/error_spec.rb
106
+ - spec/auction_inc/shipping/item_ship_rate_spec.rb
107
+ - spec/auction_inc/shipping/response_spec.rb
108
+ - spec/fixtures/auction_inc_detail_level_1_response.xml
109
+ - spec/fixtures/auction_inc_detail_level_2_response.xml
110
+ - spec/fixtures/auction_inc_detail_level_3_response.xml
111
+ - spec/fixtures/auction_inc_get_time_response.xml
112
+ - spec/fixtures/auction_inc_type_1_error_response.xml
113
+ - spec/fixtures/auction_inc_type_2_error_response.xml
87
114
  - spec/spec.opts
88
115
  - spec/spec_helper.rb
89
116
  has_rdoc: true
@@ -120,4 +147,7 @@ specification_version: 3
120
147
  summary: Ruby wrapper around Auction Inc's shipping API.
121
148
  test_files:
122
149
  - spec/auction_inc/shipping/base_spec.rb
150
+ - spec/auction_inc/shipping/error_spec.rb
151
+ - spec/auction_inc/shipping/item_ship_rate_spec.rb
152
+ - spec/auction_inc/shipping/response_spec.rb
123
153
  - spec/spec_helper.rb