xero-ruby 3.9.0 → 3.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/xero-ruby/api/accounting_api.rb +403 -0
- data/lib/xero-ruby/api/project_api.rb +263 -0
- data/lib/xero-ruby/models/accounting/batch_payment_delete.rb +244 -0
- data/lib/xero-ruby/models/accounting/batch_payment_delete_by_url_param.rb +229 -0
- data/lib/xero-ruby/models/accounting/organisation.rb +3 -2
- data/lib/xero-ruby/models/accounting/repeating_invoice.rb +53 -5
- data/lib/xero-ruby/models/accounting/tax_rate.rb +3 -2
- data/lib/xero-ruby/models/accounting/tax_type.rb +1 -0
- data/lib/xero-ruby/models/payroll_au/earnings_type.rb +2 -0
- data/lib/xero-ruby/models/payroll_au/employee.rb +1 -1
- data/lib/xero-ruby/models/payroll_au/leave_category_code.rb +46 -0
- data/lib/xero-ruby/models/payroll_au/leave_type.rb +24 -4
- data/lib/xero-ruby/models/payroll_au/tax_declaration.rb +11 -1
- data/lib/xero-ruby/models/projects/task.rb +6 -6
- data/lib/xero-ruby/models/projects/task_create_or_update.rb +1 -1
- data/lib/xero-ruby/version.rb +2 -2
- data/lib/xero-ruby.rb +3 -0
- metadata +9 -6
@@ -93,6 +93,91 @@ module XeroRuby
|
|
93
93
|
return data, status_code, headers
|
94
94
|
end
|
95
95
|
|
96
|
+
# Allows you to create a task
|
97
|
+
# Allows you to create a specific task
|
98
|
+
# @param xero_tenant_id [String] Xero identifier for Tenant
|
99
|
+
# @param project_id [String] You can create a task on a specified projectId
|
100
|
+
# @param task_create_or_update [TaskCreateOrUpdate] The task object you are creating
|
101
|
+
# @param [Hash] opts the optional parameters
|
102
|
+
# @return [nil]
|
103
|
+
def create_task(xero_tenant_id, project_id, task_create_or_update, opts = {})
|
104
|
+
create_task_with_http_info(xero_tenant_id, project_id, task_create_or_update, opts)
|
105
|
+
nil
|
106
|
+
end
|
107
|
+
|
108
|
+
# Allows you to create a task
|
109
|
+
# Allows you to create a specific task
|
110
|
+
# @param xero_tenant_id [String] Xero identifier for Tenant
|
111
|
+
# @param project_id [String] You can create a task on a specified projectId
|
112
|
+
# @param task_create_or_update [TaskCreateOrUpdate] The task object you are creating
|
113
|
+
# @param [Hash] opts the optional parameters
|
114
|
+
# @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
|
115
|
+
def create_task_with_http_info(xero_tenant_id, project_id, task_create_or_update, options = {})
|
116
|
+
opts = options.dup
|
117
|
+
if @api_client.config.debugging
|
118
|
+
@api_client.config.logger.debug 'Calling API: ProjectApi.create_task ...'
|
119
|
+
end
|
120
|
+
# verify the required parameter 'xero_tenant_id' is set
|
121
|
+
if @api_client.config.client_side_validation && xero_tenant_id.nil?
|
122
|
+
fail ArgumentError, "Missing the required parameter 'xero_tenant_id' when calling ProjectApi.create_task"
|
123
|
+
end
|
124
|
+
# verify the required parameter 'project_id' is set
|
125
|
+
if @api_client.config.client_side_validation && project_id.nil?
|
126
|
+
fail ArgumentError, "Missing the required parameter 'project_id' when calling ProjectApi.create_task"
|
127
|
+
end
|
128
|
+
# verify the required parameter 'task_create_or_update' is set
|
129
|
+
if @api_client.config.client_side_validation && task_create_or_update.nil?
|
130
|
+
fail ArgumentError, "Missing the required parameter 'task_create_or_update' when calling ProjectApi.create_task"
|
131
|
+
end
|
132
|
+
# resource path
|
133
|
+
local_var_path = '/Projects/{projectId}/Tasks'.sub('{' + 'projectId' + '}', project_id.to_s)
|
134
|
+
|
135
|
+
# camelize keys of incoming `where` opts
|
136
|
+
opts[:'where'] = @api_client.parameterize_where(opts[:'where']) if !opts[:'where'].nil?
|
137
|
+
|
138
|
+
# query parameters
|
139
|
+
query_params = opts[:query_params] || {}
|
140
|
+
|
141
|
+
# XeroAPI's `IDs` convention openapi-generator does not snake_case properly.. manual over-riding `i_ds` malformations:
|
142
|
+
query_params[:'IDs'] = @api_client.build_collection_param(opts[:'ids'], :csv) if !opts[:'ids'].nil?
|
143
|
+
query_params[:'ContactIDs'] = @api_client.build_collection_param(opts[:'contact_ids'], :csv) if !opts[:'contact_ids'].nil?
|
144
|
+
|
145
|
+
# header parameters
|
146
|
+
header_params = opts[:header_params] || {}
|
147
|
+
# HTTP header 'Accept' (if needed)
|
148
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
149
|
+
# HTTP header 'Content-Type'
|
150
|
+
header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
|
151
|
+
header_params[:'Xero-Tenant-Id'] = xero_tenant_id
|
152
|
+
|
153
|
+
# form parameters
|
154
|
+
form_params = opts[:form_params] || {}
|
155
|
+
|
156
|
+
# http body (model)
|
157
|
+
post_body = opts[:body] || @api_client.object_to_http_body(task_create_or_update)
|
158
|
+
|
159
|
+
# return_type
|
160
|
+
return_type = opts[:return_type]
|
161
|
+
|
162
|
+
# auth_names
|
163
|
+
auth_names = opts[:auth_names] || ['OAuth2']
|
164
|
+
|
165
|
+
new_options = opts.merge(
|
166
|
+
:header_params => header_params,
|
167
|
+
:query_params => query_params,
|
168
|
+
:form_params => form_params,
|
169
|
+
:body => post_body,
|
170
|
+
:auth_names => auth_names,
|
171
|
+
:return_type => return_type
|
172
|
+
)
|
173
|
+
|
174
|
+
data, status_code, headers = @api_client.call_api(:POST, local_var_path, "ProjectApi", new_options)
|
175
|
+
if @api_client.config.debugging
|
176
|
+
@api_client.config.logger.debug "API called: ProjectApi#create_task\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
177
|
+
end
|
178
|
+
return data, status_code, headers
|
179
|
+
end
|
180
|
+
|
96
181
|
# Creates a time entry for a specific project
|
97
182
|
# Allows you to create a specific task
|
98
183
|
# @param xero_tenant_id [String] Xero identifier for Tenant
|
@@ -178,6 +263,89 @@ module XeroRuby
|
|
178
263
|
return data, status_code, headers
|
179
264
|
end
|
180
265
|
|
266
|
+
# Allows you to delete a task
|
267
|
+
# Allows you to delete a specific task
|
268
|
+
# @param xero_tenant_id [String] Xero identifier for Tenant
|
269
|
+
# @param project_id [String] You can specify an individual project by appending the projectId to the endpoint
|
270
|
+
# @param task_id [String] You can specify an individual task by appending the id to the endpoint
|
271
|
+
# @param [Hash] opts the optional parameters
|
272
|
+
# @return [nil]
|
273
|
+
def delete_task(xero_tenant_id, project_id, task_id, opts = {})
|
274
|
+
delete_task_with_http_info(xero_tenant_id, project_id, task_id, opts)
|
275
|
+
nil
|
276
|
+
end
|
277
|
+
|
278
|
+
# Allows you to delete a task
|
279
|
+
# Allows you to delete a specific task
|
280
|
+
# @param xero_tenant_id [String] Xero identifier for Tenant
|
281
|
+
# @param project_id [String] You can specify an individual project by appending the projectId to the endpoint
|
282
|
+
# @param task_id [String] You can specify an individual task by appending the id to the endpoint
|
283
|
+
# @param [Hash] opts the optional parameters
|
284
|
+
# @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
|
285
|
+
def delete_task_with_http_info(xero_tenant_id, project_id, task_id, options = {})
|
286
|
+
opts = options.dup
|
287
|
+
if @api_client.config.debugging
|
288
|
+
@api_client.config.logger.debug 'Calling API: ProjectApi.delete_task ...'
|
289
|
+
end
|
290
|
+
# verify the required parameter 'xero_tenant_id' is set
|
291
|
+
if @api_client.config.client_side_validation && xero_tenant_id.nil?
|
292
|
+
fail ArgumentError, "Missing the required parameter 'xero_tenant_id' when calling ProjectApi.delete_task"
|
293
|
+
end
|
294
|
+
# verify the required parameter 'project_id' is set
|
295
|
+
if @api_client.config.client_side_validation && project_id.nil?
|
296
|
+
fail ArgumentError, "Missing the required parameter 'project_id' when calling ProjectApi.delete_task"
|
297
|
+
end
|
298
|
+
# verify the required parameter 'task_id' is set
|
299
|
+
if @api_client.config.client_side_validation && task_id.nil?
|
300
|
+
fail ArgumentError, "Missing the required parameter 'task_id' when calling ProjectApi.delete_task"
|
301
|
+
end
|
302
|
+
# resource path
|
303
|
+
local_var_path = '/Projects/{projectId}/Tasks/{taskId}'.sub('{' + 'projectId' + '}', project_id.to_s).sub('{' + 'taskId' + '}', task_id.to_s)
|
304
|
+
|
305
|
+
# camelize keys of incoming `where` opts
|
306
|
+
opts[:'where'] = @api_client.parameterize_where(opts[:'where']) if !opts[:'where'].nil?
|
307
|
+
|
308
|
+
# query parameters
|
309
|
+
query_params = opts[:query_params] || {}
|
310
|
+
|
311
|
+
# XeroAPI's `IDs` convention openapi-generator does not snake_case properly.. manual over-riding `i_ds` malformations:
|
312
|
+
query_params[:'IDs'] = @api_client.build_collection_param(opts[:'ids'], :csv) if !opts[:'ids'].nil?
|
313
|
+
query_params[:'ContactIDs'] = @api_client.build_collection_param(opts[:'contact_ids'], :csv) if !opts[:'contact_ids'].nil?
|
314
|
+
|
315
|
+
# header parameters
|
316
|
+
header_params = opts[:header_params] || {}
|
317
|
+
# HTTP header 'Accept' (if needed)
|
318
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
319
|
+
header_params[:'Xero-Tenant-Id'] = xero_tenant_id
|
320
|
+
|
321
|
+
# form parameters
|
322
|
+
form_params = opts[:form_params] || {}
|
323
|
+
|
324
|
+
# http body (model)
|
325
|
+
post_body = opts[:body]
|
326
|
+
|
327
|
+
# return_type
|
328
|
+
return_type = opts[:return_type]
|
329
|
+
|
330
|
+
# auth_names
|
331
|
+
auth_names = opts[:auth_names] || ['OAuth2']
|
332
|
+
|
333
|
+
new_options = opts.merge(
|
334
|
+
:header_params => header_params,
|
335
|
+
:query_params => query_params,
|
336
|
+
:form_params => form_params,
|
337
|
+
:body => post_body,
|
338
|
+
:auth_names => auth_names,
|
339
|
+
:return_type => return_type
|
340
|
+
)
|
341
|
+
|
342
|
+
data, status_code, headers = @api_client.call_api(:DELETE, local_var_path, "ProjectApi", new_options)
|
343
|
+
if @api_client.config.debugging
|
344
|
+
@api_client.config.logger.debug "API called: ProjectApi#delete_task\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
345
|
+
end
|
346
|
+
return data, status_code, headers
|
347
|
+
end
|
348
|
+
|
181
349
|
# Deletes a time entry for a specific project
|
182
350
|
# Allows you to delete a specific time entry
|
183
351
|
# @param xero_tenant_id [String] Xero identifier for Tenant
|
@@ -229,6 +397,8 @@ module XeroRuby
|
|
229
397
|
|
230
398
|
# header parameters
|
231
399
|
header_params = opts[:header_params] || {}
|
400
|
+
# HTTP header 'Accept' (if needed)
|
401
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
232
402
|
header_params[:'Xero-Tenant-Id'] = xero_tenant_id
|
233
403
|
|
234
404
|
# form parameters
|
@@ -1047,6 +1217,97 @@ module XeroRuby
|
|
1047
1217
|
return data, status_code, headers
|
1048
1218
|
end
|
1049
1219
|
|
1220
|
+
# Allows you to update a task
|
1221
|
+
# Allows you to update a specific task
|
1222
|
+
# @param xero_tenant_id [String] Xero identifier for Tenant
|
1223
|
+
# @param project_id [String] You can specify an individual project by appending the projectId to the endpoint
|
1224
|
+
# @param task_id [String] You can specify an individual task by appending the id to the endpoint
|
1225
|
+
# @param task_create_or_update [TaskCreateOrUpdate] The task object you are updating
|
1226
|
+
# @param [Hash] opts the optional parameters
|
1227
|
+
# @return [nil]
|
1228
|
+
def update_task(xero_tenant_id, project_id, task_id, task_create_or_update, opts = {})
|
1229
|
+
update_task_with_http_info(xero_tenant_id, project_id, task_id, task_create_or_update, opts)
|
1230
|
+
nil
|
1231
|
+
end
|
1232
|
+
|
1233
|
+
# Allows you to update a task
|
1234
|
+
# Allows you to update a specific task
|
1235
|
+
# @param xero_tenant_id [String] Xero identifier for Tenant
|
1236
|
+
# @param project_id [String] You can specify an individual project by appending the projectId to the endpoint
|
1237
|
+
# @param task_id [String] You can specify an individual task by appending the id to the endpoint
|
1238
|
+
# @param task_create_or_update [TaskCreateOrUpdate] The task object you are updating
|
1239
|
+
# @param [Hash] opts the optional parameters
|
1240
|
+
# @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
|
1241
|
+
def update_task_with_http_info(xero_tenant_id, project_id, task_id, task_create_or_update, options = {})
|
1242
|
+
opts = options.dup
|
1243
|
+
if @api_client.config.debugging
|
1244
|
+
@api_client.config.logger.debug 'Calling API: ProjectApi.update_task ...'
|
1245
|
+
end
|
1246
|
+
# verify the required parameter 'xero_tenant_id' is set
|
1247
|
+
if @api_client.config.client_side_validation && xero_tenant_id.nil?
|
1248
|
+
fail ArgumentError, "Missing the required parameter 'xero_tenant_id' when calling ProjectApi.update_task"
|
1249
|
+
end
|
1250
|
+
# verify the required parameter 'project_id' is set
|
1251
|
+
if @api_client.config.client_side_validation && project_id.nil?
|
1252
|
+
fail ArgumentError, "Missing the required parameter 'project_id' when calling ProjectApi.update_task"
|
1253
|
+
end
|
1254
|
+
# verify the required parameter 'task_id' is set
|
1255
|
+
if @api_client.config.client_side_validation && task_id.nil?
|
1256
|
+
fail ArgumentError, "Missing the required parameter 'task_id' when calling ProjectApi.update_task"
|
1257
|
+
end
|
1258
|
+
# verify the required parameter 'task_create_or_update' is set
|
1259
|
+
if @api_client.config.client_side_validation && task_create_or_update.nil?
|
1260
|
+
fail ArgumentError, "Missing the required parameter 'task_create_or_update' when calling ProjectApi.update_task"
|
1261
|
+
end
|
1262
|
+
# resource path
|
1263
|
+
local_var_path = '/Projects/{projectId}/Tasks/{taskId}'.sub('{' + 'projectId' + '}', project_id.to_s).sub('{' + 'taskId' + '}', task_id.to_s)
|
1264
|
+
|
1265
|
+
# camelize keys of incoming `where` opts
|
1266
|
+
opts[:'where'] = @api_client.parameterize_where(opts[:'where']) if !opts[:'where'].nil?
|
1267
|
+
|
1268
|
+
# query parameters
|
1269
|
+
query_params = opts[:query_params] || {}
|
1270
|
+
|
1271
|
+
# XeroAPI's `IDs` convention openapi-generator does not snake_case properly.. manual over-riding `i_ds` malformations:
|
1272
|
+
query_params[:'IDs'] = @api_client.build_collection_param(opts[:'ids'], :csv) if !opts[:'ids'].nil?
|
1273
|
+
query_params[:'ContactIDs'] = @api_client.build_collection_param(opts[:'contact_ids'], :csv) if !opts[:'contact_ids'].nil?
|
1274
|
+
|
1275
|
+
# header parameters
|
1276
|
+
header_params = opts[:header_params] || {}
|
1277
|
+
# HTTP header 'Accept' (if needed)
|
1278
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
1279
|
+
# HTTP header 'Content-Type'
|
1280
|
+
header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
|
1281
|
+
header_params[:'Xero-Tenant-Id'] = xero_tenant_id
|
1282
|
+
|
1283
|
+
# form parameters
|
1284
|
+
form_params = opts[:form_params] || {}
|
1285
|
+
|
1286
|
+
# http body (model)
|
1287
|
+
post_body = opts[:body] || @api_client.object_to_http_body(task_create_or_update)
|
1288
|
+
|
1289
|
+
# return_type
|
1290
|
+
return_type = opts[:return_type]
|
1291
|
+
|
1292
|
+
# auth_names
|
1293
|
+
auth_names = opts[:auth_names] || ['OAuth2']
|
1294
|
+
|
1295
|
+
new_options = opts.merge(
|
1296
|
+
:header_params => header_params,
|
1297
|
+
:query_params => query_params,
|
1298
|
+
:form_params => form_params,
|
1299
|
+
:body => post_body,
|
1300
|
+
:auth_names => auth_names,
|
1301
|
+
:return_type => return_type
|
1302
|
+
)
|
1303
|
+
|
1304
|
+
data, status_code, headers = @api_client.call_api(:PUT, local_var_path, "ProjectApi", new_options)
|
1305
|
+
if @api_client.config.debugging
|
1306
|
+
@api_client.config.logger.debug "API called: ProjectApi#update_task\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
1307
|
+
end
|
1308
|
+
return data, status_code, headers
|
1309
|
+
end
|
1310
|
+
|
1050
1311
|
# Updates a time entry for a specific project
|
1051
1312
|
# Allows you to update time entry in a project
|
1052
1313
|
# @param xero_tenant_id [String] Xero identifier for Tenant
|
@@ -1104,6 +1365,8 @@ module XeroRuby
|
|
1104
1365
|
|
1105
1366
|
# header parameters
|
1106
1367
|
header_params = opts[:header_params] || {}
|
1368
|
+
# HTTP header 'Accept' (if needed)
|
1369
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
1107
1370
|
# HTTP header 'Content-Type'
|
1108
1371
|
header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
|
1109
1372
|
header_params[:'Xero-Tenant-Id'] = xero_tenant_id
|
@@ -0,0 +1,244 @@
|
|
1
|
+
=begin
|
2
|
+
#Xero Accounting API
|
3
|
+
|
4
|
+
#No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
5
|
+
|
6
|
+
Contact: api@xero.com
|
7
|
+
Generated by: https://openapi-generator.tech
|
8
|
+
OpenAPI Generator version: 4.3.1
|
9
|
+
|
10
|
+
=end
|
11
|
+
|
12
|
+
require 'time'
|
13
|
+
require 'date'
|
14
|
+
|
15
|
+
module XeroRuby::Accounting
|
16
|
+
require 'bigdecimal'
|
17
|
+
|
18
|
+
class BatchPaymentDelete
|
19
|
+
# The Xero generated unique identifier for the bank transaction (read-only)
|
20
|
+
attr_accessor :batch_payment_id
|
21
|
+
|
22
|
+
# The status of the batch payment.
|
23
|
+
attr_accessor :status
|
24
|
+
|
25
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
26
|
+
def self.attribute_map
|
27
|
+
{
|
28
|
+
:'batch_payment_id' => :'BatchPaymentID',
|
29
|
+
:'status' => :'Status'
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
# Attribute type mapping.
|
34
|
+
def self.openapi_types
|
35
|
+
{
|
36
|
+
:'batch_payment_id' => :'String',
|
37
|
+
:'status' => :'String'
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
# Initializes the object
|
42
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
43
|
+
def initialize(attributes = {})
|
44
|
+
if (!attributes.is_a?(Hash))
|
45
|
+
fail ArgumentError, "The input argument (attributes) must be a hash in `XeroRuby::Accounting::BatchPaymentDelete` initialize method"
|
46
|
+
end
|
47
|
+
|
48
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
49
|
+
attributes = attributes.each_with_object({}) { |(k, v), h|
|
50
|
+
if (!self.class.attribute_map.key?(k.to_sym))
|
51
|
+
fail ArgumentError, "`#{k}` is not a valid attribute in `XeroRuby::Accounting::BatchPaymentDelete`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
|
52
|
+
end
|
53
|
+
h[k.to_sym] = v
|
54
|
+
}
|
55
|
+
|
56
|
+
if attributes.key?(:'batch_payment_id')
|
57
|
+
self.batch_payment_id = attributes[:'batch_payment_id']
|
58
|
+
end
|
59
|
+
|
60
|
+
if attributes.key?(:'status')
|
61
|
+
self.status = attributes[:'status']
|
62
|
+
else
|
63
|
+
self.status = 'DELETED'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
68
|
+
# @return Array for valid properties with the reasons
|
69
|
+
def list_invalid_properties
|
70
|
+
invalid_properties = Array.new
|
71
|
+
if @batch_payment_id.nil?
|
72
|
+
invalid_properties.push('invalid value for "batch_payment_id", batch_payment_id cannot be nil.')
|
73
|
+
end
|
74
|
+
|
75
|
+
if @status.nil?
|
76
|
+
invalid_properties.push('invalid value for "status", status cannot be nil.')
|
77
|
+
end
|
78
|
+
|
79
|
+
invalid_properties
|
80
|
+
end
|
81
|
+
|
82
|
+
# Check to see if the all the properties in the model are valid
|
83
|
+
# @return true if the model is valid
|
84
|
+
def valid?
|
85
|
+
return false if @batch_payment_id.nil?
|
86
|
+
return false if @status.nil?
|
87
|
+
true
|
88
|
+
end
|
89
|
+
|
90
|
+
# Checks equality by comparing each attribute.
|
91
|
+
# @param [Object] Object to be compared
|
92
|
+
def ==(o)
|
93
|
+
return true if self.equal?(o)
|
94
|
+
self.class == o.class &&
|
95
|
+
batch_payment_id == o.batch_payment_id &&
|
96
|
+
status == o.status
|
97
|
+
end
|
98
|
+
|
99
|
+
# @see the `==` method
|
100
|
+
# @param [Object] Object to be compared
|
101
|
+
def eql?(o)
|
102
|
+
self == o
|
103
|
+
end
|
104
|
+
|
105
|
+
# Calculates hash code according to all attributes.
|
106
|
+
# @return [Integer] Hash code
|
107
|
+
def hash
|
108
|
+
[batch_payment_id, status].hash
|
109
|
+
end
|
110
|
+
|
111
|
+
# Builds the object from hash
|
112
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
113
|
+
# @return [Object] Returns the model itself
|
114
|
+
def self.build_from_hash(attributes)
|
115
|
+
new.build_from_hash(attributes)
|
116
|
+
end
|
117
|
+
|
118
|
+
# Builds the object from hash
|
119
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
120
|
+
# @return [Object] Returns the model itself
|
121
|
+
def build_from_hash(attributes)
|
122
|
+
return nil unless attributes.is_a?(Hash)
|
123
|
+
self.class.openapi_types.each_pair do |key, type|
|
124
|
+
if type =~ /\AArray<(.*)>/i
|
125
|
+
# check to ensure the input is an array given that the attribute
|
126
|
+
# is documented as an array but the input is not
|
127
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
128
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
|
129
|
+
end
|
130
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
131
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
132
|
+
end # or else data not found in attributes(hash), not an issue as the data can be optional
|
133
|
+
end
|
134
|
+
|
135
|
+
self
|
136
|
+
end
|
137
|
+
|
138
|
+
# Deserializes the data based on type
|
139
|
+
# @param string type Data type
|
140
|
+
# @param string value Value to be deserialized
|
141
|
+
# @return [Object] Deserialized data
|
142
|
+
def _deserialize(type, value)
|
143
|
+
case type.to_sym
|
144
|
+
when :DateTime
|
145
|
+
DateTime.parse(parse_date(value))
|
146
|
+
when :Date
|
147
|
+
Date.parse(parse_date(value))
|
148
|
+
when :String
|
149
|
+
value.to_s
|
150
|
+
when :Integer
|
151
|
+
value.to_i
|
152
|
+
when :Float
|
153
|
+
value.to_f
|
154
|
+
when :BigDecimal
|
155
|
+
BigDecimal(value.to_s)
|
156
|
+
when :Boolean
|
157
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
158
|
+
true
|
159
|
+
else
|
160
|
+
false
|
161
|
+
end
|
162
|
+
when :Object
|
163
|
+
# generic object (usually a Hash), return directly
|
164
|
+
value
|
165
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
166
|
+
inner_type = Regexp.last_match[:inner_type]
|
167
|
+
value.map { |v| _deserialize(inner_type, v) }
|
168
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
169
|
+
k_type = Regexp.last_match[:k_type]
|
170
|
+
v_type = Regexp.last_match[:v_type]
|
171
|
+
{}.tap do |hash|
|
172
|
+
value.each do |k, v|
|
173
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
else # model
|
177
|
+
XeroRuby::Accounting.const_get(type).build_from_hash(value)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
# Returns the string representation of the object
|
182
|
+
# @return [String] String presentation of the object
|
183
|
+
def to_s
|
184
|
+
to_hash.to_s
|
185
|
+
end
|
186
|
+
|
187
|
+
# to_body is an alias to to_hash (backward compatibility)
|
188
|
+
# @return [Hash] Returns the object in the form of hash
|
189
|
+
def to_body
|
190
|
+
to_hash
|
191
|
+
end
|
192
|
+
|
193
|
+
# Returns the object in the form of hash
|
194
|
+
# @return [Hash] Returns the object in the form of hash
|
195
|
+
def to_hash(downcase: false)
|
196
|
+
hash = {}
|
197
|
+
self.class.attribute_map.each_pair do |attr, param|
|
198
|
+
value = self.send(attr)
|
199
|
+
next if value.nil?
|
200
|
+
key = downcase ? attr : param
|
201
|
+
hash[key] = _to_hash(value, downcase: downcase)
|
202
|
+
end
|
203
|
+
hash
|
204
|
+
end
|
205
|
+
|
206
|
+
# Returns the object in the form of hash with snake_case
|
207
|
+
def to_attributes
|
208
|
+
to_hash(downcase: true)
|
209
|
+
end
|
210
|
+
|
211
|
+
# Outputs non-array value in the form of hash
|
212
|
+
# For object, use to_hash. Otherwise, just return the value
|
213
|
+
# @param [Object] value Any valid value
|
214
|
+
# @return [Hash] Returns the value in the form of hash
|
215
|
+
def _to_hash(value, downcase: false)
|
216
|
+
if value.is_a?(Array)
|
217
|
+
value.map do |v|
|
218
|
+
v.to_hash(downcase: downcase)
|
219
|
+
end
|
220
|
+
elsif value.is_a?(Hash)
|
221
|
+
{}.tap do |hash|
|
222
|
+
value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) }
|
223
|
+
end
|
224
|
+
elsif value.respond_to? :to_hash
|
225
|
+
value.to_hash(downcase: downcase)
|
226
|
+
else
|
227
|
+
value
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
def parse_date(datestring)
|
232
|
+
if datestring.include?('Date')
|
233
|
+
date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\//
|
234
|
+
original, date, timezone = *date_pattern.match(datestring)
|
235
|
+
date = (date.to_i / 1000)
|
236
|
+
Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s
|
237
|
+
elsif /(\d\d\d\d)-(\d\d)/.match(datestring) # handles dates w/out Days: YYYY-MM*-DD
|
238
|
+
Time.parse(datestring + '-01').strftime('%Y-%m-%dT%H:%M:%S').to_s
|
239
|
+
else # handle date 'types' for small subset of payroll API's
|
240
|
+
Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|