Class: Citrix::Training::Namespace::Trainings

Inherits:
Object
  • Object
show all
Includes:
Helpers::HttpClient, Helpers::Initializer
Defined in:
lib/citrix/training/namespace/trainings.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::HttpClient

#http_client, #json_parser, #url_for

Methods included from Helpers::Initializer

#initialize

Instance Attribute Details

#credentialsObject

Set the credentials.



9
10
11
# File 'lib/citrix/training/namespace/trainings.rb', line 9

def credentials
  @credentials
end

Instance Method Details

#allObject

Retrieve information on all scheduled trainings for a given organizer.

The trainings are returned in the order in which they were created. Completed trainings are not included; ongoing trainings with past sessions are included along with the past sessions. If the organizer does not have any scheduled trainings, the response will be empty.

Endpoint: developer.citrixonline.com/api/gototraining-rest-api/apimethod/get-trainings



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/citrix/training/namespace/trainings.rb', line 59

def all
  url = url_for("organizers", credentials.organizer_key, "trainings")
  response = http_client.get(url)

  if response.ok?
    trainings = response.data.map do |attrs|
      Resource::Training.new Resource::Training.deserialize(attrs)
    end
  end

  [response, trainings]
end

#create(attributes) ⇒ Object

Create a new training.

response, training = client.trainings.create({
  name: "Ruby on Rails",
  description: "Getting started with Ruby on Rails",
  timezone: "America/Sao_Paulo",
  dates: [date],
  web_registration: false,
  confirmation_email: false,
  organizers: [organizer]
})

if response.ok?
else
end

Options:

  • ‘name`: Name of the training. Required.

  • ‘description`: Description of the training. Required.

  • ‘timezone`: Time zone of the training. Required.

  • ‘dates`: Array containing instances of `Citrix::Training::TrainingDate`. Required.

  • ‘organizers`: Array containing instances of `Citrix::Training::Organizer`. Optional.

  • ‘web_registration`: Disable/Enable web registration. Optional.

  • ‘confirmation_email`: Disable/Enable confirmation e-mails. Optional.

Endpoint: developer.citrixonline.com/api/gototraining-rest-api/apimethod/create-training-0



39
40
41
42
43
44
45
46
47
48
# File 'lib/citrix/training/namespace/trainings.rb', line 39

def create(attributes)
  training = Resource::Training.new(attributes)

  url = url_for("organizers", credentials.organizer_key, "trainings")
  response = http_client.post(url, training.serialize)

  training.key = json_parser.load(response.body) if response.ok?

  [response, training]
end

#find(key) ⇒ Object

Find a scheduled or completed training by its key.



73
74
75
76
77
78
79
80
81
82
# File 'lib/citrix/training/namespace/trainings.rb', line 73

def find(key)
  url = url_for("organizers", credentials.organizer_key, "trainings", key)
  response = http_client.get(url)

  if response.ok?
    training = Resource::Training.new Resource::Training.deserialize(response.data)
  end

  [response, training]
end

#remove(training) ⇒ Object

Deletes a scheduled or completed training.

For scheduled trainings, it deletes all scheduled sessions of the training. For completed trainings, the sessions remain in the database. No email is sent to organizers or registrants, but when participants attempt to start or join the training, they are directed to a page that states: ‘Training Not Found: The training you are trying to join is no longer available.`

response = client.trainings.remove(training)
response.ok? #=> successfully removed


96
97
98
99
# File 'lib/citrix/training/namespace/trainings.rb', line 96

def remove(training)
  url = url_for("organizers", credentials.organizer_key, "trainings", training.key)
  http_client.delete(url)
end