Module: ScormEngine::Api::Endpoints::Dispatches
- Included in:
- ScormEngine::Api::Endpoints
- Defined in:
- lib/scorm_engine/api/endpoints/dispatches.rb
Instance Method Summary collapse
-
#delete_dispatch(options = {}) ⇒ ScormEngine::Response
Delete a dispatch.
-
#get_dispatch(options = {}) ⇒ ScormEngine::Models::Dispatch
Get a dispatch.
-
#get_dispatch_enabled(options = {}) ⇒ ScormEngine::Response
Get the enabled status of a dispatch.
-
#get_dispatch_zip(options = {}) ⇒ ScormEngine::Models::DispatchZip
Get the ZIP dispatch package.
-
#get_dispatches(options = {}) ⇒ Enumerator<ScormEngine::Models::Dispatch>
Get a list of dispatches.
-
#post_dispatch(options = {}) ⇒ ScormEngine::Response
Create a dispatch.
-
#put_dispatch(options = {}) ⇒ ScormEngine::Response
Update a dispatch.
-
#put_dispatch_enabled(options = {}) ⇒ ScormEngine::Response
Enable or disable the dispatch.
Instance Method Details
#delete_dispatch(options = {}) ⇒ ScormEngine::Response
Delete a dispatch.
207 208 209 210 211 212 213 |
# File 'lib/scorm_engine/api/endpoints/dispatches.rb', line 207 def delete_dispatch( = {}) (, :dispatch_id) response = delete("dispatches/#{[:dispatch_id]}") Response.new(raw_response: response) end |
#get_dispatch(options = {}) ⇒ ScormEngine::Models::Dispatch
Get a dispatch.
128 129 130 131 132 133 134 135 136 |
# File 'lib/scorm_engine/api/endpoints/dispatches.rb', line 128 def get_dispatch( = {}) (, :dispatch_id) response = get("dispatches/#{[:dispatch_id]}") result = response.success? ? ScormEngine::Models::Dispatch.new_from_api(response.body) : nil Response.new(raw_response: response, result: result) end |
#get_dispatch_enabled(options = {}) ⇒ ScormEngine::Response
Get the enabled status of a dispatch.
227 228 229 230 231 232 233 234 235 |
# File 'lib/scorm_engine/api/endpoints/dispatches.rb', line 227 def get_dispatch_enabled( = {}) (, :dispatch_id) response = get("dispatches/#{[:dispatch_id]}/enabled") result = response.success? ? response.body : nil Response.new(raw_response: response, result: result) end |
#get_dispatch_zip(options = {}) ⇒ ScormEngine::Models::DispatchZip
Get the ZIP dispatch package.
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'lib/scorm_engine/api/endpoints/dispatches.rb', line 277 def get_dispatch_zip( = {}) (, :dispatch_id) = .dup dispatch_id = .delete(:dispatch_id) [:type] ||= "SCORM12" response = get("dispatches/#{dispatch_id}/zip", ) result = if response.success? ScormEngine::Models::DispatchZip.new( dispatch_id: dispatch_id, type: [: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.
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( = {}) = .dup response = get("dispatches", ) 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.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/scorm_engine/api/endpoints/dispatches.rb', line 80 def post_dispatch( = {}) (, :dispatch_id, :destination_id, :course_id) = .dup [:allow_new_registrations] = false unless [:allow_new_registrations] [:instanced] = false unless [:instanced] [:registration_cap] = [0, [:registration_cap].to_i].max [:expiration_date] = begin date = [:expiration_date] date = date.is_a?(String) ? Date.parse(date) : date date&.iso8601 # might be nil rescue ArgumentError "none" end body = { dispatches: [ id: [:dispatch_id], data: { destinationId: [:destination_id], courseId: [:course_id], allowNewRegistrations: [:allow_new_registrations], instanced: [:instanced], registrationCap: [:registration_cap], expirationDate: [:expiration_date], externalConfig: [:external_config], }, ] } response = post("dispatches", {}, body) Response.new(raw_response: response) end |
#put_dispatch(options = {}) ⇒ ScormEngine::Response
Update a dispatch.
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/scorm_engine/api/endpoints/dispatches.rb', line 177 def put_dispatch( = {}) (, :dispatch_id, :destination_id, :course_id) body = { destinationId: [:destination_id], courseId: [:course_id], allowNewRegistrations: [:allow_new_registrations], instanced: [:instanced], registrationCap: [:registration_cap], expirationDate: [:expiration_date], externalConfig: [:external_config], } response = put("dispatches/#{[:dispatch_id]}", {}, body) Response.new(raw_response: response) end |
#put_dispatch_enabled(options = {}) ⇒ ScormEngine::Response
Enable or disable the dispatch.
252 253 254 255 256 257 258 259 260 |
# File 'lib/scorm_engine/api/endpoints/dispatches.rb', line 252 def put_dispatch_enabled( = {}) (, :dispatch_id, :enabled) body = [:enabled].to_s response = put("dispatches/#{[:dispatch_id]}/enabled", {}, body) Response.new(raw_response: response) end |