authlete 0.3.6 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/lib/authlete.rb +14 -14
  3. data/lib/authlete/api.rb +115 -35
  4. data/lib/authlete/authentication-server.rb +4 -4
  5. data/lib/authlete/model/client-list.rb +127 -181
  6. data/lib/authlete/model/client.rb +444 -492
  7. data/lib/authlete/model/hashable.rb +65 -0
  8. data/lib/authlete/model/request/authentication-callback-request.rb +91 -0
  9. data/lib/authlete/model/request/authorization-fail-request.rb +107 -0
  10. data/lib/authlete/model/request/authorization-issue-request.rb +136 -0
  11. data/lib/authlete/model/request/authorization-request.rb +104 -0
  12. data/lib/authlete/model/request/developer-authentication-callback-request.rb +85 -0
  13. data/lib/authlete/model/request/introspection-request.rb +40 -0
  14. data/lib/authlete/model/request/token-fail-request.rb +104 -0
  15. data/lib/authlete/model/request/token-issue-request.rb +104 -0
  16. data/lib/authlete/model/request/token-request.rb +124 -0
  17. data/lib/authlete/model/response/authentication-callback-response.rb +54 -0
  18. data/lib/authlete/model/response/authorization-fail-response.rb +47 -0
  19. data/lib/authlete/model/response/authorization-issue-response.rb +47 -0
  20. data/lib/authlete/model/response/authorization-response.rb +146 -0
  21. data/lib/authlete/model/response/developer-authentication-callback-response.rb +56 -0
  22. data/lib/authlete/model/response/introspection-response.rb +129 -0
  23. data/lib/authlete/model/response/result.rb +45 -0
  24. data/lib/authlete/model/response/service-creatable-response.rb +51 -0
  25. data/lib/authlete/model/response/token-fail-response.rb +48 -0
  26. data/lib/authlete/model/response/token-issue-response.rb +48 -0
  27. data/lib/authlete/model/response/token-response.rb +69 -0
  28. data/lib/authlete/model/scope.rb +17 -42
  29. data/lib/authlete/model/service-list.rb +19 -74
  30. data/lib/authlete/model/service-owner.rb +16 -40
  31. data/lib/authlete/model/service.rb +20 -76
  32. data/lib/authlete/model/sns-credentials.rb +16 -41
  33. data/lib/authlete/model/tagged-value.rb +105 -135
  34. data/lib/authlete/utility.rb +29 -5
  35. data/lib/authlete/version.rb +1 -1
  36. metadata +24 -10
  37. data/lib/authlete/request/authentication-callback-request.rb +0 -90
  38. data/lib/authlete/request/developer-authentication-callback-request.rb +0 -84
  39. data/lib/authlete/response/authentication-callback-response.rb +0 -58
  40. data/lib/authlete/response/base-response.rb +0 -41
  41. data/lib/authlete/response/developer-authentication-callback-response.rb +0 -60
  42. data/lib/authlete/response/introspection-response.rb +0 -130
  43. data/lib/authlete/response/service-creatable-response.rb +0 -52
