Class: Codewars::Attempt

Inherits:
Thor
  • Object
show all
Defined in:
lib/codewars/attempt.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Attempt

Returns a new instance of Attempt.

Raises:

  • (Thor::Error)


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/codewars/attempt.rb', line 3

def initialize(client)
  api_key = Configuration.option('api_key')
  raise Thor::Error, 'You should set an api-key to use this command' unless api_key

  desc = Description.new
  project_id = desc.take_value_from_file(/Project ID: (.+)/, 'Project ID')
  solution_id = desc.take_value_from_file(/Solution ID: (.+)/, 'Solution ID')
  solution = read_solution_file

  attempt = client.attempt_solution(
    project_id: project_id,
    solution_id: solution_id,
    code: solution
  )

  say 'Your solution has been uploaded. Waiting for a result of tests on the server.'

  deferred_response = deferred_response(client, attempt)
  handle_deferred_response(deferred_response)
end