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:



76
77
78
79
80
81
82
# File 'lib/scorm_engine/api/endpoints/courses.rb', line 76

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:



100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/scorm_engine/api/endpoints/courses.rb', line 100

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.raw_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:



137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/scorm_engine/api/endpoints/courses.rb', line 137

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.raw_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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/scorm_engine/api/endpoints/courses.rb', line 26

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

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

  response = get(path, options)

  result = Enumerator.new do |enum|
    if single_course_id
      # Single course endpoint returns course data directly
      if response.success? && response.raw_response.body.is_a?(Hash) # rubocop:disable Style/IfUnlessModifier
        enum << ScormEngine::Models::Course.new_from_api(response.raw_response.body)
      end
    else
      # Multiple courses endpoint returns array in "courses" key
      loop do
        break unless response.success? && response.raw_response.body.is_a?(Hash)

        courses = response.raw_response.body["courses"]
        break unless courses.is_a?(Array)

        courses.each do |course|
          enum << ScormEngine::Models::Course.new_from_api(course)
        end

        more_url = response.raw_response.body["more"]
        break if more_url.nil?

        response = get(more_url)
      end
    end
  end

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