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

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

Instance Method Summary collapse

Instance Method Details

#get_course_import(options = {}) ⇒ ScormEngine::Models::CourseImport

This method will check the status of a course import.

Parameters:

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

Options Hash (options):

  • :id (String)

    The id of the import to check.

Returns:

See Also:



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

def get_course_import(options = {})
  require_options(options, :id)

  response = get("courses/importJobs/#{options[:id]}")

  # jobId is not always returned. :why:
  result = response&.success? ? ScormEngine::Models::CourseImport.new_from_api({ "jobId" => options[:id] }.merge(response.raw_response.body)) : nil

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

#post_course_import(options = {}) ⇒ ScormEngine::Models::CourseImport

Import a course

Either the actual contents of the zip file to import may be posted, or JSON that references the remote location to import from.

Parameters:

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

Options Hash (options):

  • :course_id (String)

    A unique identifier your application will use to identify the course after import. Your application is responsible both for generating this unique ID and for keeping track of the ID for later use.

  • :url (String)

    URL path to the .zip package representing the course or the manifest file defining the course. Mutually exclusive with :pathname.

  • :pathname (String)

    Local file path to the .zip package representing the course. Mutually exclusive with :url.

  • :may_create_new_version (Boolean) — default: false

    Is it OK to create a new version of this course? If this is set to false and the course already exists, the upload will fail. If true and the course already exists then a new version will be created. No effect if the course doesn’t already exist.

  • :name (String) — default: value of :course

    A unique identifier that may be used as part of the directory name on disk.

Returns:

See Also:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/scorm_engine/api/endpoints/courses/import.rb', line 43

def post_course_import(options = {})
  require_options(options, :course_id)
  require_exclusive_option(options, :url, :pathname)

  # API v2 uses courseId as query param, v1 used 'course'
  query_params = if current_api_version == 2
                   {
                     courseId: options[:course_id],
                     mayCreateNewVersion: !!options[:may_create_new_version]
                   }
                 else
                   # Original v1 API parameter structure
                   {
                     course: options[:course_id],
                     mayCreateNewVersion: !!options[:may_create_new_version]
                   }
                 end

  # Handle file content posting for API requests
  body = if options[:url]
           # API v2 (SCORM Engine v23) doesn't accept courseName parameter or courseId in body
           if current_api_version == 2
             { url: options[:url] }
           else
             # API v1 compatibility - include courseName
             { url: options[:url], courseName: options[:name] || options[:course_id] }
           end
         elsif options[:pathname]
           # File upload via multipart form data
           if current_api_version == 2
             { file: options[:pathname] }
           else
             # API v1 compatibility - include courseName for file uploads
             { file: options[:pathname], courseName: options[:name] || options[:course_id] }
           end
         else
           raise ArgumentError, "Either :url or :pathname must be provided for course import"
         end

  response = post("courses/importJobs", query_params, body)
  result = response&.success? ? ScormEngine::Models::CourseImport.new_from_api(response.raw_response.body) : nil

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