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.
Files changed (131) hide show
  1. checksums.yaml +8 -8
  2. data/.gitignore +37 -0
  3. data/.idea/caliper-ruby.iml +98 -0
  4. data/.idea/encodings.xml +5 -0
  5. data/.idea/misc.xml +5 -0
  6. data/.idea/modules.xml +9 -0
  7. data/.idea/scopes/scope_settings.xml +5 -0
  8. data/.idea/vcs.xml +7 -0
  9. data/Gemfile +12 -1
  10. data/Gemfile.lock +42 -1
  11. data/LICENSE +67 -0
  12. data/NOTICE +15 -0
  13. data/README.md +13 -5
  14. data/caliper.gemspec +2 -8
  15. data/lib/caliper/defaults.rb +4 -4
  16. data/lib/caliper/entities/annotation/annotation.rb +14 -4
  17. data/lib/caliper/entities/annotation/bookmark_annotation.rb +14 -4
  18. data/lib/caliper/entities/annotation/highlight_annotation.rb +14 -3
  19. data/lib/caliper/entities/annotation/shared_annotation.rb +12 -3
  20. data/lib/caliper/entities/annotation/tag_annotation.rb +13 -3
  21. data/lib/caliper/entities/assessment/assessment.rb +27 -0
  22. data/lib/caliper/entities/assessment/assessment_item.rb +26 -0
  23. data/lib/caliper/entities/assignable/assignable_digital_resource.rb +47 -0
  24. data/lib/caliper/entities/assignable/attempt.rb +32 -0
  25. data/lib/caliper/entities/digital_resource.rb +36 -35
  26. data/lib/caliper/entities/entity.rb +50 -36
  27. data/lib/caliper/entities/foaf/agent.rb +1 -1
  28. data/lib/caliper/entities/jsonable.rb +56 -0
  29. data/lib/caliper/entities/learning_objective.rb +26 -0
  30. data/lib/caliper/entities/lis/course_offering.rb +30 -0
  31. data/lib/caliper/entities/lis/course_section.rb +27 -15
  32. data/lib/caliper/entities/lis/group.rb +27 -0
  33. data/lib/caliper/entities/lis/membership.rb +32 -0
  34. data/lib/caliper/entities/lis/organization.rb +20 -17
  35. data/lib/caliper/entities/lis/person.rb +23 -10
  36. data/lib/caliper/entities/lis/roles.rb +77 -0
  37. data/lib/caliper/entities/lis/status.rb +19 -0
  38. data/lib/caliper/entities/media/audio_object.rb +21 -0
  39. data/lib/caliper/entities/media/image_object.rb +21 -0
  40. data/lib/caliper/entities/media/media_location.rb +23 -0
  41. data/lib/caliper/entities/media/media_object.rb +38 -0
  42. data/lib/caliper/entities/media/video_object.rb +21 -0
  43. data/lib/caliper/entities/reading/epub_volume.rb +15 -7
  44. data/lib/caliper/entities/reading/frame.rb +7 -15
  45. data/lib/caliper/entities/response/fillin_blank_response.rb +20 -0
  46. data/lib/caliper/entities/response/multiple_choice_response.rb +20 -0
  47. data/lib/caliper/entities/response/multiple_response_response.rb +20 -0
  48. data/lib/caliper/entities/response/response.rb +23 -0
  49. data/lib/caliper/entities/response/response_type.rb +13 -0
  50. data/lib/caliper/entities/response/select_type_response.rb +20 -0
  51. data/lib/caliper/entities/response/true_false_response.rb +21 -0
  52. data/lib/caliper/entities/schemadotorg/software_application.rb +8 -8
  53. data/lib/caliper/entities/session.rb +25 -17
  54. data/lib/caliper/entities/software_application.rb +16 -7
  55. data/lib/caliper/entities/web_page.rb +2 -0
  56. data/lib/caliper/entity_envelope.rb +21 -0
  57. data/lib/caliper/event/annotation_event.rb +10 -6
  58. data/lib/caliper/event/assessment_event.rb +19 -0
  59. data/lib/caliper/event/assessment_item_event.rb +19 -0
  60. data/lib/caliper/event/assignable_event.rb +19 -0
  61. data/lib/caliper/event/event.rb +70 -50
  62. data/lib/caliper/event/jsonable.rb +55 -0
  63. data/lib/caliper/event/navigation_event.rb +2 -7
  64. data/lib/caliper/event/outcome_event.rb +1 -1
  65. data/lib/caliper/event/session_event.rb +13 -14
  66. data/lib/caliper/event/view_event.rb +6 -7
  67. data/lib/caliper/event_envelope.rb +22 -0
  68. data/lib/caliper/jsonable.rb +53 -0
  69. data/lib/caliper/profiles/annotation_profile.rb +56 -53
  70. data/lib/caliper/profiles/assessment_profile.rb +48 -0
  71. data/lib/caliper/profiles/assignable_profile.rb +44 -0
  72. data/lib/caliper/profiles/media_profile.rb +54 -0
  73. data/lib/caliper/profiles/profile.rb +38 -38
  74. data/lib/caliper/profiles/reading_profile.rb +31 -28
  75. data/lib/caliper/profiles/session_profile.rb +17 -18
  76. data/lib/caliper/request/event_store_requestor.rb +26 -26
  77. data/lib/caliper/sensor.rb +46 -35
  78. data/lib/caliper/version.rb +1 -1
  79. data/spec/lib/entities/entity.json +9 -0
  80. data/spec/lib/entities/entity_spec.rb +37 -0
  81. data/spec/lib/entities/lis/person_spec.rb +37 -0
  82. data/spec/lib/entities/lis/student.json +11 -0
  83. data/spec/lib/event/annotation_event_bookmark_spec.rb +159 -0
  84. data/spec/lib/event/annotation_event_highlight_spec.rb +160 -0
  85. data/spec/lib/event/annotation_event_shared_spec.rb +172 -0
  86. data/spec/lib/event/annotation_event_tag_spec.rb +159 -0
  87. data/spec/lib/event/assessment_event_spec.rb +207 -0
  88. data/spec/lib/event/assessment_item_completed_event_spec.rb +223 -0
  89. data/spec/lib/event/assessment_item_started_event_spec.rb +207 -0
  90. data/spec/lib/event/media_event_spec.rb +157 -0
  91. data/spec/lib/event/navigated_event_spec.rb +160 -0
  92. data/spec/lib/event/session_event_login_spec.rb +160 -0
  93. data/spec/lib/event/session_event_logout_spec.rb +145 -0
  94. data/spec/lib/event/session_event_timeout_spec.rb +145 -0
  95. data/spec/lib/event/viewed_event_spec.rb +149 -0
  96. data/spec/lib/event_helper.rb +145 -0
  97. data/spec/lib/sensor_spec.rb +30 -0
  98. data/spec/spec_helper.rb +3 -2
  99. metadata +84 -61
  100. data/lib/caliper/client.rb +0 -33
  101. data/lib/caliper/consumer/base.rb +0 -46
  102. data/lib/caliper/consumer/queue.rb +0 -40
  103. data/lib/caliper/consumer/socket.rb +0 -132
  104. data/lib/caliper/entities/annotation/text_position_selector.rb +0 -14
  105. data/lib/caliper/entities/schemadotorg/audio_object.rb +0 -15
  106. data/lib/caliper/entities/schemadotorg/image_object.rb +0 -15
  107. data/lib/caliper/entities/schemadotorg/media_object.rb +0 -19
  108. data/lib/caliper/entities/schemadotorg/video_object.rb +0 -15
  109. data/lib/caliper/event/.shared.rb.swp +0 -0
  110. data/spec/lib/client_spec.rb +0 -35
  111. data/spec/lib/consumer/base_spec.rb +0 -28
  112. data/spec/lib/consumer/queue_spec.rb +0 -16
  113. data/spec/lib/event/annotation_spec.rb +0 -12
  114. data/spec/lib/event/bookmarked_spec.rb +0 -17
  115. data/spec/lib/event/commented_spec.rb +0 -19
  116. data/spec/lib/event/highlighted_spec.rb +0 -18
  117. data/spec/lib/event/navigation_spec.rb +0 -15
  118. data/spec/lib/event/shared_spec.rb +0 -18
  119. data/spec/lib/event/tagged_spec.rb +0 -17
  120. data/spec/lib/event/used_spec.rb +0 -15
  121. data/spec/lib/event/viewed_spec.rb +0 -15
  122. data/test/caliper/events/session_login_event_test.rb +0 -58
  123. data/test/caliper/events/session_logout_event_test.rb +0 -55
  124. data/test/caliper/events/session_timeout_event_test.rb +0 -55
  125. data/test/caliper/request/http_requestor_test.rb +0 -59
  126. data/test/caliper/test_event.rb +0 -53
  127. data/test/caliper/test_utils.rb +0 -198
  128. data/test/fixtures/caliper_session_login_event.json +0 -71
  129. data/test/fixtures/caliper_session_logout_event.json +0 -52
  130. data/test/fixtures/caliper_session_timeout_event.json +0 -52
  131. data/test/fixtures/event_store_payload.json +0 -85
