xeroizer 2.15.6 → 2.15.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/xeroizer/http.rb CHANGED
@@ -133,17 +133,22 @@ module Xeroizer
133
133
  def handle_oauth_error!(response)
134
134
  error_details = CGI.parse(response.plain_body)
135
135
  description = error_details["oauth_problem_advice"].first
136
+ problem = error_details["oauth_problem"].first
136
137
 
137
138
  # see http://oauth.pbworks.com/ProblemReporting
138
139
  # In addition to token_expired and token_rejected, Xero also returns
139
140
  # 'rate limit exceeded' when more than 60 requests have been made in
140
141
  # a second.
141
- case (error_details["oauth_problem"].first)
142
- when "token_expired" then raise OAuth::TokenExpired.new(description)
143
- when "token_rejected" then raise OAuth::TokenInvalid.new(description)
144
- when "rate limit exceeded" then raise OAuth::RateLimitExceeded.new(description)
145
- when error_details["oauth_problem"] then raise OAuth::UnknownError.new(error_details["oauth_problem"].first + ':' + description)
146
- else raise OAuth::UnknownError.new("Xero API may be down or the way OAuth errors are provided by Xero may have changed.")
142
+ if problem
143
+ case (problem)
144
+ when "token_expired" then raise OAuth::TokenExpired.new(description)
145
+ when "token_rejected" then raise OAuth::TokenInvalid.new(description)
146
+ when "rate limit exceeded" then raise OAuth::RateLimitExceeded.new(description)
147
+ when "consumer_key_unknown" then raise OAuth::ConsumerKeyUnknown.new(description)
148
+ else raise OAuth::UnknownError.new(problem + ':' + description)
149
+ end
150
+ else
151
+ raise OAuth::UnknownError.new("Xero API may be down or the way OAuth errors are provided by Xero may have changed.")
147
152
  end
148
153
  end
149
154
 
@@ -1,10 +1,13 @@
1
1
  require 'xeroizer/models/line_item'
2
2
  require 'xeroizer/models/line_item_sum'
3
+ require 'xeroizer/models/attachment'
3
4
 
4
5
  module Xeroizer
5
6
  module Record
6
7
  class BankTransactionModel < BaseModel
7
8
  set_permissions :read
9
+
10
+ include AttachmentModel::Extensions
8
11
  end
9
12
 
10
13
  class BankTransaction < Base
@@ -15,6 +18,7 @@ module Xeroizer
15
18
  } unless defined?(BANK_TRANSACTION_STATUS)
16
19
  BANK_TRANSACTION_STATUSES = BANK_TRANSACTION_STATUS.keys.sort
17
20
 
21
+ include Attachment::Extensions
18
22
 
19
23
  def initialize(parent)
20
24
  super parent
@@ -14,11 +14,9 @@ module Xeroizer
14
14
  end
15
15
 
16
16
  class TaxRate < Base
17
- set_primary_key :tax_type
18
- set_possible_primary_keys :tax_type, :name
19
-
20
17
  set_primary_key :name
21
-
18
+ set_possible_primary_keys :tax_type, :name
19
+
22
20
  string :name
23
21
  string :tax_type
24
22
  string :status
@@ -27,8 +27,9 @@ module Xeroizer
27
27
  class TokenExpired < StandardError; end
28
28
  class TokenInvalid < StandardError; end
29
29
  class RateLimitExceeded < StandardError; end
30
+ class ConsumerKeyUnknown < StandardError; end
30
31
  class UnknownError < StandardError; end
31
-
32
+
32
33
  unless defined? XERO_CONSUMER_OPTIONS