@@ -0,0 +1,45 @@
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 Response
21
+ # == Authlete::Model::Response::BaseResponse
22
+ #
23
+ # The base class of responses from Authlete Web APIs.
24
+ class Result
25
+ include Authlete::Utility
26
+ # The code assigned to the result of the API call.
27
+ # (String)
28
+ attr_accessor :result_code
29
+
30
+ # The message about the result of the API call.
31
+ # (String)
32
+ attr_accessor :result_message
33
+
34
+ private
35
+
36
+ # The constructor which takes a hash that represents a JSON response
37
+ # from /api/auth/introspection API.
38
+ def initialize(hash = {})
39
+ @result_code = extract_value(hash, :resultCode)
40
+ @response_content = extract_value(hash, :responseContent)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,51 @@
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
+ module Authlete
19
+ module Model
20
+ module Response
21
+ # == Authlete::Model::Response::ServiceCreatableResponse class
22
+ class ServiceCreatableResponse
23
+ include Authlete::Utility
24
+ # A boolean flag to indicate whether the service owner can
25
+ # create a new service or not.
26
+ attr_accessor :creatable
27
+
28
+ # The number of services that the service owner currently has.
29
+ attr_accessor :count
30
+
31
+ # The maximum number of services allowed in the plan of the
32
+ # service owner.
33
+ attr_accessor :limit
34
+
35
+ # The plan of the service owner.
36
+ attr_accessor :plan
37
+
38
+ # The constructor which takes a hash that represents a JSON
39
+ # response from /api/service/creatable API.
40
+ def initialize(hash = {})
41
+ @creatable = extract_boolean_value(hash, :creatable)
42
+ @count = extract_value(hash, :count);
43
+ @limit = extract_value(hash, :limit);
44
+ @plan = extract_value(hash, :plan);
45
+ end
46
+
47
+ alias_method :creatable?, :creatable
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,48 @@
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 Response
21
+ # == Authlete::Model::Response::TokenFailRequest class
22
+ #
23
+ # This class represents a response from Authlete's /api/auth/token API.
24
+ class TokenFailRequest
25
+ include Authlete::Utility < Authlete::Model::Response::Result
26
+ # The next action that the service implementation should take.
27
+ # (String)
28
+ attr_accessor :action
29
+
30
+ # The response content which can be used to generate a response
31
+ # to the client application. The format of the value varies
32
+ # depending on the value of "action". (String)
33
+ attr_accessor :response_content
34
+
35
+ private
36
+
37
+ # The constructor which takes a hash that represents a JSON response
38
+ # from Authlete's /api/auth/token/fail API.
39
+ def initialize(hash = {})
40
+ super(hash)
41
+
42
+ @action = extract_value(hash, :action)
43
+ @response_content = extract_value(hash, :responseContent)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,48 @@
1
+ authorization-response.rb# :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 Response
21
+ # == Authlete::Model::Response::TokenIssueResponse class
22
+ #
23
+ # This class represents a response from Authlete's /api/auth/token/issue API.
24
+ class TokenIssueResponse < Authlete::Model::Response::Result
25
+ include Authlete::Utility
26
+ # The next action that the service implementation should take.
27
+ # (String)
28
+ attr_accessor :action
29
+
30
+ # The response content which can be used to generate a response
31
+ # to the client application. The format of the value varies
32
+ # depending on the value of "action". (String)
33
+ attr_accessor :response_content
34
+
35
+ private
36
+
37
+ # The constructor which takes a hash that represents a JSON response
38
+ # from Authlete's /api/auth/token/issue API.
39
+ def initialize(hash = {})
40
+ super(hash)
41
+
42
+ @action = extract_value(hash, :action)
43
+ @response_content = extract_value(hash, :responseContent)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,69 @@
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 Response
21
+ # == Authlete::Model::Response::TokenResponse class
22
+ #
23
+ # This class represents a response from Authlete's /api/auth/token API.
24
+ class TokenResponse < Authlete::Model::Response::Result
25
+ include Authlete::Utility
26
+ # The next action that the service implementation should take.
27
+ # (String)
28
+ attr_accessor :action
29
+
30
+ # The value of "password" request parameter.
31
+ #
32
+ # This value is non-null only when the value of
33
+ # "grant_type" request parameter in the token request is "password".
34
+ attr_accessor :password
35
+
36
+ # The response content which can be used to generate a response
37
+ # to the client application. The format of the value varies
38
+ # depending on the value of "action". (String)
39
+ attr_accessor :response_content
40
+
41
+ # The ticket issued from Authlete's /api/auth/token endpoint.
42
+ # This parameter is to be used as "ticket" request parameter
43
+ # for /api/auth/token/issue API or /api/auth/token/fail API.
44
+ # This parameter is non-null only when "action" is "PASSWORD PASSWORD".
45
+ attr_accessor :ticket
46
+
47
+ # The value of "username" request parameter.
48
+ #
49
+ # This value is non-null only when the value of
50
+ # "grant_type" request parameter in the token request is "password".
51
+ attr_accessor :username
52
+
53
+ private
54
+
55
+ # The constructor which takes a hash that represents a JSON response
56
+ # from Authlete's /api/auth/token API.
57
+ def initialize(hash = {})
58
+ super(hash)
59
+
60
+ @action = extract_value(hash, :action)
61
+ @response_content = extract_value(hash, :responseContent)
62
+ @password = extract_value(hash, :password)
63
+ @ticket = extract_value(hash, :ticket)
64
+ @username = extract_value(hash, :username)
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -20,7 +20,7 @@ require 'set'
20
20
 