@@ -1,13 +1,17 @@
1
+ require_relative 'event'
2
+ require_relative '../profiles/annotation_profile'
3
+
1
4
  module Caliper
2
5
  module Event
6
+
7
+ #
8
+ # Annotation Event per Caliper Annotation Profile
9
+ #
3
10
  class AnnotationEvent < Event
4
- attr_accessor :location
5
11
 
6
- def initialize(action)
7
- @context = "http://purl.imsglobal.org/ctx/caliper/v1/AnnotationEvent"
8
- @type = "http://purl.imsglobal.org/caliper/v1/AnnotationEvent"
9
- # only subclasses should be instantiated
10
- @action = action
12
+ def initialize
13
+ @context = Caliper::Event::EventContext::ANNOTATION
14
+ @type = Caliper::Event::EventType::ANNOTATION
11
15
  end
12
16
  end
13
17
  end
@@ -0,0 +1,19 @@
1
+ require_relative 'event'
2
+
3
+ module Caliper
4
+ module Event
5
+ class AssessmentEvent < Event
6
+ attr_accessor :context,
7
+ :type,
8
+ :action,
9
+ :object,
10
+ :target
11
+
12
+ def initialize
13
+ super
14
+ @context = EventContext::ASSESSMENT
15
+ @type = EventType::ASSESSMENT
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require_relative 'event'
2
+
3
+ module Caliper
4
+ module Event
5
+ class AssessmentItemEvent < Event
6
+ attr_accessor :context,
7
+ :type,
8
+ :action,
9
+ :object,
10
+ :target
11
+
12
+ def initialize
13
+ super
14
+ @context = EventContext::ASSESSMENT_ITEM
15
+ @type = EventType::ASSESSMENT_ITEM
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require_relative 'event'
2
+
3
+ module Caliper
4
+ module Event
5
+ class AssignableEvent < Event
6
+ attr_accessor :context,
7
+ :type,
8
+ :action,
9
+ :object,
10
+ :target
11
+
12
+ def initialize
13
+ super
14
+ @context = EventContext::ASSIGNABLE
15
+ @type = EventType::ASSIGNABLE
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,68 +1,88 @@
1
+ require 'json'
2
+ require_relative './jsonable'
3
+
1
4
  module Caliper
