xeroizer 2.20.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +126 -185
- data/lib/xeroizer/connection.rb +49 -0
- data/lib/xeroizer/exceptions.rb +2 -0
- data/lib/xeroizer/generic_application.rb +8 -3
- data/lib/xeroizer/http.rb +5 -80
- data/lib/xeroizer/http_response.rb +154 -0
- data/lib/xeroizer/models/bank_transaction.rb +1 -0
- data/lib/xeroizer/models/batch_payment.rb +4 -1
- data/lib/xeroizer/models/contact.rb +10 -4
- data/lib/xeroizer/models/credit_note.rb +20 -20
- data/lib/xeroizer/models/history_record.rb +72 -0
- data/lib/xeroizer/models/invoice.rb +5 -1
- data/lib/xeroizer/models/line_item.rb +4 -2
- data/lib/xeroizer/models/manual_journal.rb +2 -1
- data/lib/xeroizer/models/option.rb +1 -1
- data/lib/xeroizer/models/payroll/address.rb +53 -0
- data/lib/xeroizer/models/payroll/bank_account.rb +18 -6
- data/lib/xeroizer/models/payroll/benefit_line.rb +26 -0
- data/lib/xeroizer/models/payroll/benefit_type.rb +45 -0
- data/lib/xeroizer/models/payroll/deduction_line.rb +32 -0
- data/lib/xeroizer/models/payroll/deduction_type.rb +49 -0
- data/lib/xeroizer/models/payroll/earnings_line.rb +39 -0
- data/lib/xeroizer/models/payroll/earnings_type.rb +53 -0
- data/lib/xeroizer/models/payroll/employee.rb +30 -8
- data/lib/xeroizer/models/payroll/leave_application.rb +27 -0
- data/lib/xeroizer/models/payroll/leave_line.rb +30 -0
- data/lib/xeroizer/models/payroll/leave_period.rb +15 -0
- data/lib/xeroizer/models/payroll/pay_items.rb +22 -0
- data/lib/xeroizer/models/payroll/pay_run.rb +33 -0
- data/lib/xeroizer/models/payroll/pay_schedule.rb +40 -0
- data/lib/xeroizer/models/payroll/pay_template.rb +24 -0
- data/lib/xeroizer/models/payroll/payment_method.rb +24 -0
- data/lib/xeroizer/models/payroll/paystub.rb +44 -0
- data/lib/xeroizer/models/payroll/reimbursement_line.rb +21 -0
- data/lib/xeroizer/models/payroll/reimbursement_type.rb +22 -0
- data/lib/xeroizer/models/payroll/salary_and_wage.rb +29 -0
- data/lib/xeroizer/models/payroll/super_line.rb +40 -0
- data/lib/xeroizer/models/payroll/tax_declaration.rb +50 -0
- data/lib/xeroizer/models/payroll/time_off_line.rb +20 -0
- data/lib/xeroizer/models/payroll/time_off_type.rb +32 -0
- data/lib/xeroizer/models/payroll/work_location.rb +25 -0
- data/lib/xeroizer/models/quote.rb +76 -0
- data/lib/xeroizer/models/tax_component.rb +1 -0
- data/lib/xeroizer/oauth.rb +12 -1
- data/lib/xeroizer/oauth2.rb +82 -0
- data/lib/xeroizer/oauth2_application.rb +49 -0
- data/lib/xeroizer/payroll_application.rb +8 -3
- data/lib/xeroizer/record/base_model.rb +1 -1
- data/lib/xeroizer/record/base_model_http_proxy.rb +1 -0
- data/lib/xeroizer/record/payroll_base.rb +4 -0
- data/lib/xeroizer/record/record_association_helper.rb +4 -4
- data/lib/xeroizer/record/validators/associated_validator.rb +1 -0
- data/lib/xeroizer/record/xml_helper.rb +16 -16
- data/lib/xeroizer/response.rb +22 -17
- data/lib/xeroizer/version.rb +1 -1
- data/lib/xeroizer.rb +31 -4
- data/test/acceptance/about_creating_bank_transactions_test.rb +80 -82
- data/test/acceptance/about_creating_prepayment_test.rb +25 -30
- data/test/acceptance/about_fetching_bank_transactions_test.rb +10 -10
- data/test/acceptance/about_online_invoice_test.rb +6 -10
- data/test/acceptance/acceptance_test.rb +28 -26
- data/test/acceptance/bank_transfer_test.rb +12 -17
- data/test/acceptance/bulk_operations_test.rb +18 -16
- data/test/acceptance/connections_test.rb +11 -0
- data/test/stub_responses/bad_request.json +6 -0
- data/test/stub_responses/connections.json +16 -0
- data/test/stub_responses/expired_oauth2_token.json +6 -0
- data/test/stub_responses/generic_response_error.json +6 -0
- data/test/stub_responses/invalid_oauth2_request_token.json +6 -0
- data/test/stub_responses/invalid_tenant_header.json +6 -0
- data/test/stub_responses/object_not_found.json +6 -0
- data/test/test_helper.rb +16 -11
- data/test/unit/generic_application_test.rb +21 -10
- data/test/unit/http_test.rb +281 -9
- data/test/unit/models/address_test.rb +2 -2
- data/test/unit/models/bank_transaction_model_parsing_test.rb +2 -2
- data/test/unit/models/bank_transaction_test.rb +1 -1
- data/test/unit/models/bank_transaction_validation_test.rb +1 -1
- data/test/unit/models/contact_test.rb +2 -2
- data/test/unit/models/credit_note_test.rb +8 -8
- data/test/unit/models/employee_test.rb +4 -4
- data/test/unit/models/invoice_test.rb +12 -12
- data/test/unit/models/journal_line_test.rb +6 -6
- data/test/unit/models/journal_test.rb +4 -4
- data/test/unit/models/line_item_sum_test.rb +1 -1
- data/test/unit/models/line_item_test.rb +19 -2
- data/test/unit/models/manual_journal_test.rb +3 -3
- data/test/unit/models/organisation_test.rb +2 -2
- data/test/unit/models/payment_service_test.rb +2 -2
- data/test/unit/models/phone_test.rb +7 -7
- data/test/unit/models/prepayment_test.rb +4 -4
- data/test/unit/models/repeating_invoice_test.rb +2 -2
- data/test/unit/models/tax_rate_test.rb +2 -2
- data/test/unit/oauth2_test.rb +171 -0
- data/test/unit/oauth_config_test.rb +1 -1
- data/test/unit/record/base_model_test.rb +13 -13
- data/test/unit/record/base_test.rb +5 -4
- data/test/unit/record/block_validator_test.rb +1 -1
- data/test/unit/record/connection_test.rb +60 -0
- data/test/unit/record/model_definition_test.rb +36 -36
- data/test/unit/record/parse_params_test.rb +2 -2
- data/test/unit/record/parse_where_hash_test.rb +13 -13
- data/test/unit/record/record_association_test.rb +14 -14
- data/test/unit/record/validators_test.rb +43 -43
- data/test/unit/record_definition_test.rb +7 -7
- data/test/unit/report_definition_test.rb +7 -7
- data/test/unit/report_test.rb +20 -20
- data/test/unit_test_helper.rb +16 -0
- metadata +106 -23
- data/lib/xeroizer/models/payroll/home_address.rb +0 -24
- data/lib/xeroizer/partner_application.rb +0 -51
- data/lib/xeroizer/private_application.rb +0 -25
- data/lib/xeroizer/public_application.rb +0 -21
- data/test/unit/http_tsl_12_upgrade_test.rb +0 -31
- data/test/unit/oauth_test.rb +0 -118
- data/test/unit/private_application_test.rb +0 -20
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'json'
|
3
|
-
|
4
|
-
class HttpTest < Test::Unit::TestCase
|
5
|
-
include TestHelper
|
6
|
-
|
7
|
-
def setup
|
8
|
-
@application = Xeroizer::PrivateApplication.new(CONSUMER_KEY, CONSUMER_SECRET, PRIVATE_KEY_PATH, {:xero_url => 'https://api-tls.xero.com/', :site => 'https://api-tls.xero.com/'})
|
9
|
-
@applicationExternal = Xeroizer::PrivateApplication.new(CONSUMER_KEY, CONSUMER_SECRET, PRIVATE_KEY_PATH, {:xero_url => 'https://www.howsmyssl.com', :site => 'https://www.howsmyssl.com'})
|
10
|
-
end
|
11
|
-
|
12
|
-
context "Connect to Xero TLS 1.2 Test endpoint" do
|
13
|
-
should "receive a 301 response (endpoint redirects on success)" do
|
14
|
-
begin
|
15
|
-
@application.http_get(@application.client, "https://api-tls.xero.com/")
|
16
|
-
rescue Xeroizer::Http::BadResponse => e
|
17
|
-
assert_equal "Unknown response code: 301", e.message, "Unexpected Response Code (Xero): Check TLS 1.2 is set"
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context "Connect to external TLS 1.2 Test endpoint" do
|
24
|
-
should "respond with tls version 1.2" do
|
25
|
-
response = @applicationExternal.http_get(@applicationExternal.client, "https://www.howsmyssl.com/a/check")
|
26
|
-
jsonResponse = JSON.parse(response)
|
27
|
-
assert_equal "TLS 1.2", jsonResponse['tls_version'], "Unexpected Response (External): Check TLS 1.2 is set"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
data/test/unit/oauth_test.rb
DELETED
@@ -1,118 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class OAuthTest < Test::Unit::TestCase
|
4
|
-
include TestHelper
|
5
|
-
|
6
|
-
def setup
|
7
|
-
@client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
|
8
|
-
end
|
9
|
-
|
10
|
-
context "with oauth error handling" do
|
11
|
-
|
12
|
-
should "handle token expired" do
|
13
|
-
Xeroizer::OAuth.any_instance.stubs(:get).returns(stub(:plain_body => get_file_as_string("token_expired"), :code => "401"))
|
14
|
-
|
15
|
-
assert_raises Xeroizer::OAuth::TokenExpired do
|
16
|
-
@client.Organisation.first
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
should "handle invalid request tokens" do
|
21
|
-
Xeroizer::OAuth.any_instance.stubs(:get).returns(stub(:plain_body => get_file_as_string("invalid_request_token"), :code => "401"))
|
22
|
-
|
23
|
-
assert_raises Xeroizer::OAuth::TokenInvalid do
|
24
|
-
@client.Organisation.first
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
should "handle invalid consumer key" do
|
29
|
-
Xeroizer::OAuth.any_instance.stubs(:get).returns(stub(:plain_body => get_file_as_string("invalid_consumer_key"), :code => "401"))
|
30
|
-
|
31
|
-
assert_raises Xeroizer::OAuth::TokenInvalid do
|
32
|
-
@client.Organisation.first
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
should "handle nonce used" do
|
37
|
-
Xeroizer::OAuth.any_instance.stubs(:get).returns(stub(:plain_body => get_file_as_string("nonce_used"), :code => "401"))
|
38
|
-
|
39
|
-
assert_raises Xeroizer::OAuth::NonceUsed do
|
40
|
-
@client.Organisation.first
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
should "raise rate limit exceeded" do
|
45
|
-
Xeroizer::OAuth.any_instance.stubs(:get).returns(stub(:plain_body => get_file_as_string("rate_limit_exceeded"), :code => "401"))
|
46
|
-
|
47
|
-
assert_raises Xeroizer::OAuth::RateLimitExceeded do
|
48
|
-
@client.Organisation.first
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
should "automatically handle rate limit exceeded" do
|
53
|
-
auto_rate_limit_client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET, :rate_limit_sleep => 1)
|
54
|
-
|
55
|
-
# Return rate limit exceeded on first call, OK on the second
|
56
|
-
Xeroizer::OAuth.any_instance.stubs(:get).returns(
|
57
|
-
stub(:plain_body => get_file_as_string("rate_limit_exceeded"), :code => "401"),
|
58
|
-
stub(:plain_body => get_record_xml(:organisation), :code => '200')
|
59
|
-
)
|
60
|
-
|
61
|
-
auto_rate_limit_client.expects(:sleep_for).with(1).returns(1)
|
62
|
-
|
63
|
-
auto_rate_limit_client.Organisation.first
|
64
|
-
end
|
65
|
-
|
66
|
-
should "only retry rate limited request a configurable number of times" do
|
67
|
-
auto_rate_limit_client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET, :rate_limit_sleep => 1, :rate_limit_max_attempts => 4)
|
68
|
-
Xeroizer::OAuth.any_instance.stubs(:get).returns(stub(:plain_body => get_file_as_string("rate_limit_exceeded"), :code => "401"))
|
69
|
-
|
70
|
-
auto_rate_limit_client.expects(:sleep_for).with(1).times(4).returns(1)
|
71
|
-
|
72
|
-
assert_raises Xeroizer::OAuth::RateLimitExceeded do
|
73
|
-
auto_rate_limit_client.Organisation.first
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
should "retry nonce_used failures a configurable number of times" do
|
78
|
-
nonce_used_client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET, :nonce_used_max_attempts => 4)
|
79
|
-
Xeroizer::OAuth.any_instance.stubs(:get).returns(stub(:plain_body => get_file_as_string("nonce_used"), :code => "401"))
|
80
|
-
|
81
|
-
nonce_used_client.expects(:sleep_for).with(1).times(4).returns(1)
|
82
|
-
|
83
|
-
assert_raises Xeroizer::OAuth::NonceUsed do
|
84
|
-
nonce_used_client.Organisation.first
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
should "handle unknown errors" do
|
89
|
-
Xeroizer::OAuth.any_instance.stubs(:get).returns(stub(:plain_body => get_file_as_string("bogus_oauth_error"), :code => "401"))
|
90
|
-
|
91
|
-
assert_raises Xeroizer::OAuth::UnknownError do
|
92
|
-
@client.Organisation.first
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
should "handle ApiExceptions" do
|
97
|
-
Xeroizer::OAuth.any_instance.stubs(:put).returns(stub(:plain_body => get_file_as_string("api_exception.xml"),
|
98
|
-
:code => "400"))
|
99
|
-
|
100
|
-
assert_raises Xeroizer::ApiException do
|
101
|
-
contact = @client.Contact.build(:name => 'Test Contact')
|
102
|
-
contact.save!
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
should "handle random root elements" do
|
107
|
-
Xeroizer::OAuth.any_instance.stubs(:put).returns(stub(:plain_body => "<RandomRootElement></RandomRootElement>",
|
108
|
-
:code => "200"))
|
109
|
-
|
110
|
-
assert_raises Xeroizer::UnparseableResponse do
|
111
|
-
contact = @client.Contact.build(:name => 'Test Contact')
|
112
|
-
contact.save!
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
end
|
117
|
-
|
118
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class PrivateApplicationTest < Test::Unit::TestCase
|
4
|
-
include TestHelper
|
5
|
-
|
6
|
-
def setup
|
7
|
-
@client = Xeroizer::PrivateApplication.new(CONSUMER_KEY, CONSUMER_SECRET, PRIVATE_KEY_PATH)
|
8
|
-
end
|
9
|
-
|
10
|
-
context "initialization" do
|
11
|
-
|
12
|
-
should "have a valid client" do
|
13
|
-
assert_kind_of(Xeroizer::OAuth, @client.client)
|
14
|
-
assert_equal(CONSUMER_KEY, @client.client.ctoken)
|
15
|
-
assert_equal(CONSUMER_SECRET, @client.client.csecret)
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|