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 CHANGED
@@ -1,2 +1,2 @@
1
- coverage
1
+ coverage
2
2
  Gemfile.lock
@@ -1,4 +1,8 @@
1
- language: ruby
2
- rvm:
3
- - 1.9.3
4
- - 2.0.0
1
+ language: ruby
2
+
3
+ before_install:
4
+ - gem install bundler
5
+
6
+ rvm:
7
+ - 1.9.3
8
+ - 2.0.0
data/Gemfile CHANGED
@@ -1,9 +1,3 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'simplecov', :require => false, :group => :test
4
- gem 'mocha', :require => false, :group => :test
5
- gem 'rest-client'
6
- gem 'sanitize'
7
- gem 'hashie'
8
- gem 'rake'
9
- gem 'json'
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
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
- - [Functions](#functions)
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
- ## Functions
84
- These are the currently implemented web services functions:
85
-
86
- ### Users
87
-
88
- #### core_user_get_users_by_field
89
- Retrieve users information for a specified unique field
90
- ```ruby
91
- user = client.core_user_get_users_by_field('id', [2])
92
-
93
- user.id # => 2,
94
- user.firstname # => Test
95
- user.lastname # => User
96
- user.fullname # => Test User
97
- user.email # => webservicetester@gmail.com
98
- user.firstaccess # => 139240932,
99
- user.lastaccess # => 1392471263
100
- user.profileimageurlsmall # => http://mydomain/moodle/pluginfile.php/5/user/icon/f2
101
- user.profileimageurl # => http://mydomain/moodle/pluginfile.php/5/user/icon/f1
102
- ```
103
-
104
- #### core_user_get_users
105
- Search for users matching the criteria
106
- ```ruby
107
- users = client.core_user_get_users({:email => 'suchemail@test.com'})
108
-
109
- users.each do |user|
110
- user.id # => 2,
111
- user.firstname # => Test
112
- user.lastname # => User
113
- user.fullname # => Test User
114
- user.email # => suchemail@test.com
115
- user.firstaccess # => 139240932,
116
- user.lastaccess # => 1392471263
117
- user.profileimageurlsmall # => http://mydomain/moodle/pluginfile.php/5/user/icon/f2
118
- user.profileimageurl # => http://mydomain/moodle/pluginfile.php/5/user/icon/f1
119
- end
120
- ```
121
-
122
- ### Courses
123
-
124
- #### core_course_get_courses
125
- Retrieve courses details by ids
126
- ```ruby
127
- courses = client.core_course_get_courses([2, 3])
128
-
129
- courses.each do |course|
130
- course.id # => 2
131
- course.shortname # => T
132
- course.categoryid # => 1
133
- course.categorysortorder # => 10002
134
- course.fullname # => Test
135
- course.idnumber # => TX
136
- course.summary # => test
137
- course.summaryformat # => 1
138
- course.format # => weeks
139
- course.showgrades # => 1
140
- course.newsitems # => 5
141
- course.startdate # => 1393718400
142
- course.numsections # => 10
143
- course.maxbytes # => 0
144
- course.showreports # => 0
145
- course.visible # => 1
146
- course.hiddensections # => 0
147
- course.groupmode # => 0
148
- course.groupmodeforce # => 0
149
- course.defaultgroupingid # => 0
150
- course.timecreated # => 1393693092
151
- course.timemodified # => 1393693092
152
- course.enablecompletion # => 0
153
- course.completionnotify # => 0
154
- course.lang # => en
155
- course.forcetheme # => test
156
- course.courseformatoptions.each do |format|
157
- format.name # => numsections
158
- value # => 10
159
- end
160
- end
161
- ```
162
-
163
- ### Webservices
164
-
165
- #### core_webservice_get_site_info
166
- Return some site info / user info / list web service functions
167
- ```ruby
168
- info = client.core_webservice_get_site_info
169
-
170
- info.sitename # => Webservice test
171
- info.username # => test
172
- info.firstname # => Test
173
- info.lastname # => Webservice
174
- info.fullname # => Test Webservice
175
- info.lang # => en
176
- info.userid # => 3
177
- info.siteurl # => http://mydomain/moodle
178
- info.userpictureurl # => http://mydomain/moodle/pluginfile.php/15/user/icon/f1
179
- info.functions.each do |f|
180
- f.name # => core_user_get_users_by_field
181
- f.version # => 2013111800.09
182
- end
183
- info.downloadfiles # => 0
184
- info.uploadfiles # => 0
185
- info.release # => 2.6+ (Build: 20140110)
186
- info.version # => 2013111800.09
187
- info.mobilecssurl # => ""
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
+ ```