scorm_engine 0.7.2 → 0.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a068e71a4053cf2657b2d017dad3c137bda74798e59f198badb017e2728f397f
4
- data.tar.gz: '0494b968c5585104707284aa79014dbd3b4279609705d5eb7ef3823972f9d8e7'
3
+ metadata.gz: 196bff6485fdd38ce3e44ec9e52434e9f2bea54abfa011d352f27f8ecf871914
4
+ data.tar.gz: 58386090f8f6a295ac499225ff028a8e06d7db08433cd1bb696341fe33c7a0b8
5
5
  SHA512:
6
- metadata.gz: 955980d7acc49984f4814c489f83d3451b0ff636fec501f10069e9ca2ba3f54e8507e304c489c3c4cb5a3ef4257df722bf6356c68c6fa0117d08e2500a3936e6
7
- data.tar.gz: d3d2eaa33f15c0ad4c13ab708c79c0ad9238e515f2914b292e74926b35e32328573d981679937601bcae6e02590a95093b51e5d701a844d31c2295b0cfee7811
6
+ metadata.gz: 103cc84797716352274604627f5170b32c2f102af7bee0b12c1a0e83241129bd3b108f10b311303adbe2636f32f135bd3c3507f6ee21cf1bccffc904fea9db82
7
+ data.tar.gz: fd075fb87cea8faefb90cfba079614d0dee9fe7a2bd2c3200ed96ada9f08d66a21110fdaab47d3a8c64c06e1d68d50e717e64a475f9fac0077e8556e8a2f0c89
@@ -8,6 +8,7 @@ require_relative "endpoints/ping"
8
8
  require_relative "endpoints/registrations"
9
9
  require_relative "endpoints/registrations/configuration"
10
10
  require_relative "endpoints/registrations/launch_history"
11
+ require_relative "endpoints/tenants/configuration"
11
12
 
12
13
  module ScormEngine
13
14
  module Api
@@ -22,6 +23,7 @@ module ScormEngine
22
23
  include Registrations
23
24
  include Registrations::Configuration
24
25
  include Registrations::LaunchHistory
26
+ include Tenants::Configuration
25
27
 
26
28
  private
27
29
 
@@ -1,5 +1,5 @@
1
1
  #
2
- # TODO: Consider consolidating this and Registrations::Configuration, but only
2
+ # TODO: Consider consolidating this and [Registrations|Tenants]::Configuration, but only
3
3
  # after we're sure they are really 99.9% the same in terms of functionality.
4
4
  #
5
5
  module ScormEngine
@@ -1,5 +1,5 @@
1
1
  #
2
- # TODO: Consider consolidating this and Courses::Configuration, but only after we're
2
+ # TODO: Consider consolidating this and [Courses|Tenants]::Configuration, but only after we're
3
3
  # sure they are really 99.9% the same in terms of functionality.
4
4
  #
5
5
  module ScormEngine
