Module: Exercises

Includes:
BaseAtlasClient
Included in:
Atlas
Defined in:
lib/client/exercises.rb

Instance Method Summary collapse

Methods included from BaseAtlasClient

#auth_header, #convert_keys, #convert_response, #handle_timeouts, #success?, #whitelist_params

Instance Method Details

#get_exercise(id) ⇒ HTTParty::Response

Get an exercise

Examples:

Get exercise by id

Atlas#get_exercise(id)

Returns:

  • (HTTParty::Response)

    One exercise.



24
25
26
27
28
29
30
# File 'lib/client/exercises.rb', line 24

def get_exercise(id)
  url = "#{@api_base_path}/exercises/" + id.to_s
  handle_timeouts do
    response = self.class.get(url, headers: auth_header)
    convert_response(response, "exercise")
  end
end

#get_exercisesHTTParty::Response

Get all exercises

Examples:

Get all exercises

Atlas#get_exercises

Returns:

  • (HTTParty::Response)

    All exercises.



11
12
13
14
15
16
17
# File 'lib/client/exercises.rb', line 11

def get_exercises
  url = "#{@api_base_path}/exercises"
  handle_timeouts do
    response = self.class.get(url, headers: auth_header)
    convert_response(response, "exercises")
  end
end

#update_exercise(id, options = {}) ⇒ Exercise

Update an exercise

Examples:

Update a checkpoint

Atlas#update_checkpoint(1, {name: 'Real Cool Exercise'})

Parameters:

  • id (Integer)

    An exercise id.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :name (String)

    Exercise name.

  • :body (String)

    Exercise body.

  • :status (Integer)

    Exercise status.

  • :slug (String)

    Exercise slug.

  • :specs (String)

    Exercise specs.

  • :starting_code (String)

    Exercise starting code.

  • :canonical_solution (String)

    Exercise solution.

  • :language (String)

    Exercise language.

Returns:

  • (Exercise)

    The updated checkpoint



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/client/exercises.rb', line 47

def update_exercise(id, options={})
  whitelist = [
      'name',
      'description',
      'body',
      'status',
      'slug',
      'specs',
      'starting_code',
      'canonical_solution',
      'language',
      'run_strategy_attributes',
      'starting_code',
      'canonical_solution',
      'instructions'
  ]

  options = convert_keys(options)
  params = whitelist_params(options, whitelist)
  url = "#{@api_base_path}/exercises/#{id}"

  handle_timeouts do
    response = self.class.put(url,
                              headers: auth_header,
                              body: { exercise: params })
    convert_response(response, "exercise")
  end
end