pupilfirst_xapi 0.3.5 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f5c38a8fbf57be11cda1429b9cffc1ed6d818ca11a69d220305a2cd0e954125
4
- data.tar.gz: c018dae18cd439930c6d70eba6fb60bafe8014d01a5ce2ae5be6ca3d5556f88c
3
+ metadata.gz: 9671a7b657ac2a6a5db9b4988b50f069d24bde84e08f722e17c9e510f0990f88
4
+ data.tar.gz: 1eb93f047df91dc644ee65372d6a163d732c1d64e3763189de793fdd60ccbe2a
5
5
  SHA512:
6
- metadata.gz: d3d62b03c85f3610a50d7cb3aa0bbbed2fad9ad4d6c3c9aa67fac48f972a64e9a08fdc6d59cc38a7b75e2400efecd2f555d2d6d960c7c889be617432ea347800
7
- data.tar.gz: e525ac790f096b0b70a82727901cc88bacee1aeff9b44ecbca7e227e7d0e52bb2aeb39a3007af0b22b3345f05c54204d930523ec9f374f8d8fdde4650ecc246e
6
+ metadata.gz: 69254b39c819d27d967c005fb6a91f648527cd78abadd17a2ae8b1e51294d56d2a1e9392d58671b2eb617511cfe5884a2565e73ca26f35304c0f68463c814db1
7
+ data.tar.gz: 9bf904d914c4ad290be96ca7a17fbae1d0cf0aec40f0dfe50e31201291c86942741d010b2cc17c3a103303aa6c776ceb4f2a7f5d550026b49b12b5b4b6f40cf6
@@ -3,6 +3,10 @@ require_relative 'objects/course'
3
3
  require_relative 'objects/target'
4
4
  require_relative 'objects/video_start'
5
5
  require_relative 'objects/video_end'
6
+ require_relative 'objects/survey_start'
7
+ require_relative 'objects/survey_end'
8
+ require_relative 'objects/survey'
9
+ require_relative 'objects/answer'
6
10
 
7
11
  module PupilfirstXapi
8
12
  module Objects
@@ -18,9 +22,24 @@ module PupilfirstXapi
18
22
  VideoStart.new.call(target, uri_for)
19
23
  end
20
24
 
21
-
22
25
  def self.video_end(target, uri_for)
23
26
  VideoEnd.new.call(target, uri_for)
24
27
  end
28
+
29
+ def self.survey_start(survey, uri_for)
30
+ SurveyStart.new.call(survey, uri_for)
31
+ end
32
+
33
+ def self.survey_end(survey, uri_for)
34
+ SurveyEnd.new.call(survey, uri_for)
35
+ end
36
+
37
+ def self.capability_result_viewed(survey, uri_for)
38
+ Survey.new.call(survey, uri_for)
39
+ end
40
+
41
+ def self.answer(question, uri_for)
42
+ Answer.new.call(question, uri_for)
43
+ end
25
44
  end
26
45
  end
@@ -0,0 +1,18 @@
1
+ module PupilfirstXapi
2
+ module Objects
3
+ class Answer
4
+ def call(answer, uri_for)
5
+ target_uri = uri_for.call(answer)
6
+
7
+ Builder.new(
8
+ id: target_uri,
9
+ type: 'http://adlnet.gov/expapi/activities/assessment',
10
+ name: answer.question.description,
11
+ description: answer.question.description
12
+ ).with_extension('http://adlnet.gov/expapi/activities/question', answer.question.description)
13
+ .with_extension('http://adlnet.gov/expapi/activities/answer', answer.content || answer.alternatives.as_json)
14
+ .call
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ module PupilfirstXapi
2
+ module Objects
3
+ class Survey
4
+ def call(survey, uri_for)
5
+ target_uri = uri_for.call(survey)
6
+
7
+ Builder.new(
8
+ id: target_uri,
9
+ type: 'http://id.tincanapi.com/activitytype/survey',
10
+ name: survey.name,
11
+ description: survey.external_name
12
+ ).call
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ module PupilfirstXapi
2
+ module Objects
3
+ class SurveyEnd
4
+ def call(survey, uri_for)
5
+ target_uri = uri_for.call(survey)
6
+
7
+ Builder.new(
8
+ id: target_uri,
9
+ type: 'http://adlnet.gov/expapi/activities/assessment',
10
+ name: survey.name,
11
+ description: survey.external_name
12
+ ).with_extension(
13
+ 'http://id.tincanapi.com/extension/target', survey.slug
14
+ ).call
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module PupilfirstXapi
2
+ module Objects
3
+ class SurveyStart
4
+ def call(survey, uri_for)
5
+ target_uri = uri_for.call(survey)
6
+
7
+ Builder.new(
8
+ id: target_uri,
9
+ type: 'http://adlnet.gov/expapi/activities/assessment',
10
+ name: survey.name,
11
+ description: survey.external_name
12
+ ).with_extension(
13
+ 'http://id.tincanapi.com/extension/target', survey.slug
14
+ ).call
15
+ end
16
+ end
17
+ end
18
+ end
@@ -3,6 +3,10 @@ require "pupilfirst_xapi/statements/course_registered"
3
3
  require "pupilfirst_xapi/statements/target_completed"
