⚠️

Exciting News!

Our transition to a new website is complete. Click here to seamlessly access the latest version of this article.

Kindly update any bookmarked URLs accordingly. The Development Center will no longer be accessible after April 1, 2024. Thank you for your attention to this matter.

📘

GitHub

Click here to go to GitHub

Setup

Insert OneClick.rb into your project.

Usage

First, import OneClick.rb

require './OneClick.rb'

Next, you need to create a new instance of OneClick with the client_key and client_secret.

oc = OneClick.new("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")

Generate Bearer Token

get_code_url(scope, redirect_uri)

Following that, you will need to generate the url for you to sign in and retrieve your code, which will be used to get the access token. This is done with the method get_code_url(scope, redirect_uri).

The scope can be:

  • profile - Access to user identiy and user specific information
  • oneroster - Access to oneroster info and classes
  • full - Access to all public apis

Scope will be defaulted to profile not included in method call.

The redirect_uri is the url that you will be redirected to upon login. It defaults to https://localhost:8080/code.

You can use curl or get the code from the url bar after signing in.

oc = OneClick.new("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
# Prints the url for the code
puts oc.get_code_url("full")

get_token(code)

After getting the code from the url, you need to generate the bearer token that will be used for all the requests. This will be generated using the get_token(code) method.

# Uses the code received after signing in and returns the bearer token 
puts oc.get_token("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")

Accessing the Endpoints

Now that you have your bearer token, you can access the endpoints. This can be done through a number of methods. The first method, get_info(bearer, endpoint,extract_node), allows the user to specify what endpoint they want to hit and what field to return. The rest of the methods will make requests to specific endpoints for specific information.

get_info(bearer, endpoint, extract_node)

The main method used to make a request to an endpoint is get_info(bearer, endpoint, extract_node). It takes in the bearer token, the url of the endpoint (excluding the hostname), and an optional extract_node, which will return this specific field if is not passed as an empty string.
It will return the info as a JSON response in a string.

# Prints the JSON response from the request to the endpoint
puts oc.get_info("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "/path/info", "")

get_user_info(bearer)

This method will take in the bearer token and return a JSON containing all of the available user info

# Prints user info as JSON
puts oc.get_user_info("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")

get_user_district(bearer)

This method will get the district associated with the user

# Prints the district as JSON
puts oc.get_user_disctrict("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")

get_user_profiles(bearer)

This method will get info on the user's profiles.

# Prints info on the user's profiles as JSON
puts oc.get_user_profiles("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")

get_user_children(bearer)

If the user is a parent registered for ClassLink, this will return a list of linked student accounts (their children)

# Prints children info
puts oc.get_user_children("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")

get_user_groups(bearer)

Get a list of all groups that the user is a part of

# Prints a list of all groups that the user is a part of
puts oc.get_user_groups("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")

get_user_one_roster_info(bearer)

Get all the OneRoster info about the user
Note: Only available for districts with OneRoster enabled.

# Print the oneroster info about the User
puts oc.get_user_one_roster_info("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")

get_user_one_roster_classes(bearer)

Get all the OneRoster classes the user is enrolled in.
Note: Only available for districts with OneRoster enabled.
Info

# Print the oneroster info about user's classes
puts oc.get_user_one_roster_classes("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")

get_user_one_roster_class_teachers(bearer, class_sourced_id)

Get info on the teacher of the class represented by the unique sourcedId.
Note: Only available for districts with OneRoster enabled.
Info

# Print the oneroster info on the teacher of the class
puts oc.get_user_one_roster_class_teachers("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "sourcedId")

get_user_one_roster_class_students(bearer, class_sourced_id)

Get info on the students of the class represented by the unique sourcedId.
Note: Only available for districts with OneRoster enabled.
Info

# Print the oneroster info the students of the class
puts oc.get_user_one_roster_class_students("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "sourcedId")