ims_caliper 0.9.3.3 → 0.9.3.4

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NzUwODdkM2RjNWY0NDRlMWYzNGJhZTE3NjBhYzEzODMxMjY5N2I0Zg==
4
+ YmVlM2QyNzkwMTEyMDVkMjA1NTcwNzdhMGRiNTFkZTE4M2Q0NWM3NA==
5
5
  data.tar.gz: !binary |-
6
- NjIyZjIyYmRkOTZiYjdiNWVhMjUzZTEyNDRlOTcwYmQyM2RlNTQ1NA==
6
+ ZWQwOWUzYzVkMzhhOWEwMTAxYWRlZmQ1N2ZkOWViZGQ3NDg3OTM2Yw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YWMxOWFiNzQ5ZmNhNTI4MzdlM2U0NTk3ODI2NTQ4NDMyMzgyMWU5OTkxZDRk
10
- MzUzNzRhYzBmYzAzNzI0NDcxNjNmOWE2MjQzNTRjM2ZiODRkYzEyMzc0Zjlk
11
- MGNmODQzMGJhNjFhM2NhYWIxOTQ0ODE3ZTI1YzhiY2E1MDg4MzA=
9
+ OTNmYjg3MzkxZGM4ZWE2MmExNTBkZDNhYzE1M2VhOGVkYWZiOGQyZjJmODYw
10
+ ODUyMDg1Mzg3MThiMDQ5ZGE1NDU3ZjE4MzQ5OThlMTNmNDhjMjVjNmFhYzgz
11
+ YmJiN2FhYjJmYzU0OGRhNTI4MWI5OGVlOGIyZWQwNjY0ZGUxOWM=
12
12
  data.tar.gz: !binary |-
13
- OTJiZjI0YzRlNjE5NWY1Y2NiZWIxNWQ5ZTM4NTNjNzc0MWM4MzVlMzlhMjdm
14
- YzI2MWU5NGNlOGFiMWU0MWViOTg2ZGVhMTlhYTQ1ZGE0NDQzNDM1N2U3NzA1
15
- ZDE0OTI2NmIzOGI3OGM0ZGU1YzdhOGU3MzYyYzE4ZGFmMTY2NzQ=
13
+ NjYzYjQzNmViNjRhZTkzNzliM2RjYTQxNmRhMDhmMDNiZjUyNTUyMWVkYmI5
14
+ M2FlODE4MDUzYTAwODhiODQ5NGE4NDE1MWI5MDQ0NGRlZTUzMmM1OTFkMjVj
15
+ OTVmZjdhMTExMWZhOTMwNzE3NWEwYmFjMzQzMmE4M2ZkNmE4ZGQ=
@@ -21,8 +21,8 @@
21
21
  module Caliper
22
22
  class Defaults
23
23
  HOST = "http://dev-null.comt"
24
- CONNECTION_REQUEST_TIMEOUT = 10000
25
24
  CONNECTION_TIMEOUT = 10000
26
- SOCKET_TIMEOUT = 10000
25
+ SO_TIMEOUT = 10000
26
+ CONNECTION_REQUEST_TIMEOUT = 10000
27
27
  end
28
28
  end
@@ -38,7 +38,7 @@ module Caliper
38
38
  end
39
39
 
40
40
  def initialize
41
- super
41
+
42
42
  end
43
43
  end
44
44
  end
@@ -30,7 +30,6 @@ module Caliper
30
30
  :values
31
31
 
32
32
  def initialize
33
- super
34
33
  @type = ResponseType::FILLINBLANK
35
34
  end
36
35
  end
@@ -29,7 +29,6 @@ module Caliper
29
29
  :values
30
30
 
31
31
  def initialize
32
- super
33
32
  @type = ResponseType::MULTIPLECHOICE
34
33
  end
35
34
  end
@@ -29,7 +29,6 @@ module Caliper
29
29
  :values
30
30
 
31
31
  def initialize
32
- super
33
32
  @type = ResponseType::MULTIPLERESPONSE
34
33
  end
35
34
  end
@@ -36,7 +36,6 @@ module Caliper
36
36
  :duration
37
37
 
38
38
  def initialize
39
- super
40
39
  @type = EntityType::RESPONSE
41
40
  end
42
41
  end
@@ -30,7 +30,6 @@ module Caliper
30
30
  :values
31
31
 
32
32
  def initialize
