moodle-api 1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +4 -0
  6. data/Guardfile +70 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +128 -0
  9. data/Rakefile +5 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +7 -0
  12. data/fixtures/vcr_cassettes/external_service/invalid_service.yml +48 -0
  13. data/fixtures/vcr_cassettes/external_service/token_service.yml +39 -0
  14. data/fixtures/vcr_cassettes/external_service/valid_service.yml +61 -0
  15. data/fixtures/vcr_cassettes/external_service/valid_service_empty_array_response.yml +46 -0
  16. data/fixtures/vcr_cassettes/external_service/valid_service_not_external.yml +59 -0
  17. data/fixtures/vcr_cassettes/external_service/valid_service_with_invalid_token.yml +47 -0
  18. data/fixtures/vcr_cassettes/token_service/error_invalid_service_token_service.yml +39 -0
  19. data/fixtures/vcr_cassettes/token_service/invalid_password_token_service.yml +49 -0
  20. data/fixtures/vcr_cassettes/token_service/invalid_permissions_token_service.yml +49 -0
  21. data/fixtures/vcr_cassettes/token_service/invalid_service_token_service.yml +48 -0
  22. data/fixtures/vcr_cassettes/token_service/invalid_user_token_service.yml +49 -0
  23. data/fixtures/vcr_cassettes/token_service/invalid_username_token_service.yml +49 -0
  24. data/fixtures/vcr_cassettes/token_service/token_service.yml +47 -0
  25. data/lib/moodle.rb +1 -0
  26. data/lib/moodle/api.rb +34 -0
  27. data/lib/moodle/api/client.rb +40 -0
  28. data/lib/moodle/api/configuration.rb +55 -0
  29. data/lib/moodle/api/errors.rb +5 -0
  30. data/lib/moodle/api/request.rb +45 -0
  31. data/lib/moodle/api/token_generator.rb +37 -0
  32. data/lib/moodle/api/version.rb +5 -0
  33. data/moodle-api.gemspec +38 -0
  34. metadata +175 -0
