Module: ScormEngine::Api::Endpoints::Registrations

Included in:
ScormEngine::Api::Endpoints
Defined in:
lib/scorm_engine/api/endpoints/registrations.rb,
lib/scorm_engine/api/endpoints/registrations/configuration.rb,
lib/scorm_engine/api/endpoints/registrations/launch_history.rb

Defined Under Namespace

Modules: Configuration, LaunchHistory

Instance Method Summary collapse

Instance Method Details

#delete_registration(options = {}) ⇒ ScormEngine::Response

Delete a registration.

Parameters:

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

Options Hash (options):

  • :registration_id (String)

    ID for the registration.

Returns:

See Also:


188
189
190
191
192
193
194
195
196
197
# File 'lib/scorm_engine/api/endpoints/registrations.rb', line 188

def delete_registration(options = {})
  require_options(options, :registration_id)

  options = options.dup
  registration_id = options.delete(:registration_id)

  response = delete("registrations/#{registration_id}")

  Response.new(raw_response: response)
end

#get_registration_exists(options = {}) ⇒ ScormEngine::Response

Does this registration exist? You can also use the 'instance' parameter to check if a particular instance of a registrations exists.

Parameters:

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

Options Hash (options):

  • :registration_id (String)

    ID for the registration.

  • :instance (String)

    () The instance of this registration to use. If not provided, the latest instance will be used.

Returns:

See Also:


126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/scorm_engine/api/endpoints/registrations.rb', line 126

def get_registration_exists(options = {})
  require_options(options, :registration_id)

  options = options.dup
  registration_id = options.delete(:registration_id)

  response = get("registrations/#{registration_id}", options)

  result = response.success? ? response.body["exists"] : nil

  Response.new(raw_response: response, result: result)
end

#get_registration_instances(options = {}) ⇒ Enumerator<ScormEngine::Models::Registration>

Get all the instances of this the registration specified by the registration ID

Multiple instances of a registration are created based on the value you have for the setting “WhenToRestartRegistration”. By default, Engine will “restart” a registration once that registration is completed and there is a newer version of that registration's package is available. If both of those conditions are met when the registration is launched, then Engine will create a new instance for that registration.

Parameters:

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

Options Hash (options):

  • :registration_id (String)

    ID for the registration.

  • :before (DateTime)

    () Only registrations updated before the specified ISO 8601 TimeStamp (inclusive) are included. If a time zone is not specified, the server's time zone will be used.

  • :since (DateTime)

    () Only registrations updated since the specified ISO 8601 TimeStamp (inclusive) are included. If a time zone is not specified, the server's time zone will be used.

Returns:

See Also:


87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/scorm_engine/api/endpoints/registrations.rb', line 87

def get_registration_instances(options = {})
  require_options(options, :registration_id)

  options = options.dup
  registration_id = options.delete(:registration_id)

  response = get("registrations/#{registration_id}/instances", options)

  result = Enumerator.new do |enum|
    loop do
      response.success? && response.body["registrations"].each do |registration|
        enum << ScormEngine::Models::Registration.new_from_api(registration)
      end
      break if !response.success? || response.body["more"].nil?
      response = get(response.body["more"])
    end
  end

  Response.new(raw_response: response, result: result)
end

#get_registration_progress(options = {}) ⇒ ScormEngine::Models::Registration

Get registration summary

Parameters:

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

Options Hash (options):

  • :registration_id (String)

    ID for the registration.

  • :instance (String)

    () The instance of this registration to use. If not provided, the latest instance will be used.

  • :detail (Boolean) — default: false

    Whether or not to populate 'activityDetails'.

Returns:

See Also:


159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/scorm_engine/api/endpoints/registrations.rb', line 159

def get_registration_progress(options = {})
  require_options(options, :registration_id)

  options = options.dup
  registration_id = options.delete(:registration_id)
  detail = !!options.delete(:detail)

  url = "registrations/#{registration_id}/progress"
  url += "/detail" if detail

  response = get(url, options)

  result = response.success? ? ScormEngine::Models::Registration.new_from_api(response.body) : nil

  Response.new(raw_response: response, result: result)
