xero-ruby 3.2.1 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +70 -1
- data/lib/xero-ruby.rb +7 -0
- data/lib/xero-ruby/api/app_store_api.rb +87 -0
- data/lib/xero-ruby/api_client.rb +8 -1
- data/lib/xero-ruby/configuration.rb +2 -0
- data/lib/xero-ruby/models/accounting/payment.rb +11 -1
- data/lib/xero-ruby/models/accounting/time_zone.rb +1 -0
- data/lib/xero-ruby/models/app_store/plan.rb +310 -0
- data/lib/xero-ruby/models/app_store/price.rb +257 -0
- data/lib/xero-ruby/models/app_store/problem_details.rb +272 -0
- data/lib/xero-ruby/models/app_store/product.rb +278 -0
- data/lib/xero-ruby/models/app_store/subscription.rb +324 -0
- data/lib/xero-ruby/models/app_store/subscription_item.rb +292 -0
- data/lib/xero-ruby/models/payroll_au/employee.rb +30 -1
- data/lib/xero-ruby/models/payroll_au/payroll_calendar.rb +11 -1
- data/lib/xero-ruby/version.rb +2 -2
- data/spec/app_store/api/app_store_api_spec.rb +45 -0
- data/spec/app_store/models/plan_spec.rb +62 -0
- data/spec/app_store/models/price_spec.rb +52 -0
- data/spec/app_store/models/problem_details_spec.rb +70 -0
- data/spec/app_store/models/product_spec.rb +56 -0
- data/spec/app_store/models/subscription_item_spec.rb +70 -0
- data/spec/app_store/models/subscription_spec.rb +82 -0
- metadata +23 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a94136a3e2a31cc4d5c7a162116bdd8705800ac2fc2732907a80286950fa376
|
4
|
+
data.tar.gz: 340b78c53b08a37f04b79d642bf0fc7e4e1c109595ef86b596398aa9c2b87be3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1275a668a399320fa11e6ccbcacd9eac6d4cf4ffb939108d1962ccede318376b1ee3236b4cdbb95e0db45e8e1695f860508861c4097da7c1d6a12e22cfe3672f
|
7
|
+
data.tar.gz: 49de788f087c577474ad556ed9188c0e75ccb46256f52ff6639e2fdf82ed732fceb9eebfb825a9d17cb2f6370c4b52c78c4b1ebc0b5484554e565089e5f5052d
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
[![Github stars](https://img.shields.io/github/stars/XeroAPI/xero-ruby.svg)](https://github.com/XeroAPI/xero-ruby/stargazers)
|
5
5
|
![total downloads](https://ruby-gem-downloads-badge.herokuapp.com/xero-ruby?type=total)
|
6
6
|
|
7
|
-
The xero-ruby SDK makes it easy for developers to access Xero's APIs in their Ruby code, and build robust applications and software using small business & general
|
7
|
+
The xero-ruby SDK makes it easy for developers to access Xero's APIs in their Ruby code, and build robust applications and software using small business & general ledger accounting data.
|
8
8
|
# Table of Contents
|
9
9
|
- [API Client documentation](#api-client-documentation)
|
10
10
|
- [Sample Applications](#sample-applications)
|
@@ -13,6 +13,7 @@ The xero-ruby SDK makes it easy for developers to access Xero's APIs in their Ru
|
|
13
13
|
- [Configuration](#configuration)
|
14
14
|
- [Authentication](#authentication)
|
15
15
|
- [Custom Connections](#custom-connections)
|
16
|
+
- [App Store Subscriptions](#app-store-subscriptions)
|
16
17
|
- [API Clients](#api-clients)
|
17
18
|
- [Helper Methods](#helper-methods)
|
18
19
|
- [Usage Examples](#usage-examples)
|
@@ -46,6 +47,7 @@ Sample apps can get you started quickly with simple auth flows to advanced usage
|
|
46
47
|
| [`xero-ruby-oauth2-starter`](https://github.com/XeroAPI/Xero-ruby-oauth2-starter) | A Sinatra application showing the basic getting started code to work with the sdk | <img src="https://i.imgur.com/9H4F98M.png" alt="drawing" width="300"/>
|
47
48
|
| [`xero-ruby-oauth2-app`](https://github.com/XeroAPI/Xero-ruby-oauth2-app) | Complete rails app with +95% of api set examples, complex filters, pagination, and user/token management in postgres | <img src="https://i.imgur.com/XsAp9Ww.png" alt="drawing" width="500"/>
|
48
49
|
| [`xero-ruby-custom-connections-starter`](https://github.com/XeroAPI/xero-ruby-custom-connections-starter) | A getting started Sinatra app showing Custom Connections - a Xero [premium option](https://developer.xero.com/documentation/oauth2/custom-connections) for building M2M integrations to a single org | <img src="https://i.imgur.com/YEkScui.png" alt="drawing" width="300"/>
|
50
|
+
| [`xero-ruby-sso-form`](https://github.com/XeroAPI/xero-ruby-sso-form) | A basic Sinatra app showing how to implement SSU to Lead | <img src="https://i.imgur.com/Nf95GVd.png" alt="drawing" width="300"/>
|
49
51
|
|
50
52
|
<hr>
|
51
53
|
|
@@ -155,6 +157,73 @@ Because Custom Connections are only valid for a single organisation you don't ne
|
|
155
157
|
However - due to the nature of how our SDK's are generated from our OpenAPI spec, the parameter remains which requires you to pass an empty string for now to use the SDK with a Custom Connection.
|
156
158
|
|
157
159
|
---
|
160
|
+
|
161
|
+
## App Store Subscriptions
|
162
|
+
|
163
|
+
If you are implementing subscriptions to participate in Xero's App Store you will need to setup [App Store subscriptions](https://developer.xero.com/documentation/guides/how-to-guides/xero-app-store-referrals/) endpoints.
|
164
|
+
|
165
|
+
When a plan is successfully purchased, the user is redirected back to the URL specified in the setup process. The Xero App Store appends the subscription Id to this URL so you can immediately determine what plan the user has subscribed to through the subscriptions API.
|
166
|
+
|
167
|
+
With your app credentials you can create a client via `client_credentials` grant_type with the `marketplace.billing` scope. This unique access_token will allow you to query any functions in `appStoreApi`. Client Credentials tokens to query app store endpoints will only work for apps that have completed the App Store on-boarding process.
|
168
|
+
|
169
|
+
```ruby
|
170
|
+
// => /post-purchase-url?subscriptionId=03bc74f2-1237-4477-b782-2dfb1a6d8b21
|
171
|
+
|
172
|
+
subscription_id = params[:subscriptionId]
|
173
|
+
|
174
|
+
xero_app_store_client ||= XeroRuby::ApiClient.new(credentials: {
|
175
|
+
client_id: ENV['CLIENT_ID'],
|
176
|
+
client_secret: ENV['CLIENT_SECRET'],
|
177
|
+
grant_type: 'client_credentials'
|
178
|
+
scopes: ['marketplace.billing']
|
179
|
+
})
|
180
|
+
|
181
|
+
xero_app_store_client.get_client_credentials_token
|
182
|
+
|
183
|
+
@subscription = xero_app_store_client.app_store_api.get_subscription(subscription_id)
|
184
|
+
|
185
|
+
puts @subscription.to_attributes
|
186
|
+
{
|
187
|
+
:current_period_end => Thu, 02 Sep 2021 14:08:58 +0000,
|
188
|
+
:id => "03bc74f2-1237-4477-b782-2dfb1a6d8b21",
|
189
|
+
:organisation_id => "79e8b2e5-c63d-4dce-888f-e0f3e9eac647",
|
190
|
+
:plans => [
|
191
|
+
{
|
192
|
+
:id => "6abc26f3-9390-4194-8b25-ce8b9942fda9",
|
193
|
+
:name => "Small",
|
194
|
+
:status => "ACTIVE",
|
195
|
+
:subscription_items => [
|
196
|
+
{
|
197
|
+
:id => "834cff4c-b753-4de2-9e7a-3451e14fa17a",
|
198
|
+
:price => {
|
199
|
+
:amount => 0.1e0,
|
200
|
+
:currency => "NZD",
|
201
|
+
:id => "2310de92-c7c0-4bcb-b972-fb7612177bc7"
|
202
|
+
},
|
203
|
+
:product => {
|
204
|
+
:id => "9586421f-7325-4493-bac9-d93be06a6a38",
|
205
|
+
:name => "",
|
206
|
+
:type => "FIXED"
|
207
|
+
},
|
208
|
+
:start_date => Mon, 02 Aug 2021 14:08:58 +0000,
|
209
|
+
:test_mode => true
|
210
|
+
}
|
211
|
+
]
|
212
|
+
}
|
213
|
+
],
|
214
|
+
:start_date => Mon, 02 Aug 2021 14:08:58 +0000,
|
215
|
+
:status => "ACTIVE",
|
216
|
+
:test_mode => true
|
217
|
+
}
|
218
|
+
```
|
219
|
+
You should use this subscription data to provision user access/permissions to your application.
|
220
|
+
### App Store Subscription Webhooks
|
221
|
+
|
222
|
+
In additon to a subscription Id being passed through the URL, when a purchase or an upgrade takes place you will be notified via a webhook. You can then use the subscription Id in the webhook payload to query the AppStore endpoints and determine what plan the user purchased, upgraded, downgraded or cancelled.
|
223
|
+
|
224
|
+
Refer to Xero's documenation to learn more about setting up and receiving webhooks.
|
225
|
+
> https://developer.xero.com/documentation/guides/webhooks/overview/
|
226
|
+
|
158
227
|
## API Clients
|
159
228
|
You can access the different API sets and their available methods through the following:
|
160
229
|
|
data/lib/xero-ruby.rb
CHANGED
@@ -18,6 +18,12 @@ require 'xero-ruby/version'
|
|
18
18
|
require 'xero-ruby/configuration'
|
19
19
|
|
20
20
|
# Models
|
21
|
+
require 'xero-ruby/models/app_store/plan'
|
22
|
+
require 'xero-ruby/models/app_store/price'
|
23
|
+
require 'xero-ruby/models/app_store/problem_details'
|
24
|
+
require 'xero-ruby/models/app_store/product'
|
25
|
+
require 'xero-ruby/models/app_store/subscription'
|
26
|
+
require 'xero-ruby/models/app_store/subscription_item'
|
21
27
|
require 'xero-ruby/models/payroll_uk/account'
|
22
28
|
require 'xero-ruby/models/payroll_uk/accounts'
|
23
29
|
require 'xero-ruby/models/payroll_uk/address'
|
@@ -456,6 +462,7 @@ require 'xero-ruby/models/accounting/users'
|
|
456
462
|
require 'xero-ruby/models/accounting/validation_error'
|
457
463
|
|
458
464
|
# APIs
|
465
|
+
require 'xero-ruby/api/app_store_api'
|
459
466
|
require 'xero-ruby/api/payroll_uk_api'
|
460
467
|
require 'xero-ruby/api/payroll_nz_api'
|
461
468
|
require 'xero-ruby/api/payroll_au_api'
|
@@ -0,0 +1,87 @@
|
|
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
|
+
module XeroRuby
|
13
|
+
class AppStoreApi
|
14
|
+
attr_accessor :api_client
|
15
|
+
|
16
|
+
def initialize(api_client = ApiClient.new)
|
17
|
+
@api_client = api_client
|
18
|
+
end
|
19
|
+
# Retrieves a subscription for a given subscriptionId
|
20
|
+
# @param subscription_id [String] Unique identifier for Subscription object
|
21
|
+
# @param [Hash] opts the optional parameters
|
22
|
+
# @return [Subscription]
|
23
|
+
def get_subscription(subscription_id, opts = {})
|
24
|
+
data, _status_code, _headers = get_subscription_with_http_info(subscription_id, opts)
|
25
|
+
data
|
26
|
+
end
|
27
|
+
|
28
|
+
# Retrieves a subscription for a given subscriptionId
|
29
|
+
# @param subscription_id [String] Unique identifier for Subscription object
|
30
|
+
# @param [Hash] opts the optional parameters
|
31
|
+
# @return [Array<(Subscription, Integer, Hash)>] Subscription data, response status code and response headers
|
32
|
+
def get_subscription_with_http_info(subscription_id, options = {})
|
33
|
+
opts = options.dup
|
34
|
+
if @api_client.config.debugging
|
35
|
+
@api_client.config.logger.debug 'Calling API: AppStoreApi.get_subscription ...'
|
36
|
+
end
|
37
|
+
# verify the required parameter 'subscription_id' is set
|
38
|
+
if @api_client.config.client_side_validation && subscription_id.nil?
|
39
|
+
fail ArgumentError, "Missing the required parameter 'subscription_id' when calling AppStoreApi.get_subscription"
|
40
|
+
end
|
41
|
+
# resource path
|
42
|
+
local_var_path = '/subscriptions/{subscriptionId}'.sub('{' + 'subscriptionId' + '}', subscription_id.to_s)
|
43
|
+
|
44
|
+
# camelize keys of incoming `where` opts
|
45
|
+
opts[:'where'] = @api_client.parameterize_where(opts[:'where']) if !opts[:'where'].nil?
|
46
|
+
|
47
|
+
# query parameters
|
48
|
+
query_params = opts[:query_params] || {}
|
49
|
+
|
50
|
+
# XeroAPI's `IDs` convention openapi-generator does not snake_case properly.. manual over-riding `i_ds` malformations:
|
51
|
+
query_params[:'IDs'] = @api_client.build_collection_param(opts[:'ids'], :csv) if !opts[:'ids'].nil?
|
52
|
+
query_params[:'ContactIDs'] = @api_client.build_collection_param(opts[:'contact_ids'], :csv) if !opts[:'contact_ids'].nil?
|
53
|
+
|
54
|
+
# header parameters
|
55
|
+
header_params = opts[:header_params] || {}
|
56
|
+
# HTTP header 'Accept' (if needed)
|
57
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
58
|
+
|
59
|
+
# form parameters
|
60
|
+
form_params = opts[:form_params] || {}
|
61
|
+
|
62
|
+
# http body (model)
|
63
|
+
post_body = opts[:body]
|
64
|
+
|
65
|
+
# return_type
|
66
|
+
return_type = opts[:return_type] || 'Subscription'
|
67
|
+
|
68
|
+
# auth_names
|
69
|
+
auth_names = opts[:auth_names] || ['OAuth2']
|
70
|
+
|
71
|
+
new_options = opts.merge(
|
72
|
+
:header_params => header_params,
|
73
|
+
:query_params => query_params,
|
74
|
+
:form_params => form_params,
|
75
|
+
:body => post_body,
|
76
|
+
:auth_names => auth_names,
|
77
|
+
:return_type => return_type
|
78
|
+
)
|
79
|
+
|
80
|
+
data, status_code, headers = @api_client.call_api(:GET, local_var_path, "AppStoreApi", new_options)
|
81
|
+
if @api_client.config.debugging
|
82
|
+
@api_client.config.logger.debug "API called: AppStoreApi#get_subscription\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
83
|
+
end
|
84
|
+
return data, status_code, headers
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/lib/xero-ruby/api_client.rb
CHANGED
@@ -57,7 +57,7 @@ module XeroRuby
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def authorization_url
|
60
|
-
url = URI.parse
|
60
|
+
url = URI.parse(@config.login_url)
|
61
61
|
url.query = URI.encode_www_form(
|
62
62
|
{
|
63
63
|
response_type: 'code',
|
@@ -105,6 +105,11 @@ module XeroRuby
|
|
105
105
|
XeroRuby::PayrollUkApi.new(self)
|
106
106
|
end
|
107
107
|
|
108
|
+
def app_store_api
|
109
|
+
@config.base_url = @config.app_store_url
|
110
|
+
XeroRuby::AppStoreApi.new(self)
|
111
|
+
end
|
112
|
+
|
108
113
|
# Token Helpers
|
109
114
|
def token_set
|
110
115
|
@config.token_set
|
@@ -501,6 +506,8 @@ module XeroRuby
|
|
501
506
|
XeroRuby::PayrollNz.const_get(return_type).build_from_hash(data)
|
502
507
|
when 'PayrollUkApi'
|
503
508
|
XeroRuby::PayrollUk.const_get(return_type).build_from_hash(data)
|
509
|
+
when 'AppStoreApi'
|
510
|
+
XeroRuby::AppStore.const_get(return_type).build_from_hash(data)
|
504
511
|
else
|
505
512
|
XeroRuby::Accounting.const_get(return_type).build_from_hash(data)
|
506
513
|
end
|
@@ -33,6 +33,7 @@ module XeroRuby
|
|
33
33
|
attr_accessor :payroll_au_url
|
34
34
|
attr_accessor :payroll_nz_url
|
35
35
|
attr_accessor :payroll_uk_url
|
36
|
+
attr_accessor :app_store_url
|
36
37
|
|
37
38
|
# Defines API keys used with API Key authentications.
|
38
39
|
#
|
@@ -149,6 +150,7 @@ module XeroRuby
|
|
149
150
|
@payroll_au_url = 'https://api.xero.com/payroll.xro/1.0/'
|
150
151
|
@payroll_nz_url = 'https://api.xero.com/payroll.xro/2.0/'
|
151
152
|
@payroll_uk_url = 'https://api.xero.com/payroll.xro/2.0/'
|
153
|
+
@app_store_url = 'https://api.xero.com/appstore/2.0/'
|
152
154
|
@access_token = nil
|
153
155
|
@id_token = nil
|
154
156
|
@api_key = {}
|
@@ -49,6 +49,9 @@ module XeroRuby::Accounting
|
|
49
49
|
# The amount of the payment. Must be less than or equal to the outstanding amount owing on the invoice e.g. 200.00
|
50
50
|
attr_accessor :amount
|
51
51
|
|
52
|
+
# The amount of the payment in the currency of the bank account.
|
53
|
+
attr_accessor :bank_amount
|
54
|
+
|
52
55
|
# An optional description for the payment e.g. Direct Debit
|
53
56
|
attr_accessor :reference
|
54
57
|
|
@@ -137,6 +140,7 @@ module XeroRuby::Accounting
|
|
137
140
|
:'date' => :'Date',
|
138
141
|
:'currency_rate' => :'CurrencyRate',
|
139
142
|
:'amount' => :'Amount',
|
143
|
+
:'bank_amount' => :'BankAmount',
|
140
144
|
:'reference' => :'Reference',
|
141
145
|
:'is_reconciled' => :'IsReconciled',
|
142
146
|
:'status' => :'Status',
|
@@ -168,6 +172,7 @@ module XeroRuby::Accounting
|
|
168
172
|
:'date' => :'Date',
|
169
173
|
:'currency_rate' => :'BigDecimal',
|
170
174
|
:'amount' => :'BigDecimal',
|
175
|
+
:'bank_amount' => :'BigDecimal',
|
171
176
|
:'reference' => :'String',
|
172
177
|
:'is_reconciled' => :'Boolean',
|
173
178
|
:'status' => :'String',
|
@@ -244,6 +249,10 @@ module XeroRuby::Accounting
|
|
244
249
|
self.amount = attributes[:'amount']
|
245
250
|
end
|
246
251
|
|
252
|
+
if attributes.key?(:'bank_amount')
|
253
|
+
self.bank_amount = attributes[:'bank_amount']
|
254
|
+
end
|
255
|
+
|
247
256
|
if attributes.key?(:'reference')
|
248
257
|
self.reference = attributes[:'reference']
|
249
258
|
end
|
@@ -360,6 +369,7 @@ module XeroRuby::Accounting
|
|
360
369
|
date == o.date &&
|
361
370
|
currency_rate == o.currency_rate &&
|
362
371
|
amount == o.amount &&
|
372
|
+
bank_amount == o.bank_amount &&
|
363
373
|
reference == o.reference &&
|
364
374
|
is_reconciled == o.is_reconciled &&
|
365
375
|
status == o.status &&
|
@@ -385,7 +395,7 @@ module XeroRuby::Accounting
|
|
385
395
|
# Calculates hash code according to all attributes.
|
386
396
|
# @return [Integer] Hash code
|
387
397
|
def hash
|
388
|
-
[invoice, credit_note, prepayment, overpayment, invoice_number, credit_note_number, account, code, date, currency_rate, amount, reference, is_reconciled, status, payment_type, updated_date_utc, payment_id, batch_payment_id, bank_account_number, particulars, details, has_account, has_validation_errors, status_attribute_string, validation_errors].hash
|
398
|
+
[invoice, credit_note, prepayment, overpayment, invoice_number, credit_note_number, account, code, date, currency_rate, amount, bank_amount, reference, is_reconciled, status, payment_type, updated_date_utc, payment_id, batch_payment_id, bank_account_number, particulars, details, has_account, has_validation_errors, status_attribute_string, validation_errors].hash
|
389
399
|
end
|
390
400
|
|
391
401
|
# Builds the object from hash
|
@@ -122,6 +122,7 @@ module XeroRuby::Accounting
|
|
122
122
|
HAWAIIANSTANDARDTIME = "HAWAIIANSTANDARDTIME".freeze
|
123
123
|
UTC11 = "UTC11".freeze
|
124
124
|
DATELINESTANDARDTIME = "DATELINESTANDARDTIME".freeze
|
125
|
+
EASTERISLANDSTANDARDTIME = "EASTERISLANDSTANDARDTIME".freeze
|
125
126
|
|
126
127
|
# Builds the enum from string
|
127
128
|
# @param [String] The enum value in the form of the string
|
@@ -0,0 +1,310 @@
|
|
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 Plan
|
19
|
+
# The unique identifier of the plan
|
20
|
+
attr_accessor :id
|
21
|
+
|
22
|
+
# The name of the plan. It is used in the invoice line item description.
|
23
|
+
attr_accessor :name
|
24
|
+
|
25
|
+
# Status of the plan. Available statuses are ACTIVE, PENDING_ACTIVATION.
|
26
|
+
attr_accessor :status
|
27
|
+
ACTIVE = "ACTIVE".freeze
|
28
|
+
PENDING_ACTIVATION = "PENDING_ACTIVATION".freeze
|
29
|
+
|
30
|
+
# List of the subscription items belonging to the plan. It does not include cancelled subscription items.
|
31
|
+
attr_accessor :subscription_items
|
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
|
+
:'status' => :'status',
|
61
|
+
:'subscription_items' => :'subscriptionItems'
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
# Attribute type mapping.
|
66
|
+
def self.openapi_types
|
67
|
+
{
|
68
|
+
:'id' => :'String',
|
69
|
+
:'name' => :'String',
|
70
|
+
:'status' => :'String',
|
71
|
+
:'subscription_items' => :'Array<SubscriptionItem>'
|
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::Plan` 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::Plan`. 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?(:'status')
|
99
|
+
self.status = attributes[:'status']
|
100
|
+
end
|
101
|
+
|
102
|
+
if attributes.key?(:'subscription_items')
|
103
|
+
if (value = attributes[:'subscription_items']).is_a?(Array)
|
104
|
+
self.subscription_items = value
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
110
|
+
# @return Array for valid properties with the reasons
|
111
|
+
def list_invalid_properties
|
112
|
+
invalid_properties = Array.new
|
113
|
+
if @id.nil?
|
114
|
+
invalid_properties.push('invalid value for "id", id cannot be nil.')
|
115
|
+
end
|
116
|
+
|
117
|
+
if @name.nil?
|
118
|
+
invalid_properties.push('invalid value for "name", name cannot be nil.')
|
119
|
+
end
|
120
|
+
|
121
|
+
if @status.nil?
|
122
|
+
invalid_properties.push('invalid value for "status", status cannot be nil.')
|
123
|
+
end
|
124
|
+
|
125
|
+
if @subscription_items.nil?
|
126
|
+
invalid_properties.push('invalid value for "subscription_items", subscription_items cannot be nil.')
|
127
|
+
end
|
128
|
+
|
129
|
+
invalid_properties
|
130
|
+
end
|
131
|
+
|
132
|
+
# Check to see if the all the properties in the model are valid
|
133
|
+
# @return true if the model is valid
|
134
|
+
def valid?
|
135
|
+
return false if @id.nil?
|
136
|
+
return false if @name.nil?
|
137
|
+
return false if @status.nil?
|
138
|
+
status_validator = EnumAttributeValidator.new('String', ["ACTIVE", "PENDING_ACTIVATION"])
|
139
|
+
return false unless status_validator.valid?(@status)
|
140
|
+
return false if @subscription_items.nil?
|
141
|
+
true
|
142
|
+
end
|
143
|
+
|
144
|
+
# Custom attribute writer method checking allowed values (enum).
|
145
|
+
# @param [Object] status Object to be assigned
|
146
|
+
def status=(status)
|
147
|
+
validator = EnumAttributeValidator.new('String', ["ACTIVE", "PENDING_ACTIVATION"])
|
148
|
+
unless validator.valid?(status)
|
149
|
+
fail ArgumentError, "invalid value for \"status\", must be one of #{validator.allowable_values}."
|
150
|
+
end
|
151
|
+
@status = status
|
152
|
+
end
|
153
|
+
|
154
|
+
# Checks equality by comparing each attribute.
|
155
|
+
# @param [Object] Object to be compared
|
156
|
+
def ==(o)
|
157
|
+
return true if self.equal?(o)
|
158
|
+
self.class == o.class &&
|
159
|
+
id == o.id &&
|
160
|
+
name == o.name &&
|
161
|
+
status == o.status &&
|
162
|
+
subscription_items == o.subscription_items
|
163
|
+
end
|
164
|
+
|
165
|
+
# @see the `==` method
|
166
|
+
# @param [Object] Object to be compared
|
167
|
+
def eql?(o)
|
168
|
+
self == o
|
169
|
+
end
|
170
|
+
|
171
|
+
# Calculates hash code according to all attributes.
|
172
|
+
# @return [Integer] Hash code
|
173
|
+
def hash
|
174
|
+
[id, name, status, subscription_items].hash
|
175
|
+
end
|
176
|
+
|
177
|
+
# Builds the object from hash
|
178
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
179
|
+
# @return [Object] Returns the model itself
|
180
|
+
def self.build_from_hash(attributes)
|
181
|
+
new.build_from_hash(attributes)
|
182
|
+
end
|
183
|
+
|
184
|
+
# Builds the object from hash
|
185
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
186
|
+
# @return [Object] Returns the model itself
|
187
|
+
def build_from_hash(attributes)
|
188
|
+
return nil unless attributes.is_a?(Hash)
|
189
|
+
self.class.openapi_types.each_pair do |key, type|
|
190
|
+
if type =~ /\AArray<(.*)>/i
|
191
|
+
# check to ensure the input is an array given that the attribute
|
192
|
+
# is documented as an array but the input is not
|
193
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
194
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
|
195
|
+
end
|
196
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
197
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
198
|
+
end # or else data not found in attributes(hash), not an issue as the data can be optional
|
199
|
+
end
|
200
|
+
|
201
|
+
self
|
202
|
+
end
|
203
|
+
|
204
|
+
# Deserializes the data based on type
|
205
|
+
# @param string type Data type
|
206
|
+
# @param string value Value to be deserialized
|
207
|
+
# @return [Object] Deserialized data
|
208
|
+
def _deserialize(type, value)
|
209
|
+
case type.to_sym
|
210
|
+
when :DateTime
|
211
|
+
DateTime.parse(parse_date(value))
|
212
|
+
when :Date
|
213
|
+
Date.parse(parse_date(value))
|
214
|
+
when :String
|
215
|
+
value.to_s
|
216
|
+
when :Integer
|
217
|
+
value.to_i
|
218
|
+
when :Float
|
219
|
+
value.to_f
|
220
|
+
when :BigDecimal
|
221
|
+
BigDecimal(value.to_s)
|
222
|
+
when :Boolean
|
223
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
224
|
+
true
|
225
|
+
else
|
226
|
+
false
|
227
|
+
end
|
228
|
+
when :Object
|
229
|
+
# generic object (usually a Hash), return directly
|
230
|
+
value
|
231
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
232
|
+
inner_type = Regexp.last_match[:inner_type]
|
233
|
+
value.map { |v| _deserialize(inner_type, v) }
|
234
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
235
|
+
k_type = Regexp.last_match[:k_type]
|
236
|
+
v_type = Regexp.last_match[:v_type]
|
237
|
+
{}.tap do |hash|
|
238
|
+
value.each do |k, v|
|
239
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
240
|
+
end
|
241
|
+
end
|
242
|
+
else # model
|
243
|
+
XeroRuby::AppStore.const_get(type).build_from_hash(value)
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
# Returns the string representation of the object
|
248
|
+
# @return [String] String presentation of the object
|
249
|
+
def to_s
|
250
|
+
to_hash.to_s
|
251
|
+
end
|
252
|
+
|
253
|
+
# to_body is an alias to to_hash (backward compatibility)
|
254
|
+
# @return [Hash] Returns the object in the form of hash
|
255
|
+
def to_body
|
256
|
+
to_hash
|
257
|
+
end
|
258
|
+
|
259
|
+
# Returns the object in the form of hash
|
260
|
+
# @return [Hash] Returns the object in the form of hash
|
261
|
+
def to_hash(downcase: false)
|
262
|
+
hash = {}
|
263
|
+
self.class.attribute_map.each_pair do |attr, param|
|
264
|
+
value = self.send(attr)
|
265
|
+
next if value.nil?
|
266
|
+
key = downcase ? attr : param
|
267
|
+
hash[key] = _to_hash(value, downcase: downcase)
|
268
|
+
end
|
269
|
+
hash
|
270
|
+
end
|
271
|
+
|
272
|
+
# Returns the object in the form of hash with snake_case
|
273
|
+
def to_attributes
|
274
|
+
to_hash(downcase: true)
|
275
|
+
end
|
276
|
+
|
277
|
+
# Outputs non-array value in the form of hash
|
278
|
+
# For object, use to_hash. Otherwise, just return the value
|
279
|
+
# @param [Object] value Any valid value
|
280
|
+
# @return [Hash] Returns the value in the form of hash
|
281
|
+
def _to_hash(value, downcase: false)
|
282
|
+
if value.is_a?(Array)
|
283
|
+
value.map do |v|
|
284
|
+
v.to_hash(downcase: downcase)
|
285
|
+
end
|
286
|
+
elsif value.is_a?(Hash)
|
287
|
+
{}.tap do |hash|
|
288
|
+
value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) }
|
289
|
+
end
|
290
|
+
elsif value.respond_to? :to_hash
|
291
|
+
value.to_hash(downcase: downcase)
|
292
|
+
else
|
293
|
+
value
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
def parse_date(datestring)
|
298
|
+
if datestring.include?('Date')
|
299
|
+
date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\//
|
300
|
+
original, date, timezone = *date_pattern.match(datestring)
|
301
|
+
date = (date.to_i / 1000)
|
302
|
+
Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s
|
303
|
+
elsif /(\d\d\d\d)-(\d\d)/.match(datestring) # handles dates w/out Days: YYYY-MM*-DD
|
304
|
+
Time.parse(datestring + '-01').strftime('%Y-%m-%dT%H:%M:%S').to_s
|
305
|
+
else # handle date 'types' for small subset of payroll API's
|
306
|
+
Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s
|
307
|
+
end
|
308
|
+
end
|
309
|
+
end
|
310
|
+
end
|