@@ -0,0 +1,59 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://dev.vle.getsmarter.co.za/webservice/rest/server.php?criteria%5B0%5D%5Bkey%5D=firstname&criteria%5B0%5D%5Bvalue%5D=Jon&moodlewsrestformat=json&wsfunction=core_user_get_users&wstoken=072556801bf07076fff6bff2a463b7c5
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Typhoeus - https://github.com/typhoeus/typhoeus
12
+ Accept:
13
+ - json
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ Date:
20
+ - Wed, 01 Jul 2015 12:44:52 GMT
21
+ Server:
22
+ - Apache/2.4.9 (Unix) PHP/5.5.14
23
+ X-Powered-By:
24
+ - PHP/5.5.14
25
+ Cache-Control:
26
+ - private, must-revalidate, pre-check=0, post-check=0, max-age=0
27
+ Expires:
28
+ - Thu, 01 Jan 1970 00:00:00 GMT
29
+ Pragma:
30
+ - no-cache
31
+ Accept-Ranges:
32
+ - none
33
+ Access-Control-Allow-Origin:
34
+ - "*"
35
+ Content-Length:
36
+ - '1126'
37
+ Content-Type:
38
+ - application/json
39
+ body:
40
+ encoding: UTF-8
41
+ string: '{"exception":"webservice_access_exception","errorcode":"accessexception","message":"Access
42
+ control exception","debuginfo":"Access to the function core_user_get_users()
43
+ is not allowed.\n There could be multiple reasons for
44
+ this:\n 1. The service linked to the user token does not
45
+ contain the function.\n 2. The service is user-restricted
46
+ and the user is not listed.\n 3. The service is IP-restricted
47
+ and the user IP is not listed.\n 4. The service is time-restricted
48
+ and the time has expired.\n 5. The token is time-restricted
49
+ and the time has expired.\n 6. The service requires a
50
+ specific capability which the user does not have.\n 7.
51
+ The function is called with username\/password (no user token is sent)\n and
52
+ none of the services has the function to allow the user.\n These
53
+ settings can be found in Administration > Site administration\n >
54
+ Plugins > Web services > External services and Manage tokens."}'
55
+ http_version: '1.1'
56
+ adapter_metadata:
57
+ effective_url: http://dev.vle.getsmarter.co.za/webservice/rest/server.php?criteria%5B0%5D%5Bkey%5D=firstname&criteria%5B0%5D%5Bvalue%5D=Jon&moodlewsrestformat=json&wsfunction=core_user_get_users&wstoken=072556801bf07076fff6bff2a463b7c5
58
+ recorded_at: Wed, 01 Jul 2015 12:44:52 GMT
59
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,47 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://dev.vle.getsmarter.co.za/webservice/rest/server.php?criteria%5B0%5D%5Bkey%5D=firstname&criteria%5B0%5D%5Bvalue%5D=Jon&moodlewsrestformat=json&wsfunction=core_user_get_users&wstoken=invalidtoken
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Typhoeus - https://github.com/typhoeus/typhoeus
12
+ Accept:
13
+ - json
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ Date:
20
+ - Wed, 01 Jul 2015 12:34:03 GMT
21
+ Server:
22
+ - Apache/2.4.9 (Unix) PHP/5.5.14
23
+ X-Powered-By:
24
+ - PHP/5.5.14
25
+ Cache-Control:
26
+ - private, must-revalidate, pre-check=0, post-check=0, max-age=0
27
+ Expires:
28
+ - Thu, 01 Jan 1970 00:00:00 GMT
29
+ Pragma:
30
+ - no-cache
31
+ Accept-Ranges:
32
+ - none
33
+ Access-Control-Allow-Origin:
34
+ - "*"
35
+ Content-Length:
36
+ - '103'
37
+ Content-Type:
38
+ - application/json
39
+ body:
40
+ encoding: UTF-8
41
+ string: '{"exception":"moodle_exception","errorcode":"invalidtoken","message":"Invalid
42
+ token - token not found"}'
43
+ http_version: '1.1'
44
+ adapter_metadata:
45
+ effective_url: http://dev.vle.getsmarter.co.za/webservice/rest/server.php?criteria%5B0%5D%5Bkey%5D=firstname&criteria%5B0%5D%5Bvalue%5D=Jon&moodlewsrestformat=json&wsfunction=core_user_get_users&wstoken=invalidtoken
46
+ recorded_at: Wed, 01 Jul 2015 12:34:04 GMT
47
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,39 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://dev.vle.getsmarter.co.za/login/token.php?username=ryan.mes%40email.co.za&password=mypassword&service=invalidservice
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Typhoeus - https://github.com/typhoeus/typhoeus
12
+ Accept:
13
+ - json
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ Date:
20
+ - Tue, 07 Jul 2015 08:35:13 GMT
21
+ Server:
22
+ - Apache/2.4.9 (Unix) PHP/5.5.14
23
+ X-Powered-By:
24
+ - PHP/5.5.14
25
+ Content-Length:
26
+ - '332'
27
+ Content-Type:
28
+ - application/json; charset=utf-8
29
+ body:
30
+ encoding: UTF-8
31
+ string: '{"error":"<p>Error: Database connection failed<\/p>\n<p>It is possible
32
+ that the database is overloaded or otherwise not running properly.<\/p>\n<p>The
33
+ site administrator should also check that the database details have been correctly
34
+ specified in config.php<\/p>","stacktrace":null,"debuginfo":null,"errorcode":"dbconnectionfailed"}'
35
+ http_version: '1.1'
36
+ adapter_metadata:
37
+ effective_url: http://dev.vle.getsmarter.co.za/login/token.php?username=ryan.mes%40email.co.za&password=mypassword&service=invalidservice
38
+ recorded_at: Tue, 07 Jul 2015 08:35:14 GMT
39
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,49 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://dev.vle.getsmarter.co.za/login/token.php?username=ryan.mes%40email.co.za&password=invalidpassword&service=phoenix_integration
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Typhoeus - https://github.com/typhoeus/typhoeus
12
+ Accept:
13
+ - json
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ Date:
20
+ - Tue, 07 Jul 2015 09:07:48 GMT
21
+ Server:
22
+ - Apache/2.4.9 (Unix) PHP/5.5.14
23
+ X-Powered-By:
24
+ - PHP/5.5.14
25
+ Cache-Control:
26
+ - no-store, no-cache, must-revalidate
27
+ - post-check=0, pre-check=0
28
+ Pragma:
29
+ - no-cache
30
+ Expires:
31
+ - Mon, 20 Aug 1969 09:23:00 GMT
32
+ Last-Modified:
33
+ - Tue, 07 Jul 2015 09:07:48 GMT
34
+ Accept-Ranges:
35
+ - none
36
+ Content-Length:
37
+ - '231'
38
+ Content-Type:
39
+ - application/json; charset=utf-8
40
+ body:
41
+ encoding: UTF-8
42
+ string: '{"error":"The username was not found in the database","stacktrace":"*
43
+ line 205 of \/login\/token.php: moodle_exception thrown\n","debuginfo":"\nError
44
+ code: usernamenotfound","reproductionlink":"http:\/\/dev.vle.getsmarter.co.za\/"}'
45
+ http_version: '1.1'
46
+ adapter_metadata:
47
+ effective_url: http://dev.vle.getsmarter.co.za/login/token.php?username=ryan.mes%40email.co.za&password=invalidpassword&service=phoenix_integration
48
+ recorded_at: Tue, 07 Jul 2015 09:07:48 GMT
49
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,49 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://dev.vle.getsmarter.co.za/login/token.php?username=ryan.mes%40email.co.za&password=mypassword&service=
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Typhoeus - https://github.com/typhoeus/typhoeus
12
+ Accept:
13
+ - json
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ Date:
20
+ - Fri, 03 Jul 2015 11:39:24 GMT
21
+ Server:
22
+ - Apache/2.4.9 (Unix) PHP/5.5.14
23
+ X-Powered-By:
24
+ - PHP/5.5.14
25
+ Cache-Control:
26
+ - no-store, no-cache, must-revalidate
27
+ - post-check=0, pre-check=0
28
+ Pragma:
29
+ - no-cache
30
+ Expires:
31
+ - Mon, 20 Aug 1969 09:23:00 GMT
32
+ Last-Modified:
33
+ - Fri, 03 Jul 2015 11:39:25 GMT
34
+ Accept-Ranges:
35
+ - none
36
+ Content-Length:
37
+ - '249'
38
+ Content-Type:
39
+ - application/json; charset=utf-8
40
+ body:
41
+ encoding: UTF-8
42
+ string: '{"error":"No permission to create web service token for the service
43
+ .","stacktrace":"* line 187 of \/login\/token.php: moodle_exception thrown\n","debuginfo":"\nError
44
+ code: cannotcreatetoken","reproductionlink":"http:\/\/dev.vle.getsmarter.co.za\/"}'
45
+ http_version: '1.1'
46
+ adapter_metadata:
47
+ effective_url: http://dev.vle.getsmarter.co.za/login/token.php?username=ryan.mes%40email.co.za&password=mypassword&service=
48
+ recorded_at: Fri, 03 Jul 2015 11:39:25 GMT
49
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,48 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://dev.vle.getsmarter.co.za/login/token.php?username=ryan.mes%40email.co.za&password=mypassword&service=invalidservice
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Typhoeus - https://github.com/typhoeus/typhoeus
12
+ Accept:
13
+ - json
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ Date:
20
+ - Tue, 07 Jul 2015 09:02:42 GMT
21
+ Server:
22
+ - Apache/2.4.9 (Unix) PHP/5.5.14
23
+ X-Powered-By:
24
+ - PHP/5.5.14
25
+ Cache-Control:
26
+ - no-store, no-cache, must-revalidate
27
+ - post-check=0, pre-check=0
28
+ Pragma:
29
+ - no-cache
30
+ Expires:
31
+ - Mon, 20 Aug 1969 09:23:00 GMT
32
+ Last-Modified:
33
+ - Tue, 07 Jul 2015 09:02:43 GMT
34
+ Accept-Ranges:
35
+ - none
36
+ Content-Length:
37
+ - '259'
38
+ Content-Type:
39
+ - application/json; charset=utf-8
40
+ body:
41
+ encoding: UTF-8
42
+ string: '{"error":"Web service is not available (it doesn''t exist or might be disabled)","stacktrace":"* line 86 of \/login\/token.php: moodle_exception
43
+ thrown\n","debuginfo":"\nError code: servicenotavailable","reproductionlink":"http:\/\/dev.vle.getsmarter.co.za\/"}'
44
+ http_version: '1.1'
45
+ adapter_metadata:
46
+ effective_url: http://dev.vle.getsmarter.co.za/login/token.php?username=ryan.mes%40email.co.za&password=mypassword&service=invalidservice
47
+ recorded_at: Tue, 07 Jul 2015 09:02:43 GMT
48
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,49 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://dev.vle.getsmarter.co.za/login/token.php?username=ryan.mes%40email.co.za&password=phoenix_integration&service=
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Typhoeus - https://github.com/typhoeus/typhoeus
12
+ Accept:
13
+ - json
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ Date:
20
+ - Fri, 03 Jul 2015 11:38:14 GMT
21
+ Server:
22
+ - Apache/2.4.9 (Unix) PHP/5.5.14
23
+ X-Powered-By:
24
+ - PHP/5.5.14
25
+ Cache-Control:
26
+ - no-store, no-cache, must-revalidate
27
+ - post-check=0, pre-check=0
28
+ Pragma:
29
+ - no-cache
30
+ Expires:
31
+ - Mon, 20 Aug 1969 09:23:00 GMT
32
+ Last-Modified:
33
+ - Fri, 03 Jul 2015 11:38:14 GMT
34
+ Accept-Ranges:
35
+ - none
36
+ Content-Length:
37
+ - '231'
38
+ Content-Type:
39
+ - application/json; charset=utf-8
40
+ body:
41
+ encoding: UTF-8
42
+ string: '{"error":"The username was not found in the database","stacktrace":"*
43
+ line 205 of \/login\/token.php: moodle_exception thrown\n","debuginfo":"\nError
44
+ code: usernamenotfound","reproductionlink":"http:\/\/dev.vle.getsmarter.co.za\/"}'
45
+ http_version: '1.1'
46
+ adapter_metadata:
47
+ effective_url: http://dev.vle.getsmarter.co.za/login/token.php?username=ryan.mes%40email.co.za&password=phoenix_integration&service=
48
+ recorded_at: Fri, 03 Jul 2015 11:38:14 GMT
49
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,49 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://dev.vle.getsmarter.co.za/login/token.php?username=invalidusername&password=mypassword&service=phoenix_integration
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Typhoeus - https://github.com/typhoeus/typhoeus
12
+ Accept:
13
+ - json
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ Date:
20
+ - Tue, 07 Jul 2015 09:06:32 GMT
21
+ Server:
22
+ - Apache/2.4.9 (Unix) PHP/5.5.14
23
+ X-Powered-By:
24
+ - PHP/5.5.14
25
+ Cache-Control:
26
+ - no-store, no-cache, must-revalidate
27
+ - post-check=0, pre-check=0
28
+ Pragma:
29
+ - no-cache
30
+ Expires:
31
+ - Mon, 20 Aug 1969 09:23:00 GMT
32
+ Last-Modified:
33
+ - Tue, 07 Jul 2015 09:06:32 GMT
34
+ Accept-Ranges:
35
+ - none
36
+ Content-Length:
37
+ - '231'
38
+ Content-Type:
39
+ - application/json; charset=utf-8
40
+ body:
41
+ encoding: UTF-8
42
+ string: '{"error":"The username was not found in the database","stacktrace":"*
43
+ line 205 of \/login\/token.php: moodle_exception thrown\n","debuginfo":"\nError
44
+ code: usernamenotfound","reproductionlink":"http:\/\/dev.vle.getsmarter.co.za\/"}'
45
+ http_version: '1.1'
46
+ adapter_metadata:
47
+ effective_url: http://dev.vle.getsmarter.co.za/login/token.php?username=invalidusername&password=mypassword&service=phoenix_integration
48
+ recorded_at: Tue, 07 Jul 2015 09:06:32 GMT
49
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,47 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://dev.vle.getsmarter.co.za/login/token.php?username=ryan.mes%40email.co.za&password=mypassword&service=phoenix_integration
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Typhoeus - https://github.com/typhoeus/typhoeus
12
+ Accept:
13
+ - json
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ Date:
20
+ - Fri, 03 Jul 2015 11:41:09 GMT
21
+ Server:
22
+ - Apache/2.4.9 (Unix) PHP/5.5.14
23
+ X-Powered-By:
24
+ - PHP/5.5.14
25
+ Cache-Control:
26
+ - no-store, no-cache, must-revalidate
27
+ - post-check=0, pre-check=0
28
+ Pragma:
29
+ - no-cache
30
+ Expires:
31
+ - Mon, 20 Aug 1969 09:23:00 GMT
32
+ Last-Modified:
33
+ - Fri, 03 Jul 2015 11:41:10 GMT
34
+ Accept-Ranges:
35
+ - none
36
+ Content-Length:
37
+ - '44'
38
+ Content-Type:
39
+ - application/json; charset=utf-8
40
+ body:
41
+ encoding: UTF-8
42
+ string: '{"token":"072556801bf07076fff6bff2a463b7c5"}'
43
+ http_version: '1.1'
44
+ adapter_metadata:
45
+ effective_url: http://dev.vle.getsmarter.co.za/login/token.php?username=ryan.mes%40email.co.za&password=mypassword&service=phoenix_integration
46
+ recorded_at: Fri, 03 Jul 2015 11:41:10 GMT
47
+ recorded_with: VCR 2.9.3