33
34
  XERO_CONSUMER_OPTIONS = {
34
35
  :site => "https://api.xero.com",
@@ -1,3 +1,3 @@
1
1
  module Xeroizer
2
- VERSION = "2.15.6".freeze
2
+ VERSION = "2.15.7".freeze
3
3
  end
data/lib/xeroizer.rb CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'date'
3
3
  require 'forwardable'
4
4
  require 'active_support/inflector'
5
- # require "active_support/core_ext"
5
+ require "active_support/core_ext"
6
6
  require 'oauth'
7
7
  require 'oauth/signature/rsa/sha1'
8
8
  require 'nokogiri'
@@ -11,7 +11,7 @@ require 'time'
11
11
  require 'bigdecimal'
12
12
  require 'cgi'
13
13
 
14
- $: << File.expand_path(File.dirname(__FILE__))
14
+ $: << File.expand_path(File.dirname(__FILE__))
15
15
 
16
16
  require 'big_decimal_to_s'
17
17
  require 'class_level_inheritable_attributes'
@@ -8,7 +8,7 @@ class BankTransactionValidationTest < Test::Unit::TestCase
8
8
 
9
9
  assert false == instance.valid?, "Expected invalid because of invalid type"
10
10
 
11
- expected_error = "Invalid type. Expected either SPEND or RECEIVE."
11
+ expected_error = "Invalid type. Expected either SPEND, RECEIVE, RECEIVE-PREPAYMENT or RECEIVE-OVERPAYMENT."
12
12
 
13
13
  assert_equal expected_error, instance.errors_for(:type).first, "Expected an error about type"
14
14
 
@@ -8,12 +8,12 @@ class TaxRateTest < Test::Unit::TestCase
8
8
  @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
9
9
  end
10
10
 
11
- should "have a primary key value of :tax_type" do
12
- assert_equal :tax_type, Xeroizer::Record::TaxRate.primary_key_name
11
+ should "have a primary key value of :name" do
12
+ assert_equal :name, Xeroizer::Record::TaxRate.primary_key_name
13
13
  end
14
14
 
15
15
  should "build and save a tax rate with components via PUT" do
16
- @client.expects(:http_put).with { |client, url, body, extra_params|
16
+ @client.expects(:http_post).with { |client, url, body, extra_params|
17
17
  url == "https://api.xero.com/api.xro/2.0/TaxRates" &&
18
18
  body == expected_tax_rate_create_body
19
19
  }.returns(tax_rate_create_successful_response)
@@ -75,7 +75,7 @@ class OAuthTest < Test::Unit::TestCase
75
75
  end
76
76
 
77
77
  should "handle ApiExceptions" do
78
- Xeroizer::OAuth.any_instance.stubs(:post).returns(stub(:plain_body => get_file_as_string("api_exception.xml"),
78
+ Xeroizer::OAuth.any_instance.stubs(:put).returns(stub(:plain_body => get_file_as_string("api_exception.xml"),
79
79
  :code => "400"))
80
80
 
81
81
  assert_raises Xeroizer::ApiException do
@@ -85,7 +85,7 @@ class OAuthTest < Test::Unit::TestCase
85
85
  end
86
86
 
87
87
  should "handle random root elements" do
88
- Xeroizer::OAuth.any_instance.stubs(:post).returns(stub(:plain_body => "<RandomRootElement></RandomRootElement>",
88
+ Xeroizer::OAuth.any_instance.stubs(:put).returns(stub(:plain_body => "<RandomRootElement></RandomRootElement>",
89
89
  :code => "200"))
90
90
 
91
91
  assert_raises Xeroizer::UnparseableResponse do
@@ -33,7 +33,7 @@ class RecordBaseTest < Test::Unit::TestCase
33
33
  end
34
34
 
35
35
  should "new_record? should be false after successfully creating a record" do
36
- Xeroizer::OAuth.any_instance.stubs(:post).returns(stub(:plain_body => get_record_xml(:contact), :code => '200'))
36
+ Xeroizer::OAuth.any_instance.stubs(:put).returns(stub(:plain_body => get_record_xml(:contact), :code => '200'))
37
37
  assert_equal(true, @contact.new_record?)
38
38
  assert_nil(@contact.contact_id)
39
39
  assert_equal(true, @contact.save, "Error saving contact: #{@contact.errors.inspect}")
@@ -6,7 +6,7 @@ class RecordAssociationTest < Test::Unit::TestCase
6
6
  def setup
7
7
  @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
8
8
  mock_api('Invoices')
9
- @client.stubs(:http_post).returns(get_record_xml(:invoice, "762aa45d-4632-45b5-8087-b4f47690665e"))
9
+ @client.stubs(:http_put).returns(get_record_xml(:invoice, "762aa45d-4632-45b5-8087-b4f47690665e"))
10
10
  end
11
11
 
12
12
  context "belongs_to association" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xeroizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.15.6
4
+ version: 2.15.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -630,7 +630,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
630
630
  version: '0'
631
631
  segments:
632
632
  - 0
633
- hash: 1906039754233718837
633
+ hash: -261170401126906910
634
634
  required_rubygems_version: !ruby/object:Gem::Requirement
635
635
  none: false
636
636
  requirements:
@@ -639,7 +639,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
639
639
  version: '0'
640
640
  segments:
641
641
  - 0
642
- hash: 1906039754233718837
642
+ hash: -261170401126906910
643
643
  requirements: []
644
644
  rubyforge_project:
645
645
  rubygems_version: 1.8.29