clever_sdk 0.9.0.pre.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +26 -0
- data/.env.sample +20 -0
- data/.gitignore +22 -0
- data/.tool-versions +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +65 -0
- data/Rakefile +10 -0
- data/bin/console +31 -0
- data/bin/setup +8 -0
- data/bin/test +6 -0
- data/clever_sdk.gemspec +44 -0
- data/lib/clever_sdk/api/authentication.rb +38 -0
- data/lib/clever_sdk/api/courses.rb +54 -0
- data/lib/clever_sdk/api/districts.rb +23 -0
- data/lib/clever_sdk/api/events.rb +26 -0
- data/lib/clever_sdk/api/resources.rb +49 -0
- data/lib/clever_sdk/api/response.rb +59 -0
- data/lib/clever_sdk/api/schools.rb +68 -0
- data/lib/clever_sdk/api/sections.rb +70 -0
- data/lib/clever_sdk/api/terms.rb +46 -0
- data/lib/clever_sdk/api/users.rb +81 -0
- data/lib/clever_sdk/api.rb +81 -0
- data/lib/clever_sdk/authentication.rb +67 -0
- data/lib/clever_sdk/client/courses.rb +45 -0
- data/lib/clever_sdk/client/districts.rb +21 -0
- data/lib/clever_sdk/client/events.rb +22 -0
- data/lib/clever_sdk/client/resources.rb +40 -0
- data/lib/clever_sdk/client/schools.rb +54 -0
- data/lib/clever_sdk/client/sections.rb +59 -0
- data/lib/clever_sdk/client/terms.rb +40 -0
- data/lib/clever_sdk/client/users.rb +66 -0
- data/lib/clever_sdk/client.rb +41 -0
- data/lib/clever_sdk/configuration.rb +13 -0
- data/lib/clever_sdk/data/course/refs.rb +36 -0
- data/lib/clever_sdk/data/course.rb +44 -0
- data/lib/clever_sdk/data/courses.rb +79 -0
- data/lib/clever_sdk/data/district.rb +129 -0
- data/lib/clever_sdk/data/districts.rb +37 -0
- data/lib/clever_sdk/data/event.rb +93 -0
- data/lib/clever_sdk/data/events.rb +79 -0
- data/lib/clever_sdk/data/me.rb +34 -0
- data/lib/clever_sdk/data/resource/refs.rb +45 -0
- data/lib/clever_sdk/data/resource.rb +60 -0
- data/lib/clever_sdk/data/resources.rb +79 -0
- data/lib/clever_sdk/data/school/refs.rb +42 -0
- data/lib/clever_sdk/data/school.rb +88 -0
- data/lib/clever_sdk/data/schools.rb +79 -0
- data/lib/clever_sdk/data/section/refs.rb +45 -0
- data/lib/clever_sdk/data/section.rb +100 -0
- data/lib/clever_sdk/data/sections.rb +79 -0
- data/lib/clever_sdk/data/sso.rb +44 -0
- data/lib/clever_sdk/data/term/refs.rb +32 -0
- data/lib/clever_sdk/data/term.rb +46 -0
- data/lib/clever_sdk/data/terms.rb +79 -0
- data/lib/clever_sdk/data/token.rb +67 -0
- data/lib/clever_sdk/data/tokeninfo.rb +30 -0
- data/lib/clever_sdk/data/tokens.rb +35 -0
- data/lib/clever_sdk/data/user/contact_role.rb +19 -0
- data/lib/clever_sdk/data/user/district_admin_role.rb +19 -0
- data/lib/clever_sdk/data/user/refs.rb +56 -0
- data/lib/clever_sdk/data/user/staff_role.rb +19 -0
- data/lib/clever_sdk/data/user/student_role.rb +19 -0
- data/lib/clever_sdk/data/user/teacher_role.rb +19 -0
- data/lib/clever_sdk/data/user.rb +123 -0
- data/lib/clever_sdk/data/users.rb +79 -0
- data/lib/clever_sdk/error.rb +27 -0
- data/lib/clever_sdk/version.rb +5 -0
- data/lib/clever_sdk.rb +36 -0
- metadata +255 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: aa4e893dcb0810db98da38767e7ae10b20bbdf416b775e702c8fc15111a2a510
|
4
|
+
data.tar.gz: 9251372d6e35e0089f16d9902d05f9f13f07afa7f69d077504f7a09d0af5f2b3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a1b8c193349e6f97a81deb1e4bc54c1f7978c6e78330b1536dd5e3f814384db888375321f2ea1bc6be4d583dcb15195a249794bb19c55f253fbc6216e1ae9bcd
|
7
|
+
data.tar.gz: 9f546efcebd9c955dc9d34fe18b5e92267c079b31ee94faecc5cd3bf57dbf6a639768492186483102972c62ad0fb3e24c5a8f68cca14549a8f237ddd932f4c45
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# Use the latest 2.1 version of CircleCI pipeline process engine.
|
2
|
+
# See: https://circleci.com/docs/2.0/configuration-reference
|
3
|
+
version: 2.1
|
4
|
+
|
5
|
+
# Define a job to be invoked later in a workflow.
|
6
|
+
# See: https://circleci.com/docs/2.0/configuration-reference/#jobs
|
7
|
+
jobs:
|
8
|
+
say-hello:
|
9
|
+
# Specify the execution environment. You can specify an image from Dockerhub or use one of our Convenience Images from CircleCI's Developer Hub.
|
10
|
+
# See: https://circleci.com/docs/2.0/configuration-reference/#docker-machine-macos-windows-executor
|
11
|
+
docker:
|
12
|
+
- image: cimg/base:stable
|
13
|
+
# Add steps to the job
|
14
|
+
# See: https://circleci.com/docs/2.0/configuration-reference/#steps
|
15
|
+
steps:
|
16
|
+
- checkout
|
17
|
+
- run:
|
18
|
+
name: "Say hello"
|
19
|
+
command: "echo Hello, World!"
|
20
|
+
|
21
|
+
# Invoke jobs via workflows
|
22
|
+
# See: https://circleci.com/docs/2.0/configuration-reference/#workflows
|
23
|
+
workflows:
|
24
|
+
say-hello-workflow:
|
25
|
+
jobs:
|
26
|
+
- say-hello
|
data/.env.sample
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
CLEVER_ID: "095b82cbbd8c68714d1c"
|
2
|
+
CLEVER_SECRET: "4b338489ceb4bec362461a7c96e3aa609efff049"
|
3
|
+
CLEVER_REDIRECT_URI: "http://localhost:3000/auth/clever"
|
4
|
+
|
5
|
+
# Test Credentials from https://dev.clever.com/reference/schema#schema
|
6
|
+
# CleverSDK.configuration.client_id = "095b82cbbd8c68714d1c"
|
7
|
+
# CleverSDK.configuration.client_secret = "4b338489ceb4bec362461a7c96e3aa609efff049"
|
8
|
+
# Authorization: "Basic: MDk1YjgyY2JiZDhjNjg3MTRkMWM6NGIzMzg0ODljZWI0YmVjMzYyNDYxYTdjOTZlM2FhNjA5ZWZmZjA0OQ=="
|
9
|
+
|
10
|
+
# Identity API Test tokens:
|
11
|
+
# ilc_DEMO_STUDENT_TOKEN
|
12
|
+
# ilc_DEMO_TEACHER_TOKEN
|
13
|
+
# ilc_DEMO_SCHOOL_ADMIN_TOKEN
|
14
|
+
# ilc_DEMO_DISTRICT_ADMIN_TOKEN
|
15
|
+
|
16
|
+
# Data API test tokens:
|
17
|
+
# TEST_TOKEN
|
18
|
+
|
19
|
+
# Events API test tokens:
|
20
|
+
# TEST_TOKEN
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/Gemfile.lock
|
4
|
+
/_yardoc/
|
5
|
+
coverage/*
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/tmp/
|
10
|
+
*.bundle
|
11
|
+
*.so
|
12
|
+
*.o
|
13
|
+
*.a
|
14
|
+
mkmf.log
|
15
|
+
*.sublime-project
|
16
|
+
*.sublime-workspace
|
17
|
+
|
18
|
+
.DS_Store
|
19
|
+
.env
|
20
|
+
.ruby-version
|
21
|
+
.ruby-gemset
|
22
|
+
|
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 3.1.2
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at beneggett@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Ben Eggett
|
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/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/clever_sdk.svg)](https://badge.fury.io/rb/clever_sdk)
|
2
|
+
[![CircleCI](https://dl.circleci.com/status-badge/img/gh/beneggett/clever_sdk/tree/main.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/beneggett/clever_sdk/tree/main)
|
3
|
+
|
4
|
+
# CleverSDK
|
5
|
+
|
6
|
+
Fully Implements the Clever API in a simple to use SDK in Ruby
|
7
|
+
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'clever_sdk'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install clever_sdk
|
24
|
+
|
25
|
+
Be sure to define your Clever credentials by setting up environment variables in your application appropriately. Refer to the .env.sample file for details.
|
26
|
+
```
|
27
|
+
CLEVER_ID = 'my-clever-id'
|
28
|
+
CLEVER_SECRET = 'my-clever-key'
|
29
|
+
```
|
30
|
+
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
There are many primary APIs that are wrapped. Below you will see basic examples of how to use them. For more information about what optional query parameters are available, please consult the [Clever API Docs](https://dev.clever.com/docs)
|
35
|
+
|
36
|
+
## Configuration
|
37
|
+
|
38
|
+
Place the following configuration in your apps initializer
|
39
|
+
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
CleverSDK.configure do |config|
|
43
|
+
config.clever_id = "your-value"
|
44
|
+
config.clever_secret = "your-value"
|
45
|
+
config.redirect_uri = "your-value"
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
## Development
|
50
|
+
|
51
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
52
|
+
|
53
|
+
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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/beneggett/clever_sdk. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
58
|
+
|
59
|
+
## License
|
60
|
+
|
61
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
62
|
+
|
63
|
+
## Code of Conduct
|
64
|
+
|
65
|
+
Everyone interacting in the CleverSDK project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/beneggett/clever_sdk/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require "dotenv"
|
3
|
+
Dotenv.load
|
4
|
+
require "bundler/setup"
|
5
|
+
require "clever_sdk"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
require "pry"
|
12
|
+
|
13
|
+
|
14
|
+
def reload!(print = true)
|
15
|
+
puts 'Reloading ...' if print
|
16
|
+
# Main project directory.
|
17
|
+
root_dir = File.expand_path('..', __dir__)
|
18
|
+
# Directories within the project that should be reloaded.
|
19
|
+
reload_dirs = %w{lib}
|
20
|
+
# Loop through and reload every file in all relevant project directories.
|
21
|
+
reload_dirs.each do |dir|
|
22
|
+
Dir.glob("#{root_dir}/#{dir}/**/*.rb").each { |f| load(f) }
|
23
|
+
end
|
24
|
+
# Return true when complete.
|
25
|
+
true
|
26
|
+
end
|
27
|
+
|
28
|
+
Pry.start
|
29
|
+
|
30
|
+
# require "irb"
|
31
|
+
# IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/bin/test
ADDED
data/clever_sdk.gemspec
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "clever_sdk/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "clever_sdk"
|
7
|
+
spec.version = CleverSDK::VERSION
|
8
|
+
spec.authors = ["Ben Eggett", "Mike Moore"]
|
9
|
+
spec.email = ["beneggett@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Clever API ruby wrapper"
|
12
|
+
spec.description = "Provides an SDK for interacting wth the Clever API in Ruby"
|
13
|
+
spec.homepage = "https://github.com/beneggett/clever_sdk"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
22
|
+
"public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
# Specify which files should be added to the gem when it is released.
|
26
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
27
|
+
spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
|
28
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
29
|
+
end
|
30
|
+
spec.bindir = "exe"
|
31
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
32
|
+
spec.require_paths = ["lib"]
|
33
|
+
|
34
|
+
spec.add_development_dependency "bundler"
|
35
|
+
spec.add_development_dependency "coveralls"
|
36
|
+
spec.add_development_dependency "dotenv"
|
37
|
+
spec.add_development_dependency "minitest"
|
38
|
+
spec.add_development_dependency "minitest-focus"
|
39
|
+
spec.add_development_dependency "pry"
|
40
|
+
spec.add_development_dependency "rake"
|
41
|
+
spec.add_development_dependency "simplecov"
|
42
|
+
spec.add_development_dependency "vcr"
|
43
|
+
spec.add_dependency "typhoeus"
|
44
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CleverSDK
|
4
|
+
class Api
|
5
|
+
module Authentication
|
6
|
+
# district - the district's token
|
7
|
+
def tokens(client_id:, client_secret:, district: nil)
|
8
|
+
get(
|
9
|
+
"https://clever.com/oauth/tokens",
|
10
|
+
params: params(owner_type: :district, district: district),
|
11
|
+
headers: basic_auth_headers(client_id, client_secret)
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
def tokens!(client_id:, client_secret:, code: nil, grant_type: nil, redirect_uri: nil)
|
16
|
+
post(
|
17
|
+
"https://clever.com/oauth/tokens",
|
18
|
+
body: JSON.dump(params(code: code, grant_type: grant_type, redirect_uri: redirect_uri)),
|
19
|
+
headers: basic_auth_headers(client_id, client_secret).merge({"Content-Type" => "application/json"})
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
def tokeninfo(access_token:)
|
24
|
+
get(
|
25
|
+
"https://clever.com/oauth/tokeninfo",
|
26
|
+
headers: bearer_headers(access_token)
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
def me(access_token:)
|
31
|
+
get(
|
32
|
+
"https://api.clever.com/v3.0/me",
|
33
|
+
headers: bearer_headers(access_token)
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CleverSDK
|
4
|
+
class Api
|
5
|
+
module Courses
|
6
|
+
# count - acceptable values are nil, :true, :false, :undefined
|
7
|
+
def courses(access_token:, limit: nil, starting_after: nil, ending_before: nil, count: nil)
|
8
|
+
get(
|
9
|
+
"https://api.clever.com/v3.0/courses",
|
10
|
+
params: params(limit: limit, starting_after: starting_after, ending_before: ending_before, count: count),
|
11
|
+
headers: bearer_headers(access_token)
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
def course(access_token:, id:)
|
16
|
+
get(
|
17
|
+
"https://api.clever.com/v3.0/courses/#{id}",
|
18
|
+
headers: bearer_headers(access_token)
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
def course_district(access_token:, id:)
|
23
|
+
get(
|
24
|
+
"https://api.clever.com/v3.0/courses/#{id}/district",
|
25
|
+
headers: bearer_headers(access_token)
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
def course_resources(access_token:, id:, limit: nil, starting_after: nil, ending_before: nil)
|
30
|
+
get(
|
31
|
+
"https://api.clever.com/v3.0/courses/#{id}/resources",
|
32
|
+
params: params(limit: limit, starting_after: starting_after, ending_before: ending_before),
|
33
|
+
headers: bearer_headers(access_token)
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
def course_schools(access_token:, id:, limit: nil, starting_after: nil, ending_before: nil)
|
38
|
+
get(
|
39
|
+
"https://api.clever.com/v3.0/courses/#{id}/schools",
|
40
|
+
params: params(limit: limit, starting_after: starting_after, ending_before: ending_before),
|
41
|
+
headers: bearer_headers(access_token)
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
def course_sections(access_token:, id:, limit: nil, starting_after: nil, ending_before: nil)
|
46
|
+
get(
|
47
|
+
"https://api.clever.com/v3.0/courses/#{id}/sections",
|
48
|
+
params: params(limit: limit, starting_after: starting_after, ending_before: ending_before),
|
49
|
+
headers: bearer_headers(access_token)
|
50
|
+
)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CleverSDK
|
4
|
+
class Api
|
5
|
+
module Districts
|
6
|
+
# count - acceptable values are nil, :true, :false, :undefined
|
7
|
+
def districts(access_token:, count: nil)
|
8
|
+
get(
|
9
|
+
"https://api.clever.com/v3.0/districts",
|
10
|
+
params: params(count: count),
|
11
|
+
headers: bearer_headers(access_token)
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
def district(access_token:, id:)
|
16
|
+
get(
|
17
|
+
"https://api.clever.com/v3.0/districts/#{id}",
|
18
|
+
headers: bearer_headers(access_token)
|
19
|
+
)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CleverSDK
|
4
|
+
class Api
|
5
|
+
module Events
|
6
|
+
def events(access_token:, limit: nil, starting_after: nil, ending_before: nil, school: nil, record_type: nil)
|
7
|
+
record_type = Array(record_type).flatten.compact
|
8
|
+
record_type = nil if record_type.empty?
|
9
|
+
|
10
|
+
get(
|
11
|
+
"https://api.clever.com/v3.0/events",
|
12
|
+
params: params(limit: limit, starting_after: starting_after, ending_before: ending_before,
|
13
|
+
school: school, record_type: record_type),
|
14
|
+
headers: bearer_headers(access_token)
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def event(access_token:, id:)
|
19
|
+
get(
|
20
|
+
"https://api.clever.com/v3.0/events/#{id}",
|
21
|
+
headers: bearer_headers(access_token)
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CleverSDK
|
4
|
+
class Api
|
5
|
+
module Resources
|
6
|
+
def resources(access_token:, limit: nil, starting_after: nil, ending_before: nil)
|
7
|
+
get(
|
8
|
+
"https://api.clever.com/v3.0/resources",
|
9
|
+
params: params(limit: limit, starting_after: starting_after, ending_before: ending_before),
|
10
|
+
headers: bearer_headers(access_token)
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
def resource(access_token:, id:)
|
15
|
+
get(
|
16
|
+
"https://api.clever.com/v3.0/resources/#{id}",
|
17
|
+
headers: bearer_headers(access_token)
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
def resource_courses(access_token:, id:, limit: nil, starting_after: nil, ending_before: nil)
|
22
|
+
get(
|
23
|
+
"https://api.clever.com/v3.0/resources/#{id}/courses",
|
24
|
+
params: params(limit: limit, starting_after: starting_after, ending_before: ending_before),
|
25
|
+
headers: bearer_headers(access_token)
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
def resource_sections(access_token:, id:, limit: nil, starting_after: nil, ending_before: nil)
|
30
|
+
get(
|
31
|
+
"https://api.clever.com/v3.0/resources/#{id}/sections",
|
32
|
+
params: params(limit: limit, starting_after: starting_after, ending_before: ending_before),
|
33
|
+
headers: bearer_headers(access_token)
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
# role - acceptable values are nil, :student, :teacher
|
38
|
+
def resource_users(access_token:, id:, role: nil, limit: nil, starting_after: nil, ending_before: nil)
|
39
|
+
get(
|
40
|
+
"https://api.clever.com/v3.0/resources/#{id}/users",
|
41
|
+
params: params(role: role, limit: limit, starting_after: starting_after, ending_before: ending_before),
|
42
|
+
headers: bearer_headers(access_token)
|
43
|
+
)
|
44
|
+
end
|
45
|
+
# def resource_students(access_token:, id:, limit: nil, starting_after: nil, ending_before: nil)
|
46
|
+
# def resource_teachers(access_token:, id:, limit: nil, starting_after: nil, ending_before: nil)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CleverSDK
|
4
|
+
class Api
|
5
|
+
class Response
|
6
|
+
def self.handle(typhoeus_response)
|
7
|
+
return CleverSDK::Api::Response.new(typhoeus_response) if typhoeus_response.success?
|
8
|
+
|
9
|
+
raise CleverSDK::Error.handle(typhoeus_response)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.status_code_explanations
|
13
|
+
# from https://dev.clever.com/reference/responses-errors
|
14
|
+
@status_code_explanations ||= {
|
15
|
+
200 => {meaning: "Success", action_to_take: "Process the response."},
|
16
|
+
400 => {meaning: "Bad request", action_to_take: "Check your API token and request body. Do not retry request. The troubleshooting pages for each API also have tips for what to look for!"},
|
17
|
+
401 => {meaning: "Invalid auth", action_to_take: "Check your API token and request body. Do not retry request. The troubleshooting pages for each API also have tips for what to look for!"},
|
18
|
+
404 => {meaning: "Resource not available", action_to_take: "Check your API token and request URL - you may be using the wrong token or the resource may have been unshared with your application or deleted."},
|
19
|
+
413 => {meaning: "Request entity too large", action_to_take: "Your limit parameter may be over 10000; reduce accordingly."},
|
20
|
+
429 => {meaning: "Rate limit exceeded", action_to_take: "Try again after rate limit period expires."},
|
21
|
+
500 => {meaning: "Clever API failure", action_to_take: "Wait and retry request. If you see these regularly, reach out to integrations@clever.com."},
|
22
|
+
502 => {meaning: "Clever API failure", action_to_take: "Wait and retry request. If you see these regularly, reach out to integrations@clever.com."},
|
23
|
+
503 => {meaning: "Clever API failure", action_to_take: "Wait and retry request. If you see these regularly, reach out to integrations@clever.com."},
|
24
|
+
501 => {meaning: "Not implemented", action_to_take: "Your client is attempting an unsupported request. Try an alternative request. Do not retry request."}
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize(typhoeus_response)
|
29
|
+
@_response = typhoeus_response
|
30
|
+
end
|
31
|
+
|
32
|
+
def raw_request
|
33
|
+
@_response.request
|
34
|
+
end
|
35
|
+
|
36
|
+
def raw_response
|
37
|
+
@_response
|
38
|
+
end
|
39
|
+
|
40
|
+
def code
|
41
|
+
@_response.code
|
42
|
+
end
|
43
|
+
|
44
|
+
def headers
|
45
|
+
@_response.headers
|
46
|
+
end
|
47
|
+
|
48
|
+
def body
|
49
|
+
# Any response that does not return JSON is handled as an error.
|
50
|
+
@body ||= JSON.parse(@_response.body)
|
51
|
+
end
|
52
|
+
|
53
|
+
def access_token
|
54
|
+
# Dig the access token out of the response object.
|
55
|
+
@_response.request.options.dig(:headers, "Authorization").split(" ").last
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|