authlete 0.1.4 → 0.1.5

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
  SHA1:
3
- metadata.gz: f9eebbe1dbd1b81cb3acccd34c5d443477d83261
4
- data.tar.gz: 8934d99069e18a80605e8568b443d0f6d97e08cc
3
+ metadata.gz: e7654558117fbc2aa82e0b85086b663f709d162b
4
+ data.tar.gz: 756edef67e1137db22548eafa97d4a5226faa822
5
5
  SHA512:
6
- metadata.gz: 0e8c4d385bbfa81dc02b920e35666203547af745a7fb087369b68afb7af464b5d5923b421a2ef9216834017e256e986476e5c8bd93528a6314ac46cbb51ac1b0
7
- data.tar.gz: f17bbab7957bad25c342be5cf2d71c58085a53449df19e3c67f688a7e89dec21258fb3a21444d8853fe08e3bdb47947f5e08fc5ebcf4362246a2e37e1848749b
6
+ metadata.gz: a782c1b18f97515e1e3afab5688dd55b78a10f2524144b60fa249f0d8a425352abea6207d6e83c177e57a372fa945bb2d64455368c4bcea067d428ce67a349ea
7
+ data.tar.gz: a2b5b0dc9ab9477d95011c29d39eaab24fcc178315123c710b643ab19d3e2f9f6a2ade526814afc35c77731409f2990dbbe2295b4eb56c96a115071781e8cde8
data/lib/authlete.rb CHANGED
@@ -24,15 +24,18 @@ require 'authlete/version'
24
24
  #
25
25
  module Authlete
26
26
  autoload :AuthenticationServer, 'authlete/authentication-server'
27
- autoload :Client, 'authlete/client'
27
+ autoload :Api, 'authlete/api'
28
28
  autoload :Host, 'authlete/host'
29
29
  autoload :Utility, 'authlete/utility'
30
30
 
31
31
  module Model
32
+ autoload :Client, 'authlete/model/client'
33
+ autoload :ClientList, 'authlete/model/client-list'
32
34
  autoload :Scope, 'authlete/model/scope'
33
35
  autoload :Service, 'authlete/model/service'
34
36
  autoload :ServiceList, 'authlete/model/service-list'
35
37
  autoload :SnsCredentials, 'authlete/model/sns-credentials'
38
+ autoload :TaggedValue, 'authlete/model/tagged-value'
36
39
  end
37
40
 
38
41
  module Request
@@ -21,11 +21,11 @@ require 'rest-client'
21
21
 
22
22
 
23
23
  module Authlete
24
- # == Authlete::Client Module
24
+ # == Authlete::Api Module
25
25
  #
26
26
  # A web client that accesses Authlete Web APIs.
27
27
  #
28
- class Client
28
+ class Api
29
29
  include Authlete::Utility
30
30
 
31
31
  # The host which provides Authlete Web APIs.
@@ -113,6 +113,10 @@ module Authlete
113
113
  call_api(method, path, content_type, payload, @service_owner_api_key, @service_owner_api_secret)
114
114
  end
115
115
 
116
+ def call_api_service(method, path, content_type, payload)
117
+ call_api(method, path, content_type, payload, @service_api_key, @service_api_secret)
118
+ end
119
+
116
120
  def call_api_json(path, body, user, password)
117
121
  call_api(:post, path, 'application/json;charset=UTF-8', JSON.generate(body), user, password)
118
122
  end
@@ -159,7 +163,6 @@ module Authlete
159
163
 
160
164
  public
161
165
 
162
-
163
166
  # Call Authlete's /api/service/create API.
164
167
  #
165
168
  # <tt>service</tt> is the content of a new service to create. The type of
@@ -241,6 +244,78 @@ module Authlete
241
244
  Authlete::Model::Service.new(hash)
242
245
  end
243
246
 
