authlete 0.5.1 → 1.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.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/lib/authlete.rb +24 -1
  3. data/lib/authlete/api.rb +298 -146
  4. data/lib/authlete/authentication-server.rb +1 -1
  5. data/lib/authlete/exception.rb +6 -3
  6. data/lib/authlete/model/client-extension.rb +135 -135
  7. data/lib/authlete/model/client-list.rb +128 -128
  8. data/lib/authlete/model/client.rb +468 -468
  9. data/lib/authlete/model/hashable.rb +1 -1
  10. data/lib/authlete/model/pair.rb +102 -102
  11. data/lib/authlete/model/property.rb +116 -0
  12. data/lib/authlete/model/request/authentication-callback-request.rb +90 -90
  13. data/lib/authlete/model/request/authorization-fail-request.rb +107 -104
  14. data/lib/authlete/model/request/authorization-issue-request.rb +167 -133
  15. data/lib/authlete/model/request/authorization-request.rb +101 -101
  16. data/lib/authlete/model/request/client-authorization-delete-request.rb +123 -0
  17. data/lib/authlete/model/request/client-authorization-get-list-request.rb +123 -0
  18. data/lib/authlete/model/request/client-authorization-update-request.rb +118 -0
  19. data/lib/authlete/model/request/client-secret-update-request.rb +121 -0
  20. data/lib/authlete/model/request/developer-authentication-callback-request.rb +84 -84
  21. data/lib/authlete/model/request/granted-scopes-request.rb +103 -0
  22. data/lib/authlete/model/request/introspection-request.rb +117 -39
  23. data/lib/authlete/model/request/revocation-request.rb +125 -0
  24. data/lib/authlete/model/request/standard-introspection-request.rb +102 -0
  25. data/lib/authlete/model/request/token-create-request.rb +250 -0
  26. data/lib/authlete/model/request/token-fail-request.rb +104 -101
  27. data/lib/authlete/model/request/token-issue-request.rb +116 -101
  28. data/lib/authlete/model/request/token-request.rb +127 -121
  29. data/lib/authlete/model/request/token-update-request.rb +165 -0
  30. data/lib/authlete/model/request/user-info-issue-request.rb +113 -0
  31. data/lib/authlete/model/request/user-info-request.rb +102 -0
  32. data/lib/authlete/model/response/authentication-callback-response.rb +53 -53
  33. data/lib/authlete/model/response/authorization-fail-response.rb +48 -48
  34. data/lib/authlete/model/response/authorization-issue-response.rb +85 -48
  35. data/lib/authlete/model/response/authorization-response.rb +177 -164
  36. data/lib/authlete/model/response/client-authorization-get-list-response.rb +60 -0
  37. data/lib/authlete/model/response/client-secret-refresh-response.rb +48 -0
  38. data/lib/authlete/model/response/client-secret-update-response.rb +48 -0
  39. data/lib/authlete/model/response/developer-authentication-callback-response.rb +55 -55
  40. data/lib/authlete/model/response/granted-scopes-get-response.rb +63 -0
  41. data/lib/authlete/model/response/introspection-response.rb +163 -132
  42. data/lib/authlete/model/response/revocation-response.rb +49 -0
  43. data/lib/authlete/model/response/service-creatable-response.rb +50 -50
  44. data/lib/authlete/model/response/standard-introspection-response.rb +49 -0
  45. data/lib/authlete/model/response/token-create-response.rb +100 -0
  46. data/lib/authlete/model/response/token-fail-response.rb +49 -49
  47. data/lib/authlete/model/response/token-issue-response.rb +138 -49
  48. data/lib/authlete/model/response/token-response.rb +168 -70
  49. data/lib/authlete/model/response/token-update-response.rb +62 -0
  50. data/lib/authlete/model/response/user-info-issue-response.rb +47 -0
  51. data/lib/authlete/model/response/user-info-response.rb +85 -0
  52. data/lib/authlete/model/result.rb +44 -44
  53. data/lib/authlete/model/scope.rb +1 -1
  54. data/lib/authlete/model/service-list.rb +1 -1
  55. data/lib/authlete/model/service-owner.rb +1 -1
  56. data/lib/authlete/model/service.rb +4 -2
  57. data/lib/authlete/model/sns-credentials.rb +1 -1
  58. data/lib/authlete/model/tagged-value.rb +97 -97
  59. data/lib/authlete/utility.rb +1 -1
  60. data/lib/authlete/version.rb +2 -2
  61. metadata +24 -2
