authlete 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/authlete.rb +1 -0
- data/lib/authlete/client.rb +139 -4
- data/lib/authlete/model/service-list.rb +181 -0
- data/lib/authlete/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OWIyYTAxYmQyNTRlM2I3MTI0NTJkYTdhZmRmZGM3YTNiYTRiZjM4Nw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ODNhM2RkZGY5ZjA4MzlhZmFlOTg4MjcxYjNlZTJjYzMyYTIxYTU2Yw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MThiYzIyNmYxNDMwM2E5M2Q4Nzc2MjJiNTBmNDNjMzA5MmY2Y2I2ZGNkM2Jh
|
10
|
+
NTA2MDFhNGU2MDZlMTliMDgzNzA2N2I2NDQ4OTA2MjIwMWFiZWU1NjAyNTYw
|
11
|
+
MGFmYTY1MzgwOTYzMTU4ODk0OGFjYzhjNzQwMmZhNTI5MDg0NzE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NzZhNzA4YzFmZmNlMTY3M2Y3MjI0NzU3NDM3Y2FkMWE0ZTgxNzRlMjRkNTU4
|
14
|
+
Y2M2NzE5MWM2MWExYjQ5YzNhZGNlYjRjNTE0NWE1NzgxYzRmM2FhMTg2OGZm
|
15
|
+
ZWYwOWYyYTZkMzIwMjZjNWI0OWUzNzcwM2ViODcwMTI2YjBkNTY=
|
data/lib/authlete.rb
CHANGED
data/lib/authlete/client.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# :nodoc:
|
2
2
|
#
|
3
|
-
# Copyright (C) 2014 Authlete, Inc.
|
3
|
+
# Copyright (C) 2014-2015 Authlete, Inc.
|
4
4
|
#
|
5
5
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
6
|
# you may not use this file except in compliance with the License.
|
@@ -44,6 +44,9 @@ module Authlete
|
|
44
44
|
# The API secret of a service.
|
45
45
|
attr_accessor :service_api_secret
|
46
46
|
|
47
|
+
# Extra HTTP headers
|
48
|
+
attr_accessor :extra_headers
|
49
|
+
|
47
50
|
# The constructor which takes a hash containing configuration
|
48
51
|
# parameters. Valid configuration parameter names are as follows.
|
49
52
|
#
|
@@ -64,23 +67,57 @@ module Authlete
|
|
64
67
|
private
|
65
68
|
|
66
69
|
def call_api(method, path, content_type, payload, user, password)
|
70
|
+
headers = {}
|
71
|
+
|
72
|
+
if content_type.nil? == false
|
73
|
+
headers.merge!(:content_type => content_type)
|
74
|
+
end
|
75
|
+
|
76
|
+
if @extra_headers.nil? == false
|
77
|
+
headers.merge!(@extra_headers)
|
78
|
+
end
|
79
|
+
|
67
80
|
response = RestClient::Request.new(
|
68
81
|
:method => method,
|
69
82
|
:url => @host + path,
|
70
|
-
:headers =>
|
83
|
+
:headers => headers,
|
71
84
|
:payload => payload,
|
72
85
|
:user => user,
|
73
86
|
:password => password
|
74
87
|
).execute
|
75
88
|
|
76
|
-
|
89
|
+
body = body_as_string(response)
|
90
|
+
|
91
|
+
if body.nil?
|
92
|
+
return nil
|
93
|
+
end
|
94
|
+
|
95
|
+
JSON.parse(response.body.to_s, :symbolize_names => true)
|
96
|
+
end
|
97
|
+
|
98
|
+
def body_as_string(response)
|
99
|
+
if response.body.nil?
|
100
|
+
return nil
|
101
|
+
end
|
102
|
+
|
103
|
+
body = response.body.to_s
|
104
|
+
|
105
|
+
if body.length == 0
|
106
|
+
return nil
|
107
|
+
end
|
108
|
+
|
109
|
+
return body
|
110
|
+
end
|
111
|
+
|
112
|
+
def call_api_service_owner(method, path, content_type, payload)
|
113
|
+
call_api(method, path, content_type, payload, @service_owner_api_key, @service_owner_api_secret)
|
77
114
|
end
|
78
115
|
|
79
116
|
def call_api_json(path, body, user, password)
|
80
117
|
call_api(:post, path, 'application/json;charset=UTF-8', JSON.generate(body), user, password)
|
81
118
|
end
|
82
119
|
|
83
|
-
def
|
120
|
+
def call_api_json_service_owner(path, body)
|
84
121
|
call_api_json(path, body, @service_owner_api_key, @service_owner_api_secret)
|
85
122
|
end
|
86
123
|
|
@@ -106,8 +143,105 @@ module Authlete
|
|
106
143
|
end
|
107
144
|
end
|
108
145
|
|
146
|
+
def to_query(params)
|
147
|
+
if params.nil? || params.size == 0
|
148
|
+
return ""
|
149
|
+
end
|
150
|
+
|
151
|
+
array = []
|
152
|
+
|
153
|
+
params.each do |key, value|
|
154
|
+
array.push("#{key}=#{value}")
|
155
|
+
end
|
156
|
+
|
157
|
+
return "?" + array.join("&")
|
158
|
+
end
|
159
|
+
|
109
160
|
public
|
110
161
|
|
162
|
+
|
163
|
+
# Call Authlete's /api/service/create API.
|
164
|
+
#
|
165
|
+
# <tt>service</tt> is the content of a new service to create. The type of
|
166
|
+
# the given object is either <tt>Hash</tt> or any object which
|
167
|
+
# responds to <tt>to_hash</tt>. In normal cases, Authlete::Model::Service
|
168
|
+
# (which responds to <tt>to_hash</tt>) should be used.
|
169
|
+
#
|
170
|
+
# On success, an instance of Authlete::Model::ServiceList is returned.
|
171
|
+
# On error, RestClient::Exception (of rest-client GEM) is raised.
|
172
|
+
def service_create(service)
|
173
|
+
if service.kind_of?(Hash) == false
|
174
|
+
if service.respond_to?('to_hash')
|
175
|
+
service = service.to_hash
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
hash = call_api_json_service_owner("/api/service/create", service)
|
180
|
+
|
181
|
+
Authlete::Model::Service.new(hash)
|
182
|
+
end
|
183
|
+
|
184
|
+
# Call Authlete's /api/service/delete/{api_key} API.
|
185
|
+
#
|
186
|
+
# On error, RestClient::Exception (of rest-client GEM) is raised.
|
187
|
+
def service_delete(api_key)
|
188
|
+
call_api_service_owner(:delete, "/api/service/delete/#{api_key}", nil, nil)
|
189
|
+
end
|
190
|
+
|
191
|
+
|
192
|
+
# Call Authlete's /api/service/get/{api_key} API.
|
193
|
+
#
|
194
|
+
# <tt>api_key</tt> is the API key of the service whose information
|
195
|
+
# you want to get.
|
196
|
+
#
|
197
|
+
# On success, an instance of Authlete::Model::Service is returned.
|
198
|
+
# On error, RestClient::Exception (of rest-client GEM) is raised.
|
199
|
+
def service_get(api_key)
|
200
|
+
hash = call_api_service_owner(:get, "/api/service/get/#{api_key}", nil, nil)
|
201
|
+
|
202
|
+
Authlete::Model::Service.new(hash)
|
203
|
+
end
|
204
|
+
|
205
|
+
# Call Authlete's /api/service/get/list API.
|
206
|
+
#
|
207
|
+
# <tt>params</tt> is an optional hash which contains query parameters
|
208
|
+
# for /api/service/get/list API. <tt>:start</tt> and <tt>:end</tt> are
|
209
|
+
# a start index (inclusive) and an end index (exclusive), respectively.
|
210
|
+
#
|
211
|
+
# On success, an instance of Authlete::Model::ServiceList is returned.
|
212
|
+
# On error, RestClient::Exception (of rest-client GEM) is raised.
|
213
|
+
def service_get_list(params = nil)
|
214
|
+
hash = call_api_service_owner(:get, "/api/service/get/list#{to_query(params)}", nil, nil)
|
215
|
+
|
216
|
+
Authlete::Model::ServiceList.new(hash)
|
217
|
+
end
|
218
|
+
|
219
|
+
|
220
|
+
# Call Authlete's /api/service/update/{api_key} API.
|
221
|
+
#
|
222
|
+
# <tt>api_key</tt> is the API key of the service whose information
|
223
|
+
# you want to get.
|
224
|
+
#
|
225
|
+
# <tt>service</tt> is the new content of the service. The type of
|
226
|
+
# the given object is either <tt>Hash</tt> or any object which
|
227
|
+
# responds to <tt>to_hash</tt>. In normal cases, Authlete::Model::Service
|
228
|
+
# (which responds to <tt>to_hash</tt>) should be used.
|
229
|
+
#
|
230
|
+
# On success, an instance of Authlete::Model::Service is returned.
|
231
|
+
# On error, RestClient::Exception (of rest-client GEM) is raised.
|
232
|
+
def service_update(api_key, service)
|
233
|
+
if service.kind_of?(Hash) == false
|
234
|
+
if service.respond_to?('to_hash')
|
235
|
+
service = service.to_hash
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
hash = call_api_json_service_owner("/api/service/update/#{api_key}", service)
|
240
|
+
|
241
|
+
Authlete::Model::Service.new(hash)
|
242
|
+
end
|
243
|
+
|
244
|
+
|
111
245
|
# Call Authlete's {/auth/introspection}
|
112
246
|
# [https://www.authlete.com/authlete_web_apis_introspection.html#auth_introspection]
|
113
247
|
# API.
|
@@ -136,6 +270,7 @@ module Authlete
|
|
136
270
|
Authlete::Response::IntrospectionResponse.new(hash)
|
137
271
|
end
|
138
272
|
|
273
|
+
|
139
274
|
# Ensure that the request contains a valid access token.
|
140
275
|
#
|
141
276
|
# This method extracts an access token from the given request based on the
|
@@ -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 ServiceList
|
24
|
+
# The start index (inclusive) of the services in this list.
|
25
|
+
attr_accessor :start
|
26
|
+
|
27
|
+
# The end index (exclusive) of the services in this list.
|
28
|
+
attr_accessor :end
|
29
|
+
|
30
|
+
# The total count of services.
|
31
|
+
attr_accessor :totalCount
|
32
|
+
alias_method :total_count, :totalCount
|
33
|
+
alias_method :total_count=, :totalCount=
|
34
|
+
|
35
|
+
# The list of services.
|
36
|
+
attr_accessor :services
|
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
|
+
@services = nil
|
54
|
+
|
55
|
+
# Set attribute values using the given hash.
|
56
|
+
authlete_model_serviceList_update(hash)
|
57
|
+
end
|
58
|
+
|
59
|
+
def authlete_model_serviceList_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_serviceList_simple_attribute?(key)
|
71
|
+
INTEGER_ATTRIBUTES.include?(key)
|
72
|
+
end
|
73
|
+
|
74
|
+
def authlete_model_serviceList_update(hash)
|
75
|
+
if hash.nil?
|
76
|
+
return
|
77
|
+
end
|
78
|
+
|
79
|
+
hash.each do |key, value|
|
80
|
+
key = authlete_model_serviceList_to_key(key)
|
81
|
+
|
82
|
+
# If the attribute is a simple one.
|
83
|
+
if authlete_model_serviceList_simple_attribute?(key)
|
84
|
+
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|
|
91
|
+
Authlete::Model::Service.parse(element)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
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
|
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, ServiceList.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 ServiceList.new(hash)
|
133
|
+
end
|
134
|
+
|
135
|
+
# Set attribute values using the given hash.
|
136
|
+
def update(hash)
|
137
|
+
authlete_model_serviceList_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_serviceList_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_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
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
data/lib/authlete/version.rb
CHANGED
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
|
+
version: 0.1.2
|
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-
|
11
|
+
date: 2015-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- lib/authlete/client.rb
|
72
72
|
- lib/authlete/host.rb
|
73
73
|
- lib/authlete/model/scope.rb
|
74
|
+
- lib/authlete/model/service-list.rb
|
74
75
|
- lib/authlete/model/service.rb
|
75
76
|
- lib/authlete/model/sns-credentials.rb
|
76
77
|
- lib/authlete/request/authentication-callback-request.rb
|