247
+ # Call Authlete's /api/client/create API.
248
+ #
249
+ # <tt>client</tt> is the content of a new service to create. The type of
250
+ # the given object is either <tt>Hash</tt> or any object which
251
+ # responds to <tt>to_hash</tt>. In normal cases, Authlete::Model::Client
252
+ # (which responds to <tt>to_hash</tt>) should be used.
253
+ #
254
+ # On success, an instance of Authlete::Model::ClientList is returned.
255
+ # On error, RestClient::Exception (of rest-client GEM) is raised.
256
+ def client_create(client)
257
+ if client.kind_of?(Hash) == false
258
+ if client.respond_to?('to_hash')
259
+ client = client.to_hash
260
+ end
261
+ end
262
+
263
+ hash = call_api_json_service("/api/client/create", client)
264
+
265
+ Authlete::Model::Client.new(hash)
266
+ end
267
+
268
+ # Call Authlete's /api/client/delete/{clientId} API.
269
+ #
270
+ # On error, RestClient::Exception (of rest-client GEM) is raised.
271
+ def client_delete(clientId)
272
+ call_api_service(:delete, "/api/client/delete/#{clientId}", nil, nil)
273
+ end
274
+
275
+ # Call Authlete's /api/client/get/{clientId} API.
276
+ #
277
+ # On success, an instance of Authlete::Model::Service is returned.
278
+ # On error, RestClient::Exception (of rest-client GEM) is raised.
279
+ def client_get(clientId)
280
+ hash = call_api_service(:get, "/api/client/get/#{clientId}", nil, nil)
281
+
282
+ Authlete::Model::Client.new(hash)
283
+ end
284
+
285
+ # Call Authlete's /api/client/get/list API.
286
+ #
287
+ # <tt>params</tt> is an optional hash which contains query parameters
288
+ # for /api/client/get/list API. <tt>:start</tt> and <tt>:end</tt> are
289
+ # a start index (inclusive) and an end index (exclusive), respectively.
290
+ #
291
+ # On success, an instance of Authlete::Model::ClientList is returned.
292
+ # On error, RestClient::Exception (of rest-client GEM) is raised.
293
+ def client_get_list(params = nil)
294
+ hash = call_api_service(:get, "/api/client/get/list#{to_query(params)}", nil, nil)
295
+
296
+ Authlete::Model::ClientList.new(hash)
297
+ end
298
+
299
+ # Call Authlete's /api/client/update/{clientId} API.
300
+ #
301
+ # <tt>client</tt> is the new content of the client. The type of
302
+ # the given object is either <tt>Hash</tt> or any object which
303
+ # responds to <tt>to_hash</tt>. In normal cases, Authlete::Model::Client
304
+ # (which responds to <tt>to_hash</tt>) should be used.
305
+ #
306
+ # On success, an instance of Authlete::Model::Client is returned.
307
+ # On error, RestClient::Exception (of rest-client GEM) is raised.
308
+ def client_update(client)
309
+ if client.kind_of?(Hash) == false
310
+ if client.respond_to?('to_hash')
311
+ client = client.to_hash
312
+ end
313
+ end
314
+
315
+ hash = call_api_json_service("/api/client/update/#{client[:clientId]}", client)
316
+
317
+ Authlete::Model::Client.new(hash)
318
+ end
244
319
 
245
320
  # Call Authlete's {/auth/introspection}
246
321
  # [https://www.authlete.com/authlete_web_apis_introspection.html#auth_introspection]