@@ -0,0 +1,108 @@
1
+ #
2
+ # TODO: Consider consolidating this and [Courses|Registrations]::Configuration, but only
3
+ # after we're sure they are really 99.9% the same in terms of functionality.
4
+ #
5
+ module ScormEngine
6
+ module Api
7
+ module Endpoints
8
+ module Tenants
9
+ module Configuration
10
+
11
+ #
12
+ # Returns the effective value of every setting at this level, as well
13
+ # as the effective value of any setting at a more specific level.
14
+ #
15
+ # @see http://rustici-docs.s3.amazonaws.com/engine/2017.1.x/api.html#tenant__configuration_get
16
+ #
17
+ # @return [ScormEngine::Models::TenantConfiguration]
18
+ #
19
+ def get_tenant_configuration
20
+ response = get("configuration")
21
+
22
+ result = response.success? ? ScormEngine::Models::TenantConfiguration.new_from_api(response.body) : nil
23
+
24
+ Response.new(raw_response: response, result: result)
25
+ end
26
+
27
+ #
28
+ # Bulk set configuration settings via POST request.
29
+ #
30
+ # @see http://rustici-docs.s3.amazonaws.com/engine/2017.1.x/api.html#tenant__configuration_post
31
+ #
32
+ # @param [Hash] options
33
+ #
34
+ # @option options [Hash] :settings
35
+ # Key/value pairs of configuration options to set.
36
+ #
37
+ # @return [ScormEngine::Response]
38
+ #
39
+ def post_tenant_configuration(options = {})
40
+ require_options(options, :settings)
41
+
42
+ options = options.dup
43
+ settings = options.delete(:settings)
44
+
45
+ body = { settings: settings.map { |k, v| { "settingId" => k, "value" => v.to_s } } }
46
+
47
+ response = post("configuration", options, body)
48
+
49
+ Response.new(raw_response: response)
50
+ end
51
+
52
+ #
53
+ # Returns the effective value for this configuration setting for the resource being configured.
54
+ #
55
+ # @see http://rustici-docs.s3.amazonaws.com/engine/2017.1.x/api.html#tenant__configuration__settingId__get
56
+ #
57
+ # @param [Hash] options
58
+ #
59
+ # @option options [String] :setting_id
60
+ # The ID of the setting to get.
61
+ #
62
+ # @return [String]
63
+ #
64
+ def get_tenant_configuration_setting(options = {})
65
+ require_options(options, :setting_id)
66
+
67
+ options = options.dup
68
+ setting_id = options.delete(:setting_id)
69
+
70
+ response = get("configuration/#{setting_id}", options)
71
+
72
+ result = response.success? ? response.body["value"] : nil
73
+
74
+ Response.new(raw_response: response, result: result)
75
+ end
76
+
77
+ #
78
+ # Sets the value for this configuration setting, for the resource being configured.
79
+ #
80
+ # @see http://rustici-docs.s3.amazonaws.com/engine/2017.1.x/api.html#tenant__configuration__settingId__put
81
+ #
82
+ # @param [Hash] options
83
+ #
84
+ # @option options [String] :setting_id
85
+ # The ID of the setting to set.
86
+ #
87
+ # @option options [String] :value ("")
88
+ # The value of the setting to set.
89
+ #
90
+ # @return [ScormEngine::Response]
91
+ #
92
+ def put_tenant_configuration_setting(options = {})
93
+ require_options(options, :setting_id)
94
+
95
+ options = options.dup
96
+ setting_id = options.delete(:setting_id)
97
+
98
+ body = { value: options.delete(:value).to_s }
99
+
100
+ response = put("configuration/#{setting_id}", options, body)
101
+
102
+ Response.new(raw_response: response)
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
@@ -12,3 +12,4 @@ require_relative "models/registration_activity_detail"
12
12
  require_relative "models/registration_configuration"
13
13
  require_relative "models/registration_launch_history"
14
14
  require_relative "models/registration_runtime_interaction"
15
+ require_relative "models/tenant_configuration"
@@ -0,0 +1,34 @@
1
+ module ScormEngine
2
+ module Models
3
+ class TenantConfiguration < Base
4
+ # @attr
5
+ #
6
+ # @return [Hash]
7
+ attr_accessor :settings
8
+
9
+ def self.new_from_api(options = {})
10
+ this = new
11
+
12
+ this.options = options.dup
13
+ this.settings = get_settings_from_api(options)
14
+ this
15
+ end
16
+
17
+ #
18
+ # Extract and normalize the settings from the API options.
19
+ #
20
+ # @param [Hash] options
21
+ # The API options hash
22
+ #
23
+ # @return [Hash]
24
+ # A hash of key/value pairs.
25
+ #
26
+ def self.get_settings_from_api(options = {})
27
+ options["configurationItems"].reduce({}) do |m, o|
28
+ m[o["id"]] = o["value"]
29
+ m
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,3 +1,3 @@
1
1
  module ScormEngine
2
- VERSION = "0.7.2".freeze
2
+ VERSION = "0.7.3".freeze
3
3
  end
