xero-ruby 17.0.0 → 18.0.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e32f8374264e3c569b5516a07e7b0333372a0b66be4b8b85ee1c048f7ebc3279
4
- data.tar.gz: 5a1f658681e28ff7fd54e76b098a211e463181a4e79fab1e1a9723d311e461cb
3
+ metadata.gz: 96f45f347a51f81dde31850a3d0d1fcc96bd01b1b0c7c9559e87cec16808d720
4
+ data.tar.gz: 2ab17bcfcd7df28c4df553b172c885b93372e763b380dcfae05672de11e67a53
5
5
  SHA512:
6
- metadata.gz: 045e16d9d499d8be07a004ee944ca85fd1161f4dd8d73727a00b74673d8875a0568a6ff0cdeae73ddee7c684fafc58cdb4b375c01f3fa503ea5a228fb238d39a
7
- data.tar.gz: b558f2795e55d1d9b0a6792e2c5d44aa0102a4d8e5fa65d39731861a029492513490bfa964e0194f601400296d41fca7f14f1b37a35d7dcbd02acabb223a7a94
6
+ metadata.gz: c244ccf0f61f4d4a03b4b2fe6ca7c9facaf53da212165ef9d0bde58f6443ba55c5d32a4ec1e61a00cf7f9b4f65a0b535cacb81440202e5251df0e32a8fb57122
7
+ data.tar.gz: b32b5677524d3122189c322864506cb8b248634a315d84c9d105a1816a38e9fb121ddc50bf1823245873a09ce9737a2d6fa21d18c582b711c564fa9072e7548c
@@ -4814,6 +4814,175 @@ module XeroRuby
4814
4814
  return data, status_code, headers
4815
4815
  end
4816
4816
 
