Module: ScormEngine::Api::Endpoints::Dispatches

Included in:
ScormEngine::Api::Endpoints
Defined in:
lib/scorm_engine/api/endpoints/dispatches.rb

Instance Method Summary collapse

Instance Method Details

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

Delete a dispatch.

Parameters:

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

Options Hash (options):

  • :dispatch_id (String)

    The ID of the dispatch to delete.

Returns:

See Also:



200
201
202
203
204
205
206
# File 'lib/scorm_engine/api/endpoints/dispatches.rb', line 200

def delete_dispatch(options = {})
  require_options(options, :dispatch_id)

  response = delete("dispatches/#{options[:dispatch_id]}")

  Response.new(raw_response: response)
end

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

Reset the registration count and last reset time of a dispatch.

Parameters:

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

Options Hash (options):

  • :dispatch_id (String)

    The ID of the dispatch to get.

Returns:

See Also:



326
327
328
329
330
331
332
# File 'lib/scorm_engine/api/endpoints/dispatches.rb', line 326

def delete_dispatch_registration_count(options = {})
  require_options(options, :dispatch_id)

  response = delete("dispatches/#{options[:dispatch_id]}/registrationCount")

  Response.new(raw_response: response)
end

#get_dispatch(options = {}) ⇒ ScormEngine::Models::Dispatch

Get a dispatch.

Parameters:

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

Options Hash (options):

  • :dispatch_id (String)

    The ID of the dispatch to get.

Returns:

See Also:



117
118
119
120
121
122
123
124
125
126
# File 'lib/scorm_engine/api/endpoints/dispatches.rb', line 117

def get_dispatch(options = {})
  require_options(options, :dispatch_id)

  response = get("dispatches/#{options[:dispatch_id]}")

  # merge options to pick up dispatch_id which isn't passed back in the response
  result = response.success? ? ScormEngine::Models::Dispatch.new_from_api({ "id" => options[:dispatch_id] }.merge(response.body)) : nil

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

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

Get the enabled status of a dispatch.

Parameters:

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

Options Hash (options):

  • :dispatch_id (String)

    The ID of the dispatch to delete.

Returns:

See Also:



220
221
222
223
224
225
226
227
228
# File 'lib/scorm_engine/api/endpoints/dispatches.rb', line 220

def get_dispatch_enabled(options = {})
  require_options(options, :dispatch_id)

  response = get("dispatches/#{options[:dispatch_id]}/enabled")

  result = response.success? ? response.body : nil

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

#get_dispatch_registration_count(options = {}) ⇒ ScormEngine::Models::DispatchRegistrationCount

Get the registration count and last reset time of a dispatch.

Parameters:

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

Options Hash (options):

  • :dispatch_id (String)

    The ID of the dispatch to get.

Returns:

See Also:



303
304
305
306
307
308
309
310
311
312
# File 'lib/scorm_engine/api/endpoints/dispatches.rb', line 303

def get_dispatch_registration_count(options = {})
  require_options(options, :dispatch_id)

  response = get("dispatches/#{options[:dispatch_id]}/registrationCount")

  # merge options to pick up dispatch_id which isn't passed back in the response
  result = response.success? ? ScormEngine::Models::DispatchRegistrationCount.new_from_api({ "id" => options[:dispatch_id] }.merge(response.body)) : nil

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

#get_dispatch_zip(options = {}) ⇒ ScormEngine::Models::DispatchZip

Get the ZIP dispatch package.

Parameters:

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

Options Hash (options):

  • :dispatch_id (String)

    The ID of the dispatch to delete.

  • :type (String) — default: SCORM12

    The type of dispatch package to export (SCORM12, SCORM2004-3RD or AICC)

Returns:

See Also:



270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/scorm_engine/api/endpoints/dispatches.rb', line 270

def get_dispatch_zip(options = {})
  require_options(options, :dispatch_id)

  options = options.dup
  dispatch_id = options.delete(:dispatch_id)
  options[:type] = options[:type]&.upcase || "SCORM12"

  response = get("dispatches/#{dispatch_id}/zip", options)

  result = if response.success?
             ScormEngine::Models::DispatchZip.new(
               dispatch_id: dispatch_id,
               type: options[:type],
               filename: response.headers["content-disposition"].match(/; filename="(.*?)"/)&.captures&.first,
               body: response.body,
             )
           end

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

#get_dispatches(options = {}) ⇒ Enumerator<ScormEngine::Models::Dispatch>

