school21_api_sdk 0.6.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/participants_api.rb +7 -0
- data/lib/school21/auth/authenticator.rb +16 -10
- data/lib/school21/auth/bearer_auth_credentials.rb +6 -3
- data/lib/school21/version.rb +1 -1
- metadata +4 -2
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
|
|
@@ -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
|
|
@@ -4,22 +4,28 @@ module School21
|
|
|
4
4
|
class AccessTokenError < StandardError; end
|
|
5
5
|
|
|
6
6
|
module Authenticator
|
|
7
|
+
MUTEX = Mutex.new
|
|
8
|
+
|
|
7
9
|
def self.call
|
|
8
10
|
return unless School21.config.access_token.expired?
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
+
)
|
|
14
19
|
|
|
15
|
-
|
|
20
|
+
raise AccessTokenError unless auth_api_response.success?
|
|
16
21
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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)
|
|
20
25
|
|
|
21
|
-
|
|
22
|
-
|
|
26
|
+
School21.config.access_token = access_token
|
|
27
|
+
School21.config.auth_managers[BaseApi::PLATFORM_AUTH_PARTICIPANT] = auth_header
|
|
28
|
+
end
|
|
23
29
|
end
|
|
24
30
|
end
|
|
25
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
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
|