@@ -0,0 +1,126 @@
1
+ #
2
+ # NOTE: This spec will only run if a real scorm engine is available!
3
+ # This is because the results returned expose sensitive information
4
+ # and we'd rather they not get cached to VCR fixtures.
5
+ #
6
+ RSpec.describe ScormEngine::Api::Endpoints::Tenants::Configuration do
7
+ around do |example|
8
+ if scorm_engine_is_available?
9
+ VCR.turned_off do
10
+ example.run
11
+ end
12
+ else
13
+ warn "Not running because SCORM engine is not truly available."
14
+ end
15
+ end
16
+
17
+ let(:subject) { scorm_engine_client }
18
+
19
+ describe "#get_tenant_configuration" do
20
+ let(:response) { subject.get_tenant_configuration }
21
+
22
+ it "is successful" do
23
+ expect(response.success?).to eq true
24
+ end
25
+
26
+ describe "results" do
27
+ it "makes settings available as key/value pairs" do
28
+ settings = response.result.settings
29
+ aggregate_failures do
30
+ # just a sampling
31
+ expect(settings.key?("ApiPostbackTimeoutSeconds")).to be_truthy
32
+ expect(settings.key?("ApiUseSignedLaunchLinks")).to be_truthy
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ describe "#post_tenant_configuration" do
39
+ let(:response) {
40
+ subject.post_tenant_configuration(
41
+ settings: { "ApiPostbackTimeoutSeconds" => "15",
42
+ "ApiUseSignedLaunchLinks" => "true" }
43
+ )
44
+ }
45
+
46
+ it "is successful" do
47
+ expect(response.success?).to eq true
48
+ end
49
+
50
+ it "persists the settings" do
51
+ response # trigger the api
52
+ sleep 30
53
+
54
+ configuration = subject.get_tenant_configuration.result
55
+ expect(configuration.settings["ApiPostbackTimeoutSeconds"]).to eq "15"
56
+ expect(configuration.settings["ApiUseSignedLaunchLinks"]).to eq "true"
57
+
58
+ subject.post_tenant_configuration(
59
+ settings: { "ApiPostbackTimeoutSeconds" => "20",
60
+ "ApiUseSignedLaunchLinks" => "false" }
61
+ )
62
+ sleep 30
63
+
64
+ configuration = subject.get_tenant_configuration.result
65
+ expect(configuration.settings["ApiPostbackTimeoutSeconds"]).to eq "20"
66
+ expect(configuration.settings["ApiUseSignedLaunchLinks"]).to eq "false"
67
+ end
68
+
69
+ it "fails when settings are invalid" do
70
+ response = subject.post_tenant_configuration(settings: { "NonExistentSettingTotesBogus" => "YES" })
71
+ expect(response.success?).to eq false
72
+ expect(response.status).to eq 400
73
+ expect(response.message).to match(/No configuration setting found with id.*NonExistentSettingTotesBogus/)
74
+ end
75
+ end
76
+
77
+ describe "#get_tenant_configuration_setting" do
78
+ let(:response) {
79
+ subject.put_tenant_configuration_setting(setting_id: "ApiPostbackTimeoutSeconds", value: 42)
80
+ sleep 30
81
+ subject.get_tenant_configuration_setting(setting_id: "ApiPostbackTimeoutSeconds")
82
+ }
83
+
84
+ it "is successful" do
85
+ expect(response.success?).to eq true
86
+ end
87
+
88
+ describe "results" do
89
+ it "returns the value as a string" do
90
+ expect(response.result).to eq "42"
91
+ end
92
+ end
93
+
94
+ it "fails when setting_id is invalid" do
95
+ response = subject.get_tenant_configuration_setting(setting_id: "NonExistentSettingTotesBogus")
96
+ expect(response.success?).to eq false
97
+ expect(response.status).to eq 400
98
+ expect(response.message).to match(/No configuration setting found with id.*NonExistentSettingTotesBogus/)
99
+ expect(response.result).to eq nil
100
+ end
101
+ end
102
+
103
+ describe "#put_tenant_configuration_setting" do
104
+ let(:response) { subject.put_tenant_configuration_setting(setting_id: "ApiPostbackTimeoutSeconds", value: 99) }
105
+
106
+ it "is successful" do
107
+ expect(response.success?).to eq true
108
+ end
109
+
110
+ describe "results" do
111
+ it "persists the changes" do
112
+ response # trigger the api
113
+ subject.put_tenant_configuration_setting(setting_id: "ApiPostbackTimeoutSeconds", value: 100)
114
+ new_response = subject.get_tenant_configuration_setting(setting_id: "ApiPostbackTimeoutSeconds")
115
+ expect(new_response.result).to eq "100"
116
+ end
117
+ end
118
+
119
+ it "fails when setting_id is invalid" do
120
+ response = subject.get_tenant_configuration_setting(setting_id: "NonExistentSettingTotesBogus", value: "42")
121
+ expect(response.success?).to eq false
122
+ expect(response.status).to eq 400
123
+ expect(response.message).to match(/No configuration setting found with id.*NonExistentSettingTotesBogus/)
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,16 @@
1
+ RSpec.describe ScormEngine::Models::TenantConfiguration do
2
+ describe ".new_from_api" do
3
+ describe ":settings" do
4
+ it "a hash built from configurationItems" do
5
+ config = described_class.new_from_api(
6
+ "configurationItems" => [
7
+ { "id" => "Foo", "value" => "YES" },
8
+ { "id" => "Bar", "value" => "123" },
9
+ ]
10
+ )
11
+ expect(config.settings["Foo"]).to eq "YES"
12
+ expect(config.settings["Bar"]).to eq "123"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -18,6 +18,7 @@ end
18
18
  INSERTED_CASSETTES = Set.new