33
- super
34
33
  @type = ResponseType::SELECTTEXT
35
34
  end
36
35
  end
@@ -30,7 +30,6 @@ module Caliper
30
30
  :values
31
31
 
32
32
  def initialize
33
- super
34
33
  @type = ResponseType::TRUEFALSE
35
34
  end
36
35
  end
@@ -0,0 +1,33 @@
1
+ ##
2
+ # This file is part of IMS Caliper Analytics™ and is licensed to
3
+ # IMS Global Learning Consortium, Inc. (http://www.imsglobal.org)
4
+ # under one or more contributor license agreements. See the NOTICE
5
+ # file distributed with this work for additional information.
6
+ #
7
+ # IMS Caliper is free software: you can redistribute it and/or modify it under
8
+ # the terms of the GNU Lesser General Public License as published by the Free
9
+ # Software Foundation, version 3 of the License.
10
+ #
11
+ # IMS Caliper is distributed in the hope that it will be useful, but WITHOUT
12
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13
+ # A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License along
16
+ # with this program. If not, see http://www.gnu.org/licenses/.
17
+
18
+ require 'rest_client'
19
+ require_relative "./options"
20
+ require_relative './jsonable'
21
+
22
+ #
23
+ # Caliper Sensor Entity Envelope.
24
+ #
25
+ module Caliper
26
+ class EntityEnvelope
27
+ include Caliper::Jsonable
28
+
29
+ attr_accessor :apiKey,
30
+ :sensorId,
31
+ :entity
32
+ end
33
+ end
@@ -25,7 +25,6 @@ module Caliper
25
25
  class AnnotationEvent < Event
26
26
 
27
27
  def initialize
28
- super
29
28
  @context = Caliper::Event::EventContext::ANNOTATION
30
29
  @type = Caliper::Event::EventType::ANNOTATION
31
30
  end
@@ -25,7 +25,6 @@ module Caliper
25
25
  class ViewEvent < Event
26
26
 
27
27
  def initialize
28
- super
29
28
  @type = EventType::VIEW
30
29
  @context = EventContext::VIEW
31
30
  end
@@ -0,0 +1,33 @@
1
+ ##
2
+ # This file is part of IMS Caliper Analytics™ and is licensed to
3
+ # IMS Global Learning Consortium, Inc. (http://www.imsglobal.org)
4
+ # under one or more contributor license agreements. See the NOTICE
5
+ # file distributed with this work for additional information.
6
+ #
7
+ # IMS Caliper is free software: you can redistribute it and/or modify it under
8
+ # the terms of the GNU Lesser General Public License as published by the Free
9
+ # Software Foundation, version 3 of the License.
10
+ #
11
+ # IMS Caliper is distributed in the hope that it will be useful, but WITHOUT
12
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13
+ # A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License along
16
+ # with this program. If not, see http://www.gnu.org/licenses/.
17
+
18
+ require 'rest_client'
19
+ require_relative "./options"
20
+ require_relative './jsonable'
21
+
22
+ #
23
+ # Caliper Sensor Event Envelope.
24
+ #
25
+ module Caliper
26
+ class EventEnvelope
27
+ include Caliper::Jsonable
28
+
29
+ attr_accessor :apiKey,
30
+ :sensorId,
31
+ :event
32
+ end
33
+ end
@@ -64,8 +64,7 @@ module Caliper
64
64
  end
65
65
 
66
66
  def eql?(other)
67
- @context == other.context && @apiKey == other.apiKey
68
- # @context == other.context && @sensorId == other.sensorId && @apiKey == other.apiKey
67
+ @sensorId == other.sensorId && @apiKey == other.apiKey
69
68
  end
70
69
  end
71
70
  end
@@ -20,18 +20,18 @@
20
20
  #
21
21
  module Caliper
22
22
  class Options
23
- attr_accessor :host
24
23
  attr_accessor :api_key
25
- attr_accessor :connection_request_time_out
26
- attr_accessor :connection_time_out
27
- attr_accessor :socket_time_out
24
+ attr_accessor :host
25
+ attr_accessor :time_out
28
26
  end
29
27
 
