sls_adf 0.0.1

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
+ SHA1:
3
+ metadata.gz: 320145d0c458d8b27b4851cc1b483fbfa3cd89a6
4
+ data.tar.gz: d64bfb2d2dfabf65eee07566b1741dcacef22b2a
5
+ SHA512:
6
+ metadata.gz: 339d93578a8a0e79043f27da8ca5056aa41c05062751431b17266309cd0e91505cd528b87df53e2233ddb2a368b4500478e05edad11734a75aabdd2b5aaff6ab
7
+ data.tar.gz: d3d42b2b1032839dc7aa3b93aab6b4aa96cffb71db70e5efa1772d9eda595da5cae313d4baf9338ac0f81eb5b2c671f9bacdbd72904b6a3c9419cd04676713cf
data/.codeclimate.yml ADDED
@@ -0,0 +1,3 @@
1
+ plugins:
2
+ bundler-audit:
3
+ enabled: true
data/.env.example ADDED
@@ -0,0 +1,4 @@
1
+ GRAPHQL_URL=http://example.com/graphql
2
+ GET_TOKEN_URL=https://example.com/token
3
+ CLIENT_ID=test_client_id
4
+ CLIENT_SECRET=test_client_secret
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ # Ignore actual env file
14
+ .env
data/.hound.yml ADDED
@@ -0,0 +1,2 @@
1
+ ruby:
2
+ config_file: .rubocop.yml
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format progress
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,18 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4
3
+
4
+ Layout/DotPosition:
5
+ EnforcedStyle: trailing
6
+
7
+ Metrics/BlockLength:
8
+ Enabled: true
9
+ Exclude:
10
+ - spec/**/*
11
+
12
+ Metrics/LineLength:
13
+ Max: 120
14
+
15
+ Style/FrozenStringLiteralComment:
16
+ Enabled: true
17
+ Exclude:
18
+ - spec/**/*
data/.travis.yml ADDED
@@ -0,0 +1,32 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ - ruby-head
6
+ matrix:
7
+ allow_failures:
8
+ - rvm: ruby-head
9
+
10
+ branches:
11
+ only:
12
+ - master
13
+
14
+ bundler_args: "--jobs=3 --retry=3"
15
+ cache: bundler
16
+
17
+ before_install:
18
+ - gem install bundler -v 1.16.0
19
+
20
+ before_script:
21
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
22
+ - chmod +x ./cc-test-reporter
23
+ - ./cc-test-reporter before-build
24
+
25
+ script:
26
+ - bundle exec rspec
27
+
28
+ after_script:
29
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
30
+
31
+ notifications:
32
+ disabled: true
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in sls_adf.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,82 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sls_adf (0.0.1)
5
+ graphql-client (~> 0.12)
6
+ typhoeus (~> 1.3)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (5.1.4)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (~> 0.7)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ addressable (2.5.2)
17
+ public_suffix (>= 2.0.2, < 4.0)
18
+ concurrent-ruby (1.0.5)
19
+ crack (0.4.3)
20
+ safe_yaml (~> 1.0.0)
21
+ diff-lcs (1.3)
22
+ docile (1.1.5)
23
+ dotenv (2.2.1)
24
+ ethon (0.11.0)
25
+ ffi (>= 1.3.0)
26
+ ffi (1.9.18)
27
+ graphql (1.7.7)
28
+ graphql-client (0.12.2)
29
+ activesupport (>= 3.0, < 6.0)
30
+ graphql (~> 1.6)
31
+ hashdiff (0.3.7)
32
+ i18n (0.9.1)
33
+ concurrent-ruby (~> 1.0)
34
+ json (2.1.0)
35
+ minitest (5.10.3)
36
+ public_suffix (3.0.1)
37
+ rake (10.5.0)
38
+ rdoc (6.0.0)
39
+ rspec (3.7.0)
40
+ rspec-core (~> 3.7.0)
41
+ rspec-expectations (~> 3.7.0)
42
+ rspec-mocks (~> 3.7.0)
43
+ rspec-core (3.7.0)
44
+ rspec-support (~> 3.7.0)
45
+ rspec-expectations (3.7.0)
46
+ diff-lcs (>= 1.2.0, < 2.0)
47
+ rspec-support (~> 3.7.0)
48
+ rspec-mocks (3.7.0)
49
+ diff-lcs (>= 1.2.0, < 2.0)
50
+ rspec-support (~> 3.7.0)
51
+ rspec-support (3.7.0)
52
+ safe_yaml (1.0.4)
53
+ simplecov (0.15.1)
54
+ docile (~> 1.1.0)
55
+ json (>= 1.8, < 3)
56
+ simplecov-html (~> 0.10.0)
57
+ simplecov-html (0.10.2)
58
+ thread_safe (0.3.6)
59
+ typhoeus (1.3.0)
60
+ ethon (>= 0.9.0)
61
+ tzinfo (1.2.4)
62
+ thread_safe (~> 0.1)
63
+ webmock (3.1.1)
64
+ addressable (>= 2.3.6)
65
+ crack (>= 0.3.2)
66
+ hashdiff
67
+
68
+ PLATFORMS
69
+ ruby
70
+
71
+ DEPENDENCIES
72
+ bundler (~> 1.16)
73
+ dotenv (~> 2.2)
74
+ rake (~> 10.0)
75
+ rdoc
76
+ rspec (~> 3.0)
77
+ simplecov
78
+ sls_adf!
79
+ webmock
80
+
81
+ BUNDLED WITH
82
+ 1.16.0
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Experimental Systems and Technology Lab
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,86 @@
1
+ [![Build Status](https://travis-ci.org/moexmen/sls_adf.svg?branch=master)](https://travis-ci.org/moexmen/sls_adf) [![Maintainability](https://api.codeclimate.com/v1/badges/5d7c2801d4a37ecf8cdf/maintainability)](https://codeclimate.com/github/moexmen/sls_adf/maintainability)
2
+
3
+ # SLS ADF - Ruby Client Library
4
+
5
+ Ruby support for GraphQL API calls to MOE's Student Learning Space.
6
+ This includes a few functionalities:
7
+ - Token management
8
+ - GraphQL Templates
9
+
10
+ Requires Ruby 2.4+.
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'sls_adf'
18
+ ```
19
+
20
+ Configure the gem in the following manner:
21
+ (This can be placed in `config/initializers/` for Rails applications)
22
+
23
+ ```ruby
24
+ SlsAdf.configure do |c|
25
+ c.graphql_url = 'https://example.com'
26
+ c.get_token_url = 'https://example.com/token'
27
+ c.client_id = 'Foo'
28
+ c.client_secret = 'Bar'
29
+ end
30
+ ```
31
+
32
+ And then execute:
33
+
34
+ $ bundle
35
+
36
+ ## Usage
37
+
38
+ `sls_adf` provides ruby methods which can be used to make GraphQL calls to SLS ADF.
39
+ To use, follow the installation instructions above and configure the necessary details.
40
+
41
+ ```ruby
42
+ # Queries
43
+ response = SlsAdf::Query.user('id')
44
+ response = SlsAdf::Query.context('uuid')
45
+ response = SlsAdf::Query.subject_group('uuid')
46
+ response = SlsAdf::Query.assignment('uuid')
47
+ response = SlsAdf::Query.task('uuid')
48
+
49
+ # Mutations
50
+ response = SlsAdf::Mutation.create_assignment(assignment_input)
51
+ response = SlsAdf::Mutation.update_assignment(uuid, assignment_input)
52
+ response = SlsAdf::Mutation.delete_assignment(uuid)
53
+ response = SlsAdf::Mutation.update_task(uuid, task_input)
54
+ response = SlsAdf::Mutation.create_notification(notification_input)
55
+ ```
56
+
57
+ ## Customization
58
+
59
+ `sls_adf` uses Github's [graphql-client](https://github.com/github/graphql-client) for
60
+ graphql functionality, and [Typhoeus](https://github.com/typhoeus/typhoeus) to make
61
+ http calls.
62
+
63
+ Two classes, `Adapter` (`SlsAdf::Util::Adapter`) and `Token` (`SlsAdf::Util::Token`) are
64
+ defined in this gem to support the most naive use case. These classes are designed to be
65
+ extended or replaced to support different use cases.
66
+
67
+ #### Customised GraphQL Calls
68
+
69
+ `sls_adf` provides pre-defined GraphQL calls to ADF. Should you require a different call,
70
+ you may define new GraphQL queries, mutations or fragments. Thereafter, you can construct
71
+ your own class that uses these templates and inherits from `SlsAdf::Base`.
72
+
73
+ ## Development
74
+
75
+ Key Commands:
76
+ - `bin/setup`: Install dependencies and copy `.env` file.
77
+ - `bin/console`: Run an interactive prompt (requires configuration on .`env` file)
78
+ - `rake spec` or `bundle exec rspec`: Run tests.
79
+
80
+ ## Contributing
81
+
82
+ Bug reports and pull requests are welcome on [GitHub](https://github.com/moexmen/sls_adf).
83
+
84
+ ## License
85
+
86
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
7
+
8
+ require 'rdoc/task'
9
+ desc 'Generate documentation for the SLS ADF gem.'
10
+ Rake::RDocTask.new(:rdoc) do |rdoc|
11
+ rdoc.rdoc_dir = 'rdoc'
12
+ rdoc.title = 'SLS ADF'
13
+ rdoc.options << '--line-numbers' << '--inline-source'
14
+ rdoc.rdoc_files.include('README.md', 'LICENSE')
15
+ rdoc.rdoc_files.include('lib/**/*.rb')
16
+ end
data/bin/console ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+ require 'bundler/setup'
3
+
4
+ # Load environment variables for configuration
5
+ require 'dotenv'
6
+ Dotenv.load
7
+
8
+ # Configure Gem
9
+ require 'sls_adf'
10
+ SlsAdf.configure do |config|
11
+ config.graphql_url = ENV['GRAPHQL_URL']
12
+ config.get_token_url = ENV['GET_TOKEN_URL']
13
+ config.client_id = ENV['CLIENT_ID']
14
+ config.client_secret = ENV['CLIENT_SECRET']
15
+ end
16
+
17
+ # (If you use this, don't forget to add pry to your Gemfile!)
18
+ # require 'pry'
19
+ # Pry.start
20
+
21
+ require 'irb'
22
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
9
+ cp .env.example .env
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SlsAdf
4
+ # Base class used to build custom classes to make ADF API calls.
5
+ class Base
6
+ class << self
7
+ protected
8
+
9
+ # Helper method used to execute queries.
10
+ #
11
+ # @param [GraphQL::Client::Definition] template The template to be used.
12
+ # @param [Hash] vars Variables to be passed into the query.
13
+ def execute_query(template, vars = {})
14
+ SlsAdf.client.query(template, variables: vars)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Provides configuration for the sls_adf gem.
4
+ module SlsAdf
5
+ class << self
6
+ attr_accessor :configuration
7
+ end
8
+
9
+ # Helper function to configure the sls_adf gem.
10
+ #
11
+ # @yield [configuration] Block to modify the configuration
12
+ # @yieldparam [SlsAdf::Configuration] The configuration object to be modified
13
+ def self.configure
14
+ self.configuration ||= Configuration.new
15
+ yield(configuration)
16
+ end
17
+
18
+ # Class to store sls_adf configuration.
19
+ class Configuration
20
+ attr_accessor :graphql_url, :get_token_url, :client_id, :client_secret
21
+
22
+ def initialize; end
23
+ end
24
+ end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sls_adf/template/mutation'
4
+
5
+ module SlsAdf
6
+ # Make GraphQL mutation calls to SLS ADF through Ruby methods.
7
+ #
8
+ # Sample Usage:
9
+ # response = SlsAdf::Mutation.delete_assignment('Assignment-1234')
10
+ class Mutation < Base
11
+ class << self
12
+ # Makes a call to create assignment. assignment_input has the following shape:
13
+ #
14
+ # {
15
+ # title: 'Test',
16
+ # start: '2017-11-30T10:15:30+01:00', #ISO8601 format
17
+ # end: '2017-12-30T12:15:30Z', #ISO8601 format
18
+ # createdBy: 'MOE-1234',
19
+ # type: 'QUIZ',
20
+ # subjectGroupUuid: 'subject-group-uuid',
21
+ # assignees: ['MOE-1235', 'MOE-1236', ...]
22
+ # }
23
+ #
24
+ # @param[Hash] assignment_input
25
+ # @return [GraphQL::Client::Response] The response object
26
+ def create_assignment(assignment_input)
27
+ execute_query(SlsAdf::Template::Mutation::Assignment::Create,
28
+ assignment_input: assignment_input)
29
+ end
30
+
31
+ # Makes a call to update assignment. See #create_assignment for assignment_input shape.
32
+ # If field is null, field will not be updated.
33
+ #
34
+ # @param[Hash] uuid UUID of the subject_group to be modified
35
+ # @param[Hash] assignment_input
36
+ # @return [GraphQL::Client::Response] The response object
37
+ def update_assignment(uuid, assignment_input)
38
+ execute_query(SlsAdf::Template::Mutation::Assignment::Update,
39
+ uuid: uuid, assignment_input: assignment_input)
40
+ end
41
+
42
+ # Makes a call to delete the assignment with the given UUID
43
+ #
44
+ # @param[Hash] uuid UUID of the subject_group to be modified
45
+ # @return [GraphQL::Client::Response] The response object
46
+ def delete_assignment(uuid)
47
+ execute_query(SlsAdf::Template::Mutation::Assignment::Delete, uuid: uuid)
48
+ end
49
+
50
+ # Makes a call to update the task. Task status is one of the following:
51
+ # 'NEW', 'IN_PROGRESS', 'COMPLETED'
52
+ #
53
+ # @param[String] uuid UUID of task to be updated
54
+ # @param[String] status Status of the task to be updated
55
+ # @return [GraphQL::Client::Response] The response object
56
+ def update_task(uuid, status)
57
+ execute_query(SlsAdf::Template::Mutation::Task::Update,
58
+ uuid: uuid, task_status: status)
59
+ end
60
+
61
+ # Makes a call to create a notification. notification_input has the following shape:
62
+ #
63
+ # {
64
+ # message: 'Assignment 1 has started!',
65
+ # scope: 'SUBJECT_GROUP', #
66
+ # scopeId: '', #
67
+ # eventType: '', #
68
+ # eventTypeId: '' # UUID,
69
+ # receipient: ['', '', ...] # User ID.
70
+ # }
71
+ #
72
+ # @param[Hash] notification_input
73
+ # @return [GraphQL::Client::Response] The response object
74
+ def create_notification(notification_input)
75
+ execute_query(SlsAdf::Template::Mutation::Notification::Add,
76
+ notification_input: notification_input)
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sls_adf/template/query'
4
+
5
+ module SlsAdf
6
+ # Make GraphQL query calls to SLS ADF through Ruby methods.
7
+ #
8
+ # Sample Usage:
9
+ # response = SlsAdf::Query.user('User-1234')
10
+ class Query < Base
11
+ class << self
12
+ # Query the information of the context token provided.
13
+ #
14
+ # @param [String] uuid Context token provided through loading of the application.
15
+ # @return [GraphQL::Client::Response] Response of GraphQL call.
16
+ def context(uuid)
17
+ execute_query(SlsAdf::Template::Query::Context, uuid: uuid)
18
+ end
19
+
20
+ # Query the information of the user with the given ID.
21
+ #
22
+ # @param [String] id ID of the given user.
23
+ # @return [GraphQL::Client::Response] Response of GraphQL call.
24
+ def user(id)
25
+ execute_query(SlsAdf::Template::Query::User, id: id, first: 10)
26
+ end
27
+
28
+ # Query the information of the subject group with the given UUID.
29
+ #
30
+ # @param [String] uuid UUID of the subject group.
31
+ # @return [GraphQL::Client::Response] Response of GraphQL call.
32
+ def subject_group(uuid)
33
+ execute_query(SlsAdf::Template::Query::SubjectGroup,
34
+ uuid: uuid, first_student: 45, first_teacher: 30)
35
+ end
36
+
37
+ # Query the information of the assignment with the given UUID.
38
+ #
39
+ # @param [String] uuid UUID of the assignment.
40
+ # @return [GraphQL::Client::Response] Response of GraphQL call.
41
+ def assignment(uuid)
42
+ execute_query(SlsAdf::Template::Query::Assignment, uuid: uuid)
43
+ end
44
+
45
+ # Query the information of the task with the given UUID.
46
+ #
47
+ # @param [String] uuid UUID of the task.
48
+ # @return [GraphQL::Client::Response] Response of GraphQL call.
49
+ def task(uuid)
50
+ execute_query(SlsAdf::Template::Query::Task, uuid: uuid)
51
+ end
52
+ end
53
+ end
54
+ end