school21_api_sdk 0.5.0 → 0.7.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.
- checksums.yaml +4 -4
- data/README.md +10 -3
- data/lib/generators/school21/install/install_generator.rb +15 -0
- data/lib/generators/school21/install/templates/school21.rb.tt +12 -0
- data/lib/school21/api/base_api.rb +2 -2
- data/lib/school21/api/participants_api.rb +7 -0
- data/lib/school21/auth/authenticator.rb +18 -10
- data/lib/school21/auth/bearer_auth_credentials.rb +6 -3
- data/lib/school21/version.rb +1 -1
- data/lib/school21.rb +12 -11
- data/test/graph_api_test.rb +36 -0
- data/test/support/stubs/base_stub.rb +2 -2
- data/test/support/stubs/graph_stub.rb +16 -0
- data/test/support/stubs/participants_stub.rb +1 -2
- data/test/test_helper.rb +1 -0
- metadata +7 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 99a326f17590996f1a32f8b90e1d33e24bb3f4c4af407246b183cbf36a373f1c
|
|
4
|
+
data.tar.gz: 0feee0967bc7bfc04e4858dfe760d0e9d8b3ce8ee01c37c3e697108aad3570d5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7fe2674e37b676d1a875eb28a29cbcf6ce6adc8de67bfddc9d87c36d132b40b7c5d90c87a6ab51112b72738b03fde0cb243387253bceaabacb2cd7014452809f
|
|
7
|
+
data.tar.gz: e0c4d8d7b09d4aaec925ab242a4ff9f3d56cd937e407156cff2b8d6ff75bdaa5799eff03430bc3254b6d8b0c7c594754bc54844515f30f8a75370526f0ee24ca
|
data/README.md
CHANGED
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
> you're using for the school everyday tasks.
|
|
14
14
|
> As soon as other types of authorization will be added (such as using API token), they'll be implemented for this gem as well.
|
|
15
15
|
|
|
16
|
-
|
|
17
16
|
## Installation
|
|
18
17
|
|
|
19
18
|
Install the gem and add to the application's Gemfile by executing:
|
|
@@ -28,11 +27,17 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
|
28
27
|
gem install school21_api_sdk
|
|
29
28
|
```
|
|
30
29
|
|
|
31
|
-
##
|
|
30
|
+
## Setup
|
|
32
31
|
|
|
33
32
|
Please check [docs](https://edu.21-school.ru/docs) for more information.
|
|
34
33
|
|
|
35
|
-
-
|
|
34
|
+
- Rails:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
rails generate school21:install
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
- Manual:
|
|
36
41
|
|
|
37
42
|
```ruby
|
|
38
43
|
require 'school21'
|
|
@@ -48,6 +53,8 @@ School21.configure do |config|
|
|
|
48
53
|
end
|
|
49
54
|
```
|
|
50
55
|
|
|
56
|
+
## Usage
|
|
57
|
+
|
|
51
58
|
- Select the domain specific API that you want to use. This API has all endpoints related to that domain. Here's an example of `Participant API` and a call to `/participants/:login`
|
|
52
59
|
|
|
53
60
|
```ruby
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module School21
|
|
4
|
+
module Generators
|
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
|
6
|
+
source_root File.expand_path('templates', __dir__)
|
|
7
|
+
|
|
8
|
+
desc 'Creates a School21 initializer'
|
|
9
|
+
|
|
10
|
+
def copy_initializer
|
|
11
|
+
template 'school21.rb.tt', 'config/initializers/school21.rb'
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'school21'
|
|
4
|
+
|
|
5
|
+
School21.configure do |config|
|
|
6
|
+
config.credentials = {
|
|
7
|
+
login: Rails.application.credentials.dig(:school21, :login) || ENV['SCHOOL21_LOGIN'],
|
|
8
|
+
password: Rails.application.credentials.dig(:school21, :password) || ENV['SCHOOL21_PASSWORD']
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
config.enable_logging = Rails.env.development?
|
|
12
|
+
end
|
|
@@ -9,9 +9,9 @@ module School21
|
|
|
9
9
|
def self.base_uri(server)
|
|
10
10
|
case server
|
|
11
11
|
when :api_v1
|
|
12
|
-
'https://
|
|
12
|
+
'https://platform.21-school.ru/services/21-school/api/v1'
|
|
13
13
|
when :auth
|
|
14
|
-
'https://auth.
|
|
14
|
+
'https://auth.21-school.ru/auth/realms/EduPowerKeycloak/protocol/openid-connect'
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
|
|
@@ -27,5 +27,12 @@ module School21
|
|
|
27
27
|
|
|
28
28
|
execute_request(new_request)
|
|
29
29
|
end
|
|
30
|
+
|
|
31
|
+
def participant_skills(login)
|
|
32
|
+
path = ['/participants/', login, '/skills'].join
|
|
33
|
+
new_request = request_with_auth_participant(HttpMethod::GET, path, :api_v1)
|
|
34
|
+
|
|
35
|
+
execute_request(new_request)
|
|
36
|
+
end
|
|
30
37
|
end
|
|
31
38
|
end
|
|
@@ -1,23 +1,31 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module School21
|
|
4
|
+
class AccessTokenError < StandardError; end
|
|
5
|
+
|
|
4
6
|
module Authenticator
|
|
7
|
+
MUTEX = Mutex.new
|
|
8
|
+
|
|
5
9
|
def self.call
|
|
6
10
|
return unless School21.config.access_token.expired?
|
|
7
11
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
MUTEX.synchronize do
|
|
13
|
+
return unless School21.config.access_token.expired?
|
|
14
|
+
|
|
15
|
+
auth_api_response = School21.auth_api.token(
|
|
16
|
+
login: School21.config.credentials[:login],
|
|
17
|
+
password: School21.config.credentials[:password]
|
|
18
|
+
)
|
|
12
19
|
|
|
13
|
-
|
|
20
|
+
raise AccessTokenError unless auth_api_response.success?
|
|
14
21
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
22
|
+
access_token = AccessToken.new(*auth_api_response.data.values_at(:access_token, :expires_in))
|
|
23
|
+
bearer_auth_credentials = BearerAuthCredentials.new(access_token:)
|
|
24
|
+
auth_header = AuthorizationHeader.new(bearer_auth_credentials)
|
|
18
25
|
|
|
19
|
-
|
|
20
|
-
|
|
26
|
+
School21.config.access_token = access_token
|
|
27
|
+
School21.config.auth_managers[BaseApi::PLATFORM_AUTH_PARTICIPANT] = auth_header
|
|
28
|
+
end
|
|
21
29
|
end
|
|
22
30
|
end
|
|
23
31
|
end
|
|
@@ -5,9 +5,12 @@ module School21
|
|
|
5
5
|
attr_reader :access_token
|
|
6
6
|
|
|
7
7
|
def initialize(access_token:)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
case access_token
|
|
9
|
+
in String
|
|
10
|
+
@access_token = access_token
|
|
11
|
+
in AccessToken
|
|
12
|
+
@access_token = access_token.access_token
|
|
13
|
+
end
|
|
11
14
|
end
|
|
12
15
|
end
|
|
13
16
|
end
|
data/lib/school21/version.rb
CHANGED
data/lib/school21.rb
CHANGED
|
@@ -39,17 +39,18 @@ module School21
|
|
|
39
39
|
@config = nil
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
42
|
+
API_CLASSES_MAPPINGS = [
|
|
43
|
+
AuthApi,
|
|
44
|
+
ParticipantsApi,
|
|
45
|
+
ProjectsApi,
|
|
46
|
+
CampusesApi,
|
|
47
|
+
ClustersApi,
|
|
48
|
+
GraphApi
|
|
49
|
+
].freeze
|
|
50
|
+
|
|
51
|
+
API_CLASSES_MAPPINGS.each do |klass|
|
|
52
|
+
method_name = klass.name.underscore.split('/').last.to_sym
|
|
53
|
+
define_method(method_name) do
|
|
53
54
|
klass.new
|
|
54
55
|
end
|
|
55
56
|
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'test_helper'
|
|
4
|
+
|
|
5
|
+
describe 'Graph API Test' do
|
|
6
|
+
include AuthStub
|
|
7
|
+
include GraphStub
|
|
8
|
+
|
|
9
|
+
with_configured_client do
|
|
10
|
+
let(:graph_api_call) do
|
|
11
|
+
School21.graph_api.graph
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'calls stub graph success' do
|
|
15
|
+
stubs = [
|
|
16
|
+
stub_token_success,
|
|
17
|
+
stub_graph_success
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
graph_api_call
|
|
21
|
+
|
|
22
|
+
stubs.each { |stub| assert_requested(stub) }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'calls stub graph fail' do
|
|
26
|
+
stubs = [
|
|
27
|
+
stub_token_success,
|
|
28
|
+
stub_graph_fail
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
graph_api_call
|
|
32
|
+
|
|
33
|
+
stubs.each { |stub| assert_requested(stub) }
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module BaseStub
|
|
4
|
-
BASE_AUTH_URL = 'https://auth.
|
|
5
|
-
BASE_API_V1_URL = 'https://
|
|
4
|
+
BASE_AUTH_URL = 'https://auth.21-school.ru'
|
|
5
|
+
BASE_API_V1_URL = 'https://platform.21-school.ru/services/21-school/api/v1'
|
|
6
6
|
|
|
7
7
|
def base_stub_fail(http_method, url)
|
|
8
8
|
stub_request(http_method, url)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module GraphStub
|
|
4
|
+
include BaseStub
|
|
5
|
+
|
|
6
|
+
STUBBED_GRAPH_URL = [BASE_API_V1_URL, '/graph'].join
|
|
7
|
+
|
|
8
|
+
def stub_graph_success
|
|
9
|
+
stub_request(:get, STUBBED_GRAPH_URL)
|
|
10
|
+
.to_return_json(body: { data: { user: { login: 'test_user' } } }) # Example success response
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def stub_graph_fail
|
|
14
|
+
base_stub_fail(:get, STUBBED_GRAPH_URL)
|
|
15
|
+
end
|
|
16
|
+
end
|
data/test/test_helper.rb
CHANGED
|
@@ -10,6 +10,7 @@ require_relative 'support/shared_data'
|
|
|
10
10
|
require_relative 'support/stubs/base_stub'
|
|
11
11
|
require_relative 'support/stubs/auth_stub'
|
|
12
12
|
require_relative 'support/stubs/participants_stub'
|
|
13
|
+
require_relative 'support/stubs/graph_stub'
|
|
13
14
|
|
|
14
15
|
SimpleCov.start
|
|
15
16
|
SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: school21_api_sdk
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Anton Yudin
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-01-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -105,6 +105,8 @@ files:
|
|
|
105
105
|
- README.md
|
|
106
106
|
- bin/console
|
|
107
107
|
- bin/setup
|
|
108
|
+
- lib/generators/school21/install/install_generator.rb
|
|
109
|
+
- lib/generators/school21/install/templates/school21.rb.tt
|
|
108
110
|
- lib/school21.rb
|
|
109
111
|
- lib/school21/api/auth_api.rb
|
|
110
112
|
- lib/school21/api/base_api.rb
|
|
@@ -123,10 +125,12 @@ files:
|
|
|
123
125
|
- lib/school21/version.rb
|
|
124
126
|
- test/auth_api_test.rb
|
|
125
127
|
- test/configuration_test.rb
|
|
128
|
+
- test/graph_api_test.rb
|
|
126
129
|
- test/participants_api_test.rb
|
|
127
130
|
- test/support/shared_data.rb
|
|
128
131
|
- test/support/stubs/auth_stub.rb
|
|
129
132
|
- test/support/stubs/base_stub.rb
|
|
133
|
+
- test/support/stubs/graph_stub.rb
|
|
130
134
|
- test/support/stubs/participants_stub.rb
|
|
131
135
|
- test/test_helper.rb
|
|
132
136
|
homepage: https://github.com/ikael21/school21_api_sdk
|
|
@@ -149,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
149
153
|
- !ruby/object:Gem::Version
|
|
150
154
|
version: '0'
|
|
151
155
|
requirements: []
|
|
152
|
-
rubygems_version: 3.5.
|
|
156
|
+
rubygems_version: 3.5.9
|
|
153
157
|
signing_key:
|
|
154
158
|
specification_version: 4
|
|
155
159
|
summary: School21 API SDK
|