moodle 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -1
- data/.travis.yml +8 -4
- data/Gemfile +3 -9
- data/LICENSE.md +19 -19
- data/README.md +204 -188
- data/Rakefile +7 -7
- data/lib/moodle.rb +39 -39
- data/lib/moodle/client.rb +70 -68
- data/lib/moodle/helper.rb +11 -11
- data/lib/moodle/protocols/rest.rb +11 -12
- data/lib/moodle/services/cohort.rb +22 -0
- data/lib/moodle/services/course.rb +21 -21
- data/lib/moodle/services/user.rb +39 -39
- data/lib/moodle/services/webservice.rb +9 -9
- data/moodle.gemspec +21 -13
- data/test/fixtures/config.yml +1 -1
- data/test/test_client.rb +33 -33
- data/test/test_helper.rb +9 -9
- data/test/test_moodle.rb +28 -28
- metadata +107 -8
- checksums.yaml +0 -7
data/.gitignore
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
coverage
|
1
|
+
coverage
|
2
2
|
Gemfile.lock
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/LICENSE.md
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2014 Robert Boloc
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
-
this software and associated documentation files (the "Software"), to deal in
|
7
|
-
the Software without restriction, including without limitation the rights to
|
8
|
-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
-
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
-
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, FITNESS
|
17
|
-
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Robert Boloc
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
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, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
20
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,188 +1,204 @@
|
|
1
|
-
# Moodle
|
2
|
-
[![Build Status](https://travis-ci.org/robertboloc/moodle.png)](https://travis-ci.org/robertboloc/moodle)
|
3
|
-
[![Code Climate](https://codeclimate.com/github/robertboloc/moodle.png)](https://codeclimate.com/github/robertboloc/moodle)
|
4
|
-
[![Gem Version](https://badge.fury.io/rb/moodle.png)](http://badge.fury.io/rb/moodle)
|
5
|
-
|
6
|
-
Ruby gem to interact with Moodle via web services.
|
7
|
-
|
8
|
-
## Table of contents
|
9
|
-
- [Installation](#installation)
|
10
|
-
- [Usage](#usage)
|
11
|
-
- [Protocols](#protocols)
|
12
|
-
- [
|
13
|
-
|
14
|
-
## Installation
|
15
|
-
```shell
|
16
|
-
gem install moodle
|
17
|
-
```
|
18
|
-
|
19
|
-
## Usage
|
20
|
-
To use this gem you must first have configured the moodle web services. To do that use the official documentation.
|
21
|
-
|
22
|
-
### Without a token
|
23
|
-
If you don't have a token, you can create an instance of the client using your username and password.
|
24
|
-
The client will then obtain a token for you.
|
25
|
-
```ruby
|
26
|
-
client = Moodle::Client.new(
|
27
|
-
:username => 'myusername',
|
28
|
-
:password => 'secret',
|
29
|
-
:protocol => 'rest',
|
30
|
-
:domain => 'http://mydomain/moodle',
|
31
|
-
:service => 'myservice',
|
32
|
-
:format => 'json'
|
33
|
-
)
|
34
|
-
```
|
35
|
-
|
36
|
-
### Using a token
|
37
|
-
If you already have a token the client can be created without a username and password:
|
38
|
-
```ruby
|
39
|
-
client = Moodle::Client.new(
|
40
|
-
:token => 'b31dde13bade28f25d548a31fa994816',
|
41
|
-
:protocol => 'rest',
|
42
|
-
:domain => 'http://mydomain/moodle',
|
43
|
-
:service => 'myservice',
|
44
|
-
:format => 'json'
|
45
|
-
)
|
46
|
-
```
|
47
|
-
|
48
|
-
### Short syntax
|
49
|
-
When creating the client you can use a shorter and simpler syntax:
|
50
|
-
```ruby
|
51
|
-
client = Moodle.new(
|
52
|
-
:token => 'b31dde13bade28f25d548a31fa994816',
|
53
|
-
:protocol => 'rest',
|
54
|
-
:domain => 'http://mydomain/moodle',
|
55
|
-
:service => 'myservice',
|
56
|
-
:format => 'json'
|
57
|
-
)
|
58
|
-
```
|
59
|
-
|
60
|
-
### Global configuration
|
61
|
-
Configuration can be set globally.
|
62
|
-
```ruby
|
63
|
-
# Using a hash
|
64
|
-
Moodle.configure(
|
65
|
-
:token => 'b31dde13bade28f25d548a31fa994816',
|
66
|
-
:protocol => 'rest',
|
67
|
-
:domain => 'http://mydomain/moodle',
|
68
|
-
:service => 'myservice',
|
69
|
-
:format => 'json'
|
70
|
-
)
|
71
|
-
|
72
|
-
# Using a file
|
73
|
-
Moodle.configure_with(/path/to/yaml/file)
|
74
|
-
|
75
|
-
client = Moodle.new
|
76
|
-
```
|
77
|
-
|
78
|
-
Once you have an instance of the client it's only a matter of calling the moodle web services functions.
|
79
|
-
|
80
|
-
## Protocols
|
81
|
-
Moodle implements 4 protocols: AMF, REST, SOAP, XML-RPC. Currently this gem only supports REST.
|
82
|
-
|
83
|
-
##
|
84
|
-
These are the currently implemented web services functions:
|
85
|
-
|
86
|
-
###
|
87
|
-
|
88
|
-
####
|
89
|
-
|
90
|
-
```ruby
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
####
|
105
|
-
|
106
|
-
```ruby
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
course.
|
131
|
-
course.
|
132
|
-
course.
|
133
|
-
course.
|
134
|
-
course.
|
135
|
-
course.
|
136
|
-
course.
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
info
|
185
|
-
|
186
|
-
info.
|
187
|
-
info.
|
188
|
-
|
1
|
+
# Moodle
|
2
|
+
[![Build Status](https://travis-ci.org/robertboloc/moodle.png)](https://travis-ci.org/robertboloc/moodle)
|
3
|
+
[![Code Climate](https://codeclimate.com/github/robertboloc/moodle.png)](https://codeclimate.com/github/robertboloc/moodle)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/moodle.png)](http://badge.fury.io/rb/moodle)
|
5
|
+
|
6
|
+
Ruby gem to interact with Moodle via web services.
|
7
|
+
|
8
|
+
## Table of contents
|
9
|
+
- [Installation](#installation)
|
10
|
+
- [Usage](#usage)
|
11
|
+
- [Protocols](#protocols)
|
12
|
+
- [Services](#services)
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
```shell
|
16
|
+
gem install moodle
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
To use this gem you must first have configured the moodle web services. To do that use the official documentation.
|
21
|
+
|
22
|
+
### Without a token
|
23
|
+
If you don't have a token, you can create an instance of the client using your username and password.
|
24
|
+
The client will then obtain a token for you.
|
25
|
+
```ruby
|
26
|
+
client = Moodle::Client.new(
|
27
|
+
:username => 'myusername',
|
28
|
+
:password => 'secret',
|
29
|
+
:protocol => 'rest',
|
30
|
+
:domain => 'http://mydomain/moodle',
|
31
|
+
:service => 'myservice',
|
32
|
+
:format => 'json'
|
33
|
+
)
|
34
|
+
```
|
35
|
+
|
36
|
+
### Using a token
|
37
|
+
If you already have a token the client can be created without a username and password:
|
38
|
+
```ruby
|
39
|
+
client = Moodle::Client.new(
|
40
|
+
:token => 'b31dde13bade28f25d548a31fa994816',
|
41
|
+
:protocol => 'rest',
|
42
|
+
:domain => 'http://mydomain/moodle',
|
43
|
+
:service => 'myservice',
|
44
|
+
:format => 'json'
|
45
|
+
)
|
46
|
+
```
|
47
|
+
|
48
|
+
### Short syntax
|
49
|
+
When creating the client you can use a shorter and simpler syntax:
|
50
|
+
```ruby
|
51
|
+
client = Moodle.new(
|
52
|
+
:token => 'b31dde13bade28f25d548a31fa994816',
|
53
|
+
:protocol => 'rest',
|
54
|
+
:domain => 'http://mydomain/moodle',
|
55
|
+
:service => 'myservice',
|
56
|
+
:format => 'json'
|
57
|
+
)
|
58
|
+
```
|
59
|
+
|
60
|
+
### Global configuration
|
61
|
+
Configuration can be set globally.
|
62
|
+
```ruby
|
63
|
+
# Using a hash
|
64
|
+
Moodle.configure(
|
65
|
+
:token => 'b31dde13bade28f25d548a31fa994816',
|
66
|
+
:protocol => 'rest',
|
67
|
+
:domain => 'http://mydomain/moodle',
|
68
|
+
:service => 'myservice',
|
69
|
+
:format => 'json'
|
70
|
+
)
|
71
|
+
|
72
|
+
# Using a file
|
73
|
+
Moodle.configure_with(/path/to/yaml/file)
|
74
|
+
|
75
|
+
client = Moodle.new
|
76
|
+
```
|
77
|
+
|
78
|
+
Once you have an instance of the client it's only a matter of calling the moodle web services functions.
|
79
|
+
|
80
|
+
## Protocols
|
81
|
+
Moodle implements 4 protocols: AMF, REST, SOAP, XML-RPC. Currently this gem only supports REST.
|
82
|
+
|
83
|
+
## Services
|
84
|
+
These are the currently implemented web services functions:
|
85
|
+
|
86
|
+
### Cohorts
|
87
|
+
|
88
|
+
#### core_cohort_get_cohorts
|
89
|
+
Returns cohort details
|
90
|
+
```ruby
|
91
|
+
cohorts = client.core_cohort_get_cohorts([1])
|
92
|
+
|
93
|
+
cohorts.each do |cohort|
|
94
|
+
cohort.id # => 1
|
95
|
+
cohort.name # => Test
|
96
|
+
cohort.idnumber # => 1
|
97
|
+
cohort.description # => Test Cohort
|
98
|
+
cohort.descriptionformat # => 1
|
99
|
+
end
|
100
|
+
```
|
101
|
+
|
102
|
+
### Courses
|
103
|
+
|
104
|
+
#### core_course_get_courses
|
105
|
+
Retrieve courses details by ids
|
106
|
+
```ruby
|
107
|
+
courses = client.core_course_get_courses([2, 3])
|
108
|
+
|
109
|
+
courses.each do |course|
|
110
|
+
course.id # => 2
|
111
|
+
course.shortname # => T
|
112
|
+
course.categoryid # => 1
|
113
|
+
course.categorysortorder # => 10002
|
114
|
+
course.fullname # => Test
|
115
|
+
course.idnumber # => TX
|
116
|
+
course.summary # => test
|
117
|
+
course.summaryformat # => 1
|
118
|
+
course.format # => weeks
|
119
|
+
course.showgrades # => 1
|
120
|
+
course.newsitems # => 5
|
121
|
+
course.startdate # => 1393718400
|
122
|
+
course.numsections # => 10
|
123
|
+
course.maxbytes # => 0
|
124
|
+
course.showreports # => 0
|
125
|
+
course.visible # => 1
|
126
|
+
course.hiddensections # => 0
|
127
|
+
course.groupmode # => 0
|
128
|
+
course.groupmodeforce # => 0
|
129
|
+
course.defaultgroupingid # => 0
|
130
|
+
course.timecreated # => 1393693092
|
131
|
+
course.timemodified # => 1393693092
|
132
|
+
course.enablecompletion # => 0
|
133
|
+
course.completionnotify # => 0
|
134
|
+
course.lang # => en
|
135
|
+
course.forcetheme # => test
|
136
|
+
course.courseformatoptions.each do |format|
|
137
|
+
format.name # => numsections
|
138
|
+
value # => 10
|
139
|
+
end
|
140
|
+
end
|
141
|
+
```
|
142
|
+
|
143
|
+
### Users
|
144
|
+
|
145
|
+
#### core_user_get_users_by_field
|
146
|
+
Retrieve users information for a specified unique field
|
147
|
+
```ruby
|
148
|
+
user = client.core_user_get_users_by_field('id', [2])
|
149
|
+
|
150
|
+
user.id # => 2,
|
151
|
+
user.firstname # => Test
|
152
|
+
user.lastname # => User
|
153
|
+
user.fullname # => Test User
|
154
|
+
user.email # => webservicetester@gmail.com
|
155
|
+
user.firstaccess # => 139240932,
|
156
|
+
user.lastaccess # => 1392471263
|
157
|
+
user.profileimageurlsmall # => http://mydomain/moodle/pluginfile.php/5/user/icon/f2
|
158
|
+
user.profileimageurl # => http://mydomain/moodle/pluginfile.php/5/user/icon/f1
|
159
|
+
```
|
160
|
+
|
161
|
+
#### core_user_get_users
|
162
|
+
Search for users matching the criteria
|
163
|
+
```ruby
|
164
|
+
users = client.core_user_get_users({:email => 'suchemail@test.com'})
|
165
|
+
|
166
|
+
users.each do |user|
|
167
|
+
user.id # => 2,
|
168
|
+
user.firstname # => Test
|
169
|
+
user.lastname # => User
|
170
|
+
user.fullname # => Test User
|
171
|
+
user.email # => suchemail@test.com
|
172
|
+
user.firstaccess # => 139240932,
|
173
|
+
user.lastaccess # => 1392471263
|
174
|
+
user.profileimageurlsmall # => http://mydomain/moodle/pluginfile.php/5/user/icon/f2
|
175
|
+
user.profileimageurl # => http://mydomain/moodle/pluginfile.php/5/user/icon/f1
|
176
|
+
end
|
177
|
+
```
|
178
|
+
|
179
|
+
### Webservices
|
180
|
+
|
181
|
+
#### core_webservice_get_site_info
|
182
|
+
Return some site info / user info / list web service functions
|
183
|
+
```ruby
|
184
|
+
info = client.core_webservice_get_site_info
|
185
|
+
|
186
|
+
info.sitename # => Webservice test
|
187
|
+
info.username # => test
|
188
|
+
info.firstname # => Test
|
189
|
+
info.lastname # => Webservice
|
190
|
+
info.fullname # => Test Webservice
|
191
|
+
info.lang # => en
|
192
|
+
info.userid # => 3
|
193
|
+
info.siteurl # => http://mydomain/moodle
|
194
|
+
info.userpictureurl # => http://mydomain/moodle/pluginfile.php/15/user/icon/f1
|
195
|
+
info.functions.each do |f|
|
196
|
+
f.name # => core_user_get_users_by_field
|
197
|
+
f.version # => 2013111800.09
|
198
|
+
end
|
199
|
+
info.downloadfiles # => 0
|
200
|
+
info.uploadfiles # => 0
|
201
|
+
info.release # => 2.6+ (Build: 20140110)
|
202
|
+
info.version # => 2013111800.09
|
203
|
+
info.mobilecssurl # => ""
|
204
|
+
```
|