30
- def initialize(options = {})
31
- self.host options[:host] || Defaults.HOST
32
- self.api_key options[:api_key] || ''
33
- self.connection_request_time_out options[:connection_request_time_out] || Defaults.CONNECTION_REQUEST_TIMEOUT
34
- self.connection_time_out options[:connection_time_out] || Defaults.CONNECTION_TIMEOUT
35
- self.socket_time_out options[:socket_time_out] || Defaults.SOCKET_TIMEOUT
36
- end
28
+ def initialize()
29
+ @host = Defaults.HOST
30
+ @time_out = Defaults.CONNECTION_TIMEOUT
31
+ end
32
+
33
+ def initialize(host, time_out)
34
+ @host = host
35
+ @time_out = time_out
36
+ end
37
37
  end
@@ -15,35 +15,13 @@
15
15
  # You should have received a copy of the GNU Lesser General Public License along
16
16
  # with this program. If not, see http://www.gnu.org/licenses/.
17
17
 
18
- require_relative './envelope_jsonable'
19
-
20
18
  #
21
19
  # Event store envelope. Contains event info.
22
20
  #
23
21
  module Caliper
24
- module Request
25
- module Context
26
- CONTEXT = "http://purl.imsglobal.org/caliper/ctx/v1/Envelope"
27
- end
28
-
29
- # module Type
30
- # TYPE = "http://purl.imsglobal.org/caliper/v1/Envelope"
31
- # end
32
-
33
- class Envelope
34
- include Caliper::Request::EnvelopeJsonable
35
-
36
- attr_accessor :context,
37
- :sensor,
38
- :sendTime,
39
- :data
40
-
41
- def initialize
42
- @context = Context::CONTEXT
43
- @sensor = ''
44
- @sendTime = Time.now.utc.iso8601(3)
45
- @data = []
46
- end
47
- end
48
- end
22
+ module Request
23
+ class EventStoreEnvelope
24
+ attr_accessor :id, :type, :time, :data
25
+ end
26
+ end
49
27
  end
@@ -16,7 +16,7 @@
16
16
  # with this program. If not, see http://www.gnu.org/licenses/.
17
17
 
18
18
  require 'securerandom'
19
- require_relative './envelope'
19
+ require_relative './event_store_envelope'
20
20
 
21
21
  #
22
22
  # Event store requestor.
@@ -25,26 +25,36 @@ module Caliper
25
25
  module Request
26
26
  class EventStoreRequestor
27
27
 
28
- def generate_payload(sensor, data)
29
- return get_payload_json(sensor, data)
30
- end
28
+ def get_payload_json(caliper_event, id, send_time)
31
29
 
32
- def get_payload_json(sensor, data)
33
- envelope = create_envelope(sensor, data)
34
- puts JSON.generate(envelope)
35
- return JSON.generate(envelope)
36
- end
30
+ list_payload = Array.new
31
+
32
+ # new event envelope
33
+ envelope = EventStoreEnvelope.new
34
+ envelope.id = id
35
+ envelope.type = "caliperEvent"
36
+ envelope.time = send_time.to_s
37
+ envelope.data = caliper_event
38
+
39
+ # add envelope into array
40
+ list_payload<< envelope
37
41
 
38
- def create_envelope(sensor, data)
39
- envelope = Envelope.new
40
- envelope.sensor = sensor.id
41
- envelope.data = to_array(data)
42
- return envelope
42
+ json_payload = JSON.generate(list_payload)
43
+ return json_payload
43
44
  end
44
45
 
45
- def to_array(data)
46
- return [data] if !(data.is_a?(Array))
46
+ def generate_payload(caliper_event, id, send_time)
47
+ if (id.nil?)
48
+ id = "caliper-java_" + SecureRandom.uuid
49
+ end
50
+
51
+ if (send_time.nil?)
52
+ send_time = Time.now
53
+ end
54
+
55
+ json_payload = get_payload_json(caliper_event, id, send_time)
56
+
47
57
  end
48
58
  end
49
59
  end
50
- end
60
+ end
@@ -15,9 +15,10 @@
15
15
  # You should have received a copy of the GNU Lesser General Public License along
16
16
  # with this program. If not, see http://www.gnu.org/licenses/.
17
17
 
18
- require 'rest-client'
19
- require_relative './envelope'
18
+ require "net/http"
19
+ require "uri"
20
20
  require_relative './event_store_requestor'
21
+ require_relative './event_store_envelope'
21
22
 
22
23
  module Caliper
23
24
  module Request
@@ -27,18 +28,32 @@ module Caliper
27
28
 
28
29
  def initialize(options)
29
30
  @options = options
30
- end
31
+ end
31
32
 