4817
+ # Deletes a specific bank transfer
4818
+ # @param xero_tenant_id [String] Xero identifier for Tenant
4819
+ # @param bank_transfer_id [String] Xero generated unique identifier for a bank transfer
4820
+ # @param bank_transfer_delete_by_url_param [BankTransferDeleteByUrlParam]
4821
+ # @param [Hash] opts the optional parameters
4822
+ # @option opts [String] :idempotency_key This allows you to safely retry requests without the risk of duplicate processing. 128 character max.
4823
+ # @return [BankTransfers]
4824
+ def delete_bank_transfer(xero_tenant_id, bank_transfer_id, bank_transfer_delete_by_url_param, opts = {})
4825
+ data, _status_code, _headers = delete_bank_transfer_with_http_info(xero_tenant_id, bank_transfer_id, bank_transfer_delete_by_url_param, opts)
4826
+ data
4827
+ end
4828
+
4829
+ # Deletes a specific bank transfer
4830
+ # @param xero_tenant_id [String] Xero identifier for Tenant
4831
+ # @param bank_transfer_id [String] Xero generated unique identifier for a bank transfer
4832
+ # @param bank_transfer_delete_by_url_param [BankTransferDeleteByUrlParam]
4833
+ # @param [Hash] opts the optional parameters
4834
+ # @option opts [String] :idempotency_key This allows you to safely retry requests without the risk of duplicate processing. 128 character max.
4835
+ # @return [Array<(BankTransfers, Integer, Hash)>] BankTransfers data, response status code and response headers
4836
+ def delete_bank_transfer_with_http_info(xero_tenant_id, bank_transfer_id, bank_transfer_delete_by_url_param, options = {})
4837
+ opts = options.dup
4838
+ if @api_client.config.debugging
4839
+ @api_client.config.logger.debug 'Calling API: AccountingApi.delete_bank_transfer ...'
4840
+ end
4841
+ # verify the required parameter 'xero_tenant_id' is set
4842
+ if @api_client.config.client_side_validation && xero_tenant_id.nil?
4843
+ fail ArgumentError, "Missing the required parameter 'xero_tenant_id' when calling AccountingApi.delete_bank_transfer"
4844
+ end
4845
+ # verify the required parameter 'bank_transfer_id' is set
4846
+ if @api_client.config.client_side_validation && bank_transfer_id.nil?
4847
+ fail ArgumentError, "Missing the required parameter 'bank_transfer_id' when calling AccountingApi.delete_bank_transfer"
4848
+ end
4849
+ # verify the required parameter 'bank_transfer_delete_by_url_param' is set
4850
+ if @api_client.config.client_side_validation && bank_transfer_delete_by_url_param.nil?
4851
+ fail ArgumentError, "Missing the required parameter 'bank_transfer_delete_by_url_param' when calling AccountingApi.delete_bank_transfer"
4852
+ end
4853
+ # resource path
4854
+ local_var_path = '/BankTransfers/{BankTransferID}'.sub('{' + 'BankTransferID' + '}', bank_transfer_id.to_s)
4855
+
4856
+ # camelize keys of incoming `where` opts
4857
+ opts[:'where'] = @api_client.parameterize_where(opts[:'where']) if !opts[:'where'].nil?
4858
+
4859
+ # query parameters
4860
+ query_params = opts[:query_params] || {}
4861
+
4862
+ # XeroAPI's `IDs` convention openapi-generator does not snake_case properly.. manual over-riding `i_ds` malformations:
4863
+ query_params[:'IDs'] = @api_client.build_collection_param(opts[:'ids'], :csv) if !opts[:'ids'].nil?
4864
+ query_params[:'ContactIDs'] = @api_client.build_collection_param(opts[:'contact_ids'], :csv) if !opts[:'contact_ids'].nil?
4865
+
4866
+ # header parameters
4867
+ header_params = opts[:header_params] || {}
4868
+ # HTTP header 'Accept' (if needed)
4869
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
4870
+ # HTTP header 'Content-Type'
4871
+ header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
4872
+ header_params[:'xero-tenant-id'] = xero_tenant_id
4873
+ header_params[:'Idempotency-Key'] = opts[:'idempotency_key'] if !opts[:'idempotency_key'].nil?
4874
+
4875
+ # form parameters
4876
+ form_params = opts[:form_params] || {}
4877
+
4878
+ # http body (model)
4879
+ post_body = opts[:body] || @api_client.object_to_http_body(bank_transfer_delete_by_url_param)
4880
+
4881
+ # return_type
4882
+ return_type = opts[:return_type] || 'BankTransfers'
4883
+
4884
+ # auth_names
4885
+ auth_names = opts[:auth_names] || ['OAuth2']
4886
+
4887
+ new_options = opts.merge(
4888
+ :header_params => header_params,
4889
+ :query_params => query_params,
4890
+ :form_params => form_params,
4891
+ :body => post_body,
4892
+ :auth_names => auth_names,
4893
+ :return_type => return_type
4894
+ )
4895
+
4896
+ data, status_code, headers = @api_client.call_api(:POST, local_var_path, "AccountingApi", new_options)
4897
+ if @api_client.config.debugging
4898
+ @api_client.config.logger.debug "API called: AccountingApi#delete_bank_transfer\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
4899
+ end
4900
+ return data, status_code, headers
4901
+ end
4902
+
4903
+ # Deletes one or more bank transfers
4904
+ # @param xero_tenant_id [String] Xero identifier for Tenant
4905
+ # @param bank_transfers_delete [BankTransfersDelete] BankTransfers with array of BankTransfer objects in request body
4906
+ # @param [Hash] opts the optional parameters
4907
+ # @option opts [Boolean] :summarize_errors If false return 200 OK and mix of successfully created objects and any with validation errors (default to false)
4908
+ # @option opts [String] :idempotency_key This allows you to safely retry requests without the risk of duplicate processing. 128 character max.
4909
+ # @return [BankTransfers]
4910
+ def delete_bank_transfers(xero_tenant_id, bank_transfers_delete, opts = {})
4911
+ data, _status_code, _headers = delete_bank_transfers_with_http_info(xero_tenant_id, bank_transfers_delete, opts)
4912
+ data
4913
+ end
4914
+
4915
+ # Deletes one or more bank transfers
4916
+ # @param xero_tenant_id [String] Xero identifier for Tenant
4917
+ # @param bank_transfers_delete [BankTransfersDelete] BankTransfers with array of BankTransfer objects in request body
4918
+ # @param [Hash] opts the optional parameters
4919
+ # @option opts [Boolean] :summarize_errors If false return 200 OK and mix of successfully created objects and any with validation errors
4920
+ # @option opts [String] :idempotency_key This allows you to safely retry requests without the risk of duplicate processing. 128 character max.
4921
+ # @return [Array<(BankTransfers, Integer, Hash)>] BankTransfers data, response status code and response headers
4922
+ def delete_bank_transfers_with_http_info(xero_tenant_id, bank_transfers_delete, options = {})
4923
+ opts = options.dup
4924
+ if @api_client.config.debugging
4925
+ @api_client.config.logger.debug 'Calling API: AccountingApi.delete_bank_transfers ...'
4926
+ end
4927
+ # verify the required parameter 'xero_tenant_id' is set
4928
+ if @api_client.config.client_side_validation && xero_tenant_id.nil?
4929
+ fail ArgumentError, "Missing the required parameter 'xero_tenant_id' when calling AccountingApi.delete_bank_transfers"
4930
+ end
4931
+ # verify the required parameter 'bank_transfers_delete' is set
4932
+ if @api_client.config.client_side_validation && bank_transfers_delete.nil?
4933
+ fail ArgumentError, "Missing the required parameter 'bank_transfers_delete' when calling AccountingApi.delete_bank_transfers"
4934
+ end
4935
+ # resource path
4936
+ local_var_path = '/BankTransfers'
4937
+
4938
+ # camelize keys of incoming `where` opts
4939
+ opts[:'where'] = @api_client.parameterize_where(opts[:'where']) if !opts[:'where'].nil?
4940
+
4941
+ # query parameters
4942
+ query_params = opts[:query_params] || {}
4943
+ query_params[:'summarizeErrors'] = opts[:'summarize_errors'] if !opts[:'summarize_errors'].nil?
4944
+
4945
+ # XeroAPI's `IDs` convention openapi-generator does not snake_case properly.. manual over-riding `i_ds` malformations:
4946
+ query_params[:'IDs'] = @api_client.build_collection_param(opts[:'ids'], :csv) if !opts[:'ids'].nil?
4947
+ query_params[:'ContactIDs'] = @api_client.build_collection_param(opts[:'contact_ids'], :csv) if !opts[:'contact_ids'].nil?
4948
+
4949
+ # header parameters
4950
+ header_params = opts[:header_params] || {}
4951
+ # HTTP header 'Accept' (if needed)
4952
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
4953
+ # HTTP header 'Content-Type'
4954
+ header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
4955
+ header_params[:'xero-tenant-id'] = xero_tenant_id
4956
+ header_params[:'Idempotency-Key'] = opts[:'idempotency_key'] if !opts[:'idempotency_key'].nil?
4957
+
4958
+ # form parameters
4959
+ form_params = opts[:form_params] || {}
4960
+
4961
+ # http body (model)
4962
+ post_body = opts[:body] || @api_client.object_to_http_body(bank_transfers_delete)
4963
+
4964
+ # return_type
4965
+ return_type = opts[:return_type] || 'BankTransfers'
4966
+
4967
+ # auth_names
4968
+ auth_names = opts[:auth_names] || ['OAuth2']
4969
+
4970
+ new_options = opts.merge(
4971
+ :header_params => header_params,
4972
+ :query_params => query_params,
4973
+ :form_params => form_params,
4974
+ :body => post_body,
4975
+ :auth_names => auth_names,
4976
+ :return_type => return_type
4977
+ )
4978
+
4979
+ data, status_code, headers = @api_client.call_api(:POST, local_var_path, "AccountingApi", new_options)
4980
+ if @api_client.config.debugging
4981
+ @api_client.config.logger.debug "API called: AccountingApi#delete_bank_transfers\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
4982
+ end
4983
+ return data, status_code, headers
4984
+ end
4985
+
4817
4986
  # Updates a specific batch payment for invoices and credit notes
