Class: Claw::Autograder

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/claw/autograder.rb

Overview

Autograder HTTParty Client Wrapper

Instance Method Summary collapse

Constructor Details

#initialize(token, query = {}) ⇒ Autograder

Returns a new instance of Autograder.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/claw/autograder.rb', line 10

def initialize(token, query = {})
  @options = {
    headers: {
      'Accept' => 'application/json, text/plain, */*',
      'Authorization' => "Token #{token}",
      'Cookie' => "token=#{token}"
    },
    query: query,
    verify: false
  }
end

Instance Method Details

#download_files(dirname, submission) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/claw/autograder.rb', line 39

def download_files(dirname, submission)
  puts 'Downloading submission files...'
  FileUtils.mkdir_p(File.join(Dir.pwd, dirname))

  submission['submitted_filenames'].each do |filename|
    opt_merge = {
      query: {
        'filename' => filename
      }
    }

    File.open(File.join(Dir.pwd, dirname, filename), 'w') do |f|
      f.write(self.class.get("/api/submissions/#{submission['pk']}/file/", @options.merge(opt_merge)))
    end
  end
end

#get_group_id_from_uniqname(projectid, name) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/claw/autograder.rb', line 22

def get_group_id_from_uniqname(projectid, name)
  puts 'Searching for user group id...'

  groups_json = self.class.get("/api/projects/#{projectid}/groups/", @options)

  groups_json.each do |group|
    return group['pk'] if group['member_names'].include?(name)
  end

  nil
end

#submissions(groupid) ⇒ Object



34
35
36
37
# File 'lib/claw/autograder.rb', line 34

def submissions(groupid)
  puts 'Fetching group submissions...'
  self.class.get("/api/groups/#{groupid}/submissions/", @options)
end