@@ -1,40 +1,118 @@
1
- # :nodoc:
2
- #
3
- # Copyright (C) 2014-2015 Authlete, Inc.
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
-
18
- module Authlete
19
- module Model
20
- module Request
21
- # == Authlete::Model::Request::IntrospectionRequest class
22
- #
23
- # This class represents a request to Authlete's /api/auth/introspection API.
24
- class IntrospectionRequest
25
- include Authlete::Utility
26
- # The constructor which takes a hash that represents a JSON request
27
- # to Authlete's /api/auth/introspection API.
28
- def initialize(hash = nil)
29
- end
30
-
31
- # Parse a JSON string which represents a request to
32
- # Authlete's /api/auth/introspection API
33
- # and generate an instance of IntrospectionRequest.
34
- def self.parse(json)
35
- IntrospectionRequest.new(parse_json(json))
36
- end
37
- end
38
- end
39
- end
1
+ # :nodoc:
2
+ #
3
+ # Copyright (C) 2014-2018 Authlete, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+
18
+ require 'set'
19
+
20
+
21
+ module Authlete
22
+ module Model
23
+ module Request
24
+ # == Authlete::Model::Request::IntrospectionRequest class
25
+ #
26
+ # This class represents a request to Authlete's /api/auth/introspection API.
27
+ class IntrospectionRequest < Authlete::Model::Hashable
28
+ # An access token to introspect. (String)
29
+ attr_accessor :token
30
+
31
+ # Scopes which are required to access the target protected resource.
32
+ # (String array)
33
+ attr_accessor :scopes
34
+
35
+ # Unique user ID. (String)
36
+ attr_accessor :subject
37
+
38
+ private
39
+
40
+ # String attributes.
41
+ STRING_ATTRIBUTES = ::Set.new([ :token, :subject ])
42
+
43
+ # String array attributes.
44
+ STRING_ARRAY_ATTRIBUTES = ::Set.new([ :scopes ])
45
+
46
+ # The constructor which takes a hash that represents a JSON request to
47
+ # Authlete's /api/auth/introspection API.
48
+ def initialize(hash = nil)
49
+ # Set default values to string attributes.
50
+ STRING_ATTRIBUTES.each do |attr|
51
+ send("#{attr}=", nil)
52
+ end
53
+
54
+ # Set default values to string array attributes.
55
+ STRING_ARRAY_ATTRIBUTES.each do |attr|
56
+ send("#{attr}=", nil)
57
+ end
58
+
59
+ # Set attribute values using the given hash.
60
+ authlete_model_update(hash)
61
+ end
62
+
63
+ def authlete_model_convert_key(key)
64
+ key.to_sym
65
+ end
66
+
67
+ def authlete_model_simple_attribute?(key)
68
+ STRING_ATTRIBUTES.include?(key) or
69
+ STRING_ARRAY_ATTRIBUTES.include?(key)
70
+ end
71
+
72
+ def authlete_model_update(hash)
73
+ return if hash.nil?
74
+
75
+ hash.each do |key, value|
76
+ key = authlete_model_convert_key(key)
77
+
78
+ if authlete_model_simple_attribute?(key)
79
+ send("#{key}=", value)
80
+ end
81
+ end
82
+
83
+ self
84
+ end
85
+
86
+ public
87
+
88
+ # Construct an instance from the given hash.
89
+ #
90
+ # If the given argument is nil or is not a Hash, nil is returned.
91
+ # Otherwise, IntrospectionRequest.new(hash) is returned.
92
+ def self.parse(hash)
93
+ if hash.nil? or (hash.kind_of?(Hash) == false)
94
+ return nil
95
+ end
96
+
97
+ return IntrospectionRequest.new(hash)
98
+ end
99
+
100
+ # Convert this object into a hash.
101
+ def to_hash
102
+ hash = {}
103
+
104
+ instance_variables.each do |var|
105
+ key = var.to_s.delete("@").to_sym
106
+ val = instance_variable_get(var)
107
+
108
+ if authlete_model_simple_attribute?(key) or val.nil?
109
+ hash[key] = val
110
+ end
111
+ end
112
+
113
+ hash
114
+ end
115
+ end
116
+ end
117
+ end
40
118
  end