32
- def send(sensor, data)
33
- payload = generate_payload(sensor, data)
33
+ def send(event)
34
+ status = false
34
35
 
35
- puts payload
36
+ # the option.host returns whole url string
37
+ uri = URI(@options.host)
38
+ Net::HTTP.start(uri.host, uri.port) do |http|
39
+ request = Net::HTTP::Post.new uri
36
40
 
37
- puts @options['host']
41
+ response = http.request request # Net::HTTPResponse object
42
+ end
38
43
 
39
- # What about the api key (authorization)?
40
- RestClient.post @options['host'], payload, :content_type => :json, :accept => :json
41
- end
44
+ if (response.code != 200)
45
+ status_code = response.code
46
+
47
+ # failed call
48
+ status = false
49
+ fail "Failed: HTTP error code: " + status_code
50
+ else
51
+ # success call
52
+ status = true
53
+ end
54
+
55
+ return status
56
+ end
42
57
  end
43
58
  end
44
59
  end
@@ -15,9 +15,10 @@
15
15
  # You should have received a copy of the GNU Lesser General Public License along
16
16
  # with this program. If not, see http://www.gnu.org/licenses/.
17
17
 
18
-
19
- require_relative './options'
20
- require_relative './request/http_requestor'
18
+ require 'rest_client'
19
+ require_relative "./options"
20
+ require_relative "./event_envelope"
21
+ require_relative "./entity_envelope"
21
22
 
22
23
  #
23
24
  # Caliper Sensor.
@@ -25,23 +26,33 @@ require_relative './request/http_requestor'
25
26
  module Caliper
26
27
  class Sensor
27
28
 
28
- attr_accessor :id
29
-
30
- def initialize(id, options)
31
- @id = id
29
+ def initialize(options)
32
30
  @options = options
31
+ puts "Sensor - initializing with options = #{@options}"
32
+ end
33
+
34
+ def send(event)
35
+ raise ArgumentError, "Expecting Caliper::Event but got #{event.class.to_s}" unless event.is_a?(Caliper::Event::Event)
36
+
37
+ envelope = EventEnvelope.new
38
+ envelope.apiKey = @options['apiKey']
39
+ envelope.sensorId = @options['sensorId']
40
+ envelope.event = event
41
+
42
+ RestClient.post @options['host'], envelope.to_json, :content_type => :json, :accept => :json
43
+
33
44
  end
34
45
 
35
46
  def describe(entity)
36
47
  raise ArgumentError, "Expecting Caliper::Entity but got #{entity.class.to_s}" unless entity.is_a?(Caliper::Entities::Entity)
37
48
 
38
- Caliper::Request::HttpRequestor.new(@options).send(self, entity)
39
- end
49
+ envelope = EntityEnvelope.new
50
+ envelope.apiKey = @options['apiKey']
51
+ envelope.sensorId = @options['sensorId']
52
+ envelope.entity = entity
40
53
 
41
- def send(event)
42
- raise ArgumentError, "Expecting Caliper::Event but got #{event.class.to_s}" unless event.is_a?(Caliper::Event::Event)
54
+ RestClient.post @options['host'], envelope.to_json, :content_type => :json, :accept => :json
43
55
 
44
- Caliper::Request::HttpRequestor.new(@options).send(self, event)
45
56
  end
46
57
  end
47
58
  end
@@ -19,5 +19,5 @@
19
19
  # Version.
20
20
  #
21
21
  module Caliper
22
- VERSION = "0.9.3.3"
22
+ VERSION = "0.9.3.4"
23
23
  end
@@ -25,10 +25,10 @@ require_all 'lib/caliper/entities/lis/status.rb'
25
25
  require_all 'lib/caliper/entities/lis/course_section.rb'
26
26
  require_all 'lib/caliper/entities/lis/course_offering.rb'
27
27
  require_all 'lib/caliper/entities/lis/group.rb'
28
- require_all 'lib/caliper/entities/reading/epub_volume.rb'
29
28
  require_all 'lib/caliper/entities/session/session.rb'
30
29
  require_all 'lib/caliper/event/session_event.rb'
31
30
  require_all 'lib/caliper/profiles/session_profile.rb'
31
+ require_all 'lib/caliper/entities/reading/epub_volume.rb'
32
32
  require 'json_spec'
33
33
 
34
34
  module Caliper
@@ -18,6 +18,7 @@
18
18
  require 'require_all'