4
4
  require "pupilfirst_xapi/statements/video_started"
5
5
  require "pupilfirst_xapi/statements/video_ended"
6
+ require "pupilfirst_xapi/statements/survey_started"
7
+ require "pupilfirst_xapi/statements/survey_ended"
8
+ require "pupilfirst_xapi/statements/capability_result_viewed"
9
+ require "pupilfirst_xapi/statements/question_answered"
6
10
 
7
11
  module PupilfirstXapi
8
12
  module Statements
@@ -20,7 +24,11 @@ module PupilfirstXapi
20
24
  :submission_graded => TargetCompleted,
21
25
  :submission_automatically_verified => TargetCompleted,
22
26
  :video_started => VideoStarted,
23
- :video_ended => VideoEnded
27
+ :video_ended => VideoEnded,
28
+ :survey_started => SurveyStarted,
29
+ :survey_ended => SurveyEnded,
30
+ :capability_result_viewed => CapabilityResultViewed,
31
+ :question_answered => QuestionAnswered
24
32
  }
25
33
  end
26
34
  end
@@ -0,0 +1,20 @@
1
+ module PupilfirstXapi
2
+ module Statements
3
+ class CapabilityResultViewed
4
+ def initialize(repository, uri_for)
5
+ @repository = repository
6
+ @uri_for = uri_for
7
+ end
8
+
9
+ def call(actor_id:, resource_id:)
10
+ actor = @repository.call(:user, actor_id)
11
+ survey = @repository.call(:survey, resource_id)
12
+ Xapi.create_statement(
13
+ actor: Actors.agent(actor),
14
+ verb: Verbs::VIEWED,
15
+ object: Objects.capability_result_viewed(survey, @uri_for)
16
+ )
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ module PupilfirstXapi
2
+ module Statements
3
+ class QuestionAnswered
4
+ def initialize(repository, uri_for)
5
+ @repository = repository
6
+ @uri_for = uri_for
7
+ end
8
+
9
+ def call(actor_id:, resource_id:)
10
+ actor = @repository.call(:user, actor_id)
11
+ answer = @repository.call(:answer, resource_id)
12
+
13
+ Xapi.create_statement(
14
+ actor: Actors.agent(actor),
15
+ verb: Verbs::ANSWERED,
16
+ object: Objects.answer(answer, @uri_for)
17
+ )
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module PupilfirstXapi
2
+ module Statements
3
+ class SurveyEnded
4
+ def initialize(repository, uri_for)
5
+ @repository = repository
6
+ @uri_for = uri_for
7
+ end
8
+
9
+ def call(actor_id:, resource_id:)
10
+ actor = @repository.call(:user, actor_id)
11
+ survey = @repository.call(:survey, resource_id)
12
+
13
+ Xapi.create_statement(
14
+ actor: Actors.agent(actor),
15
+ verb: Verbs::COMPLETED,
16
+ object: Objects.survey_end(survey, @uri_for)
17
+ )
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module PupilfirstXapi
2
+ module Statements
3
+ class SurveyStarted
4
+ def initialize(repository, uri_for)
5
+ @repository = repository
6
+ @uri_for = uri_for
7
+ end
8
+
9
+ def call(actor_id:, resource_id:)
10
+ actor = @repository.call(:user, actor_id)
11
+ survey = @repository.call(:survey, resource_id)
12
+
13
+ Xapi.create_statement(
14
+ actor: Actors.agent(actor),
15
+ verb: Verbs::STARTED,
16
+ object: Objects.survey_start(survey, @uri_for)
17
+ )
18
+ end
19
+ end
20
+ end
21
+ end
@@ -5,5 +5,8 @@ module PupilfirstXapi
5
5
  REGISTERED = Xapi.create_verb(id: 'http://adlnet.gov/expapi/verbs/registered', name: 'registered')
