strongmind-platform-sdk 2.12.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a243823042f3dfa6eaa652a252e7451934b63ad347b4eb2afc2ef893d5cc4b1f
4
+ data.tar.gz: 895357021f6b8ba4645ed641626efb1a2c079e73e6eb7d48501fc6d74eed8147
5
+ SHA512:
6
+ metadata.gz: f7bffcc7532752361f356f8a6db181e278bb9b5b4a7fc86854ea95ac38a468d678bf841e403b181755c9c39b3b0e45ea2660ca8585cc311e2e13f46bd9947499
7
+ data.tar.gz: 04251ddea5e958ef6208e939c7bddef8235ede1c5ed0d82742f35bc04759b27408cb33ca8d11154ab11c419bd42e618fbad5d2ae0db0027623ce00676629bb6b
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,16 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
14
+
15
+ Metrics/BlockLength:
16
+ IgnoredMethods: ['describe', 'context']
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.1.3
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-05-13
4
+
5
+ - Initial release
data/CODEOWNERS ADDED
@@ -0,0 +1,10 @@
1
+ # This File was Automatically generated by Devops
2
+ # The first few lines should be consistant across all repos
3
+ /.github/* @StrongMind/binary-ops
4
+ /infrastructure/* @StrongMind/binary-ops
5
+
6
+ # The following lines were originally made by pulling the teams
7
+ # assigned to each repo and setting them as CodeOwner over the
8
+ # entire repository
9
+
10
+ * @StrongMind/horseshoes
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at ryan.wolfe@strongmind.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ source "https://rubygems.pkg.github.com/StrongMind" do
6
+ gem "oneroster_client", "~> 2.0.3"
7
+ end
8
+
9
+ # Specify your gem's dependencies in platform_sdk-ruby-sdk.gemspec
10
+ gemspec
11
+
12
+ gem "factory_bot"
13
+ gem "faker"
14
+ gem "jwt", "~> 1.5", ">= 1.5.4"
15
+ gem "rake", "~> 13.0"
16
+ gem "rspec", "~> 3.6", ">= 3.6.0"
17
+ gem "rubocop"
data/Gemfile.lock ADDED
@@ -0,0 +1,114 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ platform-sdk (2.12.0)
5
+ aws-sdk-secretsmanager (~> 1.66)
6
+ faraday (~> 2.5, >= 2.5.2)
7
+ oneroster_client (~> 2.0.1)
8
+ uri
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ activesupport (7.0.4)
14
+ concurrent-ruby (~> 1.0, >= 1.0.2)
15
+ i18n (>= 1.6, < 2)
16
+ minitest (>= 5.1)
17
+ tzinfo (~> 2.0)
18
+ ast (2.4.2)
19
+ aws-eventstream (1.2.0)
20
+ aws-partitions (1.688.0)
21
+ aws-sdk-core (3.168.4)
22
+ aws-eventstream (~> 1, >= 1.0.2)
23
+ aws-partitions (~> 1, >= 1.651.0)
24
+ aws-sigv4 (~> 1.5)
25
+ jmespath (~> 1, >= 1.6.1)
26
+ aws-sdk-secretsmanager (1.70.0)
27
+ aws-sdk-core (~> 3, >= 3.165.0)
28
+ aws-sigv4 (~> 1.1)
29
+ aws-sigv4 (1.5.2)
30
+ aws-eventstream (~> 1, >= 1.0.2)
31
+ concurrent-ruby (1.1.10)
32
+ diff-lcs (1.5.0)
33
+ ethon (0.15.0)
34
+ ffi (>= 1.15.0)
35
+ factory_bot (6.2.1)
36
+ activesupport (>= 5.0.0)
37
+ faker (2.23.0)
38
+ i18n (>= 1.8.11, < 2)
39
+ faraday (2.7.2)
40
+ faraday-net_http (>= 2.0, < 3.1)
41
+ ruby2_keywords (>= 0.0.4)
42
+ faraday-net_http (3.0.2)
43
+ ffi (1.15.5)
44
+ i18n (1.12.0)
45
+ concurrent-ruby (~> 1.0)
46
+ jmespath (1.6.2)
47
+ json (2.6.2)
48
+ jwt (1.5.6)
49
+ minitest (5.16.3)
50
+ parallel (1.22.1)
51
+ parser (3.1.2.1)
52
+ ast (~> 2.4.1)
53
+ rainbow (3.1.1)
54
+ rake (13.0.6)
55
+ regexp_parser (2.6.0)
56
+ rexml (3.2.5)
57
+ rspec (3.11.0)
58
+ rspec-core (~> 3.11.0)
59
+ rspec-expectations (~> 3.11.0)
60
+ rspec-mocks (~> 3.11.0)
61
+ rspec-core (3.11.0)
62
+ rspec-support (~> 3.11.0)
63
+ rspec-expectations (3.11.1)
64
+ diff-lcs (>= 1.2.0, < 2.0)
65
+ rspec-support (~> 3.11.0)
66
+ rspec-mocks (3.11.1)
67
+ diff-lcs (>= 1.2.0, < 2.0)
68
+ rspec-support (~> 3.11.0)
69
+ rspec-support (3.11.1)
70
+ rubocop (1.37.0)
71
+ json (~> 2.3)
72
+ parallel (~> 1.10)
73
+ parser (>= 3.1.2.1)
74
+ rainbow (>= 2.2.2, < 4.0)
75
+ regexp_parser (>= 1.8, < 3.0)
76
+ rexml (>= 3.2.5, < 4.0)
77
+ rubocop-ast (>= 1.22.0, < 2.0)
78
+ ruby-progressbar (~> 1.7)
79
+ unicode-display_width (>= 1.4.0, < 3.0)
80
+ rubocop-ast (1.23.0)
81
+ parser (>= 3.1.1.0)
82
+ ruby-progressbar (1.11.0)
83
+ ruby2_keywords (0.0.5)
84
+ typhoeus (1.4.0)
85
+ ethon (>= 0.9.0)
86
+ tzinfo (2.0.5)
87
+ concurrent-ruby (~> 1.0)
88
+ unicode-display_width (2.3.0)
89
+ uri (0.12.0)
90
+
91
+ GEM
92
+ remote: https://rubygems.pkg.github.com/StrongMind/
93
+ specs:
94
+ oneroster_client (2.0.3)
95
+ json (~> 2.1, >= 2.1.0)
96
+ typhoeus (~> 1.0, >= 1.0.1)
97
+
98
+ PLATFORMS
99
+ ruby
100
+ x86_64-darwin-21
101
+ x86_64-linux
102
+
103
+ DEPENDENCIES
104
+ factory_bot
105
+ faker
106
+ jwt (~> 1.5, >= 1.5.4)
107
+ oneroster_client (~> 2.0.3)!
108
+ platform-sdk!
109
+ rake (~> 13.0)
110
+ rspec (~> 3.6, >= 3.6.0)
111
+ rubocop
112
+
113
+ BUNDLED WITH
114
+ 2.3.16
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Ryan Wolfe
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/Makefile ADDED
@@ -0,0 +1,5 @@
1
+ install:
2
+ bundle install
3
+
4
+ test:
5
+ bundle exec rspec
data/README.md ADDED
@@ -0,0 +1,112 @@
1
+ # Platform::Sdk
2
+
3
+ This gem is intended to provide clients and models for accessing the Platform APIs.
4
+
5
+ [![Ruby Gem](https://github.com/StrongMind/platform-ruby-sdk/actions/workflows/gem-push.yml/badge.svg)](https://github.com/StrongMind/platform-ruby-sdk/actions/workflows/gem-push.yml)
6
+
7
+ ## Installation
8
+
9
+ First [configure your GitHub credentials](#configure-github-credentials)
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ ```
14
+ gem "strongmind-platform-sdk", "~> 2.9.1"
15
+ ```
16
+
17
+ If bundler is not being used to manage dependencies, install the gem by executing:
18
+
19
+ $ gem install strongmind-platform-sdk
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Configure GitHub credentials
26
+
27
+ - Create a GitHub PAT (personal access token) with the following scopes:
28
+ `delete:packages, write:packages, repo`
29
+
30
+ - Edit (or create) a `~/.gem.credentials` file to include the following, replacing TOKEN with your PAT from GitHub
31
+ ```
32
+ ---
33
+ :github: Bearer TOKEN
34
+ ```
35
+
36
+ - Edit (or create) a `~/.gemrc` file and add the following:
37
+ ```
38
+
39
+ :backtrace: false
40
+ :bulk_threshold: 1000
41
+ :sources:
42
+ - https://rubygems.org/
43
+ - https://USERNAME:TOKEN@rubygems.pkg.github.com/StrongMind/
44
+ :update_sources: true
45
+ :verbose: true
46
+ ```
47
+
48
+ - You will also need to configure your bundler to use your GitHub credentials:
49
+ ```$ bundle config set —-global rubygems.pkg.github.com USERNAME:TOKEN```
50
+
51
+ NOTE: If your username has an `@` symbol, edit your `~/.bundle/config` file and replace the `@` with `%40`
52
+ ```
53
+ ---
54
+ BUNDLE_RUBYGEMS__PKG__GITHUB__COM: "USERNAME:TOKEN"
55
+ ```
56
+
57
+ ## Build/Publish Gem
58
+
59
+ To publish the gem, update the `version.rb` file and push the update to the main branch. The github actions will publish the gem automatically.
60
+
61
+ If you would like to publish the gem from your local machine for development purposes, run the following commands:
62
+
63
+ ```
64
+ gem build platform-sdk.gemspec
65
+ gem push --key github --host https://rubygems.pkg.github.com/StrongMind platform-sdk-0.0.0.gem
66
+ ```
67
+
68
+ ## Development
69
+
70
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
71
+
72
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
73
+
74
+ ## Contributing
75
+
76
+ Bug reports and pull requests are welcome on GitHub at https://github.com/StrongMind/platform-ruby-sdk. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/platform-ruby-sdk/blob/main/CODE_OF_CONDUCT.md).
77
+
78
+ ## License
79
+
80
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
81
+
82
+ ## Code of Conduct
83
+
84
+ Everyone interacting in the Platform::Ruby::Sdk project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/platform-ruby-sdk/blob/main/CODE_OF_CONDUCT.md).
85
+
86
+ ## Setting up IRB for OneRoster Calls
87
+ Require needed dependencies:
88
+ `require 'platform_sdk'`
89
+
90
+ Open IRB and initialize dependencies:
91
+ * IDENTITY_CLIENT_ID
92
+ * IDENTITY_CLIENT_SECRET
93
+ * IDENTITY_BASE_URL
94
+ * STRONGMIND_APP_BASE_URL
95
+ * ONEROSTER_BASE_URL
96
+ * ID_MAPPER_DOMAIN
97
+ * ID_MAPPER_TOKEN
98
+
99
+ Create Identity Auth Client:
100
+ `auth_client = PlatformSdk::Identity::AuthClient.new(IDENTITY_BASE_URL, IDENTITY_CLIENT_ID, IDENTITY_CLIENT_SECRET)`
101
+
102
+ Create OneRoster Client:
103
+ `one_roster_client = PlatformSdk::OneRoster::Client.new(ONEROSTER_BASE_URL, auth_client)`
104
+
105
+ Create Aws Client:
106
+ `aws_client = PlatformSdk::Aws::SecretsManagerClient.new(access_key_id: 'ACCESS_KEY_ID', secret_access_key: 'SECRET_ACCESS_KEY', region: 'REGION')`
107
+
108
+ Create PowerSchool Client:
109
+ `power_school_client = PlatformSdk::PowerSchool::Client.new(base_url: 'BASE_URL', bearer_token: 'BEARER_TOKEN')`
110
+
111
+ Create IdMapper Client:
112
+ `id_mapper_client = PlatformSdk::IdMapper::Client.new(domain: 'ID_MAPPER_DOMAIN', token: 'SECRET_TOKEN')`
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,35 @@
1
+ require "aws-sdk-secretsmanager"
2
+
3
+ module PlatformSdk
4
+ module Aws
5
+ class SecretsManagerClient
6
+ attr_reader :client
7
+
8
+ def initialize(access_key_id:, secret_access_key:, region: "us-west-2")
9
+ @client = ::Aws::SecretsManager::Client.new(
10
+ access_key_id: access_key_id,
11
+ secret_access_key: secret_access_key,
12
+ region: region
13
+ )
14
+ end
15
+
16
+ def secret(secret_key:, arn: nil, secret_name: nil)
17
+ raise(ArgumentError, "Must provide either an arn or a secret name") if arn.nil? && secret_name.nil?
18
+
19
+ secret = secret_store(secret_name: (arn || secret_name))
20
+ secret[secret_key]
21
+ end
22
+
23
+ def powerschool_token(domain:, environment:)
24
+ secret(secret_name: "powerschool_token_#{domain}_#{environment}", secret_key: "access_token")
25
+ end
26
+
27
+ private
28
+
29
+ def secret_store(secret_name:)
30
+ store = @client.get_secret_value(secret_id: secret_name)
31
+ JSON.parse(store.secret_string)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,7 @@
1
+ require "platform_sdk/aws/secrets_manager_client"
2
+
3
+ module PlatformSdk
4
+ module Aws
5
+ class Error < StandardError; end
6
+ end
7
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PlatformSdk
4
+ module IdMapper
5
+ # IdMapper::Client
6
+ class Client
7
+ attr_reader :token, :domain, :conn
8
+
9
+ def initialize(secret)
10
+ @token = secret[:token]
11
+ @domain = secret[:domain]
12
+ @token ||= PlatformSdk::IdMapper.token
13
+ @domain ||= PlatformSdk::IdMapper.domain
14
+
15
+ @conn = Faraday.new("https://#{@domain}") do |faraday|
16
+ faraday.headers = headers
17
+ faraday.adapter Faraday.default_adapter
18
+ faraday.response :json, content_type: /\bjson$/
19
+ faraday.response :raise_error
20
+ end
21
+ end
22
+
23
+ def pairs(guid)
24
+ begin
25
+ response = @conn.get("api/v1/pairs/#{guid}")
26
+ rescue Faraday::ResourceNotFound
27
+ raise PlatformSdk::IdMapper::PairNotFoundError, msg = guid
28
+ end
29
+ response.body
30
+ end
31
+
32
+ private
33
+
34
+ def headers
35
+ { "Authorization" => "Token #{@token}" }
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PlatformSdk
4
+ module IdMapper
5
+ module Constants
6
+ module User
7
+ ONE_ROSTER_ID = "com.strongmind.user.id"
8
+ IDENTITY_ID = "com.strongmind.identity.user.id"
9
+ CLEVER_ID = "com.clever.user.id"
10
+ LEGACY_SIS_ID = "com.strongmind.sis.user.id"
11
+ LOUDMOUTH_ID = "com.strongmind.loudmouth.user.id"
12
+ POWERSCHOOL_NUMBERS = "com.powerschool.user.numbers"
13
+ POWERSCHOOL_DCIDS = "com.powerschool.user.dcids"
14
+ POWERSCHOOL_STAFF_NUMBERS = "com.powerschool.staff.numbers"
15
+ POWERSCHOOL_STAFF_IDS = "com.powerschool.staff.ids"
16
+ POWERSCHOOL_CONTACT_IDS = "com.powerschool.contact.ids"
17
+ CANVAS_IDS = "com.instructure.canvas.users"
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+ require 'platform_sdk/id_mapper/client'
3
+ require 'platform_sdk/id_mapper/constants'
4
+
5
+ module PlatformSdk
6
+ module IdMapper
7
+ class Error < StandardError; end
8
+
9
+ class TokenNotSet < Error; end
10
+
11
+ class DomainNotSet < Error; end
12
+
13
+ class PairNotFoundError < Error; end
14
+
15
+ def self.token
16
+ raise TokenNotSet if @token.nil?
17
+
18
+ @token
19
+ end
20
+
21
+ def self.token=(token)
22
+ @token = token
23
+ end
24
+
25
+ def self.domain
26
+ raise DomainNotSet if @domain.nil?
27
+
28
+ @domain
29
+ end
30
+
31
+ def self.domain=(domain)
32
+ @domain = domain
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PlatformSdk
4
+ module Identity
5
+ # Client for making calls to the Identity Server API
6
+ class Client
7
+ def initialize(identity_base_url, client_id, client_secret, auth_client = nil)
8
+ @auth = auth_client.nil? ? AuthClient.new(identity_base_url, client_id, client_secret) : auth_client
9
+
10
+ @conn = Faraday.new(identity_base_url) do |conn|
11
+ conn.request :authorization, "Bearer", -> { @auth.auth_token }
12
+ conn.request :retry
13
+ conn.response :json
14
+ conn.adapter :net_http
15
+ end
16
+ end
17
+
18
+ def with_rescue
19
+ yield
20
+ rescue IdentityNotFoundError => e
21
+ puts e
22
+ end
23
+ end
24
+
25
+ # Client for getting auth tokens from identity server
26
+ class AuthClient
27
+ attr_accessor :conn, :token
28
+
29
+ def initialize(base_url, client_id, client_secret)
30
+ @client_id = client_id
31
+ @client_secret = client_secret
32
+ @conn = Faraday.new(base_url) do |conn|
33
+ conn.request :url_encoded
34
+ conn.response :raise_error
35
+ conn.response :json
36
+ conn.adapter :net_http
37
+ end
38
+ end
39
+
40
+ def auth_token
41
+ if expired?
42
+ response = @conn.post("/connect/token", request_body)
43
+ @token = response.body.transform_keys(&:to_sym)
44
+ end
45
+
46
+ @token[:access_token]
47
+ end
48
+
49
+ def expired?
50
+ return true if @token.nil?
51
+
52
+ token_expired?(@token[:access_token])
53
+ end
54
+
55
+ def token_expired?(jwt)
56
+ begin
57
+ expiry_time = Time.at(JWT.decode(jwt, nil, false)[0]["exp"])
58
+ rescue JWT::ExpiredSignature
59
+ return true
60
+ end
61
+ expiry_time <= Time.now.utc + 30
62
+ end
63
+
64
+ def refresh_token(jwt:, refresh_token:)
65
+ raise ArgumentError if refresh_token.nil? || jwt.nil?
66
+ return unless token_expired?(jwt)
67
+
68
+ response = @conn.post("/connect/token", request_body(
69
+ grant_type: "refresh_token", refresh_token:))
70
+ response.body.transform_keys!(&:to_sym)
71
+ end
72
+
73
+ def refresh_session(session: {})
74
+ raise ArgumentError if session[:id_token].nil? || session[:refresh_token].nil?
75
+
76
+ refreshed_tokens = refresh_token(jwt: session[:id_token], refresh_token: session[:refresh_token])
77
+
78
+ return if refreshed_tokens.nil?
79
+
80
+ session[:id_token] = refreshed_tokens[:id_token]
81
+ session[:access_token] = refreshed_tokens[:access_token]
82
+ session[:refresh_token] = refreshed_tokens[:refresh_token]
83
+ end
84
+
85
+ private
86
+
87
+ def request_body(grant_type: "client_credentials", refresh_token: nil)
88
+ return { grant_type:, client_id: @client_id, client_secret: @client_secret } if refresh_token.nil?
89
+
90
+ { grant_type:, client_id: @client_id, client_secret: @client_secret, refresh_token: }
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "date"
4
+ require "faraday"
5
+ require "faraday/net_http"
6
+ require "json"
7
+
8
+ require "platform_sdk/identity/clients"
9
+
10
+ module PlatformSdk
11
+ module Identity
12
+ class IdentityNotFoundError < StandardError; end
13
+ end
14
+ end
@@ -0,0 +1,165 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PlatformSdk
4
+ module OneRoster
5
+ # OneRoster Client which wraps the swagger generated OneRoster Management APIs
6
+ class Client
7
+ attr_accessor :users_api, :classes_api, :courses_api, :enrollments_api, :academic_sessions_api,
8
+ :line_items_api, :results_api, :orgs_api, :demographics_api
9
+
10
+ def initialize(oneroster_base_url, auth_client)
11
+ @auth = auth_client
12
+
13
+ uri = URI.parse(oneroster_base_url)
14
+ ::OneRosterClient.configure do |config|
15
+ # Configure OAuth2 access token for authorization: OAuth2Security
16
+ config.scheme = uri.scheme
17
+ config.host = uri.host
18
+ config.base_path = uri.path
19
+ end
20
+
21
+ init_apis
22
+ end
23
+
24
+ def init_apis
25
+ @users_api = ::OneRosterClient::UsersManagementApi.new
26
+ @classes_api = ::OneRosterClient::ClassesManagementApi.new
27
+ @courses_api = ::OneRosterClient::CoursesManagementApi.new
28
+ @enrollments_api = ::OneRosterClient::EnrollmentsManagementApi.new
29
+ @academic_sessions_api = ::OneRosterClient::AcademicSessionsManagementApi.new
30
+ @line_items_api = ::OneRosterClient::LineItemsManagementApi.new
31
+ @results_api = ::OneRosterClient::ResultsManagementApi.new
32
+ @orgs_api = ::OneRosterClient::OrgsManagementApi.new
33
+ @demographics_api = ::OneRosterClient::DemographicsManagementApi.new
34
+ end
35
+
36
+ %i[user class course enrollment academic_session line_item result org demographic].each do |record_type|
37
+ define_method(record_type) do |sourced_id, include = {}|
38
+ api = management_api(record_type)
39
+ with_rescue_and_set_token do
40
+ record = one_roster_record(api, record_type, sourced_id)
41
+ record_with_included(include, record)
42
+ end
43
+ end
44
+ end
45
+
46
+ # @param [Hash] opts the optional parameters
47
+ # @option opts [Integer] :limit To define the download segmentation value i.e. the maximum number of records to be contained in the response.
48
+ # @option opts [Integer] :offset The number of the first record to be supplied in the segmented response message.
49
+ # @option opts [String] :continuation_token Allows the client to resume retrieving results from where the previous page left off
50
+ # @option opts [String] :sort Identifies the sort criteria to be used for the records in the response message. Use with the orderBy parameter.
51
+ # @option opts [String] :order_by The form of ordering for response to the sorted request i.e. ascending (asc) or descending (desc).
52
+ # @option opts [String] :filter The filtering rules to be applied when identifying the records to be supplied in the response message.
53
+ # @option opts [Array<String>] :fields To identify the range of fields that should be supplied in the response message.
54
+ # @return [Array<(UsersType, Integer, Hash)>] UsersType data, response status code and response headers
55
+ %i[users classes courses enrollments demographics orgs line_items results].each do |records_type|
56
+ define_method(records_type) do |opts = {}|
57
+ api = instance_variable_get "@#{records_type}_api"
58
+ with_rescue_and_set_token do
59
+ one_roster_records(api, records_type, opts)
60
+ end
61
+ end
62
+ end
63
+
64
+ def pluralize_oneroster_type(record_type)
65
+ if record_type == :class
66
+ "#{record_type}es"
67
+ else
68
+ "#{record_type}s"
69
+ end
70
+ end
71
+
72
+ def with_rescue_and_set_token
73
+ ::OneRosterClient.configure.access_token = @auth.auth_token
74
+ yield
75
+ rescue ::OneRosterClient::Error => e
76
+ error(e)
77
+ end
78
+
79
+ def error(api_error)
80
+ case api_error.response[:status]
81
+ when 404
82
+ nil
83
+ else
84
+ puts "Exception when calling OneRoster resource: #{api_error}"
85
+ raise
86
+ end
87
+ end
88
+
89
+ def function_name(key)
90
+ {
91
+ student: "user",
92
+ agents: "user",
93
+ orgs: "org",
94
+ school: "org",
95
+ terms: "academic_session",
96
+ school_year: "academic_session",
97
+ grading_period: "academic_session",
98
+ parent: "academic_session"
99
+ }[key] || key
100
+ end
101
+
102
+ def key_map(key)
103
+ {
104
+ class: "_class",
105
+ demographic: "demographics"
106
+ }[key] || key
107
+ end
108
+
109
+ private
110
+
111
+ def management_api(record_type)
112
+ pluralized_record_type = pluralize_oneroster_type(record_type)
113
+ instance_variable_get "@#{pluralized_record_type}_api"
114
+ end
115
+
116
+ def one_roster_record(api, record_type, sourced_id)
117
+ single_type = api.send("get_#{record_type}", sourced_id)
118
+ single_type.send(key_map(record_type))
119
+ end
120
+
121
+ def one_roster_records(api, records_type, opts = {})
122
+ records_with_key = api.send("get_#{records_type}", opts)
123
+ records_with_key.send(records_type)
124
+ end
125
+
126
+ def record_with_included(include, record)
127
+ include ||= {}
128
+ include.each do |key, value|
129
+ ignore_invalid_includes do
130
+ attribute_name = key_map key
131
+ child = record.send(attribute_name)
132
+ child_as_record = child_record(child, key, value)
133
+ record.send("#{attribute_name}=", child_as_record)
134
+ end
135
+ end
136
+ record
137
+ end
138
+
139
+ def ignore_invalid_includes
140
+ yield
141
+ rescue NoMethodError
142
+ # Do nothing
143
+ end
144
+
145
+ def child_record(child, key, value)
146
+ function_name = function_name(key)
147
+ if child.is_a? Array
148
+ handle_child_as_array(child, function_name, value)
149
+ else
150
+ send(function_name, child.sourced_id, value)
151
+ end
152
+ end
153
+
154
+ def handle_child_as_array(child, function_name, value)
155
+ child_with_records = []
156
+ child.each do |item|
157
+ object = send(function_name, item.sourced_id, value)
158
+ child_with_records.append(object) unless object.nil?
159
+ end
160
+ child_with_records
161
+ end
162
+
163
+ end
164
+ end
165
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "uri"
4
+
5
+ require "oneroster_client"
6
+ require "platform_sdk/identity"
7
+ require "platform_sdk/one_roster/client"
8
+
9
+ module PlatformSdk
10
+ module OneRoster
11
+ class Error < StandardError; end
12
+ end
13
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+ module PlatformSdk
3
+ module PowerSchool
4
+ # Powerschool::Client
5
+ class Client
6
+ attr_reader :bearer_token, :conn
7
+
8
+ def initialize(base_url:, bearer_token: nil, expansions: nil)
9
+ @bearer_token = bearer_token
10
+ @bearer_token ||= PlatformSdk::PowerSchool.bearer_token
11
+ @expansions = expansions || self.class.expansions
12
+
13
+ @conn = Faraday.new(base_url, headers:) do |conn|
14
+ conn.response :raise_error
15
+ conn.request :json
16
+ conn.response :json
17
+ conn.adapter :net_http
18
+ end
19
+ end
20
+
21
+ def headers
22
+ {
23
+ "Authorization" => "Bearer #{@bearer_token}",
24
+ "Content-Type" => "application/json",
25
+ "Accept" => "application/json"
26
+ }
27
+ end
28
+
29
+ def power_query(query_name)
30
+ scrub_query(query_name)
31
+ @conn.post("/ws/schema/query/com.strongmind.#{query_name}?pagesize=0").body["record"]
32
+ end
33
+
34
+ def special_programs
35
+ records_as_json = power_query("specialprograms")
36
+ records_as_json.map { |record| SpecialProgram.new(record) }
37
+ end
38
+
39
+ def self.expansions
40
+ {
41
+ STUDENTS: %w[demographics addresses alerts phones school_enrollment ethnicity_race contact contact_info
42
+ initial_enrollment schedule_setup fees lunch],
43
+ SECTIONS: %w[term],
44
+ TEACHERS: %w[addresses emails phones school_affiliations]
45
+ }
46
+ end
47
+
48
+ def valid_power_query_names
49
+ %w[specialprograms]
50
+ end
51
+
52
+ def scrub_query(query_name)
53
+ raise PowerQueryNotValid unless valid_power_query_names.include?(query_name)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PlatformSdk
4
+ module PowerSchool
5
+ class SpecialProgram
6
+ attr_accessor :special_enrollments_dcid, :special_enrollments_id, :program_id, :enter_date, :exit_date,
7
+ :code1, :code2, :exit_code, :special_comment, :school_id, :grade_level,
8
+ :student_id, :program_name, :student_uuid, :special_enrollment_uuid, :enroll_status
9
+
10
+ def initialize(attributes = {})
11
+ attributes.each do |name, value|
12
+ send("#{self.class.attribute_map(name)}=", value)
13
+ end
14
+ end
15
+
16
+ def self.attribute_map(key)
17
+ {
18
+ spenrollments_dcid: "special_enrollments_dcid",
19
+ spenrollments_id: "special_enrollments_id",
20
+ programid: "program_id",
21
+ exitcode: "exit_code",
22
+ sp_comment: "special_comment",
23
+ schoolid: "school_id",
24
+ gradelevel: "grade_level",
25
+ studentid: "student_id",
26
+ spenrollment_uuid: "special_enrollment_uuid"
27
+ } [key.to_sym] || key
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "uri"
4
+ require "platform_sdk/power_school/client"
5
+ require "platform_sdk/power_school/special_program"
6
+
7
+ module PlatformSdk
8
+ # PowerSchool SDK for interacting with the PowerSchool API
9
+ module PowerSchool
10
+ class Error < StandardError; end
11
+
12
+ class BearerTokenNotSet < StandardError; end
13
+
14
+ class PowerQueryNotValid < StandardError; end
15
+
16
+ def self.bearer_token
17
+ raise BearerTokenNotSet if @bearer_token.nil?
18
+
19
+ @bearer_token
20
+ end
21
+
22
+ def self.bearer_token=(bearer_token)
23
+ @bearer_token = bearer_token
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PlatformSdk
4
+ VERSION = "2.12.0"
5
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "platform_sdk/version"
4
+ require "platform_sdk/one_roster"
5
+ require "platform_sdk/identity"
6
+ require "platform_sdk/power_school"
7
+ require "platform_sdk/aws"
8
+ require "platform_sdk/id_mapper"
9
+
10
+ module PlatformSdk
11
+ class Error < StandardError; end
12
+ # Your code goes here...
13
+ end
@@ -0,0 +1,27 @@
1
+ module PlatformSdk
2
+ module Identity
3
+ class AuthClient
4
+ @client_id: String
5
+ @client_secret: String
6
+ @conn: Object
7
+
8
+ attr_accessor conn: Object
9
+
10
+ attr_accessor token: String
11
+
12
+ def auth_token: -> String
13
+
14
+ def expired?: -> bool
15
+
16
+ def refresh_session: -> nil
17
+
18
+ def refresh_token: -> Hash[Symbol, String]
19
+
20
+ def token_expired?: -> bool
21
+
22
+ private
23
+
24
+ def request_body: -> Hash[Symbol, String]
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,4 @@
1
+ module PlatformSdk
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: strongmind-platform-sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.12.0
5
+ platform: ruby
6
+ authors:
7
+ - Platform Team
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-03-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.5'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.5.2
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '2.5'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.5.2
33
+ - !ruby/object:Gem::Dependency
34
+ name: oneroster_client
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 2.0.1
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 2.0.1
47
+ - !ruby/object:Gem::Dependency
48
+ name: uri
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: aws-sdk-secretsmanager
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.66'
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.66'
75
+ description: Includes a wrapper for the swagger generated OneRoster management clients
76
+ email:
77
+ - horseshoes@strongmind.com
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - ".rspec"
83
+ - ".rubocop.yml"
84
+ - ".ruby-version"
85
+ - CHANGELOG.md
86
+ - CODEOWNERS
87
+ - CODE_OF_CONDUCT.md
88
+ - Gemfile
89
+ - Gemfile.lock
90
+ - LICENSE.txt
91
+ - Makefile
92
+ - README.md
93
+ - Rakefile
94
+ - lib/platform_sdk.rb
95
+ - lib/platform_sdk/aws.rb
96
+ - lib/platform_sdk/aws/secrets_manager_client.rb
97
+ - lib/platform_sdk/id_mapper.rb
98
+ - lib/platform_sdk/id_mapper/client.rb
99
+ - lib/platform_sdk/id_mapper/constants.rb
100
+ - lib/platform_sdk/identity.rb
101
+ - lib/platform_sdk/identity/clients.rb
102
+ - lib/platform_sdk/one_roster.rb
103
+ - lib/platform_sdk/one_roster/client.rb
104
+ - lib/platform_sdk/power_school.rb
105
+ - lib/platform_sdk/power_school/client.rb
106
+ - lib/platform_sdk/power_school/special_program.rb
107
+ - lib/platform_sdk/version.rb
108
+ - sig/platform_sdk/identity/auth_client.rbs
109
+ - sig/platform_sdk/platform_sdk.rbs
110
+ homepage: https://github.com/StrongMind/platform-ruby-sdk
111
+ licenses:
112
+ - MIT
113
+ metadata:
114
+ github_repo: git@github.com:StrongMind/platform-ruby-sdk.git
115
+ homepage_uri: https://github.com/StrongMind/platform-ruby-sdk
116
+ source_code_uri: https://github.com/StrongMind/platform-ruby-sdk
117
+ changelog_uri: https://github.com/StrongMind/platform-ruby-sdk/blob/main/CHANGELOG.md
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: 2.6.0
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubygems_version: 3.3.26
134
+ signing_key:
135
+ specification_version: 4
136
+ summary: This gem is intended to provide clients and models for accessing the Platform
137
+ APIs.
138
+ test_files: []