Sha256: c5337777aaef659427cce497a29f7cc6d8b75b91ab4e593f8dd3baa484668251
Contents?: true
Size: 1.79 KB
Versions: 5
Compression:
Stored size: 1.79 KB
Contents
module MoodleRb class Enrolments include HTTParty include Utility attr_reader :token, :query_options STUDENT_ROLE_ID = 5 TEACHER_ROLE_ID = 3 def initialize(token, url, query_options) @token = token @query_options = query_options self.class.base_uri url end # required params: # user_id course_id # optional params: # role_id - defaults to student role id 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(query_options) ) check_for_errors(response) response.code == 200 && response.parsed_response.nil? end # required params: # user_id course_id # optional params: # role_id - defaults to student role id 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(query_options) ) check_for_errors(response) response.code == 200 && response.parsed_response.nil? end end end
Version data entries
5 entries across 5 versions & 1 rubygems