2
5
  module Event
3
- module EventContext
4
- ANNOTATION = "http://purl.imsglobal.org/ctx/caliper/v1/AnnotationEvent"
5
- ASSESSMENT = "http://purl.imsglobal.org/ctx/caliper/v1/AssessmentEvent"
6
- ASSESSMENT_ITEM = "http://purl.imsglobal.org/ctx/caliper/v1/AssessmentItemEvent"
7
- ASSIGNABLE = "http://purl.imsglobal.org/ctx/caliper/v1/AssignableEvent"
8
- EVENT = "http://purl.imsglobal.org/ctx/caliper/v1/Event"
9
- MEDIA = "http://purl.imsglobal.org/ctx/caliper/v1/MediaEvent"
10
- NAVIGATION = "http://purl.imsglobal.org/ctx/caliper/v1/NavigationEvent"
11
- OUTCOME = "http://purl.imsglobal.org/ctx/caliper/v1/OutcomeEvent"
12
- SESSION = "http://purl.imsglobal.org/ctx/caliper/v1/SessionEvent"
13
- VIEW = "http://purl.imsglobal.org/ctx/caliper/v1/ViewEvent"
14
- end
15
- module EventType
16
- ANNOTATION = "http://purl.imsglobal.org/caliper/v1/AnnotationEvent"
17
- ASSESSMENT = "http://purl.imsglobal.org/caliper/v1/AssessmentEvent"
18
- ASSESSMENT_ITEM = "http://purl.imsglobal.org/caliper/v1/AssessmentItemEvent"
19
- ASSIGNABLE = "http://purl.imsglobal.org/caliper/v1/AssignableEvent"
20
- EVENT = "http://purl.imsglobal.org/caliper/v1/Event"
21
- MEDIA = "http://purl.imsglobal.org/caliper/v1/MediaEvent"
22
- NAVIGATION = "http://purl.imsglobal.org/caliper/v1/NavigationEvent"
23
- OUTCOME = "http://purl.imsglobal.org/caliper/v1/OutcomeEvent"
24
- SESSION = "http://purl.imsglobal.org/caliper/v1/SessionEvent"
25
- VIEW = "http://purl.imsglobal.org/caliper/v1/ViewEvent"
26
- end
6
+ module EventContext
7
+ ANNOTATION = "http://purl.imsglobal.org/ctx/caliper/v1/AnnotationEvent"
8
+ ASSESSMENT = "http://purl.imsglobal.org/ctx/caliper/v1/AssessmentEvent"
9
+ ASSESSMENT_ITEM = "http://purl.imsglobal.org/ctx/caliper/v1/AssessmentItemEvent"
10
+ ASSIGNABLE = "http://purl.imsglobal.org/ctx/caliper/v1/AssignableEvent"
11
+ EVENT = "http://purl.imsglobal.org/ctx/caliper/v1/Event"
12
+ MEDIA = "http://purl.imsglobal.org/ctx/caliper/v1/MediaEvent"
13
+ NAVIGATION = "http://purl.imsglobal.org/ctx/caliper/v1/NavigationEvent"
14
+ OUTCOME = "http://purl.imsglobal.org/ctx/caliper/v1/OutcomeEvent"
15
+ SESSION = "http://purl.imsglobal.org/ctx/caliper/v1/SessionEvent"
16
+ VIEW = "http://purl.imsglobal.org/ctx/caliper/v1/ViewEvent"
17
+ end
18
+ module EventType
19
+ ANNOTATION = "http://purl.imsglobal.org/caliper/v1/AnnotationEvent"
20
+ ASSESSMENT = "http://purl.imsglobal.org/caliper/v1/AssessmentEvent"
21
+ ASSESSMENT_ITEM = "http://purl.imsglobal.org/caliper/v1/AssessmentItemEvent"
22
+ ASSIGNABLE = "http://purl.imsglobal.org/caliper/v1/AssignableEvent"
23
+ EVENT = "http://purl.imsglobal.org/caliper/v1/Event"
24
+ MEDIA = "http://purl.imsglobal.org/caliper/v1/MediaEvent"
25
+ NAVIGATION = "http://purl.imsglobal.org/caliper/v1/NavigationEvent"
26
+ OUTCOME = "http://purl.imsglobal.org/caliper/v1/OutcomeEvent"
27
+ SESSION = "http://purl.imsglobal.org/caliper/v1/SessionEvent"
28
+ VIEW = "http://purl.imsglobal.org/caliper/v1/ViewEvent"
29
+ end
27
30
  class Event
