Module: ScormEngine::Api::Endpoints::Courses

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

Defined Under Namespace

Modules: Configuration, Import

Instance Method Summary collapse

Instance Method Details

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

Delete a course

Parameters:

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

Options Hash (options):

  • :course_id (String)

    The ID of the course to delete.

Returns:

See Also:



59
60
61
62
63
64
65
# File 'lib/scorm_engine/api/endpoints/courses.rb', line 59

def delete_course(options = {})
  require_options(options, :course_id)

  response = delete("courses/#{options[:course_id]}")

  Response.new(raw_response: response)
end

#get_course_detail(options = {}) ⇒ ScormEngine::Models::Course

Get the details of a course

Parameters:

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

Options Hash (options):

  • :course_id (String)

    The ID of the course to get.

  • :version (Integer) — default: nil

    The version of this course to use. If not provided, the latest version will be used.

Returns:

See Also:



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/scorm_engine/api/endpoints/courses.rb', line 83

def get_course_detail(options = {})
  require_options(options, :course_id)

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

  response = get("courses/#{course_id}/detail", options)

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

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

#get_course_preview(options = {}) ⇒ String

Returns the launch link to use to preview this course

Parameters:

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

Options Hash (options):

  • :course_id (String)

    The ID of the course to get.

  • :version (Integer) — default: nil

    The version of this course to use. If not provided, the latest version will be used.

  • :expiry (Integer) — default: 0

    Number of seconds from now this link will expire in. Use 0 for no expiration.

  • :redirect_on_exit_url (String)

    The URL the application should redirect to when the learner exits a course. If not specified, configured value will be used.

Returns:

  • (String)

See Also:



120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/scorm_engine/api/endpoints/courses.rb', line 120

def get_course_preview(options = {})
  require_options(options, :course_id)

  options = options.dup
  course_id = options.delete(:course_id)
  options[:redirectOnExitUrl] = options.delete(:redirect_on_exit_url) if options.key?(:redirect_on_exit_url)

  response = get("courses/#{course_id}/preview", options)

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

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

#get_courses(options = {}) ⇒ Enumerator<ScormEngine::Models::Course>

Get the list of courses

Parameters:

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

Options Hash (options):

  • :course_id (String)

    The ID of the single course to retrieve. If set no other options are respected. Note that multiple results may be returned if the course has multiple versions.

  • :since (DateTime)

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



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/scorm_engine/api/endpoints/courses.rb', line 26

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

  path = "courses"
  path = "courses/#{options.delete(:course_id)}" if options[:course_id]

  response = get(path, options)

  result = Enumerator.new do |enum|
    loop do
      response.success? && response.body["courses"].each do |course|
        enum << ScormEngine::Models::Course.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