scorm_engine 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/lib/scorm_engine/api/endpoints.rb +12 -2
  3. data/lib/scorm_engine/api/endpoints/destinations.rb +225 -0
  4. data/lib/scorm_engine/api/endpoints/dispatches.rb +301 -0
  5. data/lib/scorm_engine/faraday/connection.rb +0 -1
  6. data/lib/scorm_engine/models.rb +3 -0
  7. data/lib/scorm_engine/models/destination.rb +27 -0
  8. data/lib/scorm_engine/models/dispatch.rb +51 -0
  9. data/lib/scorm_engine/models/dispatch_zip.rb +18 -0
  10. data/lib/scorm_engine/version.rb +1 -1
  11. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_delete_destination/raises_ArgumentError_when_destination_id_is_missing.yml +32 -0
  12. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_delete_destination/returns_success_even_when_id_is_invalid.yml +32 -0
  13. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_delete_destination/works.yml +32 -0
  14. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_get_destination/fails_when_id_is_invalid.yml +38 -0
  15. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_get_destination/is_successful.yml +38 -0
  16. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_get_destination/results/sucessfully_creates_the_destination_attributes.yml +38 -0
  17. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_get_destination_dispatches_registration_count/fails_when_invalid.yml +38 -0
  18. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_get_destination_dispatches_registration_count/works.yml +36 -0
  19. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_get_destinations/_more_option_pagination_/returns_all_the_destinations.yml +73 -0
  20. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_get_destinations/_more_option_pagination_/returns_the_more_key_in_the_raw_response.yml +38 -0
  21. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_get_destinations/_since_option/fails_when_passed_an_invalid_value.yml +37 -0
  22. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_get_destinations/_since_option/works.yml +38 -0
  23. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_get_destinations/is_successful.yml +38 -0
  24. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_get_destinations/results/is_an_enumerator_of_Destination_models.yml +38 -0
  25. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_get_destinations/results/sucessfully_creates_the_Destination_attributes.yml +38 -0
  26. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_post_destination/is_successful.yml +61 -0
  27. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_post_destination/is_successful_even_if_the_destination_id_is_not_unique.yml +32 -0
  28. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_post_destination_dispatches_enabled/fails_when_invalid.yml +38 -0
  29. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_post_destination_dispatches_enabled/works_when_false.yml +32 -0
  30. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_post_destination_dispatches_enabled/works_when_true.yml +32 -0
  31. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_post_destination_dispatches_registration_instancing/fails_when_invalid.yml +38 -0
  32. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_post_destination_dispatches_registration_instancing/works_when_false.yml +32 -0
  33. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_post_destination_dispatches_registration_instancing/works_when_true.yml +32 -0
  34. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_put_destination/is_successful.yml +32 -0
  35. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_put_destination/results/sucessfully_creates_the_destination_attributes.yml +67 -0
  36. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_delete_dispatch/returns_success_even_when_id_is_invalid.yml +30 -0
  37. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_delete_dispatch/works.yml +30 -0
  38. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatch/fails_when_id_is_invalid.yml +36 -0
  39. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatch/is_successful.yml +36 -0
  40. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatch/results/sucessfully_creates_the_dispatch_attributes.yml +36 -0
  41. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatch_enabled/is_false_when_disabled.yml +63 -0
  42. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatch_enabled/is_true_when_enabled.yml +63 -0
  43. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatch_zip/fails_given_an_invalid_id.yml +36 -0
  44. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatch_zip/fails_given_an_invalid_type.yml +34 -0
  45. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatch_zip/works.yml +37 -0
  46. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatch_zip/works_when_type_is_AICC.yml +37 -0
  47. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatch_zip/works_when_type_is_SCORM12.yml +37 -0
  48. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatch_zip/works_when_type_is_SCORM20043RDEDITION.yml +35 -0
  49. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatches/_more_option_pagination_/returns_all_the_dispatches.yml +69 -0
  50. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatches/_more_option_pagination_/returns_the_more_key_in_the_raw_response.yml +36 -0
  51. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatches/_since_option/fails_when_passed_an_invalid_value.yml +35 -0
  52. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatches/_since_option/works.yml +36 -0
  53. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatches/is_successful.yml +36 -0
  54. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatches/results/is_an_enumerator_of_dispatch_models.yml +36 -0
  55. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatches/results/sucessfully_creates_the_dispatch_attributes.yml +69 -0
  56. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_post_dispatch/is_successful.yml +59 -0
  57. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_put_dispatch/is_successful.yml +32 -0
  58. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_put_dispatch/results/sucessfully_creates_the_dispatch_attributes.yml +65 -0
  59. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_put_dispatch_enabled/fails_when_invalid.yml +38 -0
  60. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_put_dispatch_enabled/works_when_false.yml +32 -0
  61. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_put_dispatch_enabled/works_when_true.yml +32 -0
  62. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Registrations/_post_registration/is_successful_even_when_given_a_UTF8/slashed_username.yml +97 -0
  63. data/spec/scorm_engine/api/endpoints/destinations_spec.rb +215 -0
  64. data/spec/scorm_engine/api/endpoints/dispatches_spec.rb +286 -0
  65. data/spec/scorm_engine/api/endpoints/registrations_spec.rb +12 -0
  66. data/spec/scorm_engine/models/destination_spec.rb +21 -0
  67. data/spec/scorm_engine/models/dispatch_spec.rb +85 -0
  68. data/spec/scorm_engine/models/dispatch_zip_spec.rb +18 -0
  69. data/spec/support/scorm_engine.rb +21 -0
  70. metadata +78 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 19b624a8b425c5651d2f7e68b7594963df61dbe48fde93b08ed69fc01a5e7011