end

#get_registrations(options = {}) ⇒ Enumerator<ScormEngine::Models::Registration>

Note:

Note the “since” parameter exists to allow retreiving only registrations that have changed, and the “before” parameter exists to allow retreiving only registrations that haven't changed.

Gets a list of registrations including a summary of the status of each registration.

Parameters:

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

Options Hash (options):

  • :before (DateTime)

    () Only registrations updated before the specified ISO 8601 TimeStamp (inclusive) are included. If a time zone is not specified, the server's time zone will be used.

  • :since (DateTime)

    () Only registrations updated since the specified ISO 8601 TimeStamp (inclusive) are included. If a time zone is not specified, the server's time zone will be used.

  • :course_id (String)

    () Only registrations for the specified course id will be included.

  • :learner_id (String)

    () Only registrations for the specified learner id will be included.

Returns:

See Also:


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/scorm_engine/api/endpoints/registrations.rb', line 37

def get_registrations(options = {})
  options = options.dup
  options[:courseId] = options.delete(:course_id) if options.key?(:course_id)
  options[:learnerId] = options.delete(:learner_id) if options.key?(:learner_id)

  response = get("registrations", options)

  result = Enumerator.new do |enum|
    loop do
      response.success? && response.body["registrations"].each do |registration|
        enum << ScormEngine::Models::Registration.new_from_api(registration)
      end
      break if !response.success? || response.body["more"].nil?
      response = get(response.body["more"])
    end
  end

  Response.new(raw_response: response, result: result)
end

#post_registration(options = {}) ⇒ ScormEngine::Response

Create a registration.

Parameters:

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

Options Hash (options):

  • :course_id (String)

    The course ID.

  • :registration_id (String)

    The registration's ID. Must be unique.

  • :learner/:id (String)

    The learner's ID.

  • :learner/:first_name (String)

    The learner's first name.

  • :learner/:last_name (String)

    The learner's last name.

  • :post_back/:url (String)

    () Specifies an optional override URL for which to post activity and status data in real time as the course is completed. By default all of these settings are read from your configuration, so only specify this if you need to control it on a per-registration basis.

  • :post_back/:auth_type (String) — default: "FORM"

    Optional parameter to specify how to authorize against the given postbackurl, can be 'FORM' or 'HTTPBASIC'. If form authentication, the username and password for authentication are submitted as form fields 'username' and 'password', and the registration data as the form field 'data'. If HTTP Basic Authentication is used, the username and password are placed in the standard Authorization HTTP header, and the registration data is the body of the message (sent as application/json content type).

  • :post_back/:user_name (String)

    () The user name to be used in authorizing the postback of data to the URL specified by postback url.

  • :post_back/:password (String)

    () The password to be used in authorizing the postback of data to the URL specified by postback url.

  • :post_back/:results_format (String) — default: "COURSE"

    This parameter allows you to specify a level of detail in the information that is posted back while the course is being taken. It may be one of three values: 'COURSE' (course summary), 'ACTIVITY' (activity summary), or 'FULL' (full detail), and is set to 'COURSE' by default. The information will be posted as JSON using the same schema as what is returned in the /progress and /progress/detail endpoints.

Returns:

See Also:


256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/scorm_engine/api/endpoints/registrations.rb', line 256

def post_registration(options = {})
  require_options(options, :course_id, :registration_id, [:learner, :id], [:learner, :first_name], [:learner, :last_name])

  options = options.dup

  body = {
    courseId: options[:course_id],
    registrationId: options[:registration_id],
    learner: {
      id: options[:learner][:id],
      firstName: options[:learner][:first_name],
      lastName: options[:learner][:last_name],
    },
  }

  if options[:post_back]
    body[:postBack] = {
      url: options[:post_back][:url],
      authType: options[:post_back][:auth_type]&.upcase,
      userName: options[:post_back][:user_name],
      password: options[:post_back][:password],
      resultsFormat: options[:post_back][:results_format]&.upcase,
    }.reject { |_k, v| v.nil? }
  end

  response = post("registrations", {}, body)

  Response.new(raw_response: response)
end