Get a list of dispatches.

Parameters:

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

Options Hash (options):

  • :course_id (String)

    Limit the results to dispatches of the specified course.

  • :since (DateTime)

    Only dispatches 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:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/scorm_engine/api/endpoints/dispatches.rb', line 23

def get_dispatches(options = {})
  options = options.dup

  response = get("dispatches", options)

  result = Enumerator.new do |enum|
    loop do
      response.success? && response.body["dispatches"].each do |course|
        enum << ScormEngine::Models::Dispatch.new_from_api(course)
      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_dispatch(options = {}) ⇒ ScormEngine::Response

Create a dispatch.

Parameters:

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

Options Hash (options):

  • :dispatch_id (String)

    The dispatch ID.

  • :destination_id (String)

    The destination ID.

  • :course_id (String)

    The course ID.

  • :allow_new_registrations (Boolean) — default: false

    If true, then new registrations can be created for this dispatch.

  • :instanced (Boolean) — default: false

    If true, then a new registration instance will be created if the client LMS doesn’t provide launch data for an existing one. Otherwise, the same instance will always be used for the given cmi.learner_id.

  • :registration_cap (Integer) — default: 0

    The maximum number of registrations that can be created for this dispatch, where ‘0’ means ‘unlimited registrations’.

  • :expiration_date (Date) — default: "none"

    The date after which this dispatch will be disabled as an ISO 8601 string, or “none” for no expiration date.

  • :external_config (String) — default: ""

    Serialized external configuration information to include when launching the dispatched package.

Returns:

See Also:



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/scorm_engine/api/endpoints/dispatches.rb', line 80

def post_dispatch(options = {})
  require_options(options, :dispatch_id, :destination_id, :course_id)

  options = coerce_dispatch_options(options.dup)

  body = {
    dispatches: [
      id: options[:dispatch_id],
      data: {
        destinationId: options[:destination_id],
        courseId: options[:course_id],
        allowNewRegistrations: options[:allow_new_registrations],
        instanced: options[:instanced],
        registrationCap: options[:registration_cap],
        expirationDate: options[:expiration_date],
        externalConfig: options[:external_config],
      },
    ]
  }

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

  Response.new(raw_response: response)
end

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

Update a dispatch.

Parameters:

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

Options Hash (options):

  • :dispatch_id (String)

    The dispatch ID.

  • :destination_id (String)

    The destination ID.

  • :course_id (String)

    The course ID.

  • :allow_new_registrations (Boolean)

    If true, then new registrations can be created for this dispatch.

  • :instanced (Boolean)

    If true, then a new registration instance will be created if the client LMS doesn’t provide launch data for an existing one. Otherwise, the same instance will always be used for the given cmi.learner_id.

  • :registration_cap (Integer)

    The maximum number of registrations that can be created for this dispatch, where ‘0’ means ‘unlimited registrations’.

  • :expiration_date (Date)

    The date after which this dispatch will be disabled as an ISO 8601 string, or “none” for no expiration date.

  • :external_config (String) — default: ""

    Serialized external configuration information to include when launching the dispatched package.

Returns:

See Also:



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/scorm_engine/api/endpoints/dispatches.rb', line 167

def put_dispatch(options = {})
  require_options(options, :dispatch_id, :destination_id, :course_id,
                  :allow_new_registrations, :instanced, :registration_cap, :expiration_date)

  options = coerce_dispatch_options(options.dup)

  body = {
    destinationId: options[:destination_id],
    courseId: options[:course_id],
    allowNewRegistrations: options[:allow_new_registrations],
    instanced: options[:instanced],
    registrationCap: options[:registration_cap],
    expirationDate: options[:expiration_date],
    externalConfig: options[:external_config],
  }

  response = put("dispatches/#{options[:dispatch_id]}", {}, body)

  Response.new(raw_response: response)
end

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

Enable or disable the dispatch.

Parameters:

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

Options Hash (options):

  • :dispatch_id (String)

    The ID of the dispatch

  • :enabled (Boolean)

    The enabledness of the dispatch

Returns:

See Also:



245
246
247
248
249
250
251
252
253
# File 'lib/scorm_engine/api/endpoints/dispatches.rb', line 245

def put_dispatch_enabled(options = {})
  require_options(options, :dispatch_id, :enabled)

  body = options[:enabled].to_s

  response = put("dispatches/#{options[:dispatch_id]}/enabled", {}, body)

  Response.new(raw_response: response)
end