4818
4987
  # @param xero_tenant_id [String] Xero identifier for Tenant
4819
4988
  # @param batch_payment_delete [BatchPaymentDelete]
@@ -7157,6 +7326,7 @@ module XeroRuby
7157
7326
  # @option opts [DateTime] :if_modified_since Only records created or modified since this timestamp will be returned
7158
7327
  # @option opts [String] :where Filter by an any element
7159
7328
  # @option opts [String] :order Order by an any element
7329
+ # @option opts [Boolean] :include_deleted e.g. includeDeleted&#x3D;true - Bank transfers with a status of DELETED will be included in the response
7160
7330
  # @return [BankTransfers]
7161
7331
  def get_bank_transfers(xero_tenant_id, opts = {})
7162
7332
  data, _status_code, _headers = get_bank_transfers_with_http_info(xero_tenant_id, opts)
@@ -7169,6 +7339,7 @@ module XeroRuby
7169
7339
  # @option opts [DateTime] :if_modified_since Only records created or modified since this timestamp will be returned
7170
7340
  # @option opts [String] :where Filter by an any element
7171
7341
  # @option opts [String] :order Order by an any element
7342
+ # @option opts [Boolean] :include_deleted e.g. includeDeleted&#x3D;true - Bank transfers with a status of DELETED will be included in the response
7172
7343
  # @return [Array<(BankTransfers, Integer, Hash)>] BankTransfers data, response status code and response headers
