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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c369d9fa76c0c36cb3142d0807256d9be76d9b706aedc32207899f355721d0b
4
- data.tar.gz: 3b314e7f8a1235eadfe9ce7cd5147bc0889c4926169a3a29740613f72f2aeb94
3
+ metadata.gz: 99a326f17590996f1a32f8b90e1d33e24bb3f4c4af407246b183cbf36a373f1c
4
+ data.tar.gz: 0feee0967bc7bfc04e4858dfe760d0e9d8b3ce8ee01c37c3e697108aad3570d5
5
5
  SHA512:
6
- metadata.gz: ddaecba86f46485941eb2a9d508ff6a2961db296657bbc28cf3b31dee962af1986648d1226cf1e46425475ef48935b2716810d4d74b34a627eba5e637d00cb4c
7
- data.tar.gz: cf9e4fc8918d2b64e4361cf45a19bc8a6fc6f6e2c520f476e71b3e8c5025222bea1074a303971ff3f24ddd00e9c57b2e5d04f032bfd650c269b358e137fc9ebc
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
- ## Usage
30
+ ## Setup
32
31
 
33
32
  Please check [docs](https://edu.21-school.ru/docs) for more information.
34
33
 
35
- - Require the gem and configure client object
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://edu-api.21-school.ru/services/21-school/api/v1'
12
+ 'https://platform.21-school.ru/services/21-school/api/v1'
13
13
  when :auth
14
- 'https://auth.sberclass.ru/auth/realms/EduPowerKeycloak/protocol/openid-connect'
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
- auth_api_response = School21.auth_api.token(
9
- login: School21.config.credentials[:login],
10
- password: School21.config.credentials[:password]
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
- raise 'Access Token Error' unless auth_api_response.success?
20
+ raise AccessTokenError unless auth_api_response.success?
14
21
 
15
- access_token = AccessToken.new(*auth_api_response.data.values_at(:access_token, :expires_in))
16
- bearer_auth_credentials = BearerAuthCredentials.new(access_token:)
17
- auth_header = AuthorizationHeader.new(bearer_auth_credentials)
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
- School21.config.access_token = access_token
20
- School21.config.auth_managers[BaseApi::PLATFORM_AUTH_PARTICIPANT] = auth_header
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
- raise ArgumentError, 'access_token cannot be nil' if access_token.nil?
9
-
10
- @access_token = access_token.access_token
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module School21
4
- VERSION = '0.5.0'
4
+ VERSION = '0.7.0'
5
5
  end
data/lib/school21.rb CHANGED
@@ -39,17 +39,18 @@ module School21
39
39
  @config = nil
40
40
  end
41
41
 
42
- API_CLASSES = {
43
- auth: AuthApi,
44
- participants: ParticipantsApi,
45
- projects: ProjectsApi,
46
- campuses: CampusesApi,
47
- clusters: ClustersApi,
48
- graph: GraphApi
49
- }.freeze
50
-
51
- API_CLASSES.each do |name, klass|
52
- define_method("#{name}_api") do
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.sberclass.ru'
5
- BASE_API_V1_URL = 'https://edu-api.21-school.ru/services/21-school/api/v1'
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
@@ -12,7 +12,6 @@ module ParticipantsStub
12
12
  end
13
13
 
14
14
  def stub_participant_fail
15
- stub_request(:get, STUBBED_PARTICIPANT_URL)
16
- .to_return(status: [500, 'Internal Server Error'])
15
+ base_stub_fail(:get, STUBBED_PARTICIPANT_URL)
17
16
  end
18
17
  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.5.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: 2025-05-18 00:00:00.000000000 Z
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.17
156
+ rubygems_version: 3.5.9
153
157
  signing_key:
154
158
  specification_version: 4
155
159
  summary: School21 API SDK