@@ -0,0 +1,181 @@
1
+ # :nodoc:
2
+ #
3
+ # Copyright (C) 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
+ require 'set'
19
+
20
+
21
+ module Authlete
22
+ module Model
23
+ class ClientList
24
+ # The start index (inclusive) of the clients in this list.
25
+ attr_accessor :start
26
+
27
+ # The end index (exclusive) of the clients in this list.
28
+ attr_accessor :end
29
+
30
+ # The total count of clients.
31
+ attr_accessor :totalCount
32
+ alias_method :total_count, :totalCount
33
+ alias_method :total_count=, :totalCount=
34
+
35
+ # The list of clients.
36
+ attr_accessor :clients
37
+
38
+ private
39
+
40
+ # Integer attributes.
41
+ INTEGER_ATTRIBUTES = ::Set.new([:start, :end, :totalCount])
42
+
43
+ # Mapping from snake cases to camel cases.
44
+ SNAKE_TO_CAMEL = { :total_count => :totalCount }
45
+
46
+ # The constructor
47
+ def initialize(hash = nil)
48
+ # Set default values to integer attributes.
49
+ INTEGER_ATTRIBUTES.each do |attr|
50
+ send("#{attr}=", 0)
51
+ end
52
+
53
+ @clients = nil
54
+
55
+ # Set attribute values using the given hash.
56
+ authlete_model_clientList_update(hash)
57
+ end
58
+
59
+ def authlete_model_clientList_to_key(key)
60
+ key = key.to_sym
61
+
62
+ # Convert snakecase to camelcase, if necessary.
63
+ if SNAKE_TO_CAMEL.has_key?(key)
64
+ key = SNAKE_TO_CAMEL[key]
65
+ end
66
+
67
+ return key
68
+ end
69
+
70
+ def authlete_model_clientList_simple_attribute?(key)
71
+ INTEGER_ATTRIBUTES.include?(key)
72
+ end
73
+
74
+ def authlete_model_clientList_update(hash)
75
+ if hash.nil?
76
+ return
77
+ end
78
+
79
+ hash.each do |key, value|
80
+ key = authlete_model_clientList_to_key(key)
81
+
82
+ # If the attribute is a simple one.
83
+ if authlete_model_clientList_simple_attribute?(key)
84
+ send("#{key}=", value)
85
+ next
86
+ end
87
+
88
+ if key == :clients
89
+ # The attribute 'clients'.
90
+ @clients = authlete_model_clientList_parse_array(value) do |element|
91
+ Authlete::Model::Client.parse(element)
92
+ end
93
+ end
94
+ end
95
+
96
+ return self
97
+ end
98
+
99
+ def authlete_model_clientList_parse_array(array)
100
+ if array.nil? or (array.kind_of?(Array) == false) or (array.length == 0)
101
+ return nil
102
+ end
103
+
104
+ elements = []
105
+
106
+ array.each do |element|
107
+ parsed_element = yield(element)
108
+
109
+ if parsed_element.nil? == false
110
+ elements.push(parsed_element)
111
+ end
112
+ end
113
+
114
+ if elements.length == 0
115
+ return nil
116
+ end
117
+
118
+ return elements
119
+ end
120
+
121
+ public
122
+
123
+ # Construct an instance from the given hash.
124
+ #
125
+ # If the given argument is nil or is not a Hash, nil is returned.
126
+ # Otherwise, ClientList.new(hash) is returned.
127
+ def self.parse(hash)
128
+ if hash.nil? or (hash.kind_of?(Hash) == false)
129
+ return nil
130
+ end
131
+
132
+ return ClientList.new(hash)
133
+ end
134
+
135
+ # Set attribute values using the given hash.
136
+ def update(hash)
137
+ authlete_model_clientList_update(hash)
138
+ end
139
+
140
+ # Convert this object into a hash.
141
+ def to_hash
142
+ hash = {}
143
+
144
+ instance_variables.each do |var|
145
+ key = var.to_s.delete("@").to_sym
146
+ val = instance_variable_get(var)
147
+
148
+ if authlete_model_clientList_simple_attribute?(key) or val.nil?
149
+ hash[key] = val
150
+ elsif val.kind_of?(Array)
151
+ hash[key] = val.map {|element| element.to_hash}
152
+ end
153
+ end
154
+
155
+ return hash
156
+ end
157
+
158
+ def [](key)
159
+ key = authlete_model_clientList_to_key(key)
160
+
161
+ if respond_to?(key)
162
+ return send(key)
163
+ else
164
+ return nil
165
+ end
166
+ end
167
+
168
+ def []=(key, value)
169
+ key = authlete_model_clientList_to_key(key)
170
+ method = "#{key}="
171
+
172
+ if respond_to?(method)
173
+ return send(method, value)
174
+ else
175
+ return nil
176
+ end
177
+ end
178
+ end
179
+ end
180
+ end
181
+
@@ -0,0 +1,492 @@
1
+ # :nodoc:
2
+ #
3
+ # Copyright (C) 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
+ require 'set'
19
+
20
+
21
+ module Authlete
22
+ module Model
23
+ class Client
24
+ # The sequential number of the client application. (Integer)
25
+ attr_accessor :number
26
+
27
+ # The sequential number of the service of the client application.
28
+ # (Integer)
29
+ attr_accessor :serviceNumber
30
+ alias_method :service_number, :serviceNumber
31
+ alias_method :service_number=, :serviceNumber=
32
+
33
+ # The developer of the client application. (String)
34
+ attr_accessor :developer
35
+
36
+ # The client ID. (Integer)
37
+ attr_accessor :clientId
38
+ alias_method :client_id, :clientId
39
+ alias_method :client_id=, :clientId=
40
+
41
+ # The client secret. (String)
42
+ attr_accessor :clientSecret
43
+ alias_method :client_secret, :clientSecret
44
+ alias_method :client_secret=, :clientSecret=
45
+
46
+ # The client type. (String)
47
+ attr_accessor :clientType
48
+ alias_method :client_type, :clientType
49
+ alias_method :client_type=, :clientType=
50
+
51
+ # Redirect URIs that the client application uses to receive a response
52
+ # from the authorization endpoint. (URI array)
53
+ attr_accessor :redirectUris
54
+ alias_method :redirect_uris, :redirectUris
55
+ alias_method :redirect_uris=, :redirectUris=
56
+
57
+ # A string array of response types which the client application declares
58
+ # that it will restrict itself to using (String array)
59
+ attr_accessor :responseTypes
60
+ alias_method :response_types, :responseTypes
61
+ alias_method :response_types=, :responseTypes=
62
+
63
+ # A string array of grant types which the client application declares
64
+ # that it will restrict itself to using. (String array)
65
+ attr_accessor :grantTypes
66
+ alias_method :grant_types, :grantTypes
67
+ alias_method :grant_types=, :grantTypes=
68
+
69
+ # The application type. (String)
70
+ attr_accessor :applicationType
71
+ alias_method :application_type, :applicationType
72
+ alias_method :application_type=, :applicationType=
73
+
74
+ # An array of email addresses of people responsible for the client application.
75
+ # (String array)
76
+ attr_accessor :contacts
77
+
78
+ # The name of the client application. (String)
79
+ attr_accessor :clientName
80
+ alias_method :client_name, :clientName
81
+ alias_method :client_name=, :clientName=
82
+
83
+ # Client names with language tags. (TaggedValue array)
84
+ attr_accessor :clientNames
85
+ alias_method :client_names, :clientNames
86
+ alias_method :client_names=, :clientNames=
87
+
88
+ # The URL pointing to the logo image of the client application. (URI)
89
+ attr_accessor :logoUri
90
+ alias_method :logo_uri, :logoUri
91
+ alias_method :logo_uri=, :logoUri=
92
+
93
+ # Logo image URLs with language tags. (TaggedValue array)
94
+ attr_accessor :logoUris
95
+ alias_method :logo_uris, :logoUris
96
+ alias_method :logo_uris=, :logoUris=
97
+
98
+ # The URL pointing to the home page of the client application. (URI)
99
+ attr_accessor :clientUri
100
+ alias_method :client_uri, :clientUri
101
+ alias_method :client_uri=, :clientUri=
102
+
103
+ # Home page URLs with language tags. (TaggedValue array)
104
+ attr_accessor :clientUris
105
+ alias_method :client_uris, :clientUris
106
+ alias_method :client_uris=, :clientUris=
107
+
108
+ # The URL pointing to the page which describes the policy
109
+ # as to how end-users' profile data are used. (URI)
110
+ attr_accessor :policyUri
111
+ alias_method :policy_uri, :policyUri
112
+ alias_method :policy_uri=, :policyUri=
113
+
114
+ # URLs of policy pages with language tags. (TaggedValue array)
115
+ attr_accessor :policyUris
116
+ alias_method :policy_uris, :policyUris
117
+ alias_method :policy_uris=, :policyUris=
118
+
119
+ # The URL pointing to the "Terms Of Service" page. (URI)
120
+ attr_accessor :tosUri
121
+ alias_method :tos_uri, :tosUri
122
+ alias_method :tos_uri=, :tosUri=
123
+
124
+ # URLs of "Terms Of Service" pages with language tags.
125
+ # (TaggedValue array)
126
+ attr_accessor :tosUris
127
+ alias_method :tos_uris, :tosUris
128
+ alias_method :tos_uris=, :tosUris=
129
+
130
+ # The URL pointing to the JWK Set of the client application. (URI)
131
+ attr_accessor :jwksUri
132
+ alias_method :jwks_uri, :jwksUri
133
+ alias_method :jwks_uri=, :jwksUri=
134
+
135
+ # The content of the JWK Set of the client application. (String)
136
+ attr_accessor :jwks
137
+
138
+ # The sector identifier which is a URL starting with https. (URI)
139
+ attr_accessor :sectorIdentifier
140
+ alias_method :sector_identifier, :sectorIdentifier
141
+ alias_method :sector_identifier=, :sectorIdentifier=
142
+
143
+ # The subject type that the client application requests. (URI)
144
+ attr_accessor :subjectType
145
+ alias_method :subject_type, :subjectType
146
+ alias_method :subject_type=, :subjectType=
147
+
148
+ # The value of alg header parameter of JWS that the client application
149
+ # requires the service to use for signing an ID token. (String)
150
+ attr_accessor :idTokenSignAlg
151
+ alias_method :id_token_sign_alg, :idTokenSignAlg
152
+ alias_method :id_token_sign_alg=, :idTokenSignAlg=
153
+
154
+ # The value of alg header parameter of JWE that the client application
155
+ # requires the service to use for encrypting an ID token. (String)
156
+ attr_accessor :idTokenEncryptionAlg
157
+ alias_method :id_token_encryption_alg, :idTokenEncryptionAlg
158
+ alias_method :id_token_encryption_alg=, :idTokenEncryptionAlg=
159
+
160
+ # The value of enc header parameter of JWE that the client application
161
+ # requires the service to use for encrypting an ID token. (String)
162
+ attr_accessor :idTokenEncryptionEnc
163
+ alias_method :id_token_encryption_enc, :idTokenEncryptionEnc
164
+ alias_method :id_token_encryption_enc=, :idTokenEncryptionEnc=
165
+
166
+ # The value of alg header parameter of JWS that the client application
167
+ # requires the service to use for signing the JWT returned from the user
168
+ # info endpoint. One of the values listed in JWS Algorithm. (String)
169
+ attr_accessor :userInfoSignAlg
170
+ alias_method :user_info_sign_alg, :userInfoSignAlg
171
+ alias_method :user_info_sign_alg=, :userInfoSignAlg=
172
+
173
+ # The value of alg header parameter of JWE that the client application
174
+ # requires the service to use for encrypting the JWT returned from
175
+ # the user info endpoint. (String)
176
+ attr_accessor :userInfoEncryptionAlg
177
+ alias_method :user_info_encryption_alg, :userInfoEncryptionAlg
178
+ alias_method :user_info_encryption_alg=, :userInfoEncryptionAlg=
179
+
180
+ # The value of enc header parameter of JWE that the client application
181
+ # requires the service to use for encrypting the JWT returned from
182
+ # the user info endpoint. (String)
183
+ attr_accessor :userInfoEncryptionEnc
184
+ alias_method :user_info_encryption_enc, :userInfoEncryptionEnc
185
+ alias_method :user_info_encryption_enc=, :userInfoEncryptionEnc=
186
+
187
+ # The value of alg header parameter of JWS that the client application
188
+ # uses for signing a request object. (String)
189
+ attr_accessor :requestSignAlg
190
+ alias_method :request_sign_alg, :requestSignAlg
191
+ alias_method :request_sign_alg=, :requestSignAlg=
192
+
193
+ # The value of alg header parameter of JWE that the client application
194
+ # uses for encrypting a request object. (String)
195
+ attr_accessor :requestEncryptionAlg
196
+ alias_method :request_encryption_alg, :requestEncryptionAlg
197
+ alias_method :request_encryption_alg=, :requestEncryptionAlg=
198
+
199
+ # The value of enc header parameter of JWE that the client application
200
+ # uses for encrypting a request object. (String)
201
+ attr_accessor :requestEncryptionEnc
202
+ alias_method :request_encryption_enc, :requestEncryptionEnc
203
+ alias_method :request_encryption_enc=, :requestEncryptionEnc=
204
+
205
+ # The client authentication method that the client application
206
+ # declares that it uses at the token endpoint. (String)
207
+ attr_accessor :tokenAuthMethod
208
+ alias_method :token_auth_method, :tokenAuthMethod
209
+ alias_method :token_auth_method=, :tokenAuthMethod=
210
+
211
+ # The value of alg header parameter of JWS which is used
212
+ # for client authentication at the token endpoint. (String)
213
+ attr_accessor :tokenAuthSignAlg
214
+ alias_method :token_auth_sign_alg, :tokenAuthSignAlg
215
+ alias_method :token_auth_sign_alg=, :tokenAuthSignAlg=
216
+
217
+ # The default maximum authentication age in seconds. (Integer)
218
+ attr_accessor :defaultMaxAge
219
+ alias_method :default_max_age, :defaultMaxAge
220
+ alias_method :default_max_age=, :defaultMaxAge=
221
+
222
+ # The default ACRs (Authentication Context Class References). (String array)
223
+ attr_accessor :defaultAcrs
224
+ alias_method :default_acrs, :defaultAcrs
225
+ alias_method :default_acrs=, :defaultAcrs=
226
+
227
+ # The flag showing the client application requires the auth_time claim
228
+ # to be in an ID token. (Boolean)
229
+ attr_accessor :authTimeRequired
230
+ alias_method :auth_time_required, :authTimeRequired
231
+ alias_method :auth_time_required=, :authTimeRequired=
232
+
233
+ # The URL which a third party can use to initiate a login by the client
234
+ # application. (URI)
235
+ attr_accessor :loginUri
236
+ alias_method :login_uri, :loginUri
237
+ alias_method :login_uri=, :loginUri=
238
+
239
+ # An array of URLs each of which points to a request object.
240
+ # (URI array)
241
+ attr_accessor :requestUris
242
+ alias_method :request_uris, :requestUris
243
+ alias_method :request_uris=, :requestUris=
244
+
245
+ # The description about the client application. At most 200 letters in unicode.
246
+ # (String)
247
+ attr_accessor :description
248
+
249
+ # Descriptions about the client application with language tags. (TaggesValue array)
250
+ attr_accessor :descriptions
251
+
252
+ # The timestamp at which the client was created. (Integer)
253
+ attr_accessor :createdAt
254
+ alias_method :created_at, :createdAt
255
+ alias_method :created_at=, :createdAt=
256
+
257
+ # The timestamp at which the client was modified. (Integer)
258
+ attr_accessor :modifiedAt
259
+ alias_method :modified_at, :modifiedAt
260
+ alias_method :modified_at=, :modifiedAt=
261
+
262
+ private
263
+
264
+ # Integer attributes.
265
+ INTEGER_ATTRIBUTES = ::Set.new([
266
+ :number, :serviceNumber, :clientId, :defaultMaxAge, :createdAt, :modifiedAt
267
+ ])
268
+
269
+ # Boolean attributes.
270
+ BOOLEAN_ATTRIBUTES = ::Set.new([ :authTimeRequired ])
271
+
272
+ # String attributes.
273
+ STRING_ATTRIBUTES = ::Set.new([
274
+ :developer, :clientSecret, :clientType, :responseTypes, :applicationType,
275
+ :clientName, :logoUri, :clientUri, :policyUri, :tosUri, :jwksUri, :jwks,
276
+ :sectorIdentifier, :subjectType, :idTokenSignAlg, :idTokenEncryptionAlg,
277
+ :idTokenEncryptionEnc, :userInfoSignAlg, :userInfoEncryptionAlg, :userInfoEncryptionEnc,
278
+ :requestSignAlg, :requestEncryptionAlg, :requestEncryptionEnc, :tokenAuthMethod,
279
+ :tokenAuthSignAlg, :loginUri, :description
280
+ ])
281
+
282
+ # String array attributes.
283
+ STRING_ARRAY_ATTRIBUTES = ::Set.new([
284
+ :redirectUris, :responseTypes, :grantTypes, :contacts, :defaultAcrs, :requestUris
285
+ ])
286
+
287
+ # Tagged value array atributes.
288
+ TAGGED_VALUE_ARRAY_ATTRIBUTES = ::Set.new([
289
+ :clientNames, :logoUris, :clientUris, :policyUris, :tosUris, :descriptions
290
+ ])
291
+
292
+ # Mapping from snake cases to camel cases.
293
+ SNAKE_TO_CAMEL = {
294
+ :service_number => :serviceNumber,
295
+ :client_id => :clientId,
296
+ :client_secret => :clientSecret,
297
+ :client_type => :clientType,
298
+ :redirect_uris => :redirectUris,
299
+ :response_types => :responseTypes,
300
+ :grant_types => :grantTypes,
301
+ :application_type => :applicationType,
302
+ :client_name => :clientName,
303
+ :client_names => :clientNames,
304
+ :logo_uri => :logoUri,
305
+ :logo_uris => :logoUris,
306
+ :client_uri => :clientUri,
307
+ :client_uris => :clientUris,
308
+ :policy_uri => :policyUri,
309
+ :policy_uris => :policyUris,
310
+ :tos_uri => :tosUri,
311
+ :tos_uris => :tosUris,
312
+ :jwks_uri => :jwksUri,
313
+ :sector_identifier => :sectorIdentifier,
314
+ :subject_type => :subjectType,
315
+ :id_token_sign_alg => :idTokenSignAlg,
316
+ :id_token_encryption_alg => :idTokenEncryptionAlg,
317
+ :id_token_encryption_enc => :idTokenEncryptionEnc,
318
+ :user_info_sign_alg => :userInfoSignAlg,
319
+ :user_info_encryption_alg => :userInfoEncryptionAlg,
320
+ :user_info_encryption_enc => :userInfoEncryptionEnc,
321
+ :request_sign_alg => :requestSignAlg,
322
+ :request_encryption_alg => :requestEncryptionAlg,
323
+ :request_encryption_enc => :requestEncryptionEnc,
324
+ :token_auth_method => :tokenAuthMethod,
325
+ :token_auth_sign_alg => :tokenAuthSignAlg,
326
+ :default_max_age => :defaultMaxAge,
327
+ :default_acrs => :defaultAcrs,
328
+ :auth_time_required => :authTimeRequired,
329
+ :login_uri => :loginUri,
330
+ :request_uris => :requestUris,
331
+ :created_at => :createdAt,
332
+ :modified_at => :modifiedAt
333
+ }
334
+
335
+ # The constructor
336
+ def initialize(hash = nil)
337
+ # Set default values to integer attributes.
338
+ INTEGER_ATTRIBUTES.each do |attr|
339
+ send("#{attr}=", 0)
340
+ end
341
+
342
+ # Set default values to boolean attributes.
343
+ BOOLEAN_ATTRIBUTES.each do |attr|
344
+ send("#{attr}=", false)
345
+ end
346
+
347
+ # Set default values to string attributes.
348
+ STRING_ATTRIBUTES.each do |attr|
349
+ send("#{attr}=", nil)
350
+ end
351
+
352
+ # Set default values to string array attributes.
353
+ STRING_ARRAY_ATTRIBUTES.each do |attr|
354
+ send("#{attr}=", nil)
355
+ end
356
+
357
+ # Set default values to tagged value array attributes.
358
+ TAGGED_VALUE_ARRAY_ATTRIBUTES.each do |attr|
359
+ send("#{attr}=", nil)
360
+ end
361
+
362
+ # Set attribute values using the given hash.
363
+ authlete_model_service_update(hash)
364
+ end
365
+
366
+ def authlete_model_service_to_key(key)
367
+ key = key.to_sym
368
+
369
+ # Convert snakecase to camelcase, if necessary.
370
+ if SNAKE_TO_CAMEL.has_key?(key)
371
+ key = SNAKE_TO_CAMEL[key]
372
+ end
373
+
374
+ return key
375
+ end
376
+
377
+ def authlete_model_client_simple_attribute?(key)
378
+ INTEGER_ATTRIBUTES.include?(key) or
379
+ BOOLEAN_ATTRIBUTES.include?(key) or
380
+ STRING_ATTRIBUTES.include?(key) or
381
+ STRING_ARRAY_ATTRIBUTES.include?(key)
382
+ end
383
+
384
+ def authlete_model_client_update(hash)
385
+ if hash.nil?
386
+ return
387
+ end
388
+
389
+ hash.each do |key, value|
390
+ key = authlete_model_client_to_key(key)
391
+
392
+ # If the attribute is a simple one.
393
+ if authlete_model_client_simple_attribute?(key)
394
+ send("#{key}=", value)
395
+ next
396
+ end
397
+
398
+ # If the attribute is an array of tagged values.
399
+ if TAGGED_VALUE_ARRAY_ATTRIBUTES.include?(key)
400
+ parsed = authlete_model_client_parse_array(value) do |element|
401
+ Authlete::Model::TaggedValue.parse(element)
402
+ end
403
+
404
+ send("#{key}=", parsed)
405
+ end
406
+ end
407
+
408
+ return self
409
+ end
410
+
411
+ def authlete_model_client_parse_array(array)
412
+ if array.nil? or (array.kind_of?(Array) == false) or (array.length == 0)
413
+ return nil
414
+ end
415
+
416
+ elements = []
417
+
418
+ array.each do |element|
419
+ parsed_element = yield(element)
420
+
421
+ if parsed_element.nil? == false
422
+ elements.push(parsed_element)
423
+ end
424
+ end
425
+
426
+ if elements.length == 0
427
+ return nil
428
+ end
429
+
430
+ return elements
431
+ end
432
+
433
+ public
434
+
435
+ # Construct an instance from the given hash.
436
+ #
437
+ # If the given argument is nil or is not a Hash, nil is returned.
438
+ # Otherwise, Service.new(hash) is returned.
439
+ def self.parse(hash)
440
+ if hash.nil? or (hash.kind_of?(Hash) == false)
441
+ return nil
442
+ end
443
+
444
+ return Client.new(hash)
445
+ end
446
+
447
+ # Set attribute values using the given hash.
448
+ def update(hash)
449
+ authlete_model_client_update(hash)
450
+ end
451
+
452
+ # Convert this object into a hash.
453
+ def to_hash
454
+ hash = {}
455
+
456
+ instance_variables.each do |var|
457
+ key = var.to_s.delete("@").to_sym
458
+ val = instance_variable_get(var)
459
+
460
+ if authlete_model_client_simple_attribute?(key) or val.nil?
461
+ hash[key] = val
462
+ elsif val.kind_of?(Array)
463
+ hash[key] = val.map {|element| element.to_hash}
464
+ end
465
+ end
466
+
467
+ return hash
468
+ end
469
+
470
+ def [](key)
471
+ key = authlete_model_client_to_key(key)
472
+
473
+ if respond_to?(key)
474
+ return send(key)
475
+ else
476
+ return nil
477
+ end
478
+ end
479
+
480
+ def []=(key, value)
481
+ key = authlete_model_client_to_key(key)
482
+ method = "#{key}="
483
+
484
+ if respond_to?(method)
485
+ return send(method, value)
486
+ else
487
+ return nil
488
+ end
489
+ end
490
+ end
491
+ end
492
+ end
@@ -0,0 +1,135 @@
1
+ # :nodoc:
2
+ #
3
+ # Copyright (C) 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
+ require 'set'
19
+
20
+
21
+ module Authlete
22
+ module Model
23
+ class TaggedValue
24
+ # The language tag part. (String)
25
+ attr_accessor :tag
26
+
27
+ # The value part. (String)
28
+ attr_accessor :value
29
+
30
+
31
+ private
32
+
33
+ # String attributes.
34
+ STRING_ATTRIBUTES = ::Set.new([:tag, :value])
35
+
36
+ # The constructor
37
+ def initialize(hash = new)
38
+ # Set default values to string attributes.
39
+ STRING_ATTRIBUTES.each do |attr|
40
+ send("#{attr}=", nil)
41
+ end
42
+
43
+ # Set attribute values using the given hash.
44
+ authlete_model_taggedValue_update(hash)
45
+ end
46
+
47
+ def authlete_model_taggedValue_to_key(key)
48
+ key = key.to_sym
49
+
50
+ # Convert snakecase to camelcase, if necessary.
51
+ if SNAKE_TO_CAMEL.has_key?(key)
52
+ key = SNAKE_TO_CAMEL[key]
53
+ end
54
+
55
+ return key
56
+ end
57
+
58
+ def authlete_model_taggedValue_simple_attribute?(key)
59
+ STRING_ATTRIBUTES.include?(key)
60
+ end
61
+
62
+ def authlete_model_taggedValue_update(hash)
63
+ if hash.nil?
64
+ return
65
+ end
66
+
67
+ hash.each do |key, value|
68
+ key = authlete_model_taggedValue_to_key(key)
69
+
70
+ # If the attribute is a simple one.
71
+ if authlete_model_taggedValue_simple_attribute?(key)
72
+ send("#{key}=", value)
73
+ next
74
+ end
75
+ end
76
+
77
+ return self
78
+ end
79
+
80
+ public
81
+
82
+ # Construct an instance from the given hash.
83
+ #
84
+ # If the given argument is nil or is not a Hash, nil is returned.
85
+ # Otherwise, TaggedValue.new(hash) is returned.
86
+ def self.parse(hash)
87
+ if hash.nil? or (hash.kind_of?(Hash) == false)
88
+ return nil
89
+ end
90
+
91
+ return Authlete::Model::TaggedValue.new(hash)
92
+ end
93
+
94
+ # Set attribute values using the given hash.
95
+ def update(hash)
96
+ authlete_model_taggedValue_update(hash)
97
+ end
98
+
99
+ # Convert this object into a hash.
100
+ def to_hash
101
+ hash = {}
102
+
103
+ instance_variables.each do |var|
104
+ key = var.to_s.delete("@").to_sym
105
+ val = instance_variable_get(var)
106
+
107
+ hash[key] = val
108
+ end
109
+
110
+ return hash
111
+ end
112
+
113
+ def [](key)
114
+ key = authlete_model_taggedValue_to_key(key)
115
+
116
+ if respond_to?(key)
117
+ return send(key)
118
+ else
119
+ return nil
120
+ end
121
+ end
122
+
123
+ def []=(key, value)
124
+ key = authlete_model_taggedValue_to_key(key)
125
+ method = "#{key}="
126
+
127
+ if respond_to?(method)
128
+ return send(method, value)
129
+ else
130
+ return nil
131
+ end
132
+ end
133
+ end
134
+ end
135
+ end
@@ -1,3 +1,3 @@
1
1
  module Authlete
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authlete
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takahiko Kawasaki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-07 00:00:00.000000000 Z
11
+ date: 2015-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -67,13 +67,16 @@ files:
67
67
  - Rakefile
68
68
  - authlete.gemspec
69
69
  - lib/authlete.rb
70
+ - lib/authlete/api.rb
70
71
  - lib/authlete/authentication-server.rb
71
- - lib/authlete/client.rb
72
72
  - lib/authlete/host.rb
73
+ - lib/authlete/model/client-list.rb
74
+ - lib/authlete/model/client.rb
73
75
  - lib/authlete/model/scope.rb
74
76
  - lib/authlete/model/service-list.rb
75
77
  - lib/authlete/model/service.rb
76
78
  - lib/authlete/model/sns-credentials.rb
79
+ - lib/authlete/model/tagged-value.rb
77
80
  - lib/authlete/request/authentication-callback-request.rb
78
81
  - lib/authlete/response/authentication-callback-response.rb
79
82
  - lib/authlete/response/base-response.rb