Class: Learn::Exercise

Inherits:
Object
  • Object
show all
Extended by:
Term::ANSIColor
Defined in:
lib/learn/exercise.rb

Class Method Summary collapse

Class Method Details

.submit(name, contents) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/learn/exercise.rb', line 9

def self.submit(name, contents)
  settings = Learn.read_settings
  begin
    legal_name = name.match(/ex(?<order>\d+)/)
    if legal_name
      response = RestClient.post(
        "#{Learn::HOST}/students/#{settings["account_number"].chomp}/exercises.json",
       {exercise: {name: name, contents: contents, ordering: legal_name[:order]}})
       print green, "Exercise #{legal_name[:order]} submitted successfully", reset, "\n"
    end
  rescue Exception => e
    puts e
    print red, "Exercise could not be submitted :(", reset, "\n"
  end
end