module MoodleRb::Utility
Public Instance Methods
api_array(*array)
click to toggle source
The Moodle API requires array arguments to be in this format
# File lib/moodle_rb/utility.rb, line 12 def api_array(*array) {}.tap do |h| array.flatten.each_with_index do |x, i| h[i] = x end end end
check_for_errors(response)
click to toggle source
# File lib/moodle_rb/utility.rb, line 30 def check_for_errors(response) return unless error_response?(response) raise MoodleError.new(response.parsed_response) end
key_value_query_format(hash)
click to toggle source
# File lib/moodle_rb/utility.rb, line 20 def key_value_query_format(hash) {}.tap do |h| hash.each_with_index do |key_value_array, i| h[i] = {} h[i][:key] = key_value_array[0] h[i][:value] = key_value_array[1] end end end
query_hash(function, token)
click to toggle source
# File lib/moodle_rb/utility.rb, line 3 def query_hash(function, token) { :wsfunction => function, :moodlewsrestformat => 'json', :wstoken => token } end
Private Instance Methods
error_response?(response)
click to toggle source
# File lib/moodle_rb/utility.rb, line 37 def error_response?(response) response && response.parsed_response.is_a?(Hash) && response.parsed_response.has_key?('exception') end