class MoodleRb::Categories
Constants
- ROOT_CATEGORY
Attributes
query_options[R]
token[R]
Public Class Methods
new(token, url, query_options)
click to toggle source
# File lib/moodle_rb/categories.rb, line 9 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: name optional params: parent_category
the parent category id inside which the new category will be created - set to nil for a root category
idnumber
the new category external reference. must be unique
description
the new category description
# File lib/moodle_rb/categories.rb, line 36 def create(params) response = self.class.post( '/webservice/rest/server.php', { :query => query_hash('core_course_create_categories', token), :body => { :categories => { '0' => { :name => params[:name], :parent => (params[:parent_category] || ROOT_CATEGORY), :idnumber => params[:idnumber], :description => params[:description] } } } }.merge(query_options) ) check_for_errors(response) response.parsed_response.first end
destroy(id)
click to toggle source
# File lib/moodle_rb/categories.rb, line 76 def destroy(id) response = self.class.post( '/webservice/rest/server.php', { :query => query_hash('core_course_delete_categories', token), :body => { :categories => { '0' => { :id => id, :recursive => 1 } } } }.merge(query_options) ) check_for_errors(response) response.parsed_response.nil? end
index()
click to toggle source
# File lib/moodle_rb/categories.rb, line 15 def index response = self.class.get( '/webservice/rest/server.php', { :query => query_hash('core_course_get_categories', token) }.merge(query_options) ) check_for_errors(response) response.parsed_response end
show(id)
click to toggle source
# File lib/moodle_rb/categories.rb, line 57 def show(id) response = self.class.post( '/webservice/rest/server.php', { :query => query_hash('core_course_get_categories', token), :body => { :criteria => { '0' => { :key => 'id', :value => id } } } }.merge(query_options) ) check_for_errors(response) response.parsed_response.first end