4
- data.tar.gz: 9c470f779c3db4b799d9c7dc71dd1c37160672109362c9fdf352a39c1d66dec7
3
+ metadata.gz: ba57a4d4caf90f530093fe8825533d1b32f59ebd809979363f5b1faaea2df09f
4
+ data.tar.gz: 68d0fec6173b12b04d7a734aae2869f1c28c9f3f3848a2bccd237951e26f06ff
5
5
  SHA512:
6
- metadata.gz: 3021b7b2e610eea43fb0ade3670c0f5ae7439c22cca01f1f7ad6547d6d02533ad68013c6bd51d5ff3caa3c4399e157baf66d17baf1a14d7ee5277ea33c1aaefa
7
- data.tar.gz: 2fb5e15db8a311ba060f8239ca84f4a73952b85c683f70165061ac796fb191075a211bf537b5ce6a49453be8055f8ae504e50ca92338214c06bf9162c98a5058
6
+ metadata.gz: f7c16bfb4b244fbe5fbf0c981d65c00b5fc728c50fce375ffe19d8bfbb94d4e8b9e9f435d92ebde05aa9e96b53059991d24158ff7410a43f04bbf8c70a5c4eca
7
+ data.tar.gz: 070d20fcc913d2d32d487a08b7bf06adce1bbac5fbe2692f446775e9a61a5e74a0a5758311501e2d21150c4622d4d476e0ceb58a9cfa31673c651f1814e29967
@@ -2,6 +2,8 @@ require_relative "endpoints/about"
2
2
  require_relative "endpoints/courses"
3
3
  require_relative "endpoints/courses/configuration"
4
4
  require_relative "endpoints/courses/import"
5
+ require_relative "endpoints/destinations"
6
+ require_relative "endpoints/dispatches"
5
7
  require_relative "endpoints/ping"
6
8
  require_relative "endpoints/registrations"
7
9
  require_relative "endpoints/registrations/configuration"
@@ -14,6 +16,8 @@ module ScormEngine
14
16
  include Courses
15
17
  include Courses::Configuration
16
18
  include Courses::Import
19
+ include Destinations
20
+ include Dispatches
17
21
  include Ping
18
22
  include Registrations
19
23
  include Registrations::Configuration
@@ -41,10 +45,16 @@ module ScormEngine
41
45
  end
42
46
 
43
47
  def require_option(haystack, *needles)
