Class: EasyLlama::Client::Learners

Inherits:
Api
  • Object
show all
Defined in:
lib/easyllama/learners.rb

Overview

This class provides methods for interacting with the Easy Llama API for learners.

Constant Summary

Constants inherited from Api

Api::DEFAULT_API_VERSION, Api::DEFAULT_URI_BASE

Instance Method Summary collapse

Methods inherited from Api

#initialize, #parse_response!, #send_request

Constructor Details

This class inherits a constructor from EasyLlama::Client::Api

Instance Method Details

#all(page: 1) ⇒ Array

Sends a GET request to retrieve all learners.

Parameters:

  • page (Integer) (defaults to: 1)

    The page number.

Returns:

  • (Array)

    The learners or an error message.



11
12
13
14
15
# File 'lib/easyllama/learners.rb', line 11

def all(page: 1)
  response = send_request(path: '/learners', body: { page: })

  parse_response!(response, 'learners')
end

#archive(id) ⇒ Object

Sends a DELETE request to archive a learner by ID.

Parameters:

  • id (Integer)

    The ID of the learner.

Returns:

  • (Object)

    An error message or an empty hash.



82
83
84
85
86
# File 'lib/easyllama/learners.rb', line 82

def archive(id)
  response = send_request(path: "/learners/#{id}", method: :delete)

  parse_response!(response)
end

#assign_training_to_learner(training_id:, learner_id:) ⇒ Object

Sends a POST request to assign a training to a learner.

Parameters:

  • training_id (Integer)

    The ID of the training.

  • learner_id (Integer)

    The ID of the learner.

Returns:

  • (Object)

    The learner training or an error message.



53
54
55
56
57
58
59
60
61
# File 'lib/easyllama/learners.rb', line 53

def assign_training_to_learner(training_id:, learner_id:)
  response = send_request(
    path: "/learners/#{learner_id}/learner_trainings",
    method: :post,
    body: { learner_id:, training_id: }
  )

  parse_response!(response, 'learner_training')
end

#create(learner_attributes = {}) ⇒ Object

Sends a POST request to create a learner.

Parameters:

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

    The attributes of the learner.

Returns:

  • (Object)

    The created learner or an error message.



31
32
33
34
35
# File 'lib/easyllama/learners.rb', line 31

def create(learner_attributes = {})
  response = send_request(path: '/learners', method: :post, body: learner_attributes)

  parse_response!(response, 'learner')
end

#find(id) ⇒ Object

Sends a GET request to retrieve a learner by ID.

Parameters:

  • id (Integer)

    The ID of the learner.

Returns:

  • (Object)

    The learner or an error message.



21
22
23
24
25
# File 'lib/easyllama/learners.rb', line 21

def find(id)
  response = send_request(path: "/learners/#{id}")

  parse_response!(response, 'learner')
end

#unassign_training_from_learner(learner_training_id:, learner_id:) ⇒ Object

Sends a DELETE request to unassign a training from a learner.

Parameters:

  • learner_training_id (Integer)

    The ID of the learner training.

  • learner_id (Integer)

    The ID of the learner.

Returns:

  • (Object)

    An error message or an empty hash.



68
69
70
71
72
73
74
75
76
# File 'lib/easyllama/learners.rb', line 68

def unassign_training_from_learner(learner_training_id:, learner_id:)
  response = send_request(
    path: "/learners/#{learner_id}/learner_trainings/#{learner_training_id}",
    method: :delete,
    body: { learner_id:, learner_training_id: }
  )

  parse_response!(response)
end

#update(id, learner_attributes = {}) ⇒ Object

Sends a PATCH request to update a learner by ID.

Parameters:

  • id (Integer)

    The ID of the learner.

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

    The attributes to update.

Returns:

  • (Object)

    The updated learner or an error message.



42
43
44
45
46
# File 'lib/easyllama/learners.rb', line 42

def update(id, learner_attributes = {})
  response = send_request(path: "/learners/#{id}", method: :patch, body: learner_attributes)

  parse_response!(response, 'learner')
end