class MoodleRb::Users
Attributes
query_options[R]
token[R]
Public Class Methods
new(token, url, query_options)
click to toggle source
# File lib/moodle_rb/users.rb, line 8 def initialize(token, url, query_options) @token = token @query_options = query_options self.class.base_uri url end
Public Instance Methods
create(params)
click to toggle source
required params: username password firstname lastname email optional params: idnumber
An arbitrary ID code number perhaps from the institution
# File lib/moodle_rb/users.rb, line 19 def create(params) response = self.class.post( '/webservice/rest/server.php', { :query => query_hash('core_user_create_users', token), :body => { :users => { '0' => params } } }.merge(query_options) ) check_for_errors(response) response.parsed_response.first end
destroy(id)
click to toggle source
# File lib/moodle_rb/users.rb, line 55 def destroy(id) response = self.class.post( '/webservice/rest/server.php', { :query => query_hash('core_user_delete_users', token), :body => { :userids => { '0' => id } } }.merge(query_options) ) check_for_errors(response) response.parsed_response.nil? end
enrolled_courses(user_id)
click to toggle source
# File lib/moodle_rb/users.rb, line 71 def enrolled_courses(user_id) response = self.class.post( '/webservice/rest/server.php', { :query => query_hash('core_enrol_get_users_courses', token), :body => { :userid => user_id } }.merge(query_options) ) check_for_errors(response) response.parsed_response end
search(params = {})
click to toggle source
input keys must be in the list of supported user columns to search id, lastname, firstname, idnumber, username, email
# File lib/moodle_rb/users.rb, line 87 def search(params = {}) response = self.class.post( '/webservice/rest/server.php', { :query => query_hash('core_user_get_users', token), :body => { :criteria => key_value_query_format(params) } }.merge(query_options) ) check_for_errors(response) response.parsed_response['users'] end
show(id)
click to toggle source
# File lib/moodle_rb/users.rb, line 35 def show(id) response = self.class.post( '/webservice/rest/server.php', { :query => query_hash('core_user_get_users', token), :body => { :criteria => { '0' => { :key => 'id', :value => id } } } }.merge(query_options) ) check_for_errors(response) response.parsed_response['users'] && response.parsed_response['users'].first end
update(params)
click to toggle source
params must include the id of the user it may include any other standard user attributes: username, password, firstname, lastname, email …
# File lib/moodle_rb/users.rb, line 104 def update(params) response = self.class.post( '/webservice/rest/server.php', { :query => query_hash('core_user_update_users', token), :body => { :users => { '0' => params } } }.merge(query_options) ) check_for_errors(response) response.response.code == '200' end