44
- value = needles.reduce(haystack) { |m, o| m[o.to_sym] || m[o.to_s] }
45
- return unless value.nil? # || (value.respond_to?(:empty?) && value.empty?)
48
+ value = needles.reduce(haystack) { |m, o| value_for_key(m, o) }
49
+ return unless value.nil?
46
50
  raise ArgumentError, "Required option #{needles.join("/")} missing"
47
51
  end
52
+
53
+ def value_for_key(memo, obj)
54
+ return memo[obj.to_sym] if memo.key?(obj.to_sym)
55
+ return memo[obj.to_s] if memo.key?(obj.to_s)
56
+ nil
57
+ end
48
58
  end
49
59
  end
50
60
  end
@@ -0,0 +1,225 @@
1
+ module ScormEngine
2
+ module Api
3
+ module Endpoints
4
+ module Destinations
5
+
6
+ #
7
+ # Get a list of destinations.
8
+ #
9
+ # @see http://rustici-docs.s3.amazonaws.com/engine/2017.1.x.dispatch/api-dispatch.html#tenant__destinations_get
10
+ #
11
+ # @param [Hash] options
12
+ #
13
+ # @option options [String] :course_id
14
+ # Limit the results to destinations that have dispatches of the specified course.
15
+ #
16
+ # @option options [DateTime] :since
17
+ # Only destinations updated since the specified ISO 8601 TimeStamp
18
+ # (inclusive) are included. If a time zone is not specified, the
19
+ # server's time zone will be used.
20
+ #
21
+ # @return [Enumerator<ScormEngine::Models::Destination>]
22
+ #
23
+ def get_destinations(options = {})
24
+ options = options.dup
25
+
26
+ response = get("destinations", options)
27
+
28
+ result = Enumerator.new do |enum|
29
+ loop do
30
+ response.success? && response.body["destinations"].each do |destination|
31
+ enum << ScormEngine::Models::Destination.new_from_api(destination)
32
+ end
33
+ break if !response.success? || response.body["more"].nil?
34
+ response = get(response.body["more"])
35
+ end
36
+ end
37
+
38
+ Response.new(raw_response: response, result: result)
39
+ end
40
+
41
+ #
42
+ # Create a destination.
43
+ #
44
+ # @see http://rustici-docs.s3.amazonaws.com/engine/2017.1.x.dispatch/api-dispatch.html#tenant__destinations_post
45
+ #
46
+ # @param [Hash] options
47
+ #
48
+ # @option options [String] :destination_id
49
+ # The destination ID.
50
+ #
51
+ # @option options [String] :name (:destination_id)
52
+ # The destination's name.
53
+ #
54
+ # @return [ScormEngine::Response]
55
+ #
56
+ def post_destination(options = {})
57
+ require_options(options, :destination_id)
58
+
59
+ options = options.dup
60
+ options[:name] ||= options[:destination_id]
61
+
62
+ body = {
63
+ destinations: [
64
+ id: options[:destination_id].to_s,
65
+ data: {
66
+ name: options[:name].to_s,
67
+ },
68
+ ]
69
+ }
70
+
71
+ response = post("destinations", {}, body)
72
+
73
+ Response.new(raw_response: response)
74
+ end
75
+
76
+ #
77
+ # Get a destination.
78
+ #
79
+ # @see http://rustici-docs.s3.amazonaws.com/engine/2017.1.x.dispatch/api-dispatch.html#tenant__destinations__destinationId__get
80
+ #
81
+ # @param [Hash] options
82
+ #
83
+ # @option options [String] :destination_id
84
+ # The ID of the destination to get.
85
+ #
86
+ # @return [ScormEngine::Models::Destination]
87
+ #
88
+ def get_destination(options = {})
89
+ require_options(options, :destination_id)
90
+
91
+ response = get("destinations/#{options[:destination_id]}")
92
+
93
+ # merge options to pick up destination_id which isn't passed back in the response
94
+ result = response.success? ? ScormEngine::Models::Destination.new_from_api(options.merge(response.body)) : nil
95
+
96
+ Response.new(raw_response: response, result: result)
97
+ end
98
+
99
+ #
100
+ # Update a destination.
101
+ #
102
+ # @see http://rustici-docs.s3.amazonaws.com/engine/2017.1.x.dispatch/api-dispatch.html#tenant__destinations__destinationId__put
103
+ #
104
+ # @param [Hash] options
105
+ #
106
+ # @option options [String] :destination_id
107
+ # The destination ID.
108
+ #
109
+ # @option options [String] :name
110
+ # The destination's new name.
111
+ #
112
+ # @return [ScormEngine::Response]
113
+ #
114
+ def put_destination(options = {})
115
+ require_options(options, :destination_id, :name)
116
+
117
+ options = options.dup
118
+
119
+ body = {
120
+ name: options[:name],
121
+ }
122
+
123
+ response = put("destinations/#{options[:destination_id]}", {}, body)
124
+
125
+ Response.new(raw_response: response)
126
+ end
127
+
128
+ #
129
+ # Delete a destination.
130
+ #
131
+ # Deleting a destination will also delete all dispatches for that
132
+ # destination.
133
+ #
134
+ # @see http://rustici-docs.s3.amazonaws.com/engine/2017.1.x.dispatch/api-dispatch.html#tenant__destinations_delete
135
+ #
136
+ # @param [Hash] options
137
+ #
138
+ # @option options [String] :destination_id
139
+ # The ID of the destination to delete.
140
+ #
141
+ # @return [ScormEngine::Response]
142
+ #
143
+ def delete_destination(options = {})
144
+ require_options(options, :destination_id)
145
+
146
+ response = delete("destinations/#{options[:destination_id]}")
147
+
148
+ Response.new(raw_response: response)
149
+ end
150
+
151
+ #
152
+ # Enable or disable all related dispatches.
153
+ #
154
+ # @see http://rustici-docs.s3.amazonaws.com/engine/2017.1.x.dispatch/api-dispatch.html#tenant__destinations__destinationId__dispatches_enabled_post
155
+ #
156
+ # @param [Hash] options
157
+ #
158
+ # @option options [String] :destination_id
159
+ # The ID of the destination
160
+ #
161
+ # @option options [Boolean] :enabled
162
+ # The enabledness of all related dispatches
163
+ #
164
+ # @return [ScormEngine::Response]
165
+ #
166
+ def post_destination_dispatches_enabled(options = {})
167
+ require_options(options, :destination_id, :enabled)
168
+
169
+ body = options[:enabled].to_s
170
+
171
+ response = post("destinations/#{options[:destination_id]}/dispatches/enabled", {}, body)
172
+
173
+ Response.new(raw_response: response)
174
+ end
175
+
176
+ #
177
+ # Enable or disable registration instancing.
178
+ #
179
+ # @see http://rustici-docs.s3.amazonaws.com/engine/2017.1.x.dispatch/api-dispatch.html#tenant__destinations__destinationId__dispatches_registrationInstancing_post
180
+ #
181
+ # @param [Hash] options
182
+ #
183
+ # @option options [String] :destination_id
184
+ # The ID of the destination to delete.
185
+ #
186
+ # @option options [Boolean] :enabled
187
+ # The enabledness of the registration instancing
188
+ #
189
+ # @return [ScormEngine::Response]
190
+ #
191
+ def post_destination_dispatches_registration_instancing(options = {})
192
+ require_options(options, :destination_id, :enabled)
193
+
194
+ body = options[:enabled].to_s
195
+
196
+ response = post("destinations/#{options[:destination_id]}/dispatches/registrationInstancing", {}, body)
197
+
198
+ Response.new(raw_response: response)
199
+ end
200
+
201
+ #
202
+ # Get an aggregate count of all related dispatch registrations.
203
+ #
204
+ # @see http://rustici-docs.s3.amazonaws.com/engine/2017.1.x.dispatch/api-dispatch.html#tenant__destinations__destinationId__dispatches_registrationCount_get
205
+ #
206
+ # @param [Hash] options
207
+ #
208
+ # @option options [String] :destination_id
209
+ # The ID of the destination to delete.
210
+ #
211
+ # @return [Integer]
212
+ #
213
+ def get_destination_dispatches_registration_count(options = {})
214
+ require_options(options, :destination_id)
215
+
216
+ response = get("destinations/#{options[:destination_id]}/dispatches/registrationCount")
217
+
218
+ result = response.success? ? response.body.to_i : nil
219
+
220
+ Response.new(raw_response: response, result: result)
221
+ end
222
+ end
223
+ end
224
+ end
225
+ end
@@ -0,0 +1,301 @@
1
+ module ScormEngine
2
+ module Api
3
+ module Endpoints
4
+ module Dispatches
5
+
6
+ #
7
+ # Get a list of dispatches.
8
+ #
9
+ # @see http://rustici-docs.s3.amazonaws.com/engine/2017.1.x.dispatch/api-dispatch.html#tenant__dispatches_get
10
+ #
11
+ # @param [Hash] options
12
+ #
13
+ # @option options [String] :course_id
14
+ # Limit the results to dispatches of the specified course.
15
+ #
16
+ # @option options [DateTime] :since
17
+ # Only dispatches updated since the specified ISO 8601 TimeStamp
18
+ # (inclusive) are included. If a time zone is not specified, the
19
+ # server's time zone will be used.
20
+ #
21
+ # @return [Enumerator<ScormEngine::Models::Dispatch>]
22
+ #
23
+ def get_dispatches(options = {})
24
+ options = options.dup
25
+
26
+ response = get("dispatches", options)
27
+
28
+ result = Enumerator.new do |enum|
29
+ loop do
30
+ response.success? && response.body["dispatches"].each do |course|
31
+ enum << ScormEngine::Models::Dispatch.new_from_api(course)
32
+ end
33
+ break if !response.success? || response.body["more"].nil?
34
+ response = get(response.body["more"])
35
+ end
36
+ end
37
+
38
+ Response.new(raw_response: response, result: result)
39
+ end
40
+
41
+ #
42
+ # Create a dispatch.
43
+ #
44
+ # @see http://rustici-docs.s3.amazonaws.com/engine/2017.1.x.dispatch/api-dispatch.html#tenant__dispatches_post
45
+ #
46
+ # @param [Hash] options
47
+ #
48
+ # @option options [String] :dispatch_id
49
+ # The dispatch ID.
50
+ #
51
+ # @option options [String] :destination_id
52
+ # The destination ID.
53
+ #
54
+ # @option options [String] :course_id
55
+ # The course ID.
56
+ #
57
+ # @option options [Boolean] :allow_new_registrations (false)
58
+ # If true, then new registrations can be created for this dispatch.
59
+ #
60
+ # @option options [Boolean] :instanced (false)
61
+ # If true, then a new registration instance will be created if the
62
+ # client LMS doesn't provide launch data for an existing one.
63
+ # Otherwise, the same instance will always be used for the given
64
+ # cmi.learner_id.
65
+ #
66
+ # @option options [Integer] :registration_cap (0)
67
+ # The maximum number of registrations that can be created for this
68
+ # dispatch, where '0' means 'unlimited registrations'.
69
+ #
70
+ # @option options [Date] :expiration_date ("none")
71
+ # The date after which this dispatch will be disabled as an ISO 8601
72
+ # string, or \"none\" for no expiration date.
73
+ #
74
+ # @option options [String] :external_config ("")
75
+ # Serialized external configuration information to include when
76
+ # launching the dispatched package.
77
+ #
78
+ # @return [ScormEngine::Response]
79
+ #
80
+ def post_dispatch(options = {})
81
+ require_options(options, :dispatch_id, :destination_id, :course_id)
82
+
83
+ options = options.dup
84
+
85
+ options[:allow_new_registrations] = false unless options[:allow_new_registrations]
86
+ options[:instanced] = false unless options[:instanced]
87
+ options[:registration_cap] = [0, options[:registration_cap].to_i].max
88
+ options[:expiration_date] = begin
89
+ date = options[:expiration_date]
90
+ date = date.is_a?(String) ? Date.parse(date) : date
91
+ date&.iso8601 # might be nil
92
+ rescue ArgumentError
93
+ "none"
94
+ end
95
+
96
+ body = {
97
+ dispatches: [
98
+ id: options[:dispatch_id],
99
+ data: {
100
+ destinationId: options[:destination_id],
101
+ courseId: options[:course_id],
102
+ allowNewRegistrations: options[:allow_new_registrations],
103
+ instanced: options[:instanced],
104
+ registrationCap: options[:registration_cap],
105
+ expirationDate: options[:expiration_date],
106
+ externalConfig: options[:external_config],
107
+ },
108
+ ]
109
+ }
110
+
111
+ response = post("dispatches", {}, body)
112
+
113
+ Response.new(raw_response: response)
114
+ end
115
+
116
+ #
117
+ # Get a dispatch.
118
+ #
119
+ # @see http://rustici-docs.s3.amazonaws.com/engine/2017.1.x.dispatch/api-dispatch.html#tenant__dispatches__dispatchId__get
120
+ #
121
+ # @param [Hash] options
122
+ #
123
+ # @option options [String] :dispatch_id
124
+ # The ID of the dispatch to get.
125
+ #
126
+ # @return [ScormEngine::Models::Dispatch]
127
+ #
128
+ def get_dispatch(options = {})
129
+ require_options(options, :dispatch_id)
130
+
131
+ response = get("dispatches/#{options[:dispatch_id]}")
132
+
133
+ result = response.success? ? ScormEngine::Models::Dispatch.new_from_api(response.body) : nil
134
+
135
+ Response.new(raw_response: response, result: result)
136
+ end
137
+
138
+ #
139
+ # Update a dispatch.
140
+ #
141
+ # @see http://rustici-docs.s3.amazonaws.com/engine/2017.1.x.dispatch/api-dispatch.html#tenant__dispatches__dispatchId__put
142
+ #
143
+ # @param [Hash] options
144
+ #
145
+ # @option options [String] :dispatch_id
146
+ # The dispatch ID.
147
+ #
148
+ # @option options [String] :destination_id
149
+ # The destination ID.
150
+ #
151
+ # @option options [String] :course_id
152
+ # The course ID.
153
+ #
154
+ # @option options [Boolean] :allow_new_registrations (false)
155
+ # If true, then new registrations can be created for this dispatch.
156
+ #
157
+ # @option options [Boolean] :instanced (false)
158
+ # If true, then a new registration instance will be created if the
159
+ # client LMS doesn't provide launch data for an existing one.
160
+ # Otherwise, the same instance will always be used for the given
161
+ # cmi.learner_id.
162
+ #
163
+ # @option options [Integer] :registration_cap (0)
164
+ # The maximum number of registrations that can be created for this
165
+ # dispatch, where '0' means 'unlimited registrations'.
166
+ #
167
+ # @option options [Date] :expiration_date ("none")
168
+ # The date after which this dispatch will be disabled as an ISO 8601
169
+ # string, or \"none\" for no expiration date.
170
+ #
171
+ # @option options [String] :external_config ("")
172
+ # Serialized external configuration information to include when
173
+ # launching the dispatched package.
174
+ #
175
+ # @return [ScormEngine::Response]
176
+ #
177
+ def put_dispatch(options = {})
178
+ require_options(options, :dispatch_id, :destination_id, :course_id)
179
+
180
+ body = {
181
+ destinationId: options[:destination_id],
182
+ courseId: options[:course_id],
183
+ allowNewRegistrations: options[:allow_new_registrations],
184
+ instanced: options[:instanced],
185
+ registrationCap: options[:registration_cap],
186
+ expirationDate: options[:expiration_date],
187
+ externalConfig: options[:external_config],
188
+ }
189
+
190
+ response = put("dispatches/#{options[:dispatch_id]}", {}, body)
191
+
192
+ Response.new(raw_response: response)
193
+ end
194
+
195
+ #
196
+ # Delete a dispatch.
197
+ #
198
+ # @see http://rustici-docs.s3.amazonaws.com/engine/2017.1.x.dispatch/api-dispatch.html#tenant__dispatches__dispatchId__delete
199
+ #
200
+ # @param [Hash] options
201
+ #
202
+ # @option options [String] :dispatch_id
203
+ # The ID of the dispatch to delete.
204
+ #
205
+ # @return [ScormEngine::Response]
206
+ #
207
+ def delete_dispatch(options = {})
208
+ require_options(options, :dispatch_id)
209
+
210
+ response = delete("dispatches/#{options[:dispatch_id]}")
211
+
212
+ Response.new(raw_response: response)
213
+ end
214
+
215
+ #
216
+ # Get the enabled status of a dispatch.
217
+ #
218
+ # @see http://rustici-docs.s3.amazonaws.com/engine/2017.1.x.dispatch/api-dispatch.html#tenant__dispatches__dispatchId__enabled_get
219
+ #
220
+ # @param [Hash] options
221
+ #
222
+ # @option options [String] :dispatch_id
223
+ # The ID of the dispatch to delete.
224
+ #
225
+ # @return [ScormEngine::Response]
226
+ #
227
+ def get_dispatch_enabled(options = {})
228
+ require_options(options, :dispatch_id)
229
+
230
+ response = get("dispatches/#{options[:dispatch_id]}/enabled")
231
+
232
+ result = response.success? ? response.body : nil
233
+
234
+ Response.new(raw_response: response, result: result)
235
+ end
236
+
237
+ #
238
+ # Enable or disable the dispatch.
239
+ #
240
+ # @see http://rustici-docs.s3.amazonaws.com/engine/2017.1.x.dispatch/api-dispatch.html#tenant__dispatches__dispatchId__enabled_put
241
+ #
242
+ # @param [Hash] options
243
+ #
244
+ # @option options [String] :dispatch_id
245
+ # The ID of the dispatch
246
+ #
247
+ # @option options [Boolean] :enabled
248
+ # The enabledness of the dispatch
249
+ #
250
+ # @return [ScormEngine::Response]
251
+ #
252
+ def put_dispatch_enabled(options = {})
253
+ require_options(options, :dispatch_id, :enabled)
254
+
255
+ body = options[:enabled].to_s
256
+
257
+ response = put("dispatches/#{options[:dispatch_id]}/enabled", {}, body)
258
+
259
+ Response.new(raw_response: response)
260
+ end
261
+
262
+ #
263
+ # Get the ZIP dispatch package.
264
+ #
265
+ # @see http://rustici-docs.s3.amazonaws.com/engine/2017.1.x.dispatch/api-dispatch.html#tenant__dispatches__dispatchId__zip_get
266
+ #
267
+ # @param [Hash] options
268
+ #
269
+ # @option options [String] :dispatch_id
270
+ # The ID of the dispatch to delete.
271
+ #
272
+ # @option options [String] :type (SCORM12)
273
+ # The type of dispatch package to export (SCORM12, SCORM20043RDEDITION or AICC)
274
+ #
275
+ # @return [ScormEngine::Models::DispatchZip]
276
+ #
277
+ def get_dispatch_zip(options = {})
278
+ require_options(options, :dispatch_id)
279
+
280
+ options = options.dup
281
+ dispatch_id = options.delete(:dispatch_id)
282
+ options[:type] ||= "SCORM12"
283
+
284
+ response = get("dispatches/#{dispatch_id}/zip", options)
285
+
286
+ result = if response.success?
287
+ ScormEngine::Models::DispatchZip.new(
288
+ dispatch_id: dispatch_id,
289
+ type: options[:type],
290
+ filename: response.headers["content-disposition"].match(/; filename="(.*?)"/)&.captures&.first,
291
+ body: response.body,
292
+ )
293
+ end
294
+
295
+ Response.new(raw_response: response, result: result)
296
+ end
297
+
298
+ end
299
+ end
300
+ end
301
+ end