19
19
  require_all 'lib/caliper/sensor.rb'
20
20
  require_relative './event_helper'
21
+ require_all 'lib/caliper/event/session_event.rb'
21
22
 
22
23
  module Caliper
23
24
 
@@ -26,20 +27,32 @@ module Caliper
26
27
 
27
28
  it "should ensure that we can create and send an event" do
28
29
 
29
- id = 'http://learning-app.some-university.edu/sensor'
30
- options = {
31
- 'host' => 'http://requestb.in/1i7pr2i1',
32
- 'apiKey' => 'test_api_key'
33
- }
30
+ options = {
31
+ 'host' => 'http://dev1.intellifylearning.com/v1custom/eventdata',
32
+ 'sensorId' => '0945062D-C8A1-40D7-9834-C1659705EC5B',
33
+ #'sensorId' => 'D9DC57B5-3AAA-41D4-B73D-58AE828D9D85',
34
+ 'apiKey' => '_-kJMcjiSymICwhUaHULbg'
35
+ #'apiKey' => '_-kJMcjiSymICwhUaHULbg'
36
+ }
34
37
 
35
- sensor = Sensor.new id, options
38
+ sensor = Sensor.new options
36
39
  event = session_event
40
+
41
+ file = File.read('spec/fixtures/caliperSessionLoginEvent.json')
42
+ data_hash = JSON.parse(file)
43
+ expected_json = data_hash.to_json # convert hash back to JSON string after parse
44
+ # puts "JSON from file = #{data_hash}"
45
+ deser_annotation_event = Caliper::Event::SessionEvent.new
46
+ deser_annotation_event.from_json data_hash
47
+ # puts "AnnotationEvent from JSON = #{deser_annotation_event.to_json}"
48
+
37
49
 
38
50
  # NOTE: To test sending events to an actual endpoint,
39
51
  # for now, uncomment the line below after setting options.host above
40
52
  # to a new/valid request bin or end point URL.
41
53
 
42
- # sensor.send event
54
+ response = sensor.send deser_annotation_event
55
+ p response
43
56
  end
44
57
  end
45
- end
58
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ims_caliper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3.3
4
+ version: 0.9.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Caliper Dev Group
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-03 00:00:00.000000000 Z
11
+ date: 2015-05-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: This is the implementation of IMSGlobal Caliper in Ruby
14
14
  email:
@@ -79,6 +79,7 @@ files:
79
79
  - lib/caliper/entities/targetable.rb
80
80
  - lib/caliper/entities/w3c/membership.rb
81
81
  - lib/caliper/entities/w3c/organization.rb
82
+ - lib/caliper/entity_envelope.rb
82
83
  - lib/caliper/event/annotation_event.rb
83
84
  - lib/caliper/event/assessment_event.rb
84
85
  - lib/caliper/event/assessment_item_event.rb
@@ -90,6 +91,7 @@ files:
90
91
  - lib/caliper/event/outcome_event.rb
91
92
  - lib/caliper/event/session_event.rb
92
93
  - lib/caliper/event/view_event.rb
94
+ - lib/caliper/event_envelope.rb
93
95
  - lib/caliper/jsonable.rb
94
96
  - lib/caliper/options.rb
95
97
  - lib/caliper/profiles/annotation_profile.rb
@@ -100,8 +102,7 @@ files:
100
102
  - lib/caliper/profiles/profile.rb
101
103
  - lib/caliper/profiles/reading_profile.rb
102
104
  - lib/caliper/profiles/session_profile.rb
103
- - lib/caliper/request/envelope.rb
104
- - lib/caliper/request/envelope_jsonable.rb
105
+ - lib/caliper/request/event_store_envelope.rb
105
106
  - lib/caliper/request/event_store_requestor.rb
106
107
  - lib/caliper/request/http_requestor.rb
107
108
  - lib/caliper/sensor.rb
@@ -136,7 +137,6 @@ files:
136
137
  - spec/lib/event/session_event_timeout_spec.rb
137
138
  - spec/lib/event/viewed_event_spec.rb
138
139
  - spec/lib/event_helper.rb
139
- - spec/lib/request/http_requestor_spec.rb
140
140
  - spec/lib/sensor_spec.rb
141
141
  - spec/spec_helper.rb
142
142
  homepage: https://github.com/IMSGlobal/caliper-ruby
@@ -183,6 +183,5 @@ test_files:
183
183
  - spec/lib/event/session_event_timeout_spec.rb