31
+ include Caliper::Event::Jsonable
32
+
28
33
  attr_accessor :context, # String Required - the JSON-LD context for the Event
29
34
 
30
- # Required - the type of the Event
31
- :type, # String
35
+ # Required - the type of the Event
36
+ :type, # String
37
+
38
+ # Learning Context
39
+ :edApp, # SoftwareApplication
32
40
 
33
- # Learning Context
34
- :ed_app, # SoftwareApplication
41
+ # LIS Group
42
+ :group, # Group
35
43
 
36
- # LIS organization
37
- :lis_organization, # Organization
44
+ # Required - Agent (User, System) that performed the action
45
+ :actor, # Agent
38
46
 
39
- # Required - Agent (User, System) that performed the action
40
- :actor, # Agent
47
+ # Required - Action performed by Agent From Metric Profile
48
+ :action, # String
41
49
 
42
- # Required - Action performed by Agent From Metric Profile
43
- :action, # String
50
+ # Required - "Activity Context" from Metric Profile
51
+ :object, # Object
44
52
 
45
- # Required - "Activity Context" from Metric Profile
46
- :object, # Object
53
+ # Optional - "target" from Metric Profile
54
+ :target, # Targetable
47
55
 
48
- # Optional - "target" from Metric Profile
49
- :target, # Targetable
56
+ # Optional - entity "generated" as result of action - from Metric Profile
57
+ :generated, # Generatable
50
58
 
51
- # Optional - entity "generated" as result of action - from Metric Profile
52
- :generated, # Generatable
59
+ # Required time that the event was started at
60
+ :startedAtTime, # ISO-8601 date string
53
61
 
54
- # Required time in milliseconds that the event was started at
55
- :started_at_time, # long
62
+ # An optional time that the event ended at
63
+ :endedAtTime, # ISO-8601 date string
56
64
 
