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
-
#get_course_import(options = {}) ⇒ ScormEngine::Models::CourseImport
This method will check the status of a course import.
-
#post_course_import(options = {}) ⇒ ScormEngine::Models::CourseImport
Import a course.
Instance Method Details
#get_course_import(options = {}) ⇒ ScormEngine::Models::CourseImport
This method will check the status of a course import.
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/scorm_engine/api/endpoints/courses/import.rb', line 82 def get_course_import( = {}) (, :id) response = get("courses/importJobs/#{[:id]}") # jobId is not always returned. :why: result = response&.success? ? ScormEngine::Models::CourseImport.new_from_api({ "jobId" => [:id] }.merge(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.
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 |
# File 'lib/scorm_engine/api/endpoints/courses/import.rb', line 43 def post_course_import( = {}) (, :course_id) require_exclusive_option(, :url, :pathname) query_params = { course: [:course_id], mayCreateNewVersion: !![:may_create_new_version] } # When loading from a URL, we pass the URL and course name in the # body as JSON. When loading from a file, the file's contents get # placed in the body. In the latter case we can't pass in any other # parameters, because the SCORM server doesn't know how to deal # with multipart bodies and will become confused. body = if [:url] { url: [:url], courseName: [:name] || [:course_id] } elsif [:pathname] { file: ::Faraday::UploadIO.new([:pathname], "application/zip") } end response = post("courses/importJobs", query_params, body) result = response&.success? ? ScormEngine::Models::CourseImport.new_from_api(response.body) : nil Response.new(raw_response: response, result: result) end |