Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/xero-ruby/api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ def payroll_au_api
XeroRuby::PayrollAuApi.new(self)
end

def payroll_au_v2_api
@config.base_url = @config.payroll_au_v2_url
XeroRuby::PayrollAuV2Api.new(self)
end

def payroll_nz_api
@config.base_url = @config.payroll_nz_url
XeroRuby::PayrollNzApi.new(self)
Expand Down Expand Up @@ -289,6 +294,8 @@ def call_api(http_method, path, api_client, opts = {})
method_base_url = @config.files_url
when "PayrollAuApi"
method_base_url = @config.payroll_au_url
when "PayrollAuV2Api"
method_base_url = @config.payroll_au_v2_url
when "PayrollNzApi"
method_base_url = @config.payroll_nz_url
when "PayrollUkApi"
Expand Down Expand Up @@ -517,6 +524,8 @@ def convert_to_type(data, return_type, api_client)
XeroRuby::Files.const_get(return_type).build_from_hash(data)
when 'PayrollAuApi'
XeroRuby::PayrollAu.const_get(return_type).build_from_hash(data)
when 'PayrollAuV2Api'
XeroRuby::PayrollAuV2.const_get(return_type).build_from_hash(data)
when 'PayrollNzApi'
XeroRuby::PayrollNz.const_get(return_type).build_from_hash(data)
when 'PayrollUkApi'
Expand Down
2 changes: 2 additions & 0 deletions lib/xero-ruby/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Configuration
attr_accessor :project_url
attr_accessor :files_url
attr_accessor :payroll_au_url
attr_accessor :payroll_au_v2_url
attr_accessor :payroll_nz_url
attr_accessor :payroll_uk_url
attr_accessor :app_store_url
Expand Down Expand Up @@ -149,6 +150,7 @@ def initialize
@project_url = 'https://api.xero.com/projects.xro/2.0/'
@files_url = 'https://api.xero.com/files.xro/1.0/'
@payroll_au_url = 'https://api.xero.com/payroll.xro/1.0/'
@payroll_au_v2_url = 'https://api.xero.com/payroll.xro/2.0/'
@payroll_nz_url = 'https://api.xero.com/payroll.xro/2.0/'
@payroll_uk_url = 'https://api.xero.com/payroll.xro/2.0/'
@app_store_url = 'https://api.xero.com/appstore/2.0/'
Expand Down
13 changes: 13 additions & 0 deletions spec/api_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@

api_client.payroll_au_api
expect(api_client.config.base_url).to eq('https://api.xero.com/payroll.xro/1.0/')

expect(api_client.payroll_au_v2_api).to be_a(XeroRuby::PayrollAuV2Api)
expect(api_client.config.base_url).to eq('https://api.xero.com/payroll.xro/2.0/')

api_client.payroll_nz_api
expect(api_client.config.base_url).to eq('https://api.xero.com/payroll.xro/2.0/')
Expand Down Expand Up @@ -221,6 +224,16 @@
expect(data).to be_instance_of(Hash)
expect(data).to eq(:message => 'Hello')
end

it 'deserializes Payroll AU v2 models in their own namespace' do
api_client = XeroRuby::ApiClient.new
headers = { 'Content-Type' => 'application/json' }
response = double('response', headers: headers, body: '{}')

data = api_client.deserialize(response, 'TimesheetObject', 'PayrollAuV2Api')

expect(data).to be_instance_of(XeroRuby::PayrollAuV2::TimesheetObject)
end
end

describe "#object_to_hash modifies a hash from snake_case to PascalCase" do
Expand Down
1 change: 1 addition & 0 deletions spec/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
expect(config.project_url).to eq('https://api.xero.com/projects.xro/2.0/')
expect(config.files_url).to eq('https://api.xero.com/files.xro/1.0/')
expect(config.payroll_au_url).to eq('https://api.xero.com/payroll.xro/1.0/')
expect(config.payroll_au_v2_url).to eq('https://api.xero.com/payroll.xro/2.0/')
expect(config.payroll_nz_url).to eq('https://api.xero.com/payroll.xro/2.0/')
expect(config.payroll_uk_url).to eq('https://api.xero.com/payroll.xro/2.0/')
expect(config.finance_url).to eq('https://api.xero.com/finance.xro/1.0/')
Expand Down