21
21
  module Authlete
22
22
  module Model
23
- class Scope
23
+ class Scope < Authlete::Model::Hashable
24
24
  # The description about this scope. (String)
25
25
  attr_accessor :description
26
26
 
@@ -36,13 +36,13 @@ module Authlete
36
36
  private
37
37
 
38
38
  # Boolean attributes.
39
- BOOLEAN_ATTRIBUTES = ::Set.new([:defaultEntry])
39
+ BOOLEAN_ATTRIBUTES = ::Set.new([ :defaultEntry ])
40
40
 
41
41
  # String attributes.
42
- STRING_ATTRIBUTES = ::Set.new([:description, :name])
42
+ STRING_ATTRIBUTES = ::Set.new([ :description, :name ])
43
43
 
44
44
  # Mapping from snake cases to camel cases.
45
- SNAKE_TO_CAMEL = {:default_entry => :defaultEntry}
45
+ SNAKE_TO_CAMEL = { :default_entry => :defaultEntry }
46
46
 
47
47
  # The constructor
48
48
  def initialize(hash = new)
@@ -57,10 +57,10 @@ module Authlete
57
57
  end
58
58
 
59
59
  # Set attribute values using the given hash.
60
- authlete_model_scope_update(hash)
60
+ authlete_model_update(hash)
61
61
  end
62
62
 
63
- def authlete_model_scope_to_key(key)
63
+ def authlete_model_convert_key(key)
64
64
  key = key.to_sym
65
65
 
66
66
  # Convert snakecase to camelcase, if necessary.
@@ -68,30 +68,26 @@ module Authlete
68
68
  key = SNAKE_TO_CAMEL[key]
69
69
  end
70
70
 
71
- return key
71
+ key
72
72
  end
73
73
 
74
- def authlete_model_scope_simple_attribute?(key)
74
+ def authlete_model_simple_attribute?(key)
75
75
  BOOLEAN_ATTRIBUTES.include?(key) or
76
76
  STRING_ATTRIBUTES.include?(key)
77
77
  end
78
78
 
79
- def authlete_model_scope_update(hash)
80
- if hash.nil?
81
- return
82
- end
79
+ def authlete_model_update(hash)
80
+ return if hash.nil?
83
81
 
84
82
  hash.each do |key, value|
85
- key = authlete_model_scope_to_key(key)
83
+ key = authlete_model_convert_key(key)
86
84
 
87
- # If the attribute is a simple one.
88
- if authlete_model_scope_simple_attribute?(key)
85
+ if authlete_model_simple_attribute?(key)
89
86
  send("#{key}=", value)
90
- next
91
87
  end
92
88
  end
93
89
 
94
- return self
90
+ self
95
91
  end
96
92
 
97
93
  public
@@ -105,12 +101,12 @@ module Authlete
105
101
  return nil
106
102
  end
107
103
 
108
- return Authlete::Model::Scope.new(hash)
104
+ Authlete::Model::Scope.new(hash)
109
105
  end
110
106
 
111
107
  # Set attribute values using the given hash.
112
108
  def update(hash)
113
- authlete_model_scope_update(hash)
109
+ authlete_model_update(hash)
114
110
  end
115
111
 
116
112
  # Convert this object into a hash.
@@ -124,29 +120,8 @@ module Authlete
124
120
  hash[key] = val
125
121
  end
126
122
 
127
- return hash
128
- end
129
-
130
- def [](key)
131
- key = authlete_model_scope_to_key(key)
132
-
133
- if respond_to?(key)
134
- return send(key)
135
- else
136
- return nil
137
- end
138
- end
139
-
140
- def []=(key, value)
141
- key = authlete_model_scope_to_key(key)
142
- method = "#{key}="
143
-
144
- if respond_to?(method)
145
- return send(method, value)
146
- else
147
- return nil
148
- end
123
+ hash
149
124
  end
150
125
  end
151
126
  end
