moodle_rb 1.0.2 → 1.1.3
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 +7 -0
- data/.github/workflows/build.yml +36 -0
- data/.github/workflows/publish.yml +27 -0
- data/Dockerfile +10 -0
- data/README.md +73 -1
- data/docker-compose.yml +6 -0
- data/lib/moodle_rb/categories.rb +12 -11
- data/lib/moodle_rb/client.rb +10 -8
- data/lib/moodle_rb/courses.rb +59 -13
- data/lib/moodle_rb/enrolments.rb +34 -9
- data/lib/moodle_rb/grades.rb +9 -14
- data/lib/moodle_rb/users.rb +35 -19
- data/lib/moodle_rb/utility.rb +7 -0
- data/lib/moodle_rb/version.rb +1 -1
- data/lib/moodle_rb.rb +2 -2
- data/moodle_rb.gemspec +2 -3
- data/spec/cassettes/MoodleRb_Categories/_create/.yml +19 -19
- data/spec/cassettes/MoodleRb_Categories/_create/when_validation_fails/.yml +19 -19
- data/spec/cassettes/MoodleRb_Categories/_destroy/when_using_invalid_token/.yml +39 -0
- data/spec/cassettes/MoodleRb_Categories/_destroy/when_using_valid_token/.yml +76 -0
- data/spec/cassettes/MoodleRb_Categories/_index/.yml +19 -19
- data/spec/cassettes/MoodleRb_Categories/_index/when_using_invalid_token/.yml +39 -0
- data/spec/cassettes/MoodleRb_Categories/_show/when_using_invalid_token/.yml +39 -0
- data/spec/cassettes/MoodleRb_Client/_site_info/when_invalid_token/.yml +20 -20
- data/spec/cassettes/MoodleRb_Client/_site_info/when_valid_token/.yml +19 -19
- data/spec/cassettes/MoodleRb_Courses/_contents/when_using_invalid_token/.yml +52 -0
- data/spec/cassettes/MoodleRb_Courses/_contents/when_using_valid_token/.yml +52 -0
- data/spec/cassettes/MoodleRb_Courses/_create/.yml +19 -19
- data/spec/cassettes/MoodleRb_Courses/_create/when_validation_fails/.yml +36 -36
- data/spec/cassettes/MoodleRb_Courses/_destroy/when_using_invalid_token/.yml +39 -0
- data/spec/cassettes/MoodleRb_Courses/_destroy/when_using_valid_token/.yml +75 -0
- data/spec/cassettes/MoodleRb_Courses/_destroy/when_using_valid_token/when_using_invalid_course_id/.yml +39 -0
- data/spec/cassettes/MoodleRb_Courses/_enrolled_users/when_using_invalid_token/.yml +39 -0
- data/spec/cassettes/MoodleRb_Courses/_enrolled_users/when_using_valid_token/.yml +75 -0
- data/spec/cassettes/MoodleRb_Courses/_grade_items/when_using_invalid_token/.yml +52 -0
- data/spec/cassettes/MoodleRb_Courses/_grade_items/when_using_valid_token/.yml +56 -0
- data/spec/cassettes/MoodleRb_Courses/_index/.yml +19 -19
- data/spec/cassettes/MoodleRb_Courses/_index/when_using_invalid_token/.yml +39 -0
- data/spec/cassettes/MoodleRb_Courses/_module/when_using_invalid_token/.yml +52 -0
- data/spec/cassettes/MoodleRb_Courses/_module/when_using_valid_token/.yml +51 -0
- data/spec/cassettes/MoodleRb_Courses/_show/.yml +19 -19
- data/spec/cassettes/MoodleRb_Courses/_show/when_using_invalid_token/.yml +39 -0
- data/spec/cassettes/MoodleRb_Enrolments/_create/.yml +19 -19
- data/spec/cassettes/MoodleRb_Enrolments/_create/when_user_or_course_id_is_invalid/.yml +19 -19
- data/spec/cassettes/MoodleRb_Enrolments/_destroy/.yml +51 -0
- data/spec/cassettes/MoodleRb_Enrolments/_destroy/when_user_or_course_id_is_invalid/.yml +52 -0
- data/spec/cassettes/MoodleRb_Grades/_by_assignment/.yml +19 -19
- data/spec/cassettes/MoodleRb_Grades/_by_course/.yml +19 -19
- data/spec/cassettes/MoodleRb_Grades/_by_course/when_invalid_parameters/.yml +19 -19
- data/spec/cassettes/MoodleRb_Users/_create/.yml +19 -19
- data/spec/cassettes/MoodleRb_Users/_create/when_missing_required_parameters/.yml +19 -19
- data/spec/cassettes/MoodleRb_Users/_destroy/.yml +19 -19
- data/spec/cassettes/MoodleRb_Users/_destroy/when_id_does_not_exist/.yml +19 -19
- data/spec/cassettes/MoodleRb_Users/_destroy/when_using_invalid_token/.yml +39 -0
- data/spec/cassettes/MoodleRb_Users/_enrolled_courses/.yml +19 -19
- data/spec/cassettes/MoodleRb_Users/_enrolled_courses/when_using_invalid_token/.yml +39 -0
- data/spec/cassettes/MoodleRb_Users/_search/.yml +21 -21
- data/spec/cassettes/MoodleRb_Users/_search/when_using_invalid_token/.yml +39 -0
- data/spec/cassettes/MoodleRb_Users/_search_identity/.yml +51 -0
- data/spec/cassettes/MoodleRb_Users/_search_identity/when_using_invalid_token/.yml +52 -0
- data/spec/cassettes/MoodleRb_Users/_show/.yml +19 -19
- data/spec/cassettes/MoodleRb_Users/_show/when_using_invalid_token/.yml +39 -0
- data/spec/cassettes/MoodleRb_Users/_update/.yml +20 -20
- data/spec/cassettes/MoodleRb_Users/_update/when_using_invalid_token/.yml +39 -0
- data/spec/lib/moodle_rb/categories_spec.rb +42 -10
- data/spec/lib/moodle_rb/client_spec.rb +7 -5
- data/spec/lib/moodle_rb/courses_spec.rb +155 -20
- data/spec/lib/moodle_rb/enrolments_spec.rb +36 -3
- data/spec/lib/moodle_rb/grades_spec.rb +4 -4
- data/spec/lib/moodle_rb/users_spec.rb +93 -9
- data/spec/lib/moodle_rb_spec.rb +2 -2
- metadata +150 -142
- data/spec/cassettes/MoodleRb_Categories/_destroy/.yml +0 -75
- data/spec/cassettes/MoodleRb_Courses/_destroy/.yml +0 -75
- data/spec/cassettes/MoodleRb_Courses/_enrolled_users/.yml +0 -75
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3fdbc847a70cefe6a1641ceebba2f874b8ab8d1459aa475c23d8f1ae70ef4c11
|
4
|
+
data.tar.gz: 7e4034e714f6ca67e92a928bc9ae323e22b48042d4ebbfbab0bf401ec4a54cec
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1e7300716079888fed475a6dea164997ceb375fec6b870370064d88ac8a3a9821a63a63e73579bdf621b63563bfb95e3c33c2be309ecdc6863eda0e7fbf89e5b
|
7
|
+
data.tar.gz: f2613f30e5676831a666a76f8e54cde9e5a2c4b939ab00972833a0c200d86ddd502c50c200fc982ab0c9373b296e47f62b98ddfc525b0ca7dd2cd8df2b275a12
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Build
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ develop ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ develop ]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
|
19
|
+
runs-on: ubuntu-latest
|
20
|
+
strategy:
|
21
|
+
matrix:
|
22
|
+
ruby-version: ['2.3']
|
23
|
+
|
24
|
+
steps:
|
25
|
+
- uses: actions/checkout@v2
|
26
|
+
- name: Set up Ruby
|
27
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
28
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
29
|
+
# uses: ruby/setup-ruby@v1
|
30
|
+
uses: ruby/setup-ruby@v1
|
31
|
+
with:
|
32
|
+
ruby-version: ${{ matrix.ruby-version }}
|
33
|
+
bundler: 1.17.3
|
34
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
35
|
+
- name: Run tests
|
36
|
+
run: bundle exec rspec spec
|
@@ -0,0 +1,27 @@
|
|
1
|
+
name: Publish
|
2
|
+
|
3
|
+
on:
|
4
|
+
release:
|
5
|
+
types: [published]
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
build:
|
9
|
+
name: Build + Publish
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
permissions:
|
12
|
+
contents: read
|
13
|
+
packages: write
|
14
|
+
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v2
|
17
|
+
- name: Set up Ruby 2.7
|
18
|
+
uses: ruby/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
ruby-version: '2.7'
|
21
|
+
|
22
|
+
- name: Publish to RubyGems
|
23
|
+
run: |
|
24
|
+
gem build *.gemspec
|
25
|
+
gem push *.gem
|
26
|
+
env:
|
27
|
+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
data/Dockerfile
ADDED
data/README.md
CHANGED
@@ -1,4 +1,9 @@
|
|
1
1
|
# MoodleRb
|
2
|
+
|
3
|
+
[](https://github.com/jobready/moodle-rb/actions/workflows/build.yml)
|
4
|
+
|
5
|
+
[](https://badge.fury.io/rb/moodle_rb)
|
6
|
+
|
2
7
|
A Ruby Client for the Moodle REST API.
|
3
8
|
|
4
9
|
https://docs.moodle.org/dev/Web_services#Developer_documentation
|
@@ -42,6 +47,21 @@ Delete a course
|
|
42
47
|
moodle.courses.destroy(course_id)
|
43
48
|
```
|
44
49
|
|
50
|
+
Get course grades
|
51
|
+
```
|
52
|
+
moodle.courses.grade_items(course_id)
|
53
|
+
```
|
54
|
+
|
55
|
+
Get course contents
|
56
|
+
```
|
57
|
+
moodle.courses.contents(course_id)
|
58
|
+
```
|
59
|
+
|
60
|
+
Get course module
|
61
|
+
```
|
62
|
+
moodle.courses.module(course_module_id)
|
63
|
+
```
|
64
|
+
|
45
65
|
### Categories
|
46
66
|
|
47
67
|
Create a category
|
@@ -68,7 +88,7 @@ moodle.categories.destroy(category_id)
|
|
68
88
|
|
69
89
|
### Enrolments
|
70
90
|
|
71
|
-
Create
|
91
|
+
Create a student enrolment
|
72
92
|
```
|
73
93
|
moodle.enrolments.create(
|
74
94
|
:user_id => user_id,
|
@@ -76,6 +96,23 @@ moodle.enrolments.create(
|
|
76
96
|
)
|
77
97
|
```
|
78
98
|
|
99
|
+
Create a teacher enrolment
|
100
|
+
```
|
101
|
+
moodle.enrolments.create(
|
102
|
+
:user_id => user_id,
|
103
|
+
:course_id => course_id,
|
104
|
+
:role_id => 3
|
105
|
+
)
|
106
|
+
```
|
107
|
+
|
108
|
+
Delete an enrolment
|
109
|
+
```
|
110
|
+
moodle.enrolments.destroy(
|
111
|
+
:user_id => user_id,
|
112
|
+
:course_id => course_id
|
113
|
+
)
|
114
|
+
```
|
115
|
+
|
79
116
|
View enrolled users by course
|
80
117
|
```
|
81
118
|
moodle.courses.enrolled_users(course_id)
|
@@ -114,16 +151,51 @@ Search for a user
|
|
114
151
|
moodle.users.search(:email => 'admin@localhost')
|
115
152
|
```
|
116
153
|
|
154
|
+
Search for a user via identity
|
155
|
+
```
|
156
|
+
moodle.users.search_identity('admin@localhost')
|
157
|
+
```
|
158
|
+
|
117
159
|
Update a user
|
118
160
|
```
|
119
161
|
moodle.users.update(:id => 4, :email => 'bwayne@wayneenterprises.com')
|
120
162
|
```
|
121
163
|
|
164
|
+
## Development
|
165
|
+
|
166
|
+
To start development, spin up a container
|
167
|
+
|
168
|
+
```
|
169
|
+
docker build -t moodle .
|
170
|
+
```
|
171
|
+
|
172
|
+
To run the test suite with docker
|
173
|
+
|
174
|
+
|
175
|
+
```
|
176
|
+
docker run -v "$(pwd):/app" --rm moodle rspec spec
|
177
|
+
```
|
178
|
+
|
179
|
+
Docker compose
|
180
|
+
|
181
|
+
```
|
182
|
+
docker-compose build
|
183
|
+
docker-compose run app bundle exec rspec spec
|
184
|
+
```
|
185
|
+
|
122
186
|
## Tests
|
123
187
|
|
188
|
+
Tests must be written for new lines of code added as part of a pull request and the test suite must pass. If creating new cassettes, consider updating the hardcoded moodle token and url parameters throughout the suite. They can also be configured with environment variables.
|
189
|
+
|
124
190
|
You will need to set some environment variables to create new cassettes. We build using MAMP https://www.mamp.info/en/ so it might be
|
125
191
|
|
126
192
|
```
|
127
193
|
export MOODLE_URL=http://localhost:8888/moodle29/
|
128
194
|
export MOODLE_TOKEN=87b95af2df709fa60b395b5c59a3fc2e
|
129
195
|
```
|
196
|
+
|
197
|
+
## Deployment
|
198
|
+
|
199
|
+
The gem is automatically published when a new release is created on github. If there is an issue or a new release is required, please contact one of the maintainers
|
200
|
+
|
201
|
+
- Jordan Huizenga (jordan.huizenga@readytech.io)
|
data/docker-compose.yml
ADDED
data/lib/moodle_rb/categories.rb
CHANGED
@@ -3,11 +3,12 @@ module MoodleRb
|
|
3
3
|
include HTTParty
|
4
4
|
include Utility
|
5
5
|
|
6
|
-
attr_reader :token
|
6
|
+
attr_reader :token, :query_options
|
7
7
|
ROOT_CATEGORY = 0
|
8
8
|
|
9
|
-
def initialize(token, url)
|
9
|
+
def initialize(token, url, query_options)
|
10
10
|
@token = token
|
11
|
+
@query_options = query_options
|
11
12
|
self.class.base_uri url
|
12
13
|
end
|
13
14
|
|
@@ -16,8 +17,9 @@ module MoodleRb
|
|
16
17
|
'/webservice/rest/server.php',
|
17
18
|
{
|
18
19
|
:query => query_hash('core_course_get_categories', token)
|
19
|
-
}
|
20
|
+
}.merge(query_options)
|
20
21
|
)
|
22
|
+
check_for_errors(response)
|
21
23
|
response.parsed_response
|
22
24
|
end
|
23
25
|
|
@@ -46,13 +48,10 @@ module MoodleRb
|
|
46
48
|
}
|
47
49
|
}
|
48
50
|
}
|
49
|
-
}
|
51
|
+
}.merge(query_options)
|
50
52
|
)
|
51
|
-
|
52
|
-
|
53
|
-
else
|
54
|
-
response.parsed_response.first
|
55
|
-
end
|
53
|
+
check_for_errors(response)
|
54
|
+
response.parsed_response.first
|
56
55
|
end
|
57
56
|
|
58
57
|
def show(id)
|
@@ -68,8 +67,9 @@ module MoodleRb
|
|
68
67
|
}
|
69
68
|
}
|
70
69
|
}
|
71
|
-
}
|
70
|
+
}.merge(query_options)
|
72
71
|
)
|
72
|
+
check_for_errors(response)
|
73
73
|
response.parsed_response.first
|
74
74
|
end
|
75
75
|
|
@@ -86,8 +86,9 @@ module MoodleRb
|
|
86
86
|
}
|
87
87
|
}
|
88
88
|
}
|
89
|
-
}
|
89
|
+
}.merge(query_options)
|
90
90
|
)
|
91
|
+
check_for_errors(response)
|
91
92
|
response.parsed_response.nil?
|
92
93
|
end
|
93
94
|
end
|
data/lib/moodle_rb/client.rb
CHANGED
@@ -3,11 +3,12 @@ module MoodleRb
|
|
3
3
|
include HTTParty
|
4
4
|
include Utility
|
5
5
|
|
6
|
-
attr_reader :token, :url
|
6
|
+
attr_reader :token, :url, :query_options
|
7
7
|
|
8
|
-
def initialize(token, url)
|
8
|
+
def initialize(token, url, query_options)
|
9
9
|
@token = token
|
10
10
|
@url = url
|
11
|
+
@query_options = query_options
|
11
12
|
self.class.base_uri url
|
12
13
|
end
|
13
14
|
|
@@ -16,29 +17,30 @@ module MoodleRb
|
|
16
17
|
'/webservice/rest/server.php',
|
17
18
|
{
|
18
19
|
:query => query_hash('core_webservice_get_site_info', token)
|
19
|
-
}
|
20
|
+
}.merge(query_options)
|
20
21
|
)
|
22
|
+
check_for_errors(response)
|
21
23
|
response.parsed_response
|
22
24
|
end
|
23
25
|
|
24
26
|
def courses
|
25
|
-
MoodleRb::Courses.new(token, url)
|
27
|
+
MoodleRb::Courses.new(token, url, query_options)
|
26
28
|
end
|
27
29
|
|
28
30
|
def categories
|
29
|
-
MoodleRb::Categories.new(token, url)
|
31
|
+
MoodleRb::Categories.new(token, url, query_options)
|
30
32
|
end
|
31
33
|
|
32
34
|
def users
|
33
|
-
MoodleRb::Users.new(token, url)
|
35
|
+
MoodleRb::Users.new(token, url, query_options)
|
34
36
|
end
|
35
37
|
|
36
38
|
def enrolments
|
37
|
-
MoodleRb::Enrolments.new(token, url)
|
39
|
+
MoodleRb::Enrolments.new(token, url, query_options)
|
38
40
|
end
|
39
41
|
|
40
42
|
def grades
|
41
|
-
MoodleRb::Grades.new(token, url)
|
43
|
+
MoodleRb::Grades.new(token, url, query_options)
|
42
44
|
end
|
43
45
|
end
|
44
46
|
end
|
data/lib/moodle_rb/courses.rb
CHANGED
@@ -3,10 +3,11 @@ module MoodleRb
|
|
3
3
|
include HTTParty
|
4
4
|
include Utility
|
5
5
|
|
6
|
-
attr_reader :token
|
6
|
+
attr_reader :token, :query_options
|
7
7
|
|
8
|
-
def initialize(token, url)
|
8
|
+
def initialize(token, url, query_options)
|
9
9
|
@token = token
|
10
|
+
@query_options = query_options
|
10
11
|
self.class.base_uri url
|
11
12
|
end
|
12
13
|
|
@@ -15,8 +16,9 @@ module MoodleRb
|
|
15
16
|
'/webservice/rest/server.php',
|
16
17
|
{
|
17
18
|
:query => query_hash('core_course_get_courses', token)
|
18
|
-
}
|
19
|
+
}.merge(query_options)
|
19
20
|
)
|
21
|
+
check_for_errors(response)
|
20
22
|
response.parsed_response
|
21
23
|
end
|
22
24
|
|
@@ -44,13 +46,10 @@ module MoodleRb
|
|
44
46
|
}
|
45
47
|
}
|
46
48
|
}
|
47
|
-
}
|
49
|
+
}.merge(query_options)
|
48
50
|
)
|
49
|
-
|
50
|
-
|
51
|
-
else
|
52
|
-
response.parsed_response.first
|
53
|
-
end
|
51
|
+
check_for_errors(response)
|
52
|
+
response.parsed_response.first
|
54
53
|
end
|
55
54
|
|
56
55
|
def show(id)
|
@@ -65,8 +64,9 @@ module MoodleRb
|
|
65
64
|
}
|
66
65
|
}
|
67
66
|
}
|
68
|
-
}
|
67
|
+
}.merge(query_options)
|
69
68
|
)
|
69
|
+
check_for_errors(response)
|
70
70
|
response.parsed_response.first
|
71
71
|
end
|
72
72
|
|
@@ -80,9 +80,10 @@ module MoodleRb
|
|
80
80
|
'0' => id
|
81
81
|
}
|
82
82
|
}
|
83
|
-
}
|
83
|
+
}.merge(query_options)
|
84
84
|
)
|
85
|
-
response
|
85
|
+
check_for_errors(response)
|
86
|
+
response.parsed_response
|
86
87
|
end
|
87
88
|
|
88
89
|
def enrolled_users(course_id)
|
@@ -93,9 +94,54 @@ module MoodleRb
|
|
93
94
|
:body => {
|
94
95
|
:courseid => course_id
|
95
96
|
}
|
96
|
-
}
|
97
|
+
}.merge(query_options)
|
97
98
|
)
|
99
|
+
check_for_errors(response)
|
98
100
|
response.parsed_response
|
99
101
|
end
|
102
|
+
|
103
|
+
def grade_items(course_id, user_id=0, group_id=0)
|
104
|
+
response = self.class.post(
|
105
|
+
'/webservice/rest/server.php',
|
106
|
+
{
|
107
|
+
:query => query_hash('gradereport_user_get_grade_items', token),
|
108
|
+
:body => {
|
109
|
+
:courseid => course_id,
|
110
|
+
:userid => user_id,
|
111
|
+
:groupid => group_id
|
112
|
+
}
|
113
|
+
}.merge(query_options)
|
114
|
+
)
|
115
|
+
check_for_errors(response)
|
116
|
+
response.parsed_response['usergrades']
|
117
|
+
end
|
118
|
+
|
119
|
+
def contents(course_id)
|
120
|
+
response = self.class.post(
|
121
|
+
'/webservice/rest/server.php',
|
122
|
+
{
|
123
|
+
:query => query_hash('core_course_get_contents', token),
|
124
|
+
:body => {
|
125
|
+
:courseid => course_id
|
126
|
+
}
|
127
|
+
}.merge(query_options)
|
128
|
+
)
|
129
|
+
check_for_errors(response)
|
130
|
+
response.parsed_response[0]
|
131
|
+
end
|
132
|
+
|
133
|
+
def module(course_module_id)
|
134
|
+
response = self.class.post(
|
135
|
+
'/webservice/rest/server.php',
|
136
|
+
{
|
137
|
+
:query => query_hash('core_course_get_course_module', token),
|
138
|
+
:body => {
|
139
|
+
:cmid => course_module_id
|
140
|
+
}
|
141
|
+
}.merge(query_options)
|
142
|
+
)
|
143
|
+
check_for_errors(response)
|
144
|
+
response.parsed_response['cm']
|
145
|
+
end
|
100
146
|
end
|
101
147
|
end
|
data/lib/moodle_rb/enrolments.rb
CHANGED
@@ -3,16 +3,20 @@ module MoodleRb
|
|
3
3
|
include HTTParty
|
4
4
|
include Utility
|
5
5
|
|
6
|
-
attr_reader :token
|
6
|
+
attr_reader :token, :query_options
|
7
7
|
STUDENT_ROLE_ID = 5
|
8
|
+
TEACHER_ROLE_ID = 3
|
8
9
|
|
9
|
-
def initialize(token, url)
|
10
|
+
def initialize(token, url, query_options)
|
10
11
|
@token = token
|
12
|
+
@query_options = query_options
|
11
13
|
self.class.base_uri url
|
12
14
|
end
|
13
15
|
|
14
16
|
# required params:
|
15
17
|
# user_id course_id
|
18
|
+
# optional params:
|
19
|
+
# role_id - defaults to student role id
|
16
20
|
def create(params)
|
17
21
|
response = self.class.post(
|
18
22
|
'/webservice/rest/server.php',
|
@@ -23,17 +27,38 @@ module MoodleRb
|
|
23
27
|
'0' => {
|
24
28
|
:userid => params[:user_id],
|
25
29
|
:courseid => params[:course_id],
|
26
|
-
:roleid => STUDENT_ROLE_ID
|
30
|
+
:roleid => params[:role_id] || STUDENT_ROLE_ID
|
27
31
|
}
|
28
32
|
}
|
29
33
|
}
|
30
|
-
}
|
34
|
+
}.merge(query_options)
|
31
35
|
)
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
36
|
+
check_for_errors(response)
|
37
|
+
response.code == 200 && response.parsed_response.nil?
|
38
|
+
end
|
39
|
+
|
40
|
+
# required params:
|
41
|
+
# user_id course_id
|
42
|
+
# optional params:
|
43
|
+
# role_id - defaults to student role id
|
44
|
+
def destroy(params)
|
45
|
+
response = self.class.post(
|
46
|
+
'/webservice/rest/server.php',
|
47
|
+
{
|
48
|
+
:query => query_hash('enrol_manual_unenrol_users', token),
|
49
|
+
:body => {
|
50
|
+
:enrolments => {
|
51
|
+
'0' => {
|
52
|
+
:userid => params[:user_id],
|
53
|
+
:courseid => params[:course_id],
|
54
|
+
:roleid => params[:role_id] || STUDENT_ROLE_ID
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}
|
58
|
+
}.merge(query_options)
|
59
|
+
)
|
60
|
+
check_for_errors(response)
|
61
|
+
response.code == 200 && response.parsed_response.nil?
|
37
62
|
end
|
38
63
|
end
|
39
64
|
end
|
data/lib/moodle_rb/grades.rb
CHANGED
@@ -3,10 +3,11 @@ module MoodleRb
|
|
3
3
|
include HTTParty
|
4
4
|
include Utility
|
5
5
|
|
6
|
-
attr_reader :token
|
6
|
+
attr_reader :token, :query_options
|
7
7
|
|
8
|
-
def initialize(token, url)
|
8
|
+
def initialize(token, url, query_options)
|
9
9
|
@token = token
|
10
|
+
@query_options = query_options
|
10
11
|
self.class.base_uri url
|
11
12
|
end
|
12
13
|
|
@@ -18,13 +19,10 @@ module MoodleRb
|
|
18
19
|
:body => {
|
19
20
|
:assignmentids => api_array(assignment_id)
|
20
21
|
}
|
21
|
-
}
|
22
|
+
}.merge(query_options)
|
22
23
|
)
|
23
|
-
|
24
|
-
|
25
|
-
else
|
26
|
-
response.parsed_response['assignments']
|
27
|
-
end
|
24
|
+
check_for_errors(response)
|
25
|
+
response.parsed_response['assignments']
|
28
26
|
end
|
29
27
|
|
30
28
|
def by_course(course_id, *user_ids)
|
@@ -36,13 +34,10 @@ module MoodleRb
|
|
36
34
|
:courseid => course_id,
|
37
35
|
:userids => api_array(user_ids)
|
38
36
|
}
|
39
|
-
}
|
37
|
+
}.merge(query_options)
|
40
38
|
)
|
41
|
-
|
42
|
-
|
43
|
-
else
|
44
|
-
response.parsed_response['items']
|
45
|
-
end
|
39
|
+
check_for_errors(response)
|
40
|
+
response.parsed_response['items']
|
46
41
|
end
|
47
42
|
end
|
48
43
|
end
|
data/lib/moodle_rb/users.rb
CHANGED
@@ -3,10 +3,11 @@ module MoodleRb
|
|
3
3
|
include HTTParty
|
4
4
|
include Utility
|
5
5
|
|
6
|
-
attr_reader :token
|
6
|
+
attr_reader :token, :query_options
|
7
7
|
|
8
|
-
def initialize(token, url)
|
8
|
+
def initialize(token, url, query_options)
|
9
9
|
@token = token
|
10
|
+
@query_options = query_options
|
10
11
|
self.class.base_uri url
|
11
12
|
end
|
12
13
|
|
@@ -25,13 +26,10 @@ module MoodleRb
|
|
25
26
|
'0' => params
|
26
27
|
}
|
27
28
|
}
|
28
|
-
}
|
29
|
+
}.merge(query_options)
|
29
30
|
)
|
30
|
-
|
31
|
-
|
32
|
-
else
|
33
|
-
response.parsed_response.first
|
34
|
-
end
|
31
|
+
check_for_errors(response)
|
32
|
+
response.parsed_response.first
|
35
33
|
end
|
36
34
|
|
37
35
|
def show(id)
|
@@ -47,9 +45,11 @@ module MoodleRb
|
|
47
45
|
}
|
48
46
|
}
|
49
47
|
}
|
50
|
-
}
|
48
|
+
}.merge(query_options)
|
51
49
|
)
|
52
|
-
response
|
50
|
+
check_for_errors(response)
|
51
|
+
response.parsed_response['users'] &&
|
52
|
+
response.parsed_response['users'].first
|
53
53
|
end
|
54
54
|
|
55
55
|
def destroy(id)
|
@@ -62,8 +62,9 @@ module MoodleRb
|
|
62
62
|
'0' => id
|
63
63
|
}
|
64
64
|
}
|
65
|
-
}
|
65
|
+
}.merge(query_options)
|
66
66
|
)
|
67
|
+
check_for_errors(response)
|
67
68
|
response.parsed_response.nil?
|
68
69
|
end
|
69
70
|
|
@@ -75,8 +76,9 @@ module MoodleRb
|
|
75
76
|
:body => {
|
76
77
|
:userid => user_id
|
77
78
|
}
|
78
|
-
}
|
79
|
+
}.merge(query_options)
|
79
80
|
)
|
81
|
+
check_for_errors(response)
|
80
82
|
response.parsed_response
|
81
83
|
end
|
82
84
|
|
@@ -90,11 +92,28 @@ module MoodleRb
|
|
90
92
|
:body => {
|
91
93
|
:criteria => key_value_query_format(params)
|
92
94
|
}
|
93
|
-
}
|
95
|
+
}.merge(query_options)
|
94
96
|
)
|
97
|
+
check_for_errors(response)
|
95
98
|
response.parsed_response['users']
|
96
99
|
end
|
97
100
|
|
101
|
+
# Return list of users identities matching the given criteria in their name or other identity fields.
|
102
|
+
# Performs a partial match on id, idnumber, fullname, and email
|
103
|
+
def search_identity(search_query)
|
104
|
+
response = self.class.post(
|
105
|
+
'/webservice/rest/server.php',
|
106
|
+
{
|
107
|
+
:query => query_hash('core_user_search_identity', token),
|
108
|
+
:body => {
|
109
|
+
:query => search_query
|
110
|
+
}
|
111
|
+
}.merge(query_options)
|
112
|
+
)
|
113
|
+
check_for_errors(response)
|
114
|
+
response.parsed_response['list']
|
115
|
+
end
|
116
|
+
|
98
117
|
# params must include the id of the user
|
99
118
|
# it may include any other standard user attributes:
|
100
119
|
# username, password, firstname, lastname, email ...
|
@@ -108,13 +127,10 @@ module MoodleRb
|
|
108
127
|
'0' => params
|
109
128
|
}
|
110
129
|
}
|
111
|
-
}
|
130
|
+
}.merge(query_options)
|
112
131
|
)
|
113
|
-
|
114
|
-
|
115
|
-
else
|
116
|
-
response.response.code == '200'
|
117
|
-
end
|
132
|
+
check_for_errors(response)
|
133
|
+
response.response.code == '200'
|
118
134
|
end
|
119
135
|
end
|
120
136
|
end
|
data/lib/moodle_rb/utility.rb
CHANGED
@@ -27,6 +27,13 @@ module MoodleRb
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
def check_for_errors(response)
|
31
|
+
return unless error_response?(response)
|
32
|
+
raise MoodleError.new(response.parsed_response)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
30
37
|
def error_response?(response)
|
31
38
|
response && response.parsed_response.is_a?(Hash) &&
|
32
39
|
response.parsed_response.has_key?('exception')
|
data/lib/moodle_rb/version.rb
CHANGED