Skip to content

moexmen/sls_adf

Repository files navigation

Gem Version Build Status Inline docs Maintainability

SLS ADF - Ruby Client Library

Ruby support for GraphQL API calls to MOE's Student Learning Space. This includes a few functionalities:

  • Token management
  • GraphQL Templates

Requires Ruby 2.4+.

Installation

Add this line to your application's Gemfile:

gem 'sls_adf'

Configure the gem in the following manner: (This can be placed in config/initializers/ for Rails applications)

SlsAdf.configure do |c|
  c.graphql_url = 'https://example.com'
  c.get_token_url = 'https://example.com/token'
  c.client_id = 'Foo'
  c.client_secret = 'Bar'
end

And then execute:

$ bundle

Usage

sls_adf provides ruby methods which can be used to make GraphQL calls to SLS ADF. To use, follow the installation instructions above and configure the necessary details.

# Queries
response = SlsAdf::Query.user('id')
response = SlsAdf::Query.context('uuid')
response = SlsAdf::Query.subject_group('uuid')
response = SlsAdf::Query.assignment('uuid')
response = SlsAdf::Query.task('uuid')

# Mutations
response = SlsAdf::Mutation.create_assignment(assignment_input)
response = SlsAdf::Mutation.update_assignment(uuid, assignment_input)
response = SlsAdf::Mutation.delete_assignment(uuid)
response = SlsAdf::Mutation.update_task(uuid, task_input)
response = SlsAdf::Mutation.create_notification(notification_input)

Customization

sls_adf uses Github's graphql-client for graphql functionality, and Typhoeus to make http calls.

Two classes, Adapter (SlsAdf::Util::Adapter) and Token (SlsAdf::Util::Token) are defined in this gem to support the most naive use case. These classes are designed to be extended or replaced to support different use cases.

Customised GraphQL Calls

sls_adf provides pre-defined GraphQL calls to ADF. Should you require other calls, you may:

  1. Declare your custom GraphQL queries or mutations using the graphql-client DSL, then execute them using SlsAdf.query with the appropriate variables.
  2. For easy reuse, create a new class that inherits from SlsAdf::Base to wrap your custom queries, mutations or fragments.

Development

Key Commands:

  • bin/setup: Install dependencies and copy .env file.
  • bin/console: Run an interactive prompt (requires configuration on .env file).
  • rake spec or bundle exec rspec: Run tests.
  • rake sls_adf:update_schema: Update the SLS ADF GraphQL schema (requires configuration on .env file).

Contributing

Bug reports and pull requests are welcome on GitHub.

License

The gem is available as open source under the terms of the MIT License.

About

(Beta) Ruby client library for SLS's Application Development Framework.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published