Class: Spartacus

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

Instance Method Summary collapse

Constructor Details

#initialize(api_jwt) ⇒ Spartacus

Returns a new instance of Spartacus.


6
7
8
# File 'lib/spartacus.rb', line 6

def initialize(api_jwt)
  @api_jwt = api_jwt
end

Instance Method Details

#base_pathString

Set Base API Path

Returns:

  • (String)

    The base api path


12
13
14
# File 'lib/spartacus.rb', line 12

def base_path
  "http://localhost:3000/api/v1"
end

#handle_timeoutsObject

Handle API timouts


17
18
19
20
21
22
23
# File 'lib/spartacus.rb', line 17

def handle_timeouts
  begin
    yield
  rescue Net::OpenTimeout, Net::ReadTimeout
    {}
  end
end

#update_checkpoint(id, options = {}) ⇒ HTTParty::Response

Update a checkpoint

Examples:

Update a checkpoint

SpartacusClient.new.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.

  • :points (Integer)

    Checkpoint point.

  • :body_and_assignment (String)

    Checkpoint body and Assignment

Returns:

  • (HTTParty::Response)

    The updated checkpoint


38
39
40
41
42
43
44
45
46
47
48
# File 'lib/spartacus.rb', line 38

def update_checkpoint(id, options={})
  accepted_params = ['name', 'summary', 'body', 'assignment', 'points', 'body_and_assignment']
  checkpoint_params = options.select {|k, v| accepted_params.include?(k) }
  update_checkpoint_url = "#{base_path}/checkpoints/#{id}"

  handle_timeouts do
    self.class.put(update_checkpoint_url,
                   headers: auth_header,
                   query: { checkpoint: checkpoint_params })
  end
end