ims_caliper 0.1.1 → 0.1.2
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 +8 -8
- data/.gitignore +37 -0
- data/.idea/caliper-ruby.iml +98 -0
- data/.idea/encodings.xml +5 -0
- data/.idea/misc.xml +5 -0
- data/.idea/modules.xml +9 -0
- data/.idea/scopes/scope_settings.xml +5 -0
- data/.idea/vcs.xml +7 -0
- data/Gemfile +12 -1
- data/Gemfile.lock +42 -1
- data/LICENSE +67 -0
- data/NOTICE +15 -0
- data/README.md +13 -5
- data/caliper.gemspec +2 -8
- data/lib/caliper/defaults.rb +4 -4
- data/lib/caliper/entities/annotation/annotation.rb +14 -4
- data/lib/caliper/entities/annotation/bookmark_annotation.rb +14 -4
- data/lib/caliper/entities/annotation/highlight_annotation.rb +14 -3
- data/lib/caliper/entities/annotation/shared_annotation.rb +12 -3
- data/lib/caliper/entities/annotation/tag_annotation.rb +13 -3
- data/lib/caliper/entities/assessment/assessment.rb +27 -0
- data/lib/caliper/entities/assessment/assessment_item.rb +26 -0
- data/lib/caliper/entities/assignable/assignable_digital_resource.rb +47 -0
- data/lib/caliper/entities/assignable/attempt.rb +32 -0
- data/lib/caliper/entities/digital_resource.rb +36 -35
- data/lib/caliper/entities/entity.rb +50 -36
- data/lib/caliper/entities/foaf/agent.rb +1 -1
- data/lib/caliper/entities/jsonable.rb +56 -0
- data/lib/caliper/entities/learning_objective.rb +26 -0
- data/lib/caliper/entities/lis/course_offering.rb +30 -0
- data/lib/caliper/entities/lis/course_section.rb +27 -15
- data/lib/caliper/entities/lis/group.rb +27 -0
- data/lib/caliper/entities/lis/membership.rb +32 -0
- data/lib/caliper/entities/lis/organization.rb +20 -17
- data/lib/caliper/entities/lis/person.rb +23 -10
- data/lib/caliper/entities/lis/roles.rb +77 -0
- data/lib/caliper/entities/lis/status.rb +19 -0
- data/lib/caliper/entities/media/audio_object.rb +21 -0
- data/lib/caliper/entities/media/image_object.rb +21 -0
- data/lib/caliper/entities/media/media_location.rb +23 -0
- data/lib/caliper/entities/media/media_object.rb +38 -0
- data/lib/caliper/entities/media/video_object.rb +21 -0
- data/lib/caliper/entities/reading/epub_volume.rb +15 -7
- data/lib/caliper/entities/reading/frame.rb +7 -15
- data/lib/caliper/entities/response/fillin_blank_response.rb +20 -0
- data/lib/caliper/entities/response/multiple_choice_response.rb +20 -0
- data/lib/caliper/entities/response/multiple_response_response.rb +20 -0
- data/lib/caliper/entities/response/response.rb +23 -0
- data/lib/caliper/entities/response/response_type.rb +13 -0
- data/lib/caliper/entities/response/select_type_response.rb +20 -0
- data/lib/caliper/entities/response/true_false_response.rb +21 -0
- data/lib/caliper/entities/schemadotorg/software_application.rb +8 -8
- data/lib/caliper/entities/session.rb +25 -17
- data/lib/caliper/entities/software_application.rb +16 -7
- data/lib/caliper/entities/web_page.rb +2 -0
- data/lib/caliper/entity_envelope.rb +21 -0
- data/lib/caliper/event/annotation_event.rb +10 -6
- data/lib/caliper/event/assessment_event.rb +19 -0
- data/lib/caliper/event/assessment_item_event.rb +19 -0
- data/lib/caliper/event/assignable_event.rb +19 -0
- data/lib/caliper/event/event.rb +70 -50
- data/lib/caliper/event/jsonable.rb +55 -0
- data/lib/caliper/event/navigation_event.rb +2 -7
- data/lib/caliper/event/outcome_event.rb +1 -1
- data/lib/caliper/event/session_event.rb +13 -14
- data/lib/caliper/event/view_event.rb +6 -7
- data/lib/caliper/event_envelope.rb +22 -0
- data/lib/caliper/jsonable.rb +53 -0
- data/lib/caliper/profiles/annotation_profile.rb +56 -53
- data/lib/caliper/profiles/assessment_profile.rb +48 -0
- data/lib/caliper/profiles/assignable_profile.rb +44 -0
- data/lib/caliper/profiles/media_profile.rb +54 -0
- data/lib/caliper/profiles/profile.rb +38 -38
- data/lib/caliper/profiles/reading_profile.rb +31 -28
- data/lib/caliper/profiles/session_profile.rb +17 -18
- data/lib/caliper/request/event_store_requestor.rb +26 -26
- data/lib/caliper/sensor.rb +46 -35
- data/lib/caliper/version.rb +1 -1
- data/spec/lib/entities/entity.json +9 -0
- data/spec/lib/entities/entity_spec.rb +37 -0
- data/spec/lib/entities/lis/person_spec.rb +37 -0
- data/spec/lib/entities/lis/student.json +11 -0
- data/spec/lib/event/annotation_event_bookmark_spec.rb +159 -0
- data/spec/lib/event/annotation_event_highlight_spec.rb +160 -0
- data/spec/lib/event/annotation_event_shared_spec.rb +172 -0
- data/spec/lib/event/annotation_event_tag_spec.rb +159 -0
- data/spec/lib/event/assessment_event_spec.rb +207 -0
- data/spec/lib/event/assessment_item_completed_event_spec.rb +223 -0
- data/spec/lib/event/assessment_item_started_event_spec.rb +207 -0
- data/spec/lib/event/media_event_spec.rb +157 -0
- data/spec/lib/event/navigated_event_spec.rb +160 -0
- data/spec/lib/event/session_event_login_spec.rb +160 -0
- data/spec/lib/event/session_event_logout_spec.rb +145 -0
- data/spec/lib/event/session_event_timeout_spec.rb +145 -0
- data/spec/lib/event/viewed_event_spec.rb +149 -0
- data/spec/lib/event_helper.rb +145 -0
- data/spec/lib/sensor_spec.rb +30 -0
- data/spec/spec_helper.rb +3 -2
- metadata +84 -61
- data/lib/caliper/client.rb +0 -33
- data/lib/caliper/consumer/base.rb +0 -46
- data/lib/caliper/consumer/queue.rb +0 -40
- data/lib/caliper/consumer/socket.rb +0 -132
- data/lib/caliper/entities/annotation/text_position_selector.rb +0 -14
- data/lib/caliper/entities/schemadotorg/audio_object.rb +0 -15
- data/lib/caliper/entities/schemadotorg/image_object.rb +0 -15
- data/lib/caliper/entities/schemadotorg/media_object.rb +0 -19
- data/lib/caliper/entities/schemadotorg/video_object.rb +0 -15
- data/lib/caliper/event/.shared.rb.swp +0 -0
- data/spec/lib/client_spec.rb +0 -35
- data/spec/lib/consumer/base_spec.rb +0 -28
- data/spec/lib/consumer/queue_spec.rb +0 -16
- data/spec/lib/event/annotation_spec.rb +0 -12
- data/spec/lib/event/bookmarked_spec.rb +0 -17
- data/spec/lib/event/commented_spec.rb +0 -19
- data/spec/lib/event/highlighted_spec.rb +0 -18
- data/spec/lib/event/navigation_spec.rb +0 -15
- data/spec/lib/event/shared_spec.rb +0 -18
- data/spec/lib/event/tagged_spec.rb +0 -17
- data/spec/lib/event/used_spec.rb +0 -15
- data/spec/lib/event/viewed_spec.rb +0 -15
- data/test/caliper/events/session_login_event_test.rb +0 -58
- data/test/caliper/events/session_logout_event_test.rb +0 -55
- data/test/caliper/events/session_timeout_event_test.rb +0 -55
- data/test/caliper/request/http_requestor_test.rb +0 -59
- data/test/caliper/test_event.rb +0 -53
- data/test/caliper/test_utils.rb +0 -198
- data/test/fixtures/caliper_session_login_event.json +0 -71
- data/test/fixtures/caliper_session_logout_event.json +0 -52
- data/test/fixtures/caliper_session_timeout_event.json +0 -52
- data/test/fixtures/event_store_payload.json +0 -85
@@ -2,40 +2,40 @@ require 'securerandom'
|
|
2
2
|
require_relative 'event_store_envelope'
|
3
3
|
|
4
4
|
module Caliper
|
5
|
-
|
6
|
-
|
5
|
+
module Request
|
6
|
+
class EventStoreRequestor
|
7
7
|
|
8
8
|
|
9
|
-
|
9
|
+
def get_payload_json(caliper_event, id, send_time)
|
10
10
|
|
11
|
-
|
11
|
+
list_payload = Array.new
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
# new event envelope
|
14
|
+
envelope = EventStoreEnvelope.new
|
15
|
+
envelope.id = id
|
16
|
+
envelope.type = "caliperEvent"
|
17
|
+
envelope.time = send_time.to_s
|
18
|
+
envelope.data = caliper_event
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
# add envelope into array
|
21
|
+
list_payload<< envelope
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
json_payload = JSON.generate(list_payload)
|
24
|
+
return json_payload
|
25
|
+
end
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
def generate_payload(caliper_event, id, send_time)
|
28
|
+
if (id.nil?)
|
29
|
+
id = "caliper-java_" + SecureRandom.uuid
|
30
|
+
end
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
if (send_time.nil?)
|
33
|
+
send_time = Time.now
|
34
|
+
end
|
35
35
|
|
36
|
-
|
36
|
+
json_payload = get_payload_json(caliper_event, id, send_time)
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
41
|
end
|
data/lib/caliper/sensor.rb
CHANGED
@@ -1,37 +1,48 @@
|
|
1
|
-
|
1
|
+
require 'rest_client'
|
2
|
+
require_relative "options"
|
3
|
+
require_relative "event_envelope"
|
4
|
+
require_relative "entity_envelope"
|
2
5
|
|
3
|
-
##
|
6
|
+
##
|
7
|
+
#
|
8
|
+
# @copyright @copyright ©2013 IMS Global Learning Consortium, Inc. All Rights Reserved.
|
9
|
+
# @license For license information contact, info@imsglobal.org
|
10
|
+
#
|
11
|
+
# Caliper Sensor
|
12
|
+
#
|
13
|
+
#
|
4
14
|
module Caliper
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
15
|
+
|
16
|
+
class Sensor
|
17
|
+
|
18
|
+
def initialize(options)
|
19
|
+
@options = options
|
20
|
+
puts "Sensor - initializing with options = #{@options}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def send(event)
|
24
|
+
raise ArgumentError, "Expecting Caliper::Event but got #{event.class.to_s}" unless event.is_a?(Caliper::Event::Event)
|
25
|
+
|
26
|
+
envelope = EventEnvelope.new
|
27
|
+
envelope.apiKey = @options['apiKey']
|
28
|
+
envelope.sensorId = @options['sensorId']
|
29
|
+
envelope.event = event
|
30
|
+
|
31
|
+
RestClient.post @options['host'], envelope.to_json, :content_type => :json, :accept => :json
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
def describe(entity)
|
36
|
+
raise ArgumentError, "Expecting Caliper::Entity but got #{entity.class.to_s}" unless entity.is_a?(Caliper::Entities::Entity)
|
37
|
+
|
38
|
+
envelope = EntityEnvelope.new
|
39
|
+
envelope.apiKey = @options['apiKey']
|
40
|
+
envelope.sensorId = @options['sensorId']
|
41
|
+
envelope.entity = entity
|
42
|
+
|
43
|
+
RestClient.post @options['host'], envelope.to_json, :content_type => :json, :accept => :json
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
data/lib/caliper/version.rb
CHANGED
@@ -0,0 +1,9 @@
|
|
1
|
+
{
|
2
|
+
"@id": "https://some-university.edu/politicalScience/2014/american-revolution-101/assessment1",
|
3
|
+
"@type": "http://purl.imsglobal.org/caliper/v1/Entity",
|
4
|
+
"name": "test",
|
5
|
+
"description": "description",
|
6
|
+
"extensions": {"customProp":42},
|
7
|
+
"dateCreated": "2015-03-15T23:09:11.000Z",
|
8
|
+
"dateModified": "2015-03-15T23:09:11.000Z"
|
9
|
+
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# require 'spec_helper.rb'
|
2
|
+
require 'require_all'
|
3
|
+
require 'json_spec'
|
4
|
+
require_all 'lib/caliper/entities/entity.rb'
|
5
|
+
|
6
|
+
module Caliper
|
7
|
+
module Entities
|
8
|
+
|
9
|
+
describe Entity do
|
10
|
+
|
11
|
+
it "should ensure that a base entity is correctly created and serialized" do
|
12
|
+
entity = Entity.new
|
13
|
+
entity.name = 'test'
|
14
|
+
entity.description = 'description'
|
15
|
+
entity.id = 'https://some-university.edu/politicalScience/2014/american-revolution-101/assessment1'
|
16
|
+
entity.extensions = {'customProp' => 42}
|
17
|
+
entity.dateCreated = '2015-03-15T23:09:11.000Z'
|
18
|
+
entity.dateModified = '2015-03-15T23:09:11.000Z'
|
19
|
+
# puts "Entity JSON = #{entity.to_json}"
|
20
|
+
|
21
|
+
# Compare JSON ouput
|
22
|
+
file = File.read('spec/lib/entities/entity.json')
|
23
|
+
data_hash = JSON.parse(file)
|
24
|
+
expected_json = data_hash.to_json # convert hash back to JSON string after parse
|
25
|
+
entity.to_json.should be_json_eql(expected_json)#.excluding("@class")
|
26
|
+
|
27
|
+
# Compare Deserialized JSON to desired Entity
|
28
|
+
des_entity = Entity.new
|
29
|
+
des_entity.from_json data_hash
|
30
|
+
# puts "Object from JSON = #{des_entity.to_json}"
|
31
|
+
expect(entity).to eql(des_entity)
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# require 'spec_helper.rb'
|
2
|
+
require 'require_all'
|
3
|
+
require_all 'lib/caliper/entities/*.rb'
|
4
|
+
require_all 'lib/caliper/entities/lis/*.rb'
|
5
|
+
|
6
|
+
module Caliper
|
7
|
+
module Entities
|
8
|
+
module LIS
|
9
|
+
describe Person do
|
10
|
+
|
11
|
+
it "should ensure that a Person is correctly created and serialized" do
|
12
|
+
student = Person.new
|
13
|
+
student.id = 'https://some-university.edu/students/dent_stu'
|
14
|
+
student.name = 'Stu Dent'
|
15
|
+
student.description = 'A super bright individual'
|
16
|
+
student.extensions = {'customProp' => 42}
|
17
|
+
student.dateCreated = '2015-03-15T23:09:11.000Z'
|
18
|
+
student.dateModified = '2015-03-15T23:09:11.000Z'
|
19
|
+
# puts "new student = #{student.to_json}"
|
20
|
+
|
21
|
+
# Compare JSON ouput
|
22
|
+
file = File.read('spec/lib/entities/lis/student.json')
|
23
|
+
data_hash = JSON.parse(file)
|
24
|
+
expected_json = data_hash.to_json # convert hash back to JSON string after parse
|
25
|
+
student.to_json.should be_json_eql(expected_json)
|
26
|
+
|
27
|
+
des_student = Person.new
|
28
|
+
des_student.from_json data_hash
|
29
|
+
# puts "Object from JSON = #{des_student.to_json}"
|
30
|
+
|
31
|
+
expect(student).to eql(des_student)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
{
|
2
|
+
"@id": "https://some-university.edu/students/dent_stu",
|
3
|
+
"@type": "http://purl.imsglobal.org/caliper/v1/lis/Person",
|
4
|
+
"name": "Stu Dent",
|
5
|
+
"description": "A super bright individual",
|
6
|
+
"extensions": {
|
7
|
+
"customProp": 42
|
8
|
+
},
|
9
|
+
"dateCreated": "2015-03-15T23:09:11.000Z",
|
10
|
+
"dateModified": "2015-03-15T23:09:11.000Z"
|
11
|
+
}
|
@@ -0,0 +1,159 @@
|
|
1
|
+
require 'require_all'
|
2
|
+
require_all 'lib/caliper/entities/entity.rb'
|
3
|
+
require_all 'lib/caliper/entities/software_application.rb'
|
4
|
+
require_all 'lib/caliper/entities/lis/person.rb'
|
5
|
+
require_all 'lib/caliper/entities/lis/membership.rb'
|
6
|
+
require_all 'lib/caliper/entities/lis/roles.rb'
|
7
|
+
require_all 'lib/caliper/entities/lis/status.rb'
|
8
|
+
require_all 'lib/caliper/entities/lis/course_section.rb'
|
9
|
+
require_all 'lib/caliper/entities/lis/course_offering.rb'
|
10
|
+
require_all 'lib/caliper/entities/lis/group.rb'
|
11
|
+
require_all 'lib/caliper/entities/reading/epub_volume.rb'
|
12
|
+
require_all 'lib/caliper/entities/annotation/bookmark_annotation.rb'
|
13
|
+
require_all 'lib/caliper/event/annotation_event.rb'
|
14
|
+
require_all 'lib/caliper/profiles/annotation_profile.rb'
|
15
|
+
require 'json_spec'
|
16
|
+
|
17
|
+
module Caliper
|
18
|
+
module Event
|
19
|
+
|
20
|
+
describe AnnotationEvent do
|
21
|
+
|
22
|
+
it 'should ensure that a AnnotationEvent (Bookmarked) is correctly created and serialized' do
|
23
|
+
|
24
|
+
# The Actor (Person/Student))
|
25
|
+
student = Caliper::Entities::LIS::Person.new
|
26
|
+
student.id = 'https://some-university.edu/user/554433'
|
27
|
+
membership1 = Caliper::Entities::LIS::Membership.new
|
28
|
+
membership1.id = "https://some-university.edu/membership/001"
|
29
|
+
membership1.member = "https://some-university.edu/user/554433"
|
30
|
+
membership1.organization = "https://some-university.edu/politicalScience/2015/american-revolution-101"
|
31
|
+
membership1.roles = [Caliper::Entities::LIS::Roles::LEARNER]
|
32
|
+
membership1.status = Caliper::Entities::LIS::Status::ACTIVE
|
33
|
+
membership1.dateCreated = "2015-08-01T06:00:00.000Z"
|
34
|
+
membership1.dateModified = nil;
|
35
|
+
membership2 = Caliper::Entities::LIS::Membership.new
|
36
|
+
membership2.id = "https://some-university.edu/membership/002"
|
37
|
+
membership2.member = "https://some-university.edu/user/554433"
|
38
|
+
membership2.organization = "https://some-university.edu/politicalScience/2015/american-revolution-101/section/001"
|
39
|
+
membership2.roles = [Caliper::Entities::LIS::Roles::LEARNER]
|
40
|
+
membership2.status = Caliper::Entities::LIS::Status::ACTIVE
|
41
|
+
membership2.dateCreated = "2015-08-01T06:00:00.000Z"
|
42
|
+
membership2.dateModified = nil
|
43
|
+
membership3 = Caliper::Entities::LIS::Membership.new
|
44
|
+
membership3.id = "https://some-university.edu/membership/003"
|
45
|
+
membership3.member = "https://some-university.edu/user/554433"
|
46
|
+
membership3.organization = "https://some-university.edu/politicalScience/2015/american-revolution-101/section/001/group/001"
|
47
|
+
membership3.roles = [Caliper::Entities::LIS::Roles::LEARNER]
|
48
|
+
membership3.status = Caliper::Entities::LIS::Status::ACTIVE
|
49
|
+
membership3.dateCreated = "2015-08-01T06:00:00.000Z"
|
50
|
+
membership3.dateModified = nil
|
51
|
+
student.hasMembership = [membership1, membership2, membership3]
|
52
|
+
student.dateCreated = '2015-08-01T06:00:00.000Z'
|
53
|
+
student.dateModified = '2015-09-02T11:30:00.000Z'
|
54
|
+
# puts "new student = #{student.to_json}"
|
55
|
+
|
56
|
+
# The Action
|
57
|
+
action = Caliper::Profiles::AnnotationActions::BOOKMARKED
|
58
|
+
|
59
|
+
# The Object of the bookmark (Frame)
|
60
|
+
ePubVolume = Caliper::Entities::Reading::EPubVolume.new
|
61
|
+
ePubVolume.id = 'https://github.com/readium/readium-js-viewer/book/34843#epubcfi(/4/3)'
|
62
|
+
ePubVolume.name = 'The Glorious Cause: The American Revolution, 1763-1789 (Oxford History of the United States)'
|
63
|
+
ePubVolume.version = '2nd ed.'
|
64
|
+
ePubVolume.dateCreated = '2015-08-01T06:00:00.000Z'
|
65
|
+
ePubVolume.dateModified = '2015-09-02T11:30:00.000Z'
|
66
|
+
|
67
|
+
frame = Caliper::Entities::Reading::Frame.new
|
68
|
+
frame.id = 'https://github.com/readium/readium-js-viewer/book/34843#epubcfi(/4/3/2)'
|
69
|
+
frame.name = 'Key Figures: Lord North'
|
70
|
+
frame.version = '2nd ed.'
|
71
|
+
frame.dateCreated = '2015-08-01T06:00:00.000Z'
|
72
|
+
frame.dateModified = '2015-09-02T11:30:00.000Z'
|
73
|
+
frame.index = 2
|
74
|
+
frame.isPartOf = ePubVolume.id
|
75
|
+
|
76
|
+
# The Generated (Annotation::BookmarkAnnotation)
|
77
|
+
bookmark = Caliper::Entities::Annotation::BookmarkAnnotation.new
|
78
|
+
bookmark.id = 'https://someEduApp.edu/bookmarks/00001'
|
79
|
+
bookmark.name = nil
|
80
|
+
bookmark.description = nil
|
81
|
+
bookmark.dateCreated = '2015-08-01T06:00:00.000Z'
|
82
|
+
bookmark.dateModified = '2015-09-02T11:30:00.000Z'
|
83
|
+
bookmark.annotated = 'https://github.com/readium/readium-js-viewer/book/34843#epubcfi(/4/3/2)'
|
84
|
+
bookmark.bookmarkNotes = 'The Intolerable Acts (1774)--bad idea Lord North'
|
85
|
+
|
86
|
+
# The course that is part of the Learning Context (edApp)
|
87
|
+
edApp = Caliper::Entities::SoftwareApplication.new
|
88
|
+
edApp.id = 'https://github.com/readium/readium-js-viewer'
|
89
|
+
edApp.name = 'Readium'
|
90
|
+
edApp.hasMembership = []
|
91
|
+
edApp.dateCreated = '2015-08-01T06:00:00.000Z'
|
92
|
+
edApp.dateModified = '2015-09-02T11:30:00.000Z'
|
93
|
+
|
94
|
+
#LIS Course Offering
|
95
|
+
courseOffering = Caliper::Entities::LIS::CourseOffering.new
|
96
|
+
courseOffering.id = "https://some-university.edu/politicalScience/2015/american-revolution-101"
|
97
|
+
courseOffering.name = "Political Science 101: The American Revolution"
|
98
|
+
courseOffering.courseNumber = "POL101"
|
99
|
+
courseOffering.academicSession = "Fall-2015"
|
100
|
+
courseOffering.membership = []
|
101
|
+
courseOffering.subOrganizationOf = nil
|
102
|
+
courseOffering.dateCreated = '2015-08-01T06:00:00.000Z'
|
103
|
+
courseOffering.dateModified = '2015-09-02T11:30:00.000Z'
|
104
|
+
|
105
|
+
# The LIS Course Section for the Caliper Event
|
106
|
+
course = Caliper::Entities::LIS::CourseSection.new
|
107
|
+
course.id = 'https://some-university.edu/politicalScience/2015/american-revolution-101/section/001'
|
108
|
+
course.name = 'American Revolution 101'
|
109
|
+
course.courseNumber = "POL101"
|
110
|
+
course.academicSession = "Fall-2015"
|
111
|
+
course.category = nil
|
112
|
+
course.membership = [membership2]
|
113
|
+
course.subOrganizationOf = courseOffering
|
114
|
+
course.dateCreated = '2015-08-01T06:00:00.000Z'
|
115
|
+
course.dateModified = '2015-09-02T11:30:00.000Z'
|
116
|
+
|
117
|
+
# LIS Group
|
118
|
+
group = Caliper::Entities::LIS::Group.new
|
119
|
+
group.id = "https://some-university.edu/politicalScience/2015/american-revolution-101/section/001/group/001"
|
120
|
+
group.name = "Discussion Group 001"
|
121
|
+
group.membership = [membership3]
|
122
|
+
group.subOrganizationOf = course
|
123
|
+
group.dateCreated = '2015-08-01T06:00:00.000Z'
|
124
|
+
group.dateModified = nil
|
125
|
+
|
126
|
+
# The (Annotation::BookmarkAnnotation) Event
|
127
|
+
annotation_event = AnnotationEvent.new
|
128
|
+
annotation_event.actor = student
|
129
|
+
annotation_event.action = action
|
130
|
+
annotation_event.object = frame
|
131
|
+
annotation_event.target = nil
|
132
|
+
annotation_event.generated = bookmark
|
133
|
+
annotation_event.edApp = edApp
|
134
|
+
annotation_event.group = group
|
135
|
+
annotation_event.startedAtTime = '2015-09-15T10:15:00.000Z'
|
136
|
+
annotation_event.endedAtTime = nil
|
137
|
+
annotation_event.duration = nil
|
138
|
+
# puts "Event JSON = #{annotation_event.to_json}'"
|
139
|
+
|
140
|
+
# Load JSON from caliper-common-fixtures for comparison
|
141
|
+
# NOTE - sym link to caliper-common-fixtures needs to exist under spec/fixtures
|
142
|
+
file = File.read('spec/fixtures/caliperBookmarkAnnotationEvent.json')
|
143
|
+
data_hash = JSON.parse(file)
|
144
|
+
expected_json = data_hash.to_json # convert hash back to JSON string after parse
|
145
|
+
annotation_event.to_json.should be_json_eql(expected_json)#.excluding("actor", "action", "object", "target", "generated", "edApp", "group")
|
146
|
+
|
147
|
+
# puts "JSON from file = #{data_hash}"
|
148
|
+
deser_annotation_event = AnnotationEvent.new
|
149
|
+
deser_annotation_event.from_json data_hash
|
150
|
+
# puts "AnnotationEvent from JSON = #{deser_annotation_event.to_json}"
|
151
|
+
|
152
|
+
# Ensure that the deserialized bookmark event object conforms
|
153
|
+
expect(annotation_event).to eql(deser_annotation_event)
|
154
|
+
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
@@ -0,0 +1,160 @@
|
|
1
|
+
require 'require_all'
|
2
|
+
require_all 'lib/caliper/entities/entity.rb'
|
3
|
+
require_all 'lib/caliper/entities/software_application.rb'
|
4
|
+
require_all 'lib/caliper/entities/lis/person.rb'
|
5
|
+
require_all 'lib/caliper/entities/lis/membership.rb'
|
6
|
+
require_all 'lib/caliper/entities/lis/roles.rb'
|
7
|
+
require_all 'lib/caliper/entities/lis/status.rb'
|
8
|
+
require_all 'lib/caliper/entities/lis/course_section.rb'
|
9
|
+
require_all 'lib/caliper/entities/lis/course_offering.rb'
|
10
|
+
require_all 'lib/caliper/entities/lis/group.rb'
|
11
|
+
require_all 'lib/caliper/entities/reading/epub_volume.rb'
|
12
|
+
require_all 'lib/caliper/entities/annotation/highlight_annotation.rb'
|
13
|
+
require_all 'lib/caliper/event/annotation_event.rb'
|
14
|
+
require_all 'lib/caliper/profiles/annotation_profile.rb'
|
15
|
+
require 'json_spec'
|
16
|
+
|
17
|
+
module Caliper
|
18
|
+
module Event
|
19
|
+
|
20
|
+
describe AnnotationEvent do
|
21
|
+
|
22
|
+
it 'should ensure that a AnnotationEvent (Highlight) is correctly created and serialized' do
|
23
|
+
|
24
|
+
# The Actor (Person/Student))
|
25
|
+
student = Caliper::Entities::LIS::Person.new
|
26
|
+
student.id = 'https://some-university.edu/user/554433'
|
27
|
+
membership1 = Caliper::Entities::LIS::Membership.new
|
28
|
+
membership1.id = "https://some-university.edu/membership/001"
|
29
|
+
membership1.member = "https://some-university.edu/user/554433"
|
30
|
+
membership1.organization = "https://some-university.edu/politicalScience/2015/american-revolution-101"
|
31
|
+
membership1.roles = [Caliper::Entities::LIS::Roles::LEARNER]
|
32
|
+
membership1.status = Caliper::Entities::LIS::Status::ACTIVE
|
33
|
+
membership1.dateCreated = "2015-08-01T06:00:00.000Z"
|
34
|
+
membership1.dateModified = nil;
|
35
|
+
membership2 = Caliper::Entities::LIS::Membership.new
|
36
|
+
membership2.id = "https://some-university.edu/membership/002"
|
37
|
+
membership2.member = "https://some-university.edu/user/554433"
|
38
|
+
membership2.organization = "https://some-university.edu/politicalScience/2015/american-revolution-101/section/001"
|
39
|
+
membership2.roles = [Caliper::Entities::LIS::Roles::LEARNER]
|
40
|
+
membership2.status = Caliper::Entities::LIS::Status::ACTIVE
|
41
|
+
membership2.dateCreated = "2015-08-01T06:00:00.000Z"
|
42
|
+
membership2.dateModified = nil
|
43
|
+
membership3 = Caliper::Entities::LIS::Membership.new
|
44
|
+
membership3.id = "https://some-university.edu/membership/003"
|
45
|
+
membership3.member = "https://some-university.edu/user/554433"
|
46
|
+
membership3.organization = "https://some-university.edu/politicalScience/2015/american-revolution-101/section/001/group/001"
|
47
|
+
membership3.roles = [Caliper::Entities::LIS::Roles::LEARNER]
|
48
|
+
membership3.status = Caliper::Entities::LIS::Status::ACTIVE
|
49
|
+
membership3.dateCreated = "2015-08-01T06:00:00.000Z"
|
50
|
+
membership3.dateModified = nil
|
51
|
+
student.hasMembership = [membership1, membership2, membership3]
|
52
|
+
student.dateCreated = '2015-08-01T06:00:00.000Z'
|
53
|
+
student.dateModified = '2015-09-02T11:30:00.000Z'
|
54
|
+
# puts "new student = #{student.to_json}"
|
55
|
+
|
56
|
+
# The Action
|
57
|
+
action = Caliper::Profiles::AnnotationActions::HIGHLIGHTED
|
58
|
+
|
59
|
+
# The Object of the highlight (Frame)
|
60
|
+
ePubVolume = Caliper::Entities::Reading::EPubVolume.new
|
61
|
+
ePubVolume.id = 'https://github.com/readium/readium-js-viewer/book/34843#epubcfi(/4/3)'
|
62
|
+
ePubVolume.name = 'The Glorious Cause: The American Revolution, 1763-1789 (Oxford History of the United States)'
|
63
|
+
ePubVolume.version = '2nd ed.'
|
64
|
+
ePubVolume.dateCreated = '2015-08-01T06:00:00.000Z'
|
65
|
+
ePubVolume.dateModified = '2015-09-02T11:30:00.000Z'
|
66
|
+
|
67
|
+
frame = Caliper::Entities::Reading::Frame.new
|
68
|
+
frame.id = 'https://github.com/readium/readium-js-viewer/book/34843#epubcfi(/4/3/1)'
|
69
|
+
frame.name = 'Key Figures: George Washington'
|
70
|
+
frame.version = '2nd ed.'
|
71
|
+
frame.dateCreated = '2015-08-01T06:00:00.000Z'
|
72
|
+
frame.dateModified = '2015-09-02T11:30:00.000Z'
|
73
|
+
frame.index = 1
|
74
|
+
frame.isPartOf = ePubVolume.id
|
75
|
+
|
76
|
+
# The Generated (Annotation::BookmarkAnnotation)
|
77
|
+
highlight = Caliper::Entities::Annotation::HighlightAnnotation.new
|
78
|
+
highlight.id = 'https://someEduApp.edu/highlights/12345'
|
79
|
+
highlight.name = nil
|
80
|
+
highlight.description = nil
|
81
|
+
highlight.dateCreated = '2015-08-01T06:00:00.000Z'
|
82
|
+
highlight.dateModified = '2015-09-02T11:30:00.000Z'
|
83
|
+
highlight.annotated = 'https://github.com/readium/readium-js-viewer/book/34843#epubcfi(/4/3/1)'
|
84
|
+
highlight.selectionText = 'Life, Liberty and the pursuit of Happiness'
|
85
|
+
highlight.selection = { 'start' => '455', 'end' => '489'}
|
86
|
+
|
87
|
+
# The course that is part of the Learning Context (edApp)
|
88
|
+
edApp = Caliper::Entities::SoftwareApplication.new
|
89
|
+
edApp.id = 'https://github.com/readium/readium-js-viewer'
|
90
|
+
edApp.name = 'Readium'
|
91
|
+
edApp.hasMembership = []
|
92
|
+
edApp.dateCreated = '2015-08-01T06:00:00.000Z'
|
93
|
+
edApp.dateModified = '2015-09-02T11:30:00.000Z'
|
94
|
+
|
95
|
+
#LIS Course Offering
|
96
|
+
courseOffering = Caliper::Entities::LIS::CourseOffering.new
|
97
|
+
courseOffering.id = "https://some-university.edu/politicalScience/2015/american-revolution-101"
|
98
|
+
courseOffering.name = "Political Science 101: The American Revolution"
|
99
|
+
courseOffering.courseNumber = "POL101"
|
100
|
+
courseOffering.academicSession = "Fall-2015"
|
101
|
+
courseOffering.membership = []
|
102
|
+
courseOffering.subOrganizationOf = nil
|
103
|
+
courseOffering.dateCreated = '2015-08-01T06:00:00.000Z'
|
104
|
+
courseOffering.dateModified = '2015-09-02T11:30:00.000Z'
|
105
|
+
|
106
|
+
# The LIS Course Section for the Caliper Event
|
107
|
+
course = Caliper::Entities::LIS::CourseSection.new
|
108
|
+
course.id = 'https://some-university.edu/politicalScience/2015/american-revolution-101/section/001'
|
109
|
+
course.name = 'American Revolution 101'
|
110
|
+
course.courseNumber = "POL101"
|
111
|
+
course.academicSession = "Fall-2015"
|
112
|
+
course.category = nil
|
113
|
+
course.membership = [membership2]
|
114
|
+
course.subOrganizationOf = courseOffering
|
115
|
+
course.dateCreated = '2015-08-01T06:00:00.000Z'
|
116
|
+
course.dateModified = '2015-09-02T11:30:00.000Z'
|
117
|
+
|
118
|
+
# LIS Group
|
119
|
+
group = Caliper::Entities::LIS::Group.new
|
120
|
+
group.id = "https://some-university.edu/politicalScience/2015/american-revolution-101/section/001/group/001"
|
121
|
+
group.name = "Discussion Group 001"
|
122
|
+
group.membership = [membership3]
|
123
|
+
group.subOrganizationOf = course
|
124
|
+
group.dateCreated = '2015-08-01T06:00:00.000Z'
|
125
|
+
group.dateModified = nil
|
126
|
+
|
127
|
+
# The (Annotation::BookmarkAnnotation) Event
|
128
|
+
annotation_event = AnnotationEvent.new
|
129
|
+
annotation_event.actor = student
|
130
|
+
annotation_event.action = action
|
131
|
+
annotation_event.object = frame
|
132
|
+
annotation_event.target = nil
|
133
|
+
annotation_event.generated = highlight
|
134
|
+
annotation_event.edApp = edApp
|
135
|
+
annotation_event.group = group
|
136
|
+
annotation_event.startedAtTime = '2015-09-15T10:15:00.000Z'
|
137
|
+
annotation_event.endedAtTime = nil
|
138
|
+
annotation_event.duration = nil
|
139
|
+
# puts "Event JSON = #{annotation_event.to_json}'"
|
140
|
+
|
141
|
+
# Load JSON from caliper-common-fixtures for comparison
|
142
|
+
# NOTE - sym link to caliper-common-fixtures needs to exist under spec/fixtures
|
143
|
+
file = File.read('spec/fixtures/caliperHighlightAnnotationEvent.json')
|
144
|
+
data_hash = JSON.parse(file)
|
145
|
+
expected_json = data_hash.to_json # convert hash back to JSON string after parse
|
146
|
+
annotation_event.to_json.should be_json_eql(expected_json)#.excluding("actor", "action", "object", "target", "generated", "edApp", "group")
|
147
|
+
|
148
|
+
# puts "JSON from file = #{data_hash}"
|
149
|
+
deser_annotation_event = AnnotationEvent.new
|
150
|
+
deser_annotation_event.from_json data_hash
|
151
|
+
# puts "AnnotationEvent from JSON = #{deser_annotation_event.to_json}"
|
152
|
+
|
153
|
+
# Ensure that the deserialized highlight event object conforms
|
154
|
+
expect(annotation_event).to eql(deser_annotation_event)
|
155
|
+
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|