6
6
  VIDEO_STARTED = Xapi.create_verb(id: 'http://activitystrea.ms/schema/1.0/start', name: 'start')
7
7
  VIDEO_ENDED = Xapi.create_verb(id: 'http://activitystrea.ms/schema/1.0/consume', name: 'consumed')
8
+ STARTED = Xapi.create_verb(id: 'http://adlnet.gov/expapi/verbs/initialized', name: 'initialized')
9
+ VIEWED = Xapi.create_verb(id: 'http://id.tincanapi.com/verb/viewed', name: 'viewed')
10
+ ANSWERED = Xapi.create_verb(id: 'https://w3id.org/xapi/dod-isd/verbs/answered', name: 'answered')
8
11
  end
9
12
  end
@@ -1,3 +1,3 @@
1
1
  module PupilfirstXapi
2
- VERSION = '0.3.5'
2
+ VERSION = '0.3.8'
3
3
  end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ module PupilfirstXapi
4
+ module Statements
5
+ RSpec.describe CapabilityResultViewed do
6
+ it do
7
+ john = double(:john, name: 'John Doe', email: 'john@doe.com')
8
+ survey = double(
9
+ :survey,
10
+ name: 'Rails for Beginners',
11
+ external_name: 'Seems easy',
12
+ created_at: 1.week.ago,
13
+ ends_at: nil,
14
+ targets: [
15
+ double(:target, title: '1st target', description: 'Seems easy'),
16
+ double(:target, title: '2nd target', description: 'Seems not easy')
17
+ ]
18
+ )
19
+
20
+ data = {
21
+ survey: { 456 => survey },
22
+ user: { 123 => john }
23
+ }
24
+
25
+ repository = ->(klass, resource_id) { data.dig(klass, resource_id) }
26
+ uri_for = ->(obj) { obj == survey ? 'rails-for-begginers' : nil }
27
+
28
+ xapi = CapabilityResultViewed.new(repository, uri_for).call(actor_id: 123, resource_id: 456)
29
+
30
+ expect(xapi).to be_a Xapi::Statement
31
+ expect_actor(xapi.actor, name: 'John Doe', email: 'john@doe.com')
32
+ expect(xapi.verb).to eq Verbs::VIEWED
33
+
34
+ expect(xapi.object).to be_a Xapi::Activity
35
+ expect(xapi.object.object_type).to eq 'Activity'
36
+ expect(xapi.object.id).to eq 'rails-for-begginers'
37
+ expect(xapi.object.definition.type).to eq 'http://id.tincanapi.com/activitytype/survey'
38
+ expect(xapi.object.definition.name).to eq({'en-US' => 'Rails for Beginners'})
39
+ expect(xapi.object.definition.description).to eq({'en-US' => 'Seems easy'})
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ module PupilfirstXapi
4
+ module Statements
5
+ RSpec.describe QuestionAnswered do
6
+ it do
7
+ john = double(:john, name: 'John Doe', email: 'john@doe.com')
8
+ question = double(:question, description: "What is your favorite animal?")
9
+ answer = double(
10
+ :answer,
11
+ answer_id: 42,
12
+ question_id: 4,
13
+ question: question,
14
+ alternative_id: nil,
15
+ survey_group_id:7,
16
+ user_external_id: 'a6ad5226-7d8b-4108-9cc9-f0821de150f5',
17
+ answer_type: 'open_ended',
18
+ content: 'Content',
19
+ score: 0.0,
20
+ level: 1.0,
21
+ language: 'en',
22
+ created_at: 1.week.ago,
23
+ ends_at: nil
24
+ )
25
+
26
+ data = {
27
+ answer: { 456 => answer },
28
+ user: { 123 => john }
29
+ }
30
+
31
+ repository = ->(klass, resource_id) { data.dig(klass, resource_id) }
32
+ uri_for = ->(obj) { obj == answer ? 'rails-for-begginers' : nil }
33
+
34
+ xapi = QuestionAnswered.new(repository, uri_for).call(actor_id: 123, resource_id: 456)
35
+
36
+ expect(xapi).to be_a Xapi::Statement
37
+ expect_actor(xapi.actor, name: 'John Doe', email: 'john@doe.com')
38
+ expect(xapi.verb).to eq Verbs::ANSWERED
39
+
40
+ expect(xapi.object).to be_a Xapi::Activity
41
+ expect(xapi.object.object_type).to eq 'Activity'
42
+ expect(xapi.object.id).to eq 'rails-for-begginers'
43
+ expect(xapi.object.definition.type).to eq 'http://adlnet.gov/expapi/activities/assessment'
44
+ expect(xapi.object.definition.name).to eq({'en-US' => 'What is your favorite animal?'})
45
+ expect(xapi.object.definition.description).to eq({'en-US' => 'What is your favorite animal?'})
46
+ expect(xapi.object.definition.extensions.fetch('http://adlnet.gov/expapi/activities/question')).to eq("What is your favorite animal?")
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ module PupilfirstXapi
4
+ module Statements
5
+ RSpec.describe SurveyEnded do
6
+ it do
7
+ john = double(:john, name: 'John Doe', email: 'john@doe.com')
8
+ survey = double(
9
+ :survey,
10
+ name: 'Rails for Beginners',
11
+ external_name: 'Seems easy',
12
+ slug: 'a6ad5226-7d8b-4108-9cc9-f0821de150f5',
13
+ created_at: 1.week.ago,
14
+ ends_at: nil,
15
+ targets: [
16
+ double(:target, title: '1st target', description: 'Seems easy'),
17
+ double(:target, title: '2nd target', description: 'Seems not easy')
18
+ ]
19
+ )
20
+
21
+ data = {
22
+ survey: { 456 => survey },
23
+ user: { 123 => john }
24
+ }
25
+
26
+ repository = ->(klass, resource_id) { data.dig(klass, resource_id) }
27
+ uri_for = ->(obj) { obj == survey ? 'rails-for-begginers' : nil }
28
+
29
+ xapi = SurveyEnded.new(repository, uri_for).call(actor_id: 123, resource_id: 456)
30
+
31
+ expect(xapi).to be_a Xapi::Statement
32
+ expect_actor(xapi.actor, name: 'John Doe', email: 'john@doe.com')
33
+ expect(xapi.verb).to eq Verbs::COMPLETED
34
+
35
+ expect(xapi.object).to be_a Xapi::Activity
36
+ expect(xapi.object.object_type).to eq 'Activity'
37
+ expect(xapi.object.id).to eq 'rails-for-begginers'
38
+ expect(xapi.object.definition.type).to eq 'http://adlnet.gov/expapi/activities/assessment'
39
+ expect(xapi.object.definition.name).to eq({'en-US' => 'Rails for Beginners'})
40
+ expect(xapi.object.definition.description).to eq({'en-US' => 'Seems easy'})
41
+ expect(xapi.object.definition.extensions.fetch('http://id.tincanapi.com/extension/target')).to eq('a6ad5226-7d8b-4108-9cc9-f0821de150f5')
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ module PupilfirstXapi
4
+ module Statements
5
+ RSpec.describe SurveyStarted do
6
+ it do
7
+ john = double(:john, name: 'John Doe', email: 'john@doe.com')
8
+ survey = double(
9
+ :survey,
10
+ name: 'Rails for Beginners',
11
+ external_name: 'Seems easy',
12
+ slug: 'a6ad5226-7d8b-4108-9cc9-f0821de150f5',
13
+ created_at: 1.week.ago,
14
+ ends_at: nil,
15
+ targets: [
16
+ double(:target, title: '1st target', description: 'Seems easy'),
17
+ double(:target, title: '2nd target', description: 'Seems not easy')
18
+ ]
19
+ )
20
+
21
+ data = {
22
+ survey: { 456 => survey },
23
+ user: { 123 => john }
24
+ }
25
+
26
+ repository = ->(klass, resource_id) { data.dig(klass, resource_id) }
27
+ uri_for = ->(obj) { obj == survey ? 'rails-for-begginers' : nil }
28
+
29
+ xapi = SurveyStarted.new(repository, uri_for).call(actor_id: 123, resource_id: 456)
30
+
31
+ expect(xapi).to be_a Xapi::Statement
32
+ expect_actor(xapi.actor, name: 'John Doe', email: 'john@doe.com')
33
+ expect(xapi.verb).to eq Verbs::STARTED
34
+
35
+ expect(xapi.object).to be_a Xapi::Activity
36
+ expect(xapi.object.object_type).to eq 'Activity'
37
+ expect(xapi.object.id).to eq 'rails-for-begginers'
38
+ expect(xapi.object.definition.type).to eq 'http://adlnet.gov/expapi/activities/assessment'
39
+ expect(xapi.object.definition.name).to eq({'en-US' => 'Rails for Beginners'})
40
+ expect(xapi.object.definition.description).to eq({'en-US' => 'Seems easy'})
41
+ expect(xapi.object.definition.extensions.fetch('http://id.tincanapi.com/extension/target')).to eq('a6ad5226-7d8b-4108-9cc9-f0821de150f5')
42
+ end
43
+ end
44
+ end
45
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pupilfirst_xapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - GrowthTribe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-21 00:00:00.000000000 Z
11
+ date: 2021-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -94,15 +94,23 @@ files:
94
94
  - lib/pupilfirst_xapi/actors.rb
