xero-ruby 3.2.0 → 3.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +71 -2
  3. data/lib/xero-ruby/api/accounting_api.rb +11 -2
  4. data/lib/xero-ruby/api/app_store_api.rb +87 -0
  5. data/lib/xero-ruby/api/finance_api.rb +866 -0
  6. data/lib/xero-ruby/api/payroll_au_api.rb +14 -14
  7. data/lib/xero-ruby/api/payroll_nz_api.rb +18 -12
  8. data/lib/xero-ruby/api/payroll_uk_api.rb +14 -2
  9. data/lib/xero-ruby/api_client.rb +30 -4
  10. data/lib/xero-ruby/configuration.rb +4 -0
  11. data/lib/xero-ruby/models/accounting/bank_transfer.rb +35 -1
  12. data/lib/xero-ruby/models/accounting/budget_balance.rb +2 -2
  13. data/lib/xero-ruby/models/accounting/contact.rb +86 -1
  14. data/lib/xero-ruby/models/accounting/payment.rb +11 -1
  15. data/lib/xero-ruby/models/accounting/time_zone.rb +1 -0
  16. data/lib/xero-ruby/models/app_store/plan.rb +310 -0
  17. data/lib/xero-ruby/models/app_store/price.rb +257 -0
  18. data/lib/xero-ruby/models/app_store/problem_details.rb +272 -0
  19. data/lib/xero-ruby/models/app_store/product.rb +288 -0
  20. data/lib/xero-ruby/models/app_store/subscription.rb +324 -0
  21. data/lib/xero-ruby/models/app_store/subscription_item.rb +292 -0
  22. data/lib/xero-ruby/models/finance/account_usage.rb +342 -0
  23. data/lib/xero-ruby/models/finance/account_usage_response.rb +254 -0
  24. data/lib/xero-ruby/models/finance/balance_sheet_account_detail.rb +262 -0
  25. data/lib/xero-ruby/models/finance/balance_sheet_account_group.rb +234 -0
  26. data/lib/xero-ruby/models/finance/balance_sheet_account_type.rb +244 -0
  27. data/lib/xero-ruby/models/finance/balance_sheet_response.rb +252 -0
  28. data/lib/xero-ruby/models/finance/bank_statement_response.rb +232 -0
  29. data/lib/xero-ruby/models/finance/cash_account_response.rb +262 -0
  30. data/lib/xero-ruby/models/finance/cash_balance.rb +242 -0
  31. data/lib/xero-ruby/models/finance/cash_validation_response.rb +262 -0
  32. data/lib/xero-ruby/models/finance/cashflow_account.rb +282 -0
  33. data/lib/xero-ruby/models/finance/cashflow_activity.rb +244 -0
  34. data/lib/xero-ruby/models/finance/cashflow_response.rb +254 -0
  35. data/lib/xero-ruby/models/finance/cashflow_type.rb +244 -0
  36. data/lib/xero-ruby/models/finance/contact_detail.rb +274 -0
  37. data/lib/xero-ruby/models/finance/contact_total_detail.rb +242 -0
  38. data/lib/xero-ruby/models/finance/contact_total_other.rb +252 -0
  39. data/lib/xero-ruby/models/finance/current_statement_response.rb +272 -0
  40. data/lib/xero-ruby/models/finance/data_source_response.rb +362 -0
  41. data/lib/xero-ruby/models/finance/history_record_response.rb +262 -0
  42. data/lib/xero-ruby/models/finance/income_by_contact_response.rb +284 -0
  43. data/lib/xero-ruby/models/finance/lock_history_model.rb +242 -0
  44. data/lib/xero-ruby/models/finance/lock_history_response.rb +244 -0
  45. data/lib/xero-ruby/models/finance/manual_journal_total.rb +222 -0
  46. data/lib/xero-ruby/models/finance/pnl_account.rb +272 -0
  47. data/lib/xero-ruby/models/finance/pnl_account_class.rb +234 -0
  48. data/lib/xero-ruby/models/finance/pnl_account_type.rb +244 -0
  49. data/lib/xero-ruby/models/finance/practice_response.rb +262 -0
  50. data/lib/xero-ruby/models/finance/problem.rb +252 -0
  51. data/lib/xero-ruby/models/finance/problem_type.rb +39 -0
  52. data/lib/xero-ruby/models/finance/profit_and_loss_response.rb +262 -0
  53. data/lib/xero-ruby/models/finance/report_history_model.rb +242 -0
  54. data/lib/xero-ruby/models/finance/report_history_response.rb +244 -0
  55. data/lib/xero-ruby/models/finance/statement_balance_response.rb +232 -0
  56. data/lib/xero-ruby/models/finance/statement_lines_response.rb +382 -0
  57. data/lib/xero-ruby/models/finance/total_detail.rb +242 -0
  58. data/lib/xero-ruby/models/finance/total_other.rb +242 -0
  59. data/lib/xero-ruby/models/finance/trial_balance_account.rb +312 -0
  60. data/lib/xero-ruby/models/finance/trial_balance_entry.rb +232 -0
  61. data/lib/xero-ruby/models/finance/trial_balance_movement.rb +252 -0
  62. data/lib/xero-ruby/models/finance/trial_balance_response.rb +244 -0
  63. data/lib/xero-ruby/models/finance/user_activities_response.rb +244 -0
  64. data/lib/xero-ruby/models/finance/user_response.rb +336 -0
  65. data/lib/xero-ruby/models/payroll_au/earnings_type.rb +2 -0
  66. data/lib/xero-ruby/models/payroll_au/employee.rb +30 -1
  67. data/lib/xero-ruby/models/payroll_au/manual_tax_type.rb +1 -0
  68. data/lib/xero-ruby/models/payroll_au/payroll_calendar.rb +11 -1
  69. data/lib/xero-ruby/models/payroll_uk/earnings_rate.rb +4 -4
  70. data/lib/xero-ruby/version.rb +6 -6
  71. data/lib/xero-ruby.rb +51 -0
  72. data/spec/api_client_spec.rb +5 -2
  73. data/spec/app_store/api/app_store_api_spec.rb +45 -0
  74. data/spec/app_store/models/plan_spec.rb +62 -0
  75. data/spec/app_store/models/price_spec.rb +52 -0
  76. data/spec/app_store/models/problem_details_spec.rb +70 -0
  77. data/spec/app_store/models/product_spec.rb +56 -0
  78. data/spec/app_store/models/subscription_item_spec.rb +70 -0
  79. data/spec/app_store/models/subscription_spec.rb +82 -0
  80. data/spec/configuration_spec.rb +1 -0
  81. data/spec/finance/api/finance_api_spec.rb +156 -0
  82. data/spec/finance/models/account_usage_response_spec.rb +58 -0
  83. data/spec/finance/models/account_usage_spec.rb +112 -0
  84. data/spec/finance/models/balance_sheet_account_detail_spec.rb +64 -0
  85. data/spec/finance/models/balance_sheet_account_group_spec.rb +46 -0
  86. data/spec/finance/models/balance_sheet_account_type_spec.rb +52 -0
  87. data/spec/finance/models/balance_sheet_response_spec.rb +58 -0
  88. data/spec/finance/models/bank_statement_response_spec.rb +46 -0
  89. data/spec/finance/models/cash_account_response_spec.rb +64 -0
  90. data/spec/finance/models/cash_balance_spec.rb +52 -0
  91. data/spec/finance/models/cash_validation_response_spec.rb +64 -0
  92. data/spec/finance/models/cashflow_account_spec.rb +76 -0
  93. data/spec/finance/models/cashflow_activity_spec.rb +52 -0
  94. data/spec/finance/models/cashflow_response_spec.rb +58 -0
  95. data/spec/finance/models/cashflow_type_spec.rb +52 -0
  96. data/spec/finance/models/current_statement_response_spec.rb +70 -0
  97. data/spec/finance/models/data_source_response_spec.rb +124 -0
  98. data/spec/finance/models/history_record_response_spec.rb +64 -0
  99. data/spec/finance/models/lock_history_model_spec.rb +52 -0
  100. data/spec/finance/models/lock_history_response_spec.rb +52 -0
  101. data/spec/finance/models/pnl_account_class_spec.rb +46 -0
  102. data/spec/finance/models/pnl_account_spec.rb +70 -0
  103. data/spec/finance/models/pnl_account_type_spec.rb +52 -0
  104. data/spec/finance/models/practice_response_spec.rb +64 -0
  105. data/spec/finance/models/problem_spec.rb +58 -0
  106. data/spec/finance/models/problem_type_spec.rb +34 -0
  107. data/spec/finance/models/profit_and_loss_response_spec.rb +64 -0
  108. data/spec/finance/models/report_history_model_spec.rb +52 -0
  109. data/spec/finance/models/report_history_response_spec.rb +52 -0
  110. data/spec/finance/models/statement_balance_response_spec.rb +46 -0
  111. data/spec/finance/models/statement_lines_response_spec.rb +136 -0
  112. data/spec/finance/models/trial_balance_account_spec.rb +94 -0
  113. data/spec/finance/models/trial_balance_entry_spec.rb +46 -0
  114. data/spec/finance/models/trial_balance_movement_spec.rb +58 -0
  115. data/spec/finance/models/trial_balance_response_spec.rb +52 -0
  116. data/spec/finance/models/user_activities_response_spec.rb +52 -0
  117. data/spec/finance/models/user_response_spec.rb +106 -0
  118. metadata +142 -3