184
184
  - spec/lib/event/viewed_event_spec.rb
185
185
  - spec/lib/event_helper.rb
186
- - spec/lib/request/http_requestor_spec.rb
187
186
  - spec/lib/sensor_spec.rb
188
187
  - spec/spec_helper.rb
@@ -1,69 +0,0 @@
1
- ##
2
- # This file is part of IMS Caliper Analytics™ and is licensed to
3
- # IMS Global Learning Consortium, Inc. (http://www.imsglobal.org)
4
- # under one or more contributor license agreements. See the NOTICE
5
- # file distributed with this work for additional information.
6
- #
7
- # IMS Caliper is free software: you can redistribute it and/or modify it under
8
- # the terms of the GNU Lesser General Public License as published by the Free
9
- # Software Foundation, version 3 of the License.
10
- #
11
- # IMS Caliper is distributed in the hope that it will be useful, but WITHOUT
12
- # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13
- # A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU Lesser General Public License along
16
- # with this program. If not, see http://www.gnu.org/licenses/.
17
-
18
- require 'json'
19
-
20
- #
21
- # Module that supports ser-des for Caliper Envelope
22
- #
23
- module Caliper
24
- module Request
25
- module EnvelopeJsonable
26
-
27
- def self.included(base)
28
- base.extend ClassMethods
29
- end
30
-
31
- module ClassMethods
32
- end
33
-
34
- def to_json(*a)
35
- # puts 'Jsonable: to_json invoked'
36
- result = {}
37
- result['@context'] = self.context
38
- # result['@type'] = self.type
39
- self.instance_variables.each do |key|
40
- # puts "got key = #{key}"
41
- next if (key[1..-1] == 'context')
42
- # next if (key[1..-1] == 'context' || key[1..-1] == 'type')
43
- value = self.instance_variable_get key
44
- # puts "setting #{key}: #{value}"
45
- result[key[1..-1]] = value
46
- end
47
- result.to_json(*a)
48
- end
49
-
50
- def from_json json_hash
51
- data = json_hash
52
- # puts "Jsonable: from_json: json_hash = #{json_hash}"
53
- self.context = data['@context']
54
- # self.type = data['@type']
55
- json_hash.each do | key, value |
56
- next if (key[1..-1] == 'context')
57
- # next if (key[1..-1] == 'context' || key[1..-1] == 'type')
58
- # puts "Jsonable - adding #{key} : #{value}"
59
- self.instance_variable_set "@#{key}", value
60
- end
61
- return self
62
- end
63
-
64
- def eql?(other)
65
- @context == other.context
66
- end
67
- end
68
- end
69
- end
@@ -1,188 +0,0 @@
1
- ##
2
- # This file is part of IMS Caliper Analytics™ and is licensed to
3
- # IMS Global Learning Consortium, Inc. (http://www.imsglobal.org)
4
- # under one or more contributor license agreements. See the NOTICE
5
- # file distributed with this work for additional information.
6
- #
7
- # IMS Caliper is free software: you can redistribute it and/or modify it under
8
- # the terms of the GNU Lesser General Public License as published by the Free
9
- # Software Foundation, version 3 of the License.
10
- #
11
- # IMS Caliper is distributed in the hope that it will be useful, but WITHOUT
12
- # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13
- # A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU Lesser General Public License along
16
- # with this program. If not, see http://www.gnu.org/licenses/.
17
-
18
- require 'require_all'
19
- require_all 'lib/caliper/entities/entity.rb'
20
- require_all 'lib/caliper/entities/agent/software_application.rb'
21
- require_all 'lib/caliper/entities/agent/person.rb'
22
- require_all 'lib/caliper/entities/lis/membership.rb'
23
- require_all 'lib/caliper/entities/lis/roles.rb'
24
- require_all 'lib/caliper/entities/lis/status.rb'
25
- require_all 'lib/caliper/entities/lis/course_section.rb'
26
- require_all 'lib/caliper/entities/lis/course_offering.rb'
27
- require_all 'lib/caliper/entities/lis/group.rb'
28
- require_all 'lib/caliper/entities/reading/epub_volume.rb'
29
- require_all 'lib/caliper/entities/reading/web_page.rb'
30
- require_all 'lib/caliper/event/navigation_event.rb'
31
- require_all 'lib/caliper/profiles/reading_profile.rb'
32
- require_all 'lib/caliper/options.rb'
33
- require_all 'lib/caliper/sensor.rb'
34
- require_all 'lib/caliper/request/http_requestor.rb'
35
-
36
- require 'json_spec'
37
-
38
- module Caliper
39
- module Request
40
-
41
- describe Envelope do
42
-
43
- it 'should ensure that a Caliper envelope comprising a NavigationEvent is correctly created and serialized' do
44
-
45
- # The Actor (Person/Student))
46
- student = Caliper::Entities::Agent::Person.new
47
- student.id = 'https://some-university.edu/user/554433'
48
- membership1 = Caliper::Entities::LIS::Membership.new
49
- membership1.id = "https://some-university.edu/membership/001"
50
- membership1.member = "https://some-university.edu/user/554433"
51
- membership1.organization = "https://some-university.edu/politicalScience/2015/american-revolution-101"
52
- membership1.roles = [Caliper::Entities::LIS::Roles::LEARNER]
53
- membership1.status = Caliper::Entities::LIS::Status::ACTIVE
54
- membership1.dateCreated = "2015-08-01T06:00:00.000Z"
55
- membership1.dateModified = nil;
56
- membership2 = Caliper::Entities::LIS::Membership.new
57
- membership2.id = "https://some-university.edu/membership/002"
58
- membership2.member = "https://some-university.edu/user/554433"
59
- membership2.organization = "https://some-university.edu/politicalScience/2015/american-revolution-101/section/001"
60
- membership2.roles = [Caliper::Entities::LIS::Roles::LEARNER]
61
- membership2.status = Caliper::Entities::LIS::Status::ACTIVE
62
- membership2.dateCreated = "2015-08-01T06:00:00.000Z"
63
- membership2.dateModified = nil
64
- membership3 = Caliper::Entities::LIS::Membership.new
65
- membership3.id = "https://some-university.edu/membership/003"
66
- membership3.member = "https://some-university.edu/user/554433"
67
- membership3.organization = "https://some-university.edu/politicalScience/2015/american-revolution-101/section/001/group/001"
68
- membership3.roles = [Caliper::Entities::LIS::Roles::LEARNER]
69
- membership3.status = Caliper::Entities::LIS::Status::ACTIVE
70
- membership3.dateCreated = "2015-08-01T06:00:00.000Z"
71
- membership3.dateModified = nil
72
- student.hasMembership = [membership1, membership2, membership3]
73
- student.dateCreated = '2015-08-01T06:00:00.000Z'
74
- student.dateModified = '2015-09-02T11:30:00.000Z'
75
- # puts "new student = #{student.to_json}"
76
-
77
- # The Action
78
- action = Caliper::Profiles::ProfileActions::NAVIGATED_TO
79
-
80
- # The Object navigated (ePub Volume)
81
- ePubVolume = Caliper::Entities::Reading::EPubVolume.new
82
- ePubVolume.id = 'https://github.com/readium/readium-js-viewer/book/34843#epubcfi(/4/3)'
83
- ePubVolume.name = 'The Glorious Cause: The American Revolution, 1763-1789 (Oxford History of the United States)'
84
- ePubVolume.version = '2nd ed.'
85
- ePubVolume.dateCreated = '2015-08-01T06:00:00.000Z'
86
- ePubVolume.dateModified = '2015-09-02T11:30:00.000Z'
87
-
88
- # The Target within the Object (frame)
89
- frame = Caliper::Entities::Reading::Frame.new
90
- frame.id = 'https://github.com/readium/readium-js-viewer/book/34843#epubcfi(/4/3/1)'
91
- frame.name = 'Key Figures: George Washington'
92
- frame.version = '2nd ed.'
93
- frame.dateCreated = '2015-08-01T06:00:00.000Z'
94
- frame.dateModified = '2015-09-02T11:30:00.000Z'
95
- frame.index = 1
96
- frame.isPartOf = ePubVolume.id
97
-
98
- # The course that is part of the Learning Context (edApp)
99
- edApp = Caliper::Entities::Agent::SoftwareApplication.new
100
- edApp.id = 'https://github.com/readium/readium-js-viewer'
101
- edApp.name = 'Readium'
102
- edApp.hasMembership = []
103
- edApp.dateCreated = '2015-08-01T06:00:00.000Z'
104
- edApp.dateModified = '2015-09-02T11:30:00.000Z'
105
-
106
- #LIS Course Offering
107
- courseOffering = Caliper::Entities::LIS::CourseOffering.new
108
- courseOffering.id = "https://some-university.edu/politicalScience/2015/american-revolution-101"
109
- courseOffering.name = "Political Science 101: The American Revolution"
110
- courseOffering.courseNumber = "POL101"
111
- courseOffering.academicSession = "Fall-2015"
112
- courseOffering.membership = []
113
- courseOffering.subOrganizationOf = nil
114
- courseOffering.dateCreated = '2015-08-01T06:00:00.000Z'
115
- courseOffering.dateModified = '2015-09-02T11:30:00.000Z'
116
-
117
- # The LIS Course Section for the Caliper Event
118
- course = Caliper::Entities::LIS::CourseSection.new
119
- course.id = 'https://some-university.edu/politicalScience/2015/american-revolution-101/section/001'
120
- course.name = 'American Revolution 101'
121
- course.courseNumber = "POL101"
122
- course.academicSession = "Fall-2015"
123
- course.category = nil
124
- course.membership = [membership2]
125
- course.subOrganizationOf = courseOffering
126
- course.dateCreated = '2015-08-01T06:00:00.000Z'
127
- course.dateModified = '2015-09-02T11:30:00.000Z'
128
-
129
- # LIS Group
130
- group = Caliper::Entities::LIS::Group.new
131
- group.id = "https://some-university.edu/politicalScience/2015/american-revolution-101/section/001/group/001"
132
- group.name = "Discussion Group 001"
133
- group.membership = [membership3]
134
- group.subOrganizationOf = course
135
- group.dateCreated = '2015-08-01T06:00:00.000Z'
136
- group.dateModified = nil
137
-
138
- # The navigatedFrom property (specific to Navigation Event)
139
- fromPage = Caliper::Entities::Reading::WebPage.new
140
- fromPage.id = 'https://some-university.edu/politicalScience/2015/american-revolution-101/index.html'
141
- fromPage.name = 'American Revolution 101 Landing Page'
142
- fromPage.dateCreated = '2015-08-01T06:00:00.000Z'
143
- fromPage.dateModified = '2015-09-02T11:30:00.000Z'
144
- fromPage.isPartOf = nil
145
- fromPage.version = '1.0'
146
-
147
- # The (Reading::BookmarkReading) Event
148
- navigated_event = Caliper::Event::NavigationEvent.new
149
- navigated_event.actor = student
150
- navigated_event.action = action
151
- navigated_event.object = ePubVolume
152
- navigated_event.target = frame
153
- navigated_event.generated = nil
154
- navigated_event.edApp = edApp
155
- navigated_event.group = group
156
- navigated_event.navigatedFrom = fromPage
157
- navigated_event.startedAtTime = '2015-09-15T10:15:00.000Z'
158
- navigated_event.endedAtTime = nil
159
- navigated_event.duration = nil
160
- # puts "Event JSON = #{navigated_event.to_json}'"
161
-
162
- # The Sensor
163
- options = Caliper::Options.new
164
- sensor = Caliper::Sensor.new("http://learning-app.some-university.edu/sensor", options)
165
- requestor = Caliper::Request::HttpRequestor.new(options)
166
- json_payload = requestor.generate_payload(sensor, navigated_event)
167
-
168
- # Swap out sendTime=DateTime.now() in favor of fixture value (or test will most assuredly fail).
169
- json_payload_sub = json_payload.sub(/\"sendTime\":\"[^\"]*\"/, "\"sendTime\":\"2015-09-15T11:05:01.000Z\"")
170
-
171
- # Load JSON from caliper-common-fixtures for comparison
172
- # NOTE - sym link to caliper-common-fixtures needs to exist under spec/fixtures
173
- file = File.read('spec/fixtures/eventStorePayload.json')
174
- data_hash = JSON.parse(file)
175
- expected_json = data_hash.to_json # convert hash back to JSON string after parse
176
- json_payload_sub.should be_json_eql(expected_json)
177
-
178
- # puts "JSON from file = #{data_hash}"
179
- # deser_envelope = Caliper::Request::Envelope.new
180
- # deser_envelope.from_json data_hash
181
- # puts "Envelope from JSON = #{deser_envelope.to_json}"
182
-
183
- # Ensure that the deserialized shared event object conforms
184
- # expect(json_payload_sub).to eql(deser_envelope)
185
- end
186
- end
187
- end
188
- end