95
95
  - lib/pupilfirst_xapi/lrs.rb
96
96
  - lib/pupilfirst_xapi/objects.rb
97
+ - lib/pupilfirst_xapi/objects/answer.rb
97
98
  - lib/pupilfirst_xapi/objects/builder.rb
98
99
  - lib/pupilfirst_xapi/objects/course.rb
100
+ - lib/pupilfirst_xapi/objects/survey.rb
101
+ - lib/pupilfirst_xapi/objects/survey_end.rb
102
+ - lib/pupilfirst_xapi/objects/survey_start.rb
99
103
  - lib/pupilfirst_xapi/objects/target.rb
100
104
  - lib/pupilfirst_xapi/objects/video_end.rb
101
105
  - lib/pupilfirst_xapi/objects/video_start.rb
102
106
  - lib/pupilfirst_xapi/outbox.rb
103
107
  - lib/pupilfirst_xapi/statements.rb
108
+ - lib/pupilfirst_xapi/statements/capability_result_viewed.rb
104
109
  - lib/pupilfirst_xapi/statements/course_completed.rb
105
110
  - lib/pupilfirst_xapi/statements/course_registered.rb
111
+ - lib/pupilfirst_xapi/statements/question_answered.rb
112
+ - lib/pupilfirst_xapi/statements/survey_ended.rb
113
+ - lib/pupilfirst_xapi/statements/survey_started.rb
106
114
  - lib/pupilfirst_xapi/statements/target_completed.rb
