xero_gateway 2.0.8 → 2.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,14 +1,17 @@
1
1
  module XeroGateway
2
2
  class ApiException < StandardError
3
3
 
4
- def initialize(type, message, xml)
4
+ def initialize(type, message, request_xml, response_xml)
5
5
  @type = type
6
6
  @message = message
7
- @xml = xml
7
+ @request_xml = request_xml
8
+ @response_xml = response_xml
8
9
  end
9
10
 
11
+ attr_reader :request_xml, :response_xml
12
+
10
13
  def message
11
- "#{@type}: #{@message} \n Generated by the following XML: \n #{@xml}"
14
+ "#{@type}: #{@message} \n Generated by the following XML: \n #{@response_xml}"
12
15
  end
13
16
 
14
17
  end
@@ -70,7 +70,7 @@ module XeroGateway
70
70
  when 200
71
71
  response.plain_body
72
72
  when 400
73
- handle_error!(response)
73
+ handle_error!(body, response)
74
74
  when 401
75
75
  handle_oauth_error!(response)
76
76
  when 404
@@ -90,13 +90,14 @@ module XeroGateway
90
90
  # a second.
91
91
  case (error_details["oauth_problem"].first)
92
92
  when "token_expired" then raise OAuth::TokenExpired.new(description)
93
+ when "consumer_key_unknown" then raise OAuth::TokenInvalid.new(description)
93
94
  when "token_rejected" then raise OAuth::TokenInvalid.new(description)
94
95
  when "rate limit exceeded" then raise OAuth::RateLimitExceeded.new(description)
95
96
  else raise OAuth::UnknownError.new(error_details["oauth_problem"].first + ':' + description)
96
97
  end
97
98
  end
98
99
 
99
- def handle_error!(response)
100
+ def handle_error!(request_xml, response)
100
101
 
101
102
  raw_response = response.plain_body
102
103
 
@@ -109,7 +110,8 @@ module XeroGateway
109
110
  if doc.root.name == "ApiException"
110
111
 
111
112
  raise ApiException.new(doc.root.elements["Type"].text,
112
- doc.root.elements["Message"].text,
113
+ doc.root.elements["Message"].text,
114
+ request_xml,
113
115
  raw_response)
114
116
 
115
117
  else
@@ -10,7 +10,7 @@ module XeroGateway
10
10
  attr_reader :errors
11
11
 
12
12
  # All accessible fields
13
- attr_accessor :line_item_id, :description, :quantity, :unit_amount, :tax_type, :tax_amount, :account_code, :tracking
13
+ attr_accessor :line_item_id, :description, :quantity, :unit_amount, :item_code, :tax_type, :tax_amount, :account_code, :tracking
14
14
 
15
15
  def initialize(params = {})
16
16
  @errors ||= []
@@ -75,6 +75,7 @@ module XeroGateway
75
75
  b.Description description
76
76
  b.Quantity quantity if quantity
77
77
  b.UnitAmount LineItem.format_money(unit_amount)
78
+ b.ItemCode item_code if item_code
78
79
  b.TaxType tax_type if tax_type
79
80
  b.TaxAmount tax_amount if tax_amount
80
81
  b.LineAmount line_amount if line_amount
@@ -100,6 +101,7 @@ module XeroGateway
100
101
  when "Description" then line_item.description = element.text
101
102
  when "Quantity" then line_item.quantity = BigDecimal(element.text)
102
103
  when "UnitAmount" then line_item.unit_amount = BigDecimal.new(element.text)
104
+ when "ItemCode" then line_item.item_code = element.text
103
105
  when "TaxType" then line_item.tax_type = element.text
104
106
  when "TaxAmount" then line_item.tax_amount = BigDecimal.new(element.text)
105
107
  when "LineAmount" then line_item.line_amount = BigDecimal.new(element.text)
@@ -114,7 +116,7 @@ module XeroGateway
114
116
  end
115
117
 
116
118
  def ==(other)
117
- [:description, :quantity, :unit_amount, :tax_type, :tax_amount, :line_amount, :account_code].each do |field|
119
+ [:description, :quantity, :unit_amount, :tax_type, :tax_amount, :line_amount, :account_code, :item_code].each do |field|
118
120
  return false if send(field) != other.send(field)
119
121
  end
120
122
  return true
@@ -18,7 +18,7 @@ class GatewayTest < Test::Unit::TestCase
18
18
  end
19
19
 
20
20
  should "handle invalid request tokens" do
21
- XeroGateway::OAuth.any_instance.stubs(:http_get).returns(stub(:plain_body => get_file_as_string("invalid_request_token"), :code => "401"))
21
+ XeroGateway::OAuth.any_instance.stubs(:get).returns(stub(:plain_body => get_file_as_string("invalid_request_token"), :code => "401"))
22
22
 
23
23
  assert_raises XeroGateway::OAuth::TokenInvalid do
24
24
  @gateway.get_accounts
@@ -26,7 +26,7 @@ class GatewayTest < Test::Unit::TestCase
26
26
  end
27
27
 
28
28
  should "handle invalid consumer key" do
29
- XeroGateway::OAuth.any_instance.stubs(:http_get).returns(stub(:plain_body => get_file_as_string("invalid_consumer_key"), :code => "401"))
29
+ XeroGateway::OAuth.any_instance.stubs(:get).returns(stub(:plain_body => get_file_as_string("invalid_consumer_key"), :code => "401"))
30
30
 
31
31
  assert_raises XeroGateway::OAuth::TokenInvalid do
32
32
  @gateway.get_accounts
data/xero_gateway.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "xero_gateway"
3
- s.version = "2.0.8"
4
- s.date = "2011-02-14"
3
+ s.version = "2.0.9"
4
+ s.date = "2011-04-12"
5
5
  s.summary = "Enables ruby based applications to communicate with the Xero API"
6
6
  s.email = "tim@connorsoftware.com"
7
7
  s.homepage = "http://github.com/tlconnor/xero_gateway"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xero_gateway
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
5
- prerelease: false
4
+ hash: 29
5
+ prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
- - 8
10
- version: 2.0.8
9
+ - 9
10
+ version: 2.0.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tim Connor
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-02-14 00:00:00 +13:00
19
+ date: 2011-04-12 00:00:00 +12:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -163,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
163
  requirements: []
164
164
 
165
165
  rubyforge_project:
166
- rubygems_version: 1.3.7
166
+ rubygems_version: 1.6.2
167
167
  signing_key:
168
168
  specification_version: 3
169
169
  summary: Enables ruby based applications to communicate with the Xero API