152
- end
127
+ end
@@ -20,7 +20,8 @@ require 'set'
20
20
 
21
21
  module Authlete
22
22
  module Model
23
- class ServiceList
23
+ class ServiceList < Authlete::Model::Hashable
24
+ include Authlete::Utility
24
25
  # The start index (inclusive) of the services in this list.
25
26
  attr_accessor :start
26
27
 
@@ -38,7 +39,7 @@ module Authlete
38
39
  private
39
40
 
40
41
  # Integer attributes.
41
- INTEGER_ATTRIBUTES = ::Set.new([:start, :end, :totalCount])
42
+ INTEGER_ATTRIBUTES = ::Set.new([ :start, :end, :totalCount ])
42
43
 
43
44
  # Mapping from snake cases to camel cases.
44
45
  SNAKE_TO_CAMEL = { :total_count => :totalCount }
@@ -53,10 +54,10 @@ module Authlete
53
54
  @services = nil
54
55
 
55
56
  # Set attribute values using the given hash.
56
- authlete_model_serviceList_update(hash)
57
+ authlete_model_update(hash)
57
58
  end
58
59
 
59
- def authlete_model_serviceList_to_key(key)
60
+ def authlete_model_convert_key(key)
60
61
  key = key.to_sym
61
62
 
62
63
  # Convert snakecase to camelcase, if necessary.
@@ -64,58 +65,29 @@ module Authlete
64
65
  key = SNAKE_TO_CAMEL[key]
65
66
  end
66
67
 
67
- return key
68
+ key
68
69
  end
69
70
 
70
- def authlete_model_serviceList_simple_attribute?(key)
71
+ def authlete_model_simple_attribute?(key)
71
72
  INTEGER_ATTRIBUTES.include?(key)
72
73
  end
73
74
 
74
- def authlete_model_serviceList_update(hash)
75
- if hash.nil?
76
- return
77
- end
75
+ def authlete_model_update(hash)
76
+ return if hash.nil?
78
77
 
79
78
  hash.each do |key, value|
80
- key = authlete_model_serviceList_to_key(key)
79
+ key = authlete_model_convert_key(key)
81
80
 
82
- # If the attribute is a simple one.
83
- if authlete_model_serviceList_simple_attribute?(key)
81
+ if authlete_model_simple_attribute?(key)
84
82
  send("#{key}=", value)
85
- next
86
- end
87
-
88
- if key == :services
89
- # The attribute 'services'.
90
- @services = authlete_model_serviceList_parse_array(value) do |element|
83
+ elsif key == :services
84
+ @services = get_parsed_array(value) do |element|
91
85
  Authlete::Model::Service.parse(element)
92
86
  end
93
87
  end
94
88
  end
95
89
 
96
- return self
97
- end
98
-
99
- def authlete_model_serviceList_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
90
+ self
119
91
  end
120
92
 
121
93
  public
@@ -129,12 +101,7 @@ module Authlete
129
101
  return nil
130
102
  end
131
103
 
132
- return ServiceList.new(hash)
133
- end
134
-
135
- # Set attribute values using the given hash.
136
- def update(hash)
137
- authlete_model_serviceList_update(hash)
104
+ ServiceList.new(hash)
138
105
  end
139
106
 
140
107
  # Convert this object into a hash.
@@ -145,37 +112,15 @@ module Authlete
145
112
  key = var.to_s.delete("@").to_sym
146
113
  val = instance_variable_get(var)
147
114
 
148
- if authlete_model_serviceList_simple_attribute?(key) or val.nil?
115
+ if authlete_model_simple_attribute?(key) or val.nil?
149
116
  hash[key] = val
150
117
  elsif val.kind_of?(Array)
151
- hash[key] = val.map {|element| element.to_hash}
118
+ hash[key] = val.map { |element| element.to_hash }
152
119
  end
153
120
  end
154
121
 
155
- return hash
156
- end
157
-
158
- def [](key)
159
- key = authlete_model_serviceList_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_serviceList_to_key(key)
170
- method = "#{key}="
171
-
172
- if respond_to?(method)
173
- return send(method, value)
174
- else
175
- return nil
176
- end
122
+ hash
177
123
  end
178
124
  end
179
125
  end
180
- end
181
-
126
+ end