module Kurki
Constants
- VERSION
Public Class Methods
get_course(id)
click to toggle source
# File lib/kurki.rb, line 21 def self.get_course(id) # First because API returns array with one element get(url + "courses/#{id}").first end
get_courses()
click to toggle source
# File lib/kurki.rb, line 13 def self.get_courses get(url + "courses") end
get_students(course_id)
click to toggle source
# File lib/kurki.rb, line 17 def self.get_students(course_id) get(url + "courses/#{course_id}/students") end
set_exam_points(course_id, points)
click to toggle source
Exam points in format: { “123123123” => {
"1" => 1, "2" => 56 }
}
# File lib/kurki.rb, line 53 def self.set_exam_points(course_id, points) post(url + "courses/#{course_id}/students", parse_exam_points(points)) end
set_exercise_points(course_id, points)
click to toggle source
Exercise points in format: { “123123123” => {
"2" => 1, "3" => 4 }
}
# File lib/kurki.rb, line 65 def self.set_exercise_points(course_id, points) post(url + "courses/#{course_id}/students", parse_exercise_points(points)) end
set_grades(course_id, grades)
click to toggle source
Grades in form {“01234567”: “3”, “01243483”: “4”}
# File lib/kurki.rb, line 32 def self.set_grades(course_id, grades) post(url + "courses/#{course_id}/students", parse_grades(grades)) end
set_grades_from_csv(course_id, file_path, delimiter=",")
click to toggle source
.csv in two columns, with one header row
# File lib/kurki.rb, line 37 def self.set_grades_from_csv(course_id, file_path, delimiter=",") grades = {} read_csv(file_path, delimiter).each do |result| grades[result[0]] = result[1] end set_grades course_id, grades end
set_students(course_id, student_ids)
click to toggle source
Student_ids in form [“12345678”, “12345678”]
# File lib/kurki.rb, line 27 def self.set_students(course_id, student_ids) post(url + "courses/#{course_id}/students", parse_students(student_ids)) end
url()
click to toggle source
# File lib/kurki.rb, line 8 def self.url return ENV["KURKI_URL"] if ENV["KURKI_URL"][-1] == "/" ENV["KURKI_URL"]+"/" end
Private Class Methods
get(address, params = {})
click to toggle source
# File lib/kurki.rb, line 112 def self.get(address, params = {}) params[:authorization] = ENV["KURKI_TOKEN"] result = RestClient::Request.execute( :url => address, :method => :get, :headers => { params: params, accept: :json, content_type: :json }, :verify_ssl => false ) JSON.parse result end
parse(items, exp)
click to toggle source
# File lib/kurki.rb, line 91 def self.parse(items, exp) json = {} json["students"] = items.map(&exp) json end
parse_exam_points(points)
click to toggle source
# File lib/kurki.rb, line 75 def self.parse_exam_points(points) parse(points, lambda {|x,y| { id: x, exams: y } }) end
parse_exercise_points(points)
click to toggle source
# File lib/kurki.rb, line 71 def self.parse_exercise_points(points) parse(points, lambda {|x,y| {id: x, exercises: y}}) end
parse_grades(grades)
click to toggle source
# File lib/kurki.rb, line 87 def self.parse_grades(grades) parse(grades, lambda {|x,y| { id: x, arvosana: y } }) end
parse_students(student_ids)
click to toggle source
# File lib/kurki.rb, line 83 def self.parse_students(student_ids) parse(student_ids, lambda { |x| {id: x} }) end
post(address, data, params = {})
click to toggle source
# File lib/kurki.rb, line 97 def self.post(address, data, params = {}) return unless data params[:authorization] = ENV["KURKI_TOKEN"] result = RestClient::Request.execute( :url => address, :method => :post, :payload => data.to_json, :headers => { params: params, accept: :json, content_type: :json }, :verify_ssl => false ) JSON.parse result end
read_csv(file_path, delimiter)
click to toggle source
# File lib/kurki.rb, line 79 def self.read_csv(file_path, delimiter) CSV.read(file_path, col_sep: delimiter).drop(1) end