57
- # An optional time in milliseconds that the event ended at
58
- :ended_at_time, # long
65
+ # An xsd:duration (http://books.xmlschemata.org/relaxng/ch19-77073.html)
66
+ # The format is expected to be PnYnMnDTnHnMnS
67
+ # Valid values include PT1004199059S, PT130S, PT2M10S, P1DT2S, -P1Y, or P1Y2M3DT5H20M30.123S.
68
+ # The following values are invalid: 1Y (leading P is missing), P1S (T separator is missing),
69
+ # P-1Y (all parts must be positive), P1M2Y (parts order is significant and Y must precede M) * or P1Y-1M (all parts must be positive). */
70
+ :duration # String
59
71
 
60
- # An xsd:duration (http://books.xmlschemata.org/relaxng/ch19-77073.html)
61
- # The format is expected to be PnYnMnDTnHnMnS
62
- # Valid values include PT1004199059S, PT130S, PT2M10S, P1DT2S, -P1Y, or P1Y2M3DT5H20M30.123S.
63
- # The following values are invalid: 1Y (leading P is missing), P1S (T separator is missing),
64
- # P-1Y (all parts must be positive), P1M2Y (parts order is significant and Y must precede M) * or P1Y-1M (all parts must be positive). */
65
- :duration # String
72
+ def initialize()
73
+ @context = EventContext::EVENT
74
+ @type = EventType::EVENT
75
+ @actor = nil
76
+ @action = nil
77
+ @object = nil
78
+ @target = nil
79
+ @generated = nil
80
+ @edApp = nil
81
+ @group = nil
82
+ @startedAtTime = Time.now.utc.iso8601(3)
83
+ @endedAtTime = nil
84
+ @duration = nil
85
+ end
66
86
  end
67
87
  end
68
88
  end
@@ -0,0 +1,55 @@
1
+ require 'json'
2
+
3
+ #
4
+ #
5
+ # @copyright @copyright ©2013 IMS Global Learning Consortium, Inc. All Rights Reserved.
6
+ # @license For license information contact, info@imsglobal.org
7
+ #
8
+ # Module that supports ser-des for Caliper Event/JSON
9
+ #
10
+ module Caliper
11
+ module Event
12
+ module Jsonable
13
+
14
+ def self.included(base)
15
+ base.extend ClassMethods
16
+ end
17
+
18
+ module ClassMethods
19
+ end
20
+
21
+ def to_json(*a)
22
+ # puts 'Jsonable: to_json invoked'
23
+ result = {}
24
+ result['@context'] = self.context
25
+ result['@type'] = self.type
26
+ self.instance_variables.each do |key|
27
+ # puts "got key = #{key}"
28
+ next if (key[1..-1] == 'context' || key[1..-1] == 'type')
29
+ value = self.instance_variable_get key
30
+ # puts "setting #{key}: #{value}"
31
+ result[key[1..-1]] = value
32
+ end
33
+ result.to_json(*a)
34
+ end
35
+
36
+ def from_json json_hash
37
+ data = json_hash
38
+ # puts "Jsonable: from_json: json_hash = #{json_hash}"
39
+ self.context = data['@context']
40
+ self.type = data['@type']
41
+ json_hash.each do | key, value |
42
+ next if (key[1..-1] == 'context' || key[1..-1] == 'type')
43
+ # puts "Jsonable - adding #{key} : #{value}"
44
+ self.instance_variable_set "@#{key}", value
45
+ end
46
+ return self
47
+ end
48
+
49
+ def eql?(other)
50
+ @context == other.context && @type == other.type && @startedAtTime == other.startedAtTime && @endedAtTime == other.endedAtTime
51
+ end
52
+
53
+ end
54
+ end
55
+ end
@@ -5,18 +5,13 @@ module Caliper
5
5
  module Event
6
6
  class NavigationEvent < Event
7
7
 
8
- attr_accessor :context,
9
- :type,
10
- :action,
11
- :object,
12
- :from_resource, #the resource from which the navigation starts
13
- :target
8
+ attr_accessor :navigatedFrom
14
9
 
15
10
  def initialize
16
11
  super
17
12
  @context = EventContext::NAVIGATION
18
13
  @type = EventType::NAVIGATION
19
- @action = Caliper::Profiles::ProfileActions::NAVIGATED_TO
14
+ @navigatedFrom = nil
20
15
  end
21
16
  end
22
17
  end
@@ -1,5 +1,5 @@
1
1
  require_relative 'event'
2
- require_relative '../profiles/profile_actions'
2
+ require_relative '../profiles/profile'
3
3
 
4
4
  module Caliper
5
5
  module Event
