Class: MoodleRb::Enrolments
- Inherits:
-
Object
- Object
- MoodleRb::Enrolments
- Includes:
- HTTParty, Utility
- Defined in:
- lib/moodle_rb/enrolments.rb
Constant Summary collapse
- STUDENT_ROLE_ID =
5
- TEACHER_ROLE_ID =
3
Instance Attribute Summary collapse
-
#query_options ⇒ Object
readonly
Returns the value of attribute query_options.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
-
#create(params) ⇒ Object
required params: user_id course_id optional params: role_id - defaults to student role id.
-
#destroy(params) ⇒ Object
required params: user_id course_id optional params: role_id - defaults to student role id.
-
#initialize(token, url, query_options) ⇒ Enrolments
constructor
A new instance of Enrolments.
Methods included from Utility
#api_array, #check_for_errors, #key_value_query_format, #query_hash
Constructor Details
#initialize(token, url, query_options) ⇒ Enrolments
Returns a new instance of Enrolments.
10 11 12 13 14 |
# File 'lib/moodle_rb/enrolments.rb', line 10 def initialize(token, url, ) @token = token @query_options = self.class.base_uri url end |
Instance Attribute Details
#query_options ⇒ Object (readonly)
Returns the value of attribute query_options.
6 7 8 |
# File 'lib/moodle_rb/enrolments.rb', line 6 def @query_options end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
6 7 8 |
# File 'lib/moodle_rb/enrolments.rb', line 6 def token @token end |
Instance Method Details
#create(params) ⇒ Object
required params: user_id course_id optional params: role_id - defaults to student role id
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/moodle_rb/enrolments.rb', line 20 def create(params) response = self.class.post( '/webservice/rest/server.php', { :query => query_hash('enrol_manual_enrol_users', token), :body => { :enrolments => { '0' => { :userid => params[:user_id], :courseid => params[:course_id], :roleid => params[:role_id] || STUDENT_ROLE_ID, :timestart => params[:time_start], :timeend => params[:time_end] }.select {|k, v| v } } } }.merge() ) check_for_errors(response) response.code == 200 && response.parsed_response.nil? end |
#destroy(params) ⇒ Object
required params: user_id course_id optional params: role_id - defaults to student role id
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/moodle_rb/enrolments.rb', line 46 def destroy(params) response = self.class.post( '/webservice/rest/server.php', { :query => query_hash('enrol_manual_unenrol_users', token), :body => { :enrolments => { '0' => { :userid => params[:user_id], :courseid => params[:course_id], :roleid => params[:role_id] || STUDENT_ROLE_ID } } } }.merge() ) check_for_errors(response) response.code == 200 && response.parsed_response.nil? end |