Module: Checkpoints

Includes:
BaseClient
Included in:
Spartacus
Defined in:
lib/client/checkpoints.rb

Instance Method Summary collapse

Methods included from BaseClient

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

Instance Method Details

#batch_create_checkpoints(section_id = nil, checkpoints = []) ⇒ Array

Create multiple checkpoints in a single request

Examples:

Create multiple checkpoints

Spartacus#batch_create_checkpoints(
  163,
  [
    {
      ids: [],
      name: 'Sample checkpoint 1',
      summary: 'Message from Tamriel',
      body: 'Listen to the Nine',
      position: 1
    },
    ...
  ]
)

Parameters:

  • roadmap_section_id (Integer)

    id for roadmap section the checkpoints belong to.

Returns:

  • (Array)

    Array of the created checkpoints.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/client/checkpoints.rb', line 67

def batch_create_checkpoints(section_id=nil, checkpoints=[])
  url = "#{@api_base_path}/checkpoints/batch_create"

  handle_timeouts do
    response = self.class.post(
      url,
      headers: auth_header,
      body: {
        section_id: section_id,
        checkpoints: checkpoints
      }
    )
    convert_response(response, "checkpoint")
  end
end

#get_checkpoint(id) ⇒ Checkpoint

Get a checkpoint

Examples:

Get a checkpoint

Spartacus#get_checkpoint(1)

Parameters:

  • id (Integer)

    A roadmap section id.

Returns:

  • (Checkpoint)

    The checkpoint.



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

def get_checkpoint(id)
  url = "#{@api_base_path}/checkpoints/#{id}"

  handle_timeouts do
    response = self.class.get(url, headers: auth_header)
    convert_response(response, "checkpoint")
  end
end

#update_checkpoint(id, options = {}) ⇒ Checkpoint

Update a checkpoint

Examples:

Update a checkpoint

Spartacus#update_checkpoint(129, {name: 'Real Cool Checkpoint'})

Parameters:

  • id (Integer)

    A checkpoint id.

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

    A customizable set of options.

Options Hash (options):

  • :name (String)

    Checkpoint name.

  • :summary (String)

    Checkpoint summary.

  • :body (String)

    Checkpoint body.

  • :assignment (String)

    Checkpoint assignment.

  • :assignment (String)

    Checkpoint body and assignment.

  • :points (Integer)

    Checkpoint point.

  • :body_and_assignment (String)

    Checkpoint body and Assignment

Returns:

  • (Checkpoint)

    The updated checkpoint



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/client/checkpoints.rb', line 34

def update_checkpoint(id, options={})
  whitelist = ['name', 'summary', 'body', 'assignment','body_and_assignment', 'points']

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

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