@@ -2,20 +2,19 @@ require_relative 'event'
2
2
  require_relative '../profiles/session_profile'
3
3
 
4
4
  module Caliper
5
- module Event
6
- class SessionEvent < Event
5
+ module Event
6
+
7
+ class SessionEvent < Event
7
8
 
8
- # Utilize builder to construct SessionEvent. Validate Session object copy rather than the
9
- # Session builder. This approach protects the class against parameter changes from another
10
- # thread during the "window of vulnerability" between the time the parameters are checked
11
- # until when they are copied. Validate properties of builder copy and if conformance violations
12
- # are found throw an IllegalStateException (Bloch, Effective Java, 2nd ed., items 2, 39, 60, 63).
13
- def initialize
14
- super
15
- @context = Caliper::Event::EventContext::SESSION
16
- @type = Caliper::Event::EventType::SESSION
17
- end
9
+ #
10
+ # Session Event per the Caliper Session Profile
11
+ #
12
+ def initialize
13
+ super
14
+ @context = Caliper::Event::EventContext::SESSION
15
+ @type = Caliper::Event::EventType::SESSION
16
+ end
18
17
 
19
- end
20
- end
18
+ end
19
+ end
21
20
  end
@@ -1,20 +1,19 @@
1
1
  require_relative 'event'
2
- require_relative '../profiles/reading_profile_key'
2
+ require_relative '../profiles/reading_profile.rb'
3
3
 
4
4
  module Caliper
5
5
  module Event
6
+
6
7
  class ViewEvent < Event
7
- attr_accessor :context,
8
- :type,
9
- :action,
10
- :object,
11
- :target
12
8
 
9
+ #
10
+ # Viewed Event per the Caliper Base Profile
11
+ #
13
12
  def initialize
14
13
  @type = EventType::VIEW
15
- @action = ReadingProfileKey::VIEWED
16
14
  @context = EventContext::VIEW
17
15
  end
16
+
18
17
  end
19
18
  end
20
19
  end
@@ -0,0 +1,22 @@
1
+ require 'rest_client'
2
+ require_relative "options"
3
+ require_relative 'jsonable'
4
+
5
+ ##
6
+ #
7
+ # @copyright @copyright ©2013 IMS Global Learning Consortium, Inc. All Rights Reserved.
8
+ # @license For license information contact, info@imsglobal.org
9
+ #
10
+ # Caliper Sensor Event Envelope
11
+ #
12
+ #
13
+ module Caliper
14
+
15
+ class EventEnvelope
16
+ include Caliper::Jsonable
17
+
18
+ attr_accessor :apiKey,
19
+ :sensorId,
20
+ :event
21
+ end
22
+ end
@@ -0,0 +1,53 @@
1
+ require 'json'
2
+
3
+ #
4
+ #
5
+ # @copyright @copyright ©2013 IMS Global Learning Consortium, Inc. All Rights Reserved.
6
+ # @license For license information contact, info@imsglobal.org
7
+ #
8
+ # Module that supports ser-des for Caliper Envelope
9
+ #
10
+ module Caliper
11
+ module Jsonable
12
+
13
+ def self.included(base)
14
+ base.extend ClassMethods
15
+ end
16
+
17
+ module ClassMethods
18
+ end
19
+
20
+ def to_json(*a)
21
+ # puts 'Jsonable: to_json invoked'
22
+ result = {}
23
+ # result['@context'] = self.context
24
+ # result['@type'] = self.type
25
+ self.instance_variables.each do |key|
26
+ # puts "got key = #{key}"
27
+ next if (key[1..-1] == 'context' || key[1..-1] == 'type')
28
+ value = self.instance_variable_get key
29
+ # puts "setting #{key}: #{value}"
30
+ result[key[1..-1]] = value
31
+ end
32
+ result.to_json(*a)
33
+ end
34
+
35
+ def from_json json_hash
36
+ data = json_hash
37
+ # puts "Jsonable: from_json: json_hash = #{json_hash}"
38
+ # self.context = data['@context']
39
+ # self.type = data['@type']
40
+ json_hash.each do | key, value |
41
+ next if (key[1..-1] == 'context' || key[1..-1] == 'type')
42
+ # puts "Jsonable - adding #{key} : #{value}"
43
+ self.instance_variable_set "@#{key}", value
44
+ end
45
+ return self
46
+ end
47
+
48
+ def eql?(other)
49
+ @sensorId == other.sensorId && @apiKey == other.apiKey
50
+ end
51
+
52
+ end
53
+ end