@@ -0,0 +1,272 @@
1
+ =begin
2
+ #Xero AppStore API
3
+
4
+ #These endpoints are for Xero Partners to interact with the App Store Billing platform
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::AppStore
16
+ require 'bigdecimal'
17
+
18
+ class ProblemDetails
19
+
20
+ attr_accessor :detail
21
+
22
+
23
+ attr_accessor :extensions
24
+
25
+
26
+ attr_accessor :instance
27
+
28
+
29
+ attr_accessor :status
30
+
31
+
32
+ attr_accessor :title
33
+
34
+
35
+ attr_accessor :type
36
+
37
+ # Attribute mapping from ruby-style variable name to JSON key.
38
+ def self.attribute_map
39
+ {
40
+ :'detail' => :'detail',
41
+ :'extensions' => :'extensions',
42
+ :'instance' => :'instance',
43
+ :'status' => :'status',
44
+ :'title' => :'title',
45
+ :'type' => :'type'
46
+ }
47
+ end
48
+
49
+ # Attribute type mapping.
50
+ def self.openapi_types
51
+ {
52
+ :'detail' => :'String',
53
+ :'extensions' => :'Object',
54
+ :'instance' => :'String',
55
+ :'status' => :'Integer',
56
+ :'title' => :'String',
57
+ :'type' => :'String'
58
+ }
59
+ end
60
+
61
+ # Initializes the object
62
+ # @param [Hash] attributes Model attributes in the form of hash
63
+ def initialize(attributes = {})
64
+ if (!attributes.is_a?(Hash))
65
+ fail ArgumentError, "The input argument (attributes) must be a hash in `XeroRuby::AppStore::ProblemDetails` initialize method"
66
+ end
67
+
68
+ # check to see if the attribute exists and convert string to symbol for hash key
69
+ attributes = attributes.each_with_object({}) { |(k, v), h|
70
+ if (!self.class.attribute_map.key?(k.to_sym))
71
+ fail ArgumentError, "`#{k}` is not a valid attribute in `XeroRuby::AppStore::ProblemDetails`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
72
+ end
73
+ h[k.to_sym] = v
74
+ }
75
+
76
+ if attributes.key?(:'detail')
77
+ self.detail = attributes[:'detail']
78
+ end
79
+
80
+ if attributes.key?(:'extensions')
81
+ self.extensions = attributes[:'extensions']
82
+ end
83
+
84
+ if attributes.key?(:'instance')
85
+ self.instance = attributes[:'instance']
86
+ end
87
+
88
+ if attributes.key?(:'status')
89
+ self.status = attributes[:'status']
90
+ end
91
+
92
+ if attributes.key?(:'title')
93
+ self.title = attributes[:'title']
94
+ end
95
+
96
+ if attributes.key?(:'type')
97
+ self.type = attributes[:'type']
98
+ end
99
+ end
100
+
101
+ # Show invalid properties with the reasons. Usually used together with valid?
102
+ # @return Array for valid properties with the reasons
103
+ def list_invalid_properties
104
+ invalid_properties = Array.new
105
+ invalid_properties
106
+ end
107
+
108
+ # Check to see if the all the properties in the model are valid
109
+ # @return true if the model is valid
110
+ def valid?
111
+ true
112
+ end
113
+
114
+ # Checks equality by comparing each attribute.
115
+ # @param [Object] Object to be compared
116
+ def ==(o)
117
+ return true if self.equal?(o)
118
+ self.class == o.class &&
119
+ detail == o.detail &&
120
+ extensions == o.extensions &&
121
+ instance == o.instance &&
122
+ status == o.status &&
123
+ title == o.title &&
124
+ type == o.type
125
+ end
126
+
127
+ # @see the `==` method
128
+ # @param [Object] Object to be compared
129
+ def eql?(o)
130
+ self == o
131
+ end
132
+
133
+ # Calculates hash code according to all attributes.
134
+ # @return [Integer] Hash code
135
+ def hash
136
+ [detail, extensions, instance, status, title, type].hash
137
+ end
138
+
139
+ # Builds the object from hash
140
+ # @param [Hash] attributes Model attributes in the form of hash
141
+ # @return [Object] Returns the model itself
142
+ def self.build_from_hash(attributes)
143
+ new.build_from_hash(attributes)
144
+ end
145
+
146
+ # Builds the object from hash
147
+ # @param [Hash] attributes Model attributes in the form of hash
148
+ # @return [Object] Returns the model itself
149
+ def build_from_hash(attributes)
150
+ return nil unless attributes.is_a?(Hash)
151
+ self.class.openapi_types.each_pair do |key, type|
152
+ if type =~ /\AArray<(.*)>/i
153
+ # check to ensure the input is an array given that the attribute
154
+ # is documented as an array but the input is not
155
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
156
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
157
+ end
158
+ elsif !attributes[self.class.attribute_map[key]].nil?
159
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
160
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
161
+ end
162
+
163
+ self
164
+ end
165
+
166
+ # Deserializes the data based on type
167
+ # @param string type Data type
168
+ # @param string value Value to be deserialized
169
+ # @return [Object] Deserialized data
170
+ def _deserialize(type, value)
171
+ case type.to_sym
172
+ when :DateTime
173
+ DateTime.parse(parse_date(value))
174
+ when :Date
175
+ Date.parse(parse_date(value))
176
+ when :String
177
+ value.to_s
178
+ when :Integer
179
+ value.to_i
180
+ when :Float
181
+ value.to_f
182
+ when :BigDecimal
183
+ BigDecimal(value.to_s)
184
+ when :Boolean
185
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
186
+ true
187
+ else
188
+ false
189
+ end
190
+ when :Object
191
+ # generic object (usually a Hash), return directly
192
+ value
193
+ when /\AArray<(?<inner_type>.+)>\z/
194
+ inner_type = Regexp.last_match[:inner_type]
195
+ value.map { |v| _deserialize(inner_type, v) }
196
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
197
+ k_type = Regexp.last_match[:k_type]
198
+ v_type = Regexp.last_match[:v_type]
199
+ {}.tap do |hash|
200
+ value.each do |k, v|
201
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
202
+ end
203
+ end
204
+ else # model
205
+ XeroRuby::AppStore.const_get(type).build_from_hash(value)
206
+ end
207
+ end
208
+
209
+ # Returns the string representation of the object
210
+ # @return [String] String presentation of the object
211
+ def to_s
212
+ to_hash.to_s
213
+ end
214
+
215
+ # to_body is an alias to to_hash (backward compatibility)
216
+ # @return [Hash] Returns the object in the form of hash
217
+ def to_body
218
+ to_hash
219
+ end
220
+
221
+ # Returns the object in the form of hash
222
+ # @return [Hash] Returns the object in the form of hash
223
+ def to_hash(downcase: false)
224
+ hash = {}
225
+ self.class.attribute_map.each_pair do |attr, param|
226
+ value = self.send(attr)
227
+ next if value.nil?
228
+ key = downcase ? attr : param
229
+ hash[key] = _to_hash(value, downcase: downcase)
230
+ end
231
+ hash
232
+ end
233
+
234
+ # Returns the object in the form of hash with snake_case
235
+ def to_attributes
236
+ to_hash(downcase: true)
237
+ end
238
+
239
+ # Outputs non-array value in the form of hash
240
+ # For object, use to_hash. Otherwise, just return the value
241
+ # @param [Object] value Any valid value
242
+ # @return [Hash] Returns the value in the form of hash
243
+ def _to_hash(value, downcase: false)
244
+ if value.is_a?(Array)
245
+ value.map do |v|
246
+ v.to_hash(downcase: downcase)
247
+ end
248
+ elsif value.is_a?(Hash)
249
+ {}.tap do |hash|
250
+ value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) }
251
+ end
252
+ elsif value.respond_to? :to_hash
253
+ value.to_hash(downcase: downcase)
254
+ else
255
+ value
256
+ end
257
+ end
258
+
259
+ def parse_date(datestring)
260
+ if datestring.include?('Date')
261
+ date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\//
262
+ original, date, timezone = *date_pattern.match(datestring)
263
+ date = (date.to_i / 1000)
264
+ Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s
265
+ elsif /(\d\d\d\d)-(\d\d)/.match(datestring) # handles dates w/out Days: YYYY-MM*-DD
266
+ Time.parse(datestring + '-01').strftime('%Y-%m-%dT%H:%M:%S').to_s
267
+ else # handle date 'types' for small subset of payroll API's
268
+ Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s
269
+ end
270
+ end
271
+ end
272
+ end
@@ -0,0 +1,288 @@
1
+ =begin
2
+ #Xero AppStore API
3
+
4
+ #These endpoints are for Xero Partners to interact with the App Store Billing platform
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::AppStore
16
+ require 'bigdecimal'
17
+
18
+ class Product
19
+ # The unique identifier for the product
20
+ attr_accessor :id
21
+
22
+ # The name of the product
23
+ attr_accessor :name
24
+
25
+ # The pricing model of the product: * FIXED: Customers are charged a fixed amount for each billing period * PER_SEAT: Customers are charged based on the number of units they purchase
26
+ attr_accessor :type
27
+ FIXED = "FIXED".freeze
28
+ PER_SEAT = "PER_SEAT".freeze
29
+
30
+ # The unit of the per seat product. e.g. \"user\", \"organisation\", \"SMS\", etc
31
+ attr_accessor :seat_unit
32
+
33
+ class EnumAttributeValidator
34
+ attr_reader :datatype
35
+ attr_reader :allowable_values
36
+
37
+ def initialize(datatype, allowable_values)
38
+ @allowable_values = allowable_values.map do |value|
39
+ case datatype.to_s
40
+ when /Integer/i
41
+ value.to_i
42
+ when /Float/i
43
+ value.to_f
44
+ else
45
+ value
46
+ end
47
+ end
48
+ end
49
+
50
+ def valid?(value)
51
+ !value || allowable_values.include?(value)
52
+ end
53
+ end
54
+
55
+ # Attribute mapping from ruby-style variable name to JSON key.
56
+ def self.attribute_map
57
+ {
58
+ :'id' => :'id',
59
+ :'name' => :'name',
60
+ :'type' => :'type',
61
+ :'seat_unit' => :'seatUnit'
62
+ }
63
+ end
64
+
65
+ # Attribute type mapping.
66
+ def self.openapi_types
67
+ {
68
+ :'id' => :'String',
69
+ :'name' => :'String',
70
+ :'type' => :'String',
71
+ :'seat_unit' => :'String'
72
+ }
73
+ end
74
+
75
+ # Initializes the object
76
+ # @param [Hash] attributes Model attributes in the form of hash
77
+ def initialize(attributes = {})
78
+ if (!attributes.is_a?(Hash))
79
+ fail ArgumentError, "The input argument (attributes) must be a hash in `XeroRuby::AppStore::Product` initialize method"
80
+ end
81
+
82
+ # check to see if the attribute exists and convert string to symbol for hash key
83
+ attributes = attributes.each_with_object({}) { |(k, v), h|
84
+ if (!self.class.attribute_map.key?(k.to_sym))
85
+ fail ArgumentError, "`#{k}` is not a valid attribute in `XeroRuby::AppStore::Product`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
86
+ end
87
+ h[k.to_sym] = v
88
+ }
89
+
90
+ if attributes.key?(:'id')
91
+ self.id = attributes[:'id']
92
+ end
93
+
94
+ if attributes.key?(:'name')
95
+ self.name = attributes[:'name']
96
+ end
97
+
98
+ if attributes.key?(:'type')
99
+ self.type = attributes[:'type']
100
+ end
101
+
102
+ if attributes.key?(:'seat_unit')
103
+ self.seat_unit = attributes[:'seat_unit']
104
+ end
105
+ end
106
+
107
+ # Show invalid properties with the reasons. Usually used together with valid?
108
+ # @return Array for valid properties with the reasons
109
+ def list_invalid_properties
110
+ invalid_properties = Array.new
111
+ invalid_properties
112
+ end
113
+
114
+ # Check to see if the all the properties in the model are valid
115
+ # @return true if the model is valid
116
+ def valid?
117
+ type_validator = EnumAttributeValidator.new('String', ["FIXED", "PER_SEAT"])
118
+ return false unless type_validator.valid?(@type)
119
+ true
120
+ end
121
+
122
+ # Custom attribute writer method checking allowed values (enum).
123
+ # @param [Object] type Object to be assigned
124
+ def type=(type)
125
+ validator = EnumAttributeValidator.new('String', ["FIXED", "PER_SEAT"])
126
+ unless validator.valid?(type)
127
+ fail ArgumentError, "invalid value for \"type\", must be one of #{validator.allowable_values}."
128
+ end
129
+ @type = type
130
+ end
131
+
132
+ # Checks equality by comparing each attribute.
133
+ # @param [Object] Object to be compared
134
+ def ==(o)
135
+ return true if self.equal?(o)
136
+ self.class == o.class &&
137
+ id == o.id &&
138
+ name == o.name &&
139
+ type == o.type &&
140
+ seat_unit == o.seat_unit
141
+ end
142
+
143
+ # @see the `==` method
144
+ # @param [Object] Object to be compared
145
+ def eql?(o)
146
+ self == o
147
+ end
148
+
149
+ # Calculates hash code according to all attributes.
150
+ # @return [Integer] Hash code
151
+ def hash
152
+ [id, name, type, seat_unit].hash
153
+ end
154
+
155
+ # Builds the object from hash
156
+ # @param [Hash] attributes Model attributes in the form of hash
157
+ # @return [Object] Returns the model itself
158
+ def self.build_from_hash(attributes)
159
+ new.build_from_hash(attributes)
160
+ end
161
+
162
+ # Builds the object from hash
163
+ # @param [Hash] attributes Model attributes in the form of hash
164
+ # @return [Object] Returns the model itself
165
+ def build_from_hash(attributes)
166
+ return nil unless attributes.is_a?(Hash)
167
+ self.class.openapi_types.each_pair do |key, type|
168
+ if type =~ /\AArray<(.*)>/i
169
+ # check to ensure the input is an array given that the attribute
170
+ # is documented as an array but the input is not
171
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
172
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
173
+ end
174
+ elsif !attributes[self.class.attribute_map[key]].nil?
175
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
176
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
177
+ end
178
+
179
+ self
180
+ end
181
+
182
+ # Deserializes the data based on type
183
+ # @param string type Data type
184
+ # @param string value Value to be deserialized
185
+ # @return [Object] Deserialized data
186
+ def _deserialize(type, value)
187
+ case type.to_sym
188
+ when :DateTime
189
+ DateTime.parse(parse_date(value))
190
+ when :Date
191
+ Date.parse(parse_date(value))
192
+ when :String
193
+ value.to_s
194
+ when :Integer
195
+ value.to_i
196
+ when :Float
197
+ value.to_f
198
+ when :BigDecimal
199
+ BigDecimal(value.to_s)
200
+ when :Boolean
201
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
202
+ true
203
+ else
204
+ false
205
+ end
206
+ when :Object
207
+ # generic object (usually a Hash), return directly
208
+ value
209
+ when /\AArray<(?<inner_type>.+)>\z/
210
+ inner_type = Regexp.last_match[:inner_type]
211
+ value.map { |v| _deserialize(inner_type, v) }
212
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
213
+ k_type = Regexp.last_match[:k_type]
214
+ v_type = Regexp.last_match[:v_type]
215
+ {}.tap do |hash|
216
+ value.each do |k, v|
217
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
218
+ end
219
+ end
220
+ else # model
221
+ XeroRuby::AppStore.const_get(type).build_from_hash(value)
222
+ end
223
+ end
224
+
225
+ # Returns the string representation of the object
226
+ # @return [String] String presentation of the object
227
+ def to_s
228
+ to_hash.to_s
229
+ end
230
+
231
+ # to_body is an alias to to_hash (backward compatibility)
232
+ # @return [Hash] Returns the object in the form of hash
233
+ def to_body
234
+ to_hash
235
+ end
236
+
237
+ # Returns the object in the form of hash
238
+ # @return [Hash] Returns the object in the form of hash
239
+ def to_hash(downcase: false)
240
+ hash = {}
241
+ self.class.attribute_map.each_pair do |attr, param|
242
+ value = self.send(attr)
243
+ next if value.nil?
244
+ key = downcase ? attr : param
245
+ hash[key] = _to_hash(value, downcase: downcase)
246
+ end
247
+ hash
248
+ end
249
+
250
+ # Returns the object in the form of hash with snake_case
251
+ def to_attributes
252
+ to_hash(downcase: true)
253
+ end
254
+
255
+ # Outputs non-array value in the form of hash
256
+ # For object, use to_hash. Otherwise, just return the value
257
+ # @param [Object] value Any valid value
258
+ # @return [Hash] Returns the value in the form of hash
259
+ def _to_hash(value, downcase: false)
260
+ if value.is_a?(Array)
261
+ value.map do |v|
262
+ v.to_hash(downcase: downcase)
263
+ end
264
+ elsif value.is_a?(Hash)
265
+ {}.tap do |hash|
266
+ value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) }
267
+ end
268
+ elsif value.respond_to? :to_hash
269
+ value.to_hash(downcase: downcase)
270
+ else
271
+ value
272
+ end
273
+ end
274
+
275
+ def parse_date(datestring)
276
+ if datestring.include?('Date')
277
+ date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\//
278
+ original, date, timezone = *date_pattern.match(datestring)
279
+ date = (date.to_i / 1000)
280
+ Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s
281
+ elsif /(\d\d\d\d)-(\d\d)/.match(datestring) # handles dates w/out Days: YYYY-MM*-DD
282
+ Time.parse(datestring + '-01').strftime('%Y-%m-%dT%H:%M:%S').to_s
283
+ else # handle date 'types' for small subset of payroll API's
284
+ Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s
285
+ end
286
+ end
287
+ end
288
+ end