19
19
  module CassetteReporter
20
20
  def insert_cassette(name, options = {})
21
+ return unless VCR.turned_on?
21
22
  INSERTED_CASSETTES << VCR::Cassette.new(name, options).file
22
23
  super
23
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scorm_engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philip Hallstrom
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-15 00:00:00.000000000 Z
11
+ date: 2019-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -185,6 +185,7 @@ files:
185
185
  - lib/scorm_engine/api/endpoints/registrations.rb
186
186
  - lib/scorm_engine/api/endpoints/registrations/configuration.rb
187
187
  - lib/scorm_engine/api/endpoints/registrations/launch_history.rb
188
+ - lib/scorm_engine/api/endpoints/tenants/configuration.rb
188
189
  - lib/scorm_engine/client.rb
189
190
  - lib/scorm_engine/configuration.rb
190
191
  - lib/scorm_engine/faraday/connection.rb
@@ -204,6 +205,7 @@ files:
204
205
  - lib/scorm_engine/models/registration_configuration.rb
205
206
  - lib/scorm_engine/models/registration_launch_history.rb
206
207
  - lib/scorm_engine/models/registration_runtime_interaction.rb
208
+ - lib/scorm_engine/models/tenant_configuration.rb
207
209
  - lib/scorm_engine/response.rb
208
210
  - lib/scorm_engine/utils.rb
209
211
  - lib/scorm_engine/version.rb
@@ -367,6 +369,7 @@ files:
367
369
  - spec/scorm_engine/api/endpoints/registrations/configuration_spec.rb
368
370
  - spec/scorm_engine/api/endpoints/registrations/launch_history_spec.rb
369
371
  - spec/scorm_engine/api/endpoints/registrations_spec.rb
372
+ - spec/scorm_engine/api/endpoints/tenants/configuration_spec.rb
370
373
  - spec/scorm_engine/configuration_spec.rb
371
374
  - spec/scorm_engine/faraday/connection_spec.rb
372
375
  - spec/scorm_engine/models/base_spec.rb
@@ -382,6 +385,7 @@ files:
382
385
  - spec/scorm_engine/models/registration_launch_history_spec.rb
383
386
  - spec/scorm_engine/models/registration_runtime_interaction_spec.rb
384
387
  - spec/scorm_engine/models/registration_spec.rb
388
+ - spec/scorm_engine/models/tenant_configuration_spec.rb
385
389
  - spec/scorm_engine/utils_spec.rb
386
390
  - spec/scorm_engine/version_spec.rb
387
391
  - spec/scorm_engine_spec.rb