moodle_rb 2.1.0 → 2.1.5
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 +4 -4
- data/README.md +8 -0
- data/lib/moodle_rb/courses.rb +18 -0
- data/lib/moodle_rb/version.rb +1 -1
- data/spec/cassettes/MoodleRb_Courses/_core_course_import_course/when_using_invalid_token/.yml +55 -0
- data/spec/cassettes/MoodleRb_Courses/_core_course_import_course/when_using_valid_token/.yml +54 -0
- data/spec/cassettes/MoodleRb_Courses/_core_course_import_course/when_using_valid_token/when_using_invalid_course_id/.yml +55 -0
- data/spec/lib/moodle_rb/courses_spec.rb +44 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: adea1a16244c97a8a745da9a7cffe186ed7e87f2d868376a86ac3d311797d183
|
4
|
+
data.tar.gz: f34de3627bb2146616461a200721edc75a51ab6ec37ab2c0e930d1f8924f26ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2469fd561371959c5d237c5a5cdc3ce1273587e0d9b430338812cc1bd0284497684ef801e2a3117515e82d5ef12ab6e1f3d4d8b03d698bab4b01a39167b7003
|
7
|
+
data.tar.gz: 9c352bc8f6e07efc68ed6a5c239fe4ce9220a6659f81a334153eef0af0d138eca98000457e8fe5e04719493ce967cacf47d1699e287ba2f18edd766869b25053
|
data/README.md
CHANGED
@@ -69,6 +69,14 @@ Get course module
|
|
69
69
|
moodle.courses.module(course_module_id)
|
70
70
|
```
|
71
71
|
|
72
|
+
Import course data from a course into another course
|
73
|
+
```
|
74
|
+
moodle.courses.core_course_import_course(
|
75
|
+
:from_course_id => from_course_id,
|
76
|
+
:to_course_id => to_course_id
|
77
|
+
)
|
78
|
+
```
|
79
|
+
|
72
80
|
### Categories
|
73
81
|
|
74
82
|
Create a category
|
data/lib/moodle_rb/courses.rb
CHANGED
@@ -160,5 +160,23 @@ module MoodleRb
|
|
160
160
|
check_for_errors(response)
|
161
161
|
response.parsed_response['cm']
|
162
162
|
end
|
163
|
+
|
164
|
+
# required params:
|
165
|
+
# from_course_id: the id of the course we are importing from
|
166
|
+
# to_course_id: the id of the course we are importing to
|
167
|
+
def core_course_import_course(params)
|
168
|
+
response = self.class.post(
|
169
|
+
'/webservice/rest/server.php',
|
170
|
+
{
|
171
|
+
:query => query_hash('core_course_import_course', token),
|
172
|
+
:body => {
|
173
|
+
:importfrom => params[:from_course_id],
|
174
|
+
:importto => params[:to_course_id]
|
175
|
+
}
|
176
|
+
}.merge(query_options)
|
177
|
+
)
|
178
|
+
check_for_errors(response)
|
179
|
+
response.code == 200 && response.parsed_response.nil?
|
180
|
+
end
|
163
181
|
end
|
164
182
|
end
|
data/lib/moodle_rb/version.rb
CHANGED
@@ -0,0 +1,55 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: http://localhost:8888/moodle28/webservice/rest/server.php?moodlewsrestformat=json&wsfunction=core_course_import_course&wstoken=
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: importfrom=&importto=
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Accept-Ranges:
|
22
|
+
- none
|
23
|
+
Access-Control-Allow-Origin:
|
24
|
+
- "*"
|
25
|
+
Age:
|
26
|
+
- '0'
|
27
|
+
Cache-Control:
|
28
|
+
- private, must-revalidate, pre-check=0, post-check=0, max-age=0
|
29
|
+
Content-Type:
|
30
|
+
- application/json
|
31
|
+
Date:
|
32
|
+
- Mon, 13 Feb 2023 02:46:46 GMT
|
33
|
+
Expires:
|
34
|
+
- Thu, 01 Jan 1970 00:00:00 GMT
|
35
|
+
Pragma:
|
36
|
+
- no-cache
|
37
|
+
Server:
|
38
|
+
- Moodle
|
39
|
+
X-Cache:
|
40
|
+
- MISS
|
41
|
+
X-Clacks-Overhead:
|
42
|
+
- GNU Terry Pratchett
|
43
|
+
X-Powered-By:
|
44
|
+
- Moodle Ninjas
|
45
|
+
Content-Length:
|
46
|
+
- '103'
|
47
|
+
Connection:
|
48
|
+
- keep-alive
|
49
|
+
body:
|
50
|
+
encoding: UTF-8
|
51
|
+
string: '{"exception":"moodle_exception","errorcode":"invalidtoken","message":"Invalid
|
52
|
+
token - token not found"}'
|
53
|
+
http_version:
|
54
|
+
recorded_at: Mon, 13 Feb 2023 02:46:46 GMT
|
55
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,54 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: http://localhost:8888/moodle28/webservice/rest/server.php?moodlewsrestformat=json&wsfunction=core_course_import_course&wstoken=60fc9c9415259404795094957e4ab32f
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: importfrom=467&importto=468
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Accept-Ranges:
|
22
|
+
- none
|
23
|
+
Access-Control-Allow-Origin:
|
24
|
+
- "*"
|
25
|
+
Age:
|
26
|
+
- '0'
|
27
|
+
Cache-Control:
|
28
|
+
- private, must-revalidate, pre-check=0, post-check=0, max-age=0
|
29
|
+
Content-Type:
|
30
|
+
- application/json
|
31
|
+
Date:
|
32
|
+
- Mon, 13 Feb 2023 02:46:43 GMT
|
33
|
+
Expires:
|
34
|
+
- Thu, 01 Jan 1970 00:00:00 GMT
|
35
|
+
Pragma:
|
36
|
+
- no-cache
|
37
|
+
Server:
|
38
|
+
- Moodle
|
39
|
+
X-Cache:
|
40
|
+
- MISS
|
41
|
+
X-Clacks-Overhead:
|
42
|
+
- GNU Terry Pratchett
|
43
|
+
X-Powered-By:
|
44
|
+
- Moodle Ninjas
|
45
|
+
Content-Length:
|
46
|
+
- '4'
|
47
|
+
Connection:
|
48
|
+
- keep-alive
|
49
|
+
body:
|
50
|
+
encoding: UTF-8
|
51
|
+
string: 'null'
|
52
|
+
http_version:
|
53
|
+
recorded_at: Mon, 13 Feb 2023 02:46:44 GMT
|
54
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,55 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: http://localhost:8888/moodle28/webservice/rest/server.php?moodlewsrestformat=json&wsfunction=core_course_import_course&wstoken=60fc9c9415259404795094957e4ab32f
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: importfrom=467&importto=-1
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Accept-Ranges:
|
22
|
+
- none
|
23
|
+
Access-Control-Allow-Origin:
|
24
|
+
- "*"
|
25
|
+
Age:
|
26
|
+
- '0'
|
27
|
+
Cache-Control:
|
28
|
+
- private, must-revalidate, pre-check=0, post-check=0, max-age=0
|
29
|
+
Content-Type:
|
30
|
+
- application/json
|
31
|
+
Date:
|
32
|
+
- Mon, 13 Feb 2023 02:46:45 GMT
|
33
|
+
Expires:
|
34
|
+
- Thu, 01 Jan 1970 00:00:00 GMT
|
35
|
+
Pragma:
|
36
|
+
- no-cache
|
37
|
+
Server:
|
38
|
+
- Moodle
|
39
|
+
X-Cache:
|
40
|
+
- MISS
|
41
|
+
X-Clacks-Overhead:
|
42
|
+
- GNU Terry Pratchett
|
43
|
+
X-Powered-By:
|
44
|
+
- Moodle Ninjas
|
45
|
+
Content-Length:
|
46
|
+
- '117'
|
47
|
+
Connection:
|
48
|
+
- keep-alive
|
49
|
+
body:
|
50
|
+
encoding: UTF-8
|
51
|
+
string: '{"exception":"moodle_exception","errorcode":"invalidcourseid","message":"You
|
52
|
+
are trying to use an invalid course ID"}'
|
53
|
+
http_version:
|
54
|
+
recorded_at: Mon, 13 Feb 2023 02:46:45 GMT
|
55
|
+
recorded_with: VCR 2.9.3
|
@@ -247,4 +247,48 @@ describe MoodleRb::Courses do
|
|
247
247
|
end
|
248
248
|
end
|
249
249
|
end
|
250
|
+
|
251
|
+
describe '#core_course_import_course', :vcr => {
|
252
|
+
:match_requests_on => [:path], :record => :once
|
253
|
+
} do
|
254
|
+
context 'when using valid token' do
|
255
|
+
let(:params) do
|
256
|
+
{
|
257
|
+
:from_course_id => 467,
|
258
|
+
:to_course_id => 468
|
259
|
+
}
|
260
|
+
end
|
261
|
+
let(:result) { course_moodle_rb.core_course_import_course(params) }
|
262
|
+
|
263
|
+
specify do
|
264
|
+
expect(result).to eq true
|
265
|
+
end
|
266
|
+
|
267
|
+
context 'when using invalid course id' do
|
268
|
+
let(:params) do
|
269
|
+
{
|
270
|
+
:from_course_id => 467,
|
271
|
+
:to_course_id => -1
|
272
|
+
}
|
273
|
+
end
|
274
|
+
|
275
|
+
specify do
|
276
|
+
expect{ course_moodle_rb.core_course_import_course(params) }.to raise_error(
|
277
|
+
MoodleRb::MoodleError,
|
278
|
+
'You are trying to use an invalid course ID'
|
279
|
+
)
|
280
|
+
end
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
context 'when using invalid token' do
|
285
|
+
let(:token) { '' }
|
286
|
+
specify do
|
287
|
+
expect{ course_moodle_rb.core_course_import_course({}) }.to raise_error(
|
288
|
+
MoodleRb::MoodleError,
|
289
|
+
'Invalid token - token not found'
|
290
|
+
)
|
291
|
+
end
|
292
|
+
end
|
293
|
+
end
|
250
294
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: moodle_rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Giffney
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -134,6 +134,9 @@ files:
|
|
134
134
|
- spec/cassettes/MoodleRb_Client/_site_info/when_valid_token/.yml
|
135
135
|
- spec/cassettes/MoodleRb_Courses/_contents/when_using_invalid_token/.yml
|
136
136
|
- spec/cassettes/MoodleRb_Courses/_contents/when_using_valid_token/.yml
|
137
|
+
- spec/cassettes/MoodleRb_Courses/_core_course_import_course/when_using_invalid_token/.yml
|
138
|
+
- spec/cassettes/MoodleRb_Courses/_core_course_import_course/when_using_valid_token/.yml
|
139
|
+
- spec/cassettes/MoodleRb_Courses/_core_course_import_course/when_using_valid_token/when_using_invalid_course_id/.yml
|
137
140
|
- spec/cassettes/MoodleRb_Courses/_create/.yml
|
138
141
|
- spec/cassettes/MoodleRb_Courses/_create/when_validation_fails/.yml
|
139
142
|
- spec/cassettes/MoodleRb_Courses/_destroy/when_using_invalid_token/.yml
|
@@ -219,6 +222,9 @@ test_files:
|
|
219
222
|
- spec/cassettes/MoodleRb_Client/_site_info/when_valid_token/.yml
|
220
223
|
- spec/cassettes/MoodleRb_Courses/_contents/when_using_invalid_token/.yml
|
221
224
|
- spec/cassettes/MoodleRb_Courses/_contents/when_using_valid_token/.yml
|
225
|
+
- spec/cassettes/MoodleRb_Courses/_core_course_import_course/when_using_invalid_token/.yml
|
226
|
+
- spec/cassettes/MoodleRb_Courses/_core_course_import_course/when_using_valid_token/.yml
|
227
|
+
- spec/cassettes/MoodleRb_Courses/_core_course_import_course/when_using_valid_token/when_using_invalid_course_id/.yml
|
222
228
|
- spec/cassettes/MoodleRb_Courses/_create/.yml
|
223
229
|
- spec/cassettes/MoodleRb_Courses/_create/when_validation_fails/.yml
|
224
230
|
- spec/cassettes/MoodleRb_Courses/_destroy/when_using_invalid_token/.yml
|