@@ -0,0 +1,125 @@
1
+ # :nodoc:
2
+ #
3
+ # Copyright (C) 2014-2018 Authlete, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+
18
+ require 'set'
19
+
20
+
21
+ module Authlete
22
+ module Model
23
+ module Request
24
+ # == Authlete::Model::Request::RevocationRequest class
25
+ #
26
+ # This class represents a request to Authlete's /api/auth/revocation API.
27
+ class RevocationRequest < Authlete::Model::Hashable
28
+ # The OAuth 2.0 revocation request parameters. (String)
29
+ attr_accessor :parameters
30
+
31
+ # Client ID. (String)
32
+ attr_accessor :clientId
33
+ alias_method :client_id, :clientId
34
+ alias_method :client_id=, :clientId=
35
+
36
+ # Client Secret. (String)
37
+ attr_accessor :clientSecret
38
+ alias_method :client_secret, :clientSecret
39
+ alias_method :client_secret=, :clientSecret=
40
+
41
+ private
42
+
43
+ # String attributes.
44
+ STRING_ATTRIBUTES = ::Set.new([ :parameters, :clientId, :clientSecret ])
45
+
46
+ # Mapping from snake cases to camel cases.
47
+ SNAKE_TO_CAMEL = {
48
+ :client_id => :clientId,
49
+ :client_secret => :clientSecret
50
+ }
51
+
52
+ # The constructor which takes a hash that represents a JSON request to
53
+ # Authlete's /api/auth/revocation API.
54
+ def initialize(hash = nil)
55
+ # Set default values to string attributes.
56
+ STRING_ATTRIBUTES.each do |attr|
57
+ send("#{attr}=", nil)
58
+ end
59
+
60
+ # Set attribute values using the given hash.
61
+ authlete_model_update(hash)
62
+ end
63
+
64
+ def authlete_model_convert_key(key)
65
+ key = key.to_sym
66
+
67
+ # Convert snakecase to camelcase, if necessary.
68
+ if SNAKE_TO_CAMEL.has_key?(key)
69
+ key = SNAKE_TO_CAMEL[key]
70
+ end
71
+
72
+ key
73
+ end
74
+
75
+ def authlete_model_simple_attribute?(key)
76
+ STRING_ATTRIBUTES.include?(key)
77
+ end
78
+
79
+ def authlete_model_update(hash)
80
+ return if hash.nil?
81
+
82
+ hash.each do |key, value|
83
+ key = authlete_model_convert_key(key)
84
+
85
+ if authlete_model_simple_attribute?(key)
86
+ send("#{key}=", value)
87
+ end
88
+ end
89
+
90
+ self
91
+ end
92
+
93
+ public
94
+
95
+ # Construct an instance from the given hash.
96
+ #
97
+ # If the given argument is nil or is not a Hash, nil is returned.
98
+ # Otherwise, RevocationRequest.new(hash) is returned.
99
+ def self.parse(hash)
100
+ if hash.nil? or (hash.kind_of?(Hash) == false)
101
+ return nil
102
+ end
103
+
104
+ return RevocationRequest.new(hash)
105
+ end
106
+
107
+ # Convert this object into a hash.
108
+ def to_hash
109
+ hash = {}
110
+
111
+ instance_variables.each do |var|
112
+ key = var.to_s.delete("@").to_sym
113
+ val = instance_variable_get(var)
114
+
115
+ if authlete_model_simple_attribute?(key) or val.nil?
116
+ hash[key] = val
117
+ end
118
+ end
119
+
120
+ hash
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,102 @@
1
+ # :nodoc:
2
+ #
3
+ # Copyright (C) 2014-2018 Authlete, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+
18
+ require 'set'
19
+
20
+
21
+ module Authlete
22
+ module Model
23
+ module Request
24
+ # == Authlete::Model::Request::StandardIntrospectionRequest class
25
+ #
26
+ # This class represents a request to Authlete's /api/auth/introspection/standard API.
27
+ class StandardIntrospectionRequest < Authlete::Model::Hashable
28
+ # The OAuth 2.0 introspection request parameters. (String)
29
+ attr_accessor :parameters
30
+
31
+ private
32
+
33
+ # String attributes.
34
+ STRING_ATTRIBUTES = ::Set.new([ :parameters ])
35
+
36
+ # The constructor which takes a hash that represents a JSON request to
37
+ # Authlete's /api/auth/introspection/standard API.
38
+ def initialize(hash = nil)
39
+ # Set default values to string attributes.
40
+ STRING_ATTRIBUTES.each do |attr|
41
+ send("#{attr}=", nil)
42
+ end
43
+
44
+ # Set attribute values using the given hash.
45
+ authlete_model_update(hash)
46
+ end
47
+
48
+ def authlete_model_convert_key(key)
49
+ key.to_sym
50
+ end
51
+
52
+ def authlete_model_simple_attribute?(key)
53
+ STRING_ATTRIBUTES.include?(key)
54
+ end
55
+
56
+ def authlete_model_update(hash)
57
+ return if hash.nil?
58
+
59
+ hash.each do |key, value|
60
+ key = authlete_model_convert_key(key)
61
+
62
+ if authlete_model_simple_attribute?(key)
63
+ send("#{key}=", value)
64
+ end
65
+ end
66
+
67
+ self
68
+ end
69
+
70
+ public
71
+
72
+ # Construct an instance from the given hash.
73
+ #
74
+ # If the given argument is nil or is not a Hash, nil is returned.
75
+ # Otherwise, StandardIntrospectionRequest.new(hash) is returned.
76
+ def self.parse(hash)
77
+ if hash.nil? or (hash.kind_of?(Hash) == false)
78
+ return nil
79
+ end
80
+
81
+ return StandardIntrospectionRequest.new(hash)
82
+ end
83
+
84
+ # Convert this object into a hash.
85
+ def to_hash
86
+ hash = {}
87
+
88
+ instance_variables.each do |var|
89
+ key = var.to_s.delete("@").to_sym
90
+ val = instance_variable_get(var)
91
+
92
+ if authlete_model_simple_attribute?(key) or val.nil?
93
+ hash[key] = val
94
+ end
95
+ end
96
+
97
+ hash
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,250 @@
1
+ # :nodoc:
2
+ #
3
+ # Copyright (C) 2014-2018 Authlete, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+
18
+ require 'set'
19
+
20
+
21
+ module Authlete
22
+ module Model
23
+ module Request
24
+ # == Authlete::Model::Request::TokenCreateRequest class
25
+ #
26
+ # This class represents a request to Authlete's /api/auth/token/create API.
27
+ class TokenCreateRequest < Authlete::Model::Hashable
28
+ # The grant type for a newly created access token. One of the following.
29
+ # "REFRESH_TOKEN" is not allowed.
30
+ #
31
+ # "AUTHORIZATION_CODE"
32
+ # "IMPLICIT"
33
+ # "PASSWORD"
34
+ # "CLINET_CREDENTIALS"
35
+ #
36
+ # When "grantType" is either "IMPLICIT" or "CLIENT_CREDENTIALS", a
37
+ # refresh token is not issued. (String)
38
+ attr_accessor :grantType
39
+ alias_method :grant_type, :grantType
40
+ alias_method :grant_type=, :grantType=
41
+
42
+ # The ID of the client application which will be associated with a
43
+ # newly created access token. (Integer)
44
+ attr_accessor :clientId
45
+ alias_method :client_id, :clientId
46
+ alias_method :client_id=, :clientId=
47
+
48
+ # The subject (= unique identifier) of the user who will be associated
49
+ # with a newly created access token. This parameter is required unless
50
+ # the grant type is CLIENT_CREDENTIALS. (String)
51
+ attr_accessor :subject
52
+
53
+ # The scopes which will be associated with a newly created access token.
54
+ # Scopes that are not supported by the service cannot be specified and
55
+ # requesting them will cause an error. (String array)
56
+ attr_accessor :scopes
57
+
58
+ # The duration of a newly created access token in seconds. If the value
59
+ # is 0, the duration is determined according to the settings of the
60
+ # service. (Integer)
61
+ attr_accessor :accessTokenDuration
62
+ alias_method :access_token_duration, :accessTokenDuration
63
+ alias_method :access_token_duration=, :accessTokenDuration=
64
+
65
+ # The duration of a newly created refresh token in seconds. If the value
66
+ # is 0, the duration is determined according to the settings of the
67
+ # service.
68
+ # A refresh token is not created (1) if the service does not support
69
+ # "REFRESH_TOKEN", or (2) if the specified grant type is either "IMPLICIT"
70
+ # or "CLIENT_CREDENTIALS". (Integer)
71
+ attr_accessor :refreshTokenDuration
72
+ alias_method :refresh_token_duration, :refreshTokenDuration
73
+ alias_method :refresh_token_duration=, :refreshTokenDuration=
74
+
75
+ # Extra properties to associate with a newly created access token.
76
+ # (Property array)
77
+ attr_accessor :properties
78
+
79
+ # A boolean request parameter which indicates whether to emulate that
80
+ # the client ID alias is used instead of the original numeric client
81
+ # ID when a new access token is created.
82
+ # This has an effect only on the value of the "aud" claim in a response
83
+ # from UserInfo endpoint. When you access the UserInfo endpoint
84
+ # (which is expected to be implemented using Authlete's /api/auth/userinfo
85
+ # API and /api/auth/userinfo/issue API) with an access token which
86
+ # has been created using Authlete's /api/auth/token/create API with
87
+ # this property (clientIdAliasUsed) "true", the client ID alias is used
88
+ # as the value of the "aud" claim in a response from the UserInfo endpoint.
89
+ # Note that if a client ID alias is not assigned to the client when
90
+ # Authlete's /api/auth/token/create API is called, this property
91
+ # (clientIdAliasUsed) has no effect (it is always regarded as "false").
92
+ # (String)
93
+ attr_accessor :clientIdAlias
94
+ alias_method :client_id_alias, :clientIdAlias
95
+ alias_method :client_id_alias=, :clientIdAlias=
96
+
97
+ # The value of the new access token.
98
+ # The /api/auth/token/create API generates an access token. Therefore,
99
+ # callers of the API do not have to specify values of newly created
100
+ # access tokens. However, in some cases, for example, if you want to
101
+ # migrate existing access tokens from an old system to Authlete, you
102
+ # may want to specify values of access tokens. In such a case, you
103
+ # can specify the value of a newly created access token by passing
104
+ # a non-nil value as the value of accessToken request parameter.
105
+ # The implementation of the /api/auth/token/create uses the value of
106
+ # the accessToken request parameter instead of generating a new value
107
+ # when the request parameter holds a non-nil value.
108
+ # Note that if the hash value of the specified access token already
109
+ # exists in Authlete's database, the access token cannot be inserted
110
+ # and the /api/auth/token/create API will report an error.
111
+ # (String)
112
+ attr_accessor :accessToken
113
+ alias_method :access_token, :accessToken
114
+ alias_method :access_token=, :accessToken=
115
+
116
+ # The value of the new refresh token.
117
+ # The /api/auth/token/create API may generate a refresh token. Therefore,
118
+ # callers of the API do not have to specify values of newly created
119
+ # refresh tokens. However, in some cases, for example, if you want
120
+ # to migrate existing refresh tokens from an old system to Authlete,
121
+ # you may want to specify values of refresh tokens. In such a case,
122
+ # you can specify the value of a newly created refresh token by passing
123
+ # a non-nil value as the value of refreshToken request parameter.
124
+ # The implementation of the /api/auth/token/create uses the value of
125
+ # the refreshToken request parameter instead of generating a new value
126
+ # when the request parameter holds a non-nil value.
127
+ # Note that if the hash value of the specified refresh token already
128
+ # exists in Authlete's database, the refresh token cannot be inserted
129
+ # and the /api/auth/token/create API will report an error.
130
+ # (String)
131
+ attr_accessor :refreshToken
132
+ alias_method :refresh_token, :refreshToken
133
+ alias_method :refresh_token=, :refreshToken=
134
+
135
+ private
136
+
137
+ # Integer attributes.
138
+ INTEGER_ATTRIBUTES = ::Set.new([ :accessTokenDuration, :clientId, :refreshTokenDuration ])
139
+
140
+ # String attributes.
141
+ STRING_ATTRIBUTES = ::Set.new([ :accessToken, :refreshToken, :grantType, :subject, :clientIdAlias ])
142
+
143
+ # String array attributes.
144
+ STRING_ARRAY_ATTRIBUTES = ::Set.new([ :scopes ])
145
+
146
+ # Mapping from snake cases to camel cases.
147
+ SNAKE_TO_CAMEL = {
148
+ :access_token => :accessToken,
149
+ :access_token_duration => :accessTokenDuration,
150
+ :client_id => :clientId,
151
+ :client_id_alias => :clientIdAlias,
152
+ :grant_type => :grantType,
153
+ :refresh_token => :refreshToken,
154
+ :refresh_token_duration => :refreshTokenDuration
155
+ }
156
+
157
+ # The constructor which takes a hash that represents a JSON request to
158
+ # Authlete's /api/auth/token/create API.
159
+ def initialize(hash = nil)
160
+ # Set default values to integer attributes.
161
+ INTEGER_ATTRIBUTES.each do |attr|
162
+ send("#{attr}=", 0)
163
+ end
164
+
165
+ # Set default values to string attributes.
166
+ STRING_ATTRIBUTES.each do |attr|
167
+ send("#{attr}=", nil)
168
+ end
169
+
170
+ # Set default values to string array attributes.
171
+ STRING_ARRAY_ATTRIBUTES.each do |attr|
172
+ send("#{attr}=", nil)
173
+ end
174
+
175
+ @properties = nil
176
+
177
+ # Set attribute values using the given hash.
178
+ authlete_model_update(hash)
179
+ end
180
+
181
+ def authlete_model_convert_key(key)
182
+ key = key.to_sym
183
+
184
+ # Convert snakecase to camelcase, if necessary.
185
+ if SNAKE_TO_CAMEL.has_key?(key)
186
+ key = SNAKE_TO_CAMEL[key]
187
+ end
188
+
189
+ key
190
+ end
191
+
192
+ def authlete_model_simple_attribute?(key)
193
+ INTEGER_ATTRIBUTES.include?(key) or
194
+ STRING_ATTRIBUTES.include?(key) or
195
+ STRING_ARRAY_ATTRIBUTES.include?(key)
196
+ end
197
+
198
+ def authlete_model_update(hash)
199
+ return if hash.nil?
200
+
201
+ hash.each do |key, value|
202
+ key = authlete_model_convert_key(key)
203
+
204
+ if authlete_model_simple_attribute?(key)
205
+ send("#{key}=", value)
206
+ elsif key == :properties
207
+ @properties = get_parsed_array(value) do |element|
208
+ Authlete::Model::Property.parse(element)
209
+ end
210
+ end
211
+ end
212
+
213
+ self
214
+ end
215
+
216
+ public
217
+
218
+ # Construct an instance from the given hash.
219
+ #
220
+ # If the given argument is nil or is not a Hash, nil is returned.
221
+ # Otherwise, TokenCreateRequest.new(hash) is returned.
222
+ def self.parse(hash)
223
+ if hash.nil? or (hash.kind_of?(Hash) == false)
224
+ return nil
225
+ end
226
+
227
+ return TokenCreateRequest.new(hash)
228
+ end
229
+
230
+ # Convert this object into a hash.
231
+ def to_hash
232
+ hash = {}
233
+
234
+ instance_variables.each do |var|
235
+ key = var.to_s.delete("@").to_sym
236
+ val = instance_variable_get(var)
237
+
238
+ if authlete_model_simple_attribute?(key) or val.nil?
239
+ hash[key] = val
240
+ elsif key == :properties
241
+ hash[key] = val.map { |element| element.to_hash }
242
+ end
243
+ end
244
+
245
+ hash
246
+ end
247
+ end
248
+ end
249
+ end
250
+ end