107
115
  - lib/pupilfirst_xapi/statements/video_ended.rb
108
116
  - lib/pupilfirst_xapi/statements/video_started.rb
@@ -114,8 +122,12 @@ files:
114
122
  - spec/outbox_spec.rb
115
123
  - spec/rails_helper.rb
116
124
  - spec/spec_helper.rb
125
+ - spec/statements/capability_result_viewed_spec.rb
117
126
  - spec/statements/course_completed_spec.rb
118
127
  - spec/statements/course_registered_spec.rb
128
+ - spec/statements/question_answered_spec.rb
129
+ - spec/statements/survey_ended_spec.rb
130
+ - spec/statements/survey_started_spec.rb
119
131
  - spec/statements/target_completed_spec.rb
120
132
  homepage: https://github.com/growthtribeacademy/pupilfirst-xapi
121
133
  licenses:
@@ -139,17 +151,21 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
151
  - !ruby/object:Gem::Version
140
152
  version: '0'
141
153
  requirements: []
142
- rubygems_version: 3.1.6
154
+ rubygems_version: 3.2.15
143
155
  signing_key:
144
156
  specification_version: 4
145
157
  summary: XAPI statements generator and publisher to LRS for Pupilfirst
146
158
  test_files:
159
+ - spec/integration_spec.rb
147
160
  - spec/objects/builder_spec.rb
161
+ - spec/outbox_job_spec.rb
162
+ - spec/outbox_spec.rb
148
163
  - spec/rails_helper.rb
149
- - spec/statements/target_completed_spec.rb
164
+ - spec/spec_helper.rb
165
+ - spec/statements/capability_result_viewed_spec.rb
150
166
  - spec/statements/course_completed_spec.rb
151
167
  - spec/statements/course_registered_spec.rb
152
- - spec/spec_helper.rb
153
- - spec/outbox_spec.rb
154
- - spec/integration_spec.rb
155
- - spec/outbox_job_spec.rb
168
+ - spec/statements/question_answered_spec.rb
169
+ - spec/statements/survey_ended_spec.rb
170
+ - spec/statements/survey_started_spec.rb
171
+ - spec/statements/target_completed_spec.rb