7173
7344
  def get_bank_transfers_with_http_info(xero_tenant_id, options = {})
7174
7345
  opts = options.dup
@@ -7189,6 +7360,7 @@ module XeroRuby
7189
7360
  query_params = opts[:query_params] || {}
7190
7361
  query_params[:'where'] = opts[:'where'] if !opts[:'where'].nil?
7191
7362
  query_params[:'order'] = opts[:'order'] if !opts[:'order'].nil?
7363
+ query_params[:'includeDeleted'] = opts[:'include_deleted'] if !opts[:'include_deleted'].nil?
7192
7364
 
7193
7365
  # XeroAPI's `IDs` convention openapi-generator does not snake_case properly.. manual over-riding `i_ds` malformations:
7194
7366
  query_params[:'IDs'] = @api_client.build_collection_param(opts[:'ids'], :csv) if !opts[:'ids'].nil?
@@ -55,9 +55,42 @@ module XeroRuby::Accounting
55
55
  # UTC timestamp of creation date of bank transfer
56
56
  attr_accessor :created_date_utc
57
57
 
58
+ # AUTHORISED or DELETED (read-only). New bank transfers will have a status of AUTHORISED.
59
+ attr_accessor :status
60
+ AUTHORISED ||= "AUTHORISED".freeze
61
+ DELETED ||= "DELETED".freeze
62
+
63
+ # Optional Tracking Category for the source account – see Tracking. A bank transfer can have a maximum of 2 tracking categories per account.
64
+ attr_accessor :from_tracking
65
+
66
+ # Optional Tracking Category for the destination account – see Tracking. A bank transfer can have a maximum of 2 tracking categories per account.
67
+ attr_accessor :to_tracking
68
+
58
69
  # Displays array of validation error messages from the API
59
70
  attr_accessor :validation_errors
60
71
 
72
+ class EnumAttributeValidator
73
+ attr_reader :datatype
74
+ attr_reader :allowable_values
75
+
76
+ def initialize(datatype, allowable_values)
77
+ @allowable_values = allowable_values.map do |value|
78
+ case datatype.to_s
79
+ when /Integer/i
80
+ value.to_i
81
+ when /Float/i
82
+ value.to_f
83
+ else
84
+ value
85
+ end
86
+ end
87
+ end
88
+
89
+ def valid?(value)
90
+ !value || allowable_values.include?(value)
91
+ end
92
+ end
93
+
61
94
  # Attribute mapping from ruby-style variable name to JSON key.
62
95
  def self.attribute_map
63
96
  {
@@ -74,6 +107,9 @@ module XeroRuby::Accounting
74
107
  :'reference' => :'Reference',
75
108
  :'has_attachments' => :'HasAttachments',
76
109
  :'created_date_utc' => :'CreatedDateUTC',
110
+ :'status' => :'Status',
111
+ :'from_tracking' => :'FromTracking',
112
+ :'to_tracking' => :'ToTracking',
77
113
  :'validation_errors' => :'ValidationErrors'
78
114
  }
79
115
  end
@@ -94,6 +130,9 @@ module XeroRuby::Accounting
94
130
  :'reference' => :'String',
95
131
  :'has_attachments' => :'Boolean',
96
132
  :'created_date_utc' => :'DateTime',
133
+ :'status' => :'String',
134
+ :'from_tracking' => :'Array<TrackingReference>',
135
+ :'to_tracking' => :'Array<TrackingReference>',
97
136
  :'validation_errors' => :'Array<ValidationError>'
98
137
  }
99
138
  end
@@ -171,6 +210,22 @@ module XeroRuby::Accounting
171
210
  self.created_date_utc = attributes[:'created_date_utc']
172
211
  end
173
212
 
213
+ if attributes.key?(:'status')
214
+ self.status = attributes[:'status']
215
+ end
216
+
217
+ if attributes.key?(:'from_tracking')
218
+ if (value = attributes[:'from_tracking']).is_a?(Array)
219
+ self.from_tracking = value
220
+ end
221
+ end
222
+
223
+ if attributes.key?(:'to_tracking')
224
+ if (value = attributes[:'to_tracking']).is_a?(Array)
225
+ self.to_tracking = value
226
+ end
227
+ end
228
+
174
229
  if attributes.key?(:'validation_errors')
175
230
  if (value = attributes[:'validation_errors']).is_a?(Array)
176
231
  self.validation_errors = value
@@ -203,9 +258,21 @@ module XeroRuby::Accounting
203
258
  return false if @from_bank_account.nil?
204
259
  return false if @to_bank_account.nil?
205
260
  return false if @amount.nil?
261
+ status_validator = EnumAttributeValidator.new('String', ["AUTHORISED", "DELETED"])
262
+ return false unless status_validator.valid?(@status)
206
263
  true
207
264
  end
208
265
 
266
+ # Custom attribute writer method checking allowed values (enum).
267
+ # @param [Object] status Object to be assigned
268
+ def status=(status)
269
+ validator = EnumAttributeValidator.new('String', ["AUTHORISED", "DELETED"])
270
+ unless validator.valid?(status)
271
+ fail ArgumentError, "invalid value for \"status\", must be one of #{validator.allowable_values}."
272
+ end
273
+ @status = status
274
+ end
275
+
209
276
  # Checks equality by comparing each attribute.
210
277
  # @param [Object] Object to be compared
211
278
  def ==(o)
@@ -224,6 +291,9 @@ module XeroRuby::Accounting
224
291
  reference == o.reference &&
225
292
  has_attachments == o.has_attachments &&
226
293
  created_date_utc == o.created_date_utc &&
294
+ status == o.status &&
295
+ from_tracking == o.from_tracking &&
296
+ to_tracking == o.to_tracking &&
227
297
  validation_errors == o.validation_errors
228
298
  end
229
299
 
@@ -236,7 +306,7 @@ module XeroRuby::Accounting
236
306
  # Calculates hash code according to all attributes.
237
307
  # @return [Integer] Hash code
238
308
  def hash
239
- [from_bank_account, to_bank_account, amount, date, bank_transfer_id, currency_rate, from_bank_transaction_id, to_bank_transaction_id, from_is_reconciled, to_is_reconciled, reference, has_attachments, created_date_utc, validation_errors].hash
309
+ [from_bank_account, to_bank_account, amount, date, bank_transfer_id, currency_rate, from_bank_transaction_id, to_bank_transaction_id, from_is_reconciled, to_is_reconciled, reference, has_attachments, created_date_utc, status, from_tracking, to_tracking, validation_errors].hash
240
310
  end
241
311
 
242
312
  # Builds the object from hash
@@ -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 BankTransferDelete
19
+ # The Xero identifier for a bank transfer
20
+ attr_accessor :bank_transfer_id
21
+
22
+ # The status of the bank transfer.
23
+ attr_accessor :status
24
+
25
+ # Attribute mapping from ruby-style variable name to JSON key.
26
+ def self.attribute_map
27
+ {
28
+ :'bank_transfer_id' => :'BankTransferID',
29
+ :'status' => :'Status'
30
+ }
31
+ end
32
+
33
+ # Attribute type mapping.
34
+ def self.openapi_types
35
+ {
36
+ :'bank_transfer_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::BankTransferDelete` 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::BankTransferDelete`. 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?(:'bank_transfer_id')
57
+ self.bank_transfer_id = attributes[:'bank_transfer_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 @bank_transfer_id.nil?
72
+ invalid_properties.push('invalid value for "bank_transfer_id", bank_transfer_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 @bank_transfer_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
+ bank_transfer_id == o.bank_transfer_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
+ [bank_transfer_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