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:
ruby
gem 'sls_adf'
Configure the gem in the following manner:
(This can be placed in config/initializers/
for Rails applications)
ruby
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.
```ruby # 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 a different call,
you may define new GraphQL queries, mutations or fragments. Thereafter, you can construct
your own class that uses these templates and inherits from SlsAdf::Base
.
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.
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.