ims_caliper 0.9.1 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. checksums.yaml +8 -8
  2. data/lib/caliper/defaults.rb +2 -2
  3. data/lib/caliper/entities/agent/organization.rb +3 -0
  4. data/lib/caliper/entities/learning_context.rb +2 -2
  5. data/lib/caliper/entities/lis/course_offering.rb +3 -2
  6. data/lib/caliper/entities/lis/group.rb +3 -0
  7. data/lib/caliper/entities/lis/membership.rb +5 -0
  8. data/lib/caliper/entities/outcome/result.rb +1 -1
  9. data/lib/caliper/entities/response/fillin_blank_response.rb +1 -0
  10. data/lib/caliper/entities/response/multiple_choice_response.rb +1 -0
  11. data/lib/caliper/entities/response/multiple_response_response.rb +1 -0
  12. data/lib/caliper/entities/response/response.rb +1 -0
  13. data/lib/caliper/entities/response/select_type_response.rb +1 -0
  14. data/lib/caliper/entities/response/true_false_response.rb +1 -0
  15. data/lib/caliper/entities/w3c/membership.rb +2 -5
  16. data/lib/caliper/entities/w3c/organization.rb +2 -3
  17. data/lib/caliper/event/annotation_event.rb +1 -0
  18. data/lib/caliper/event/view_event.rb +1 -0
  19. data/lib/caliper/jsonable.rb +2 -1
  20. data/lib/caliper/options.rb +11 -11
  21. data/lib/caliper/request/{event_store_envelope.rb → envelope.rb} +27 -5
  22. data/lib/caliper/request/envelope_jsonable.rb +69 -0
  23. data/lib/caliper/request/event_store_requestor.rb +16 -27
  24. data/lib/caliper/request/http_requestor.rb +8 -29
  25. data/lib/caliper/sensor.rb +12 -23
  26. data/lib/caliper/version.rb +1 -1
  27. data/spec/lib/event/assessment_item_started_event_spec.rb +1 -0
  28. data/spec/lib/event/session_event_login_spec.rb +1 -1
  29. data/spec/lib/request/http_requestor_spec.rb +188 -0
  30. data/spec/lib/sensor_spec.rb +11 -27
  31. metadata +6 -5
  32. data/lib/caliper/entity_envelope.rb +0 -33
  33. data/lib/caliper/event_envelope.rb +0 -33
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MTU3NzJjMmQxOGQ5ZTFhZjhlOTY5Y2UzYjBlMDMyNDY2ODk2ZWE1OQ==
4
+ OWU0MTc4MDI1OTBlMWU0ODNlZDZmOTgwMjMyN2Y1YmU4ZGQ5ZGQxZQ==
5
5
  data.tar.gz: !binary |-
6
- MTUxMGE4NGUxZGY3ZWVmNGNjMWU2MWMwNzZlNzdjMTBiMzUwYzhjYQ==
6
+ YTQxNGYwZDcyNWRiMzZjMWUxMDUyMTg3NjBhZjJhMTVmMWY0ZDU1Zg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YmFlYjZhOTNjMjA2YWE1MWIyOTg4M2ZlNjY2ZjI3YzJmMWNkN2E2NGMzYzA2
10
- NWNlNmZiNWMzYTI4YzhkZmZlNmYxY2EzNTcyNTdjMzljZTMyZTcxZTM5Zjlk
11
- ZjEzOGFmN2JhYTkxY2MzNzhlNmVlYzg4ZDAzZDc3MjQ0YzM5N2M=
9
+ OWI5YjQyODc4NzIwOTM2YzBiZTJjMmNjODg5OTEzOTRlM2RhZGFkOTcxYjhi
10
+ NTkxMjkzODcwMDcyM2MwNzViYzBiNjQ2MjI3ODE4MjFhY2FkZjVhN2U1Njk1
11
+ MDZjZWQxNWIxZjU4NDcyZTAwMTQ5YTc4MDFjYTA3NmNkMTM2N2E=
12
12
  data.tar.gz: !binary |-
13
- YTkwODgzOWU1NDJhMmIzZjU1NzU4MDM3NDQyNGQ4NTFlYjAwMWM1YWM2NDM2
14
- ZGU3YWZmMTFmMTkzYWVkNWY2ODZiNTQ3ZDI0Y2MxZjQ0YzExNzFlM2QwODIw
15
- MTAzMzYzMzNjZGQzN2E1YjYxOTU5MDMxOTUyZmFhYmQyZTM4ZjQ=
13
+ YjQ2ZjJlYWVhMjJiZTUwN2Y4ZDNkYWQzYzc1NzRjYTcyZjI0ZTdhNjBjOTBm
14
+ YzFjYzc5MTcyOWVhNTgwNTgxNTgyOTcwODI2YjRmMTM0YTkwMzc1ODFjMDQ1
15
+ MjMwNGIwZGE4ZTY4OGIxNjZkN2E1NWM2YzlmMjczYzdiZWMwN2Y=
@@ -21,8 +21,8 @@
21
21
  module Caliper
22
22
  class Defaults
23
23
  HOST = "http://dev-null.comt"
24
- CONNECTION_TIMEOUT = 10000
25
- SO_TIMEOUT = 10000
26
24
  CONNECTION_REQUEST_TIMEOUT = 10000
25
+ CONNECTION_TIMEOUT = 10000
26
+ SOCKET_TIMEOUT = 10000
27
27
  end
28
28
  end
@@ -27,6 +27,9 @@ module Caliper
27
27
  class Organization < Entity
28
28
  include Caliper::Entities::W3C::Organization
29
29
 
30
+ attr_accessor :membership,
31
+ :subOrganizationOf
32
+
30
33
  def initialize
31
34
  super
32
35
  @type = EntityType::ORGANIZATION
@@ -17,7 +17,7 @@
17
17
 
18
18
  require_relative './entity'
19
19
  require_relative './agent/software_application'
20
- require_relative './w3c/organization'
20
+ require_relative './agent/organization'
21
21
  require_relative './foaf/agent'
22
22
 
23
23
  #
@@ -34,7 +34,7 @@ module Caliper
34
34
  def initialize
35
35
  super
36
36
  @ed_app = Caliper::Entities::Agent::SoftwareApplication.new
37
- @group = Caliper::Entities::W3C::Organization.new
37
+ @group = Caliper::Entities::Agent::Organization.new
38
38
  @agent = Caliper::Entities::Entity.new
39
39
  end
40
40
  end
@@ -28,8 +28,9 @@ module Caliper
28
28
  include Caliper::Entities::W3C::Organization
29
29
 
30
30
  attr_accessor :courseNumber,
31
- :academicSession
32
-
31
+ :academicSession,
32
+ :membership,
33
+ :subOrganizationOf
33
34
  def initialize
34
35
  super
35
36
  @type = EntityType::COURSE_OFFERING
@@ -27,6 +27,9 @@ module Caliper
27
27
  class Group < Entity
28
28
  include Caliper::Entities::W3C::Organization
29
29
 
30
+ attr_accessor :membership,
31
+ :subOrganizationOf
32
+
30
33
  def initialize
31
34
  super
32
35
  @type = EntityType::GROUP
@@ -27,6 +27,11 @@ module Caliper
27
27
  class Membership < Entity
28
28
  include Caliper::Entities::W3C::Membership
29
29
 
30
+ attr_accessor :member,
31
+ :organization,
32
+ :roles,
33
+ :status
34
+
30
35
  def initialize
31
36
  super
32
37
  @type = EntityType::MEMBERSHIP
@@ -38,7 +38,7 @@ module Caliper
38
38
  end
39
39
 
40
40
  def initialize
41
-
41
+ super
42
42
  end
43
43
  end
44
44
  end
@@ -30,6 +30,7 @@ module Caliper
30
30
  :values
31
31
 
32
32
  def initialize
33
+ super
33
34
  @type = ResponseType::FILLINBLANK
34
35
  end
35
36
  end
@@ -29,6 +29,7 @@ module Caliper
29
29
  :values
30
30
 
31
31
  def initialize
32
+ super
32
33
  @type = ResponseType::MULTIPLECHOICE
33
34
  end
34
35
  end
@@ -29,6 +29,7 @@ module Caliper
29
29
  :values
30
30
 
31
31
  def initialize
32
+ super
32
33
  @type = ResponseType::MULTIPLERESPONSE
33
34
  end
34
35
  end
@@ -36,6 +36,7 @@ module Caliper
36
36
  :duration
37
37
 
38
38
  def initialize
39
+ super
39
40
  @type = EntityType::RESPONSE
40
41
  end
41
42
  end
@@ -30,6 +30,7 @@ module Caliper
30
30
  :values
31
31
 
32
32
  def initialize
33
+ super
33
34
  @type = ResponseType::SELECTTEXT
34
35
  end
35
36
  end
@@ -30,6 +30,7 @@ module Caliper
30
30
  :values
31
31
 
32
32
  def initialize
33
+ super
33
34
  @type = ResponseType::TRUEFALSE
34
35
  end
35
36
  end
@@ -21,11 +21,8 @@
21
21
  module Caliper
22
22
  module Entities
23
23
  module W3C
24
- class Membership
25
- attr_accessor :member,
26
- :organization,
27
- :roles,
28
- :status
24
+ module Membership
25
+
29
26
  end
30
27
  end
31
28
  end
@@ -21,9 +21,8 @@
21
21
  module Caliper
22
22
  module Entities
23
23
  module W3C
24
- class Organization
25
- attr_accessor :membership,
26
- :subOrganizationOf
24
+ module Organization
25
+
27
26
  end
28
27
  end
29
28
  end
@@ -25,6 +25,7 @@ module Caliper
25
25
  class AnnotationEvent < Event
26
26
 
27
27
  def initialize
28
+ super
28
29
  @context = Caliper::Event::EventContext::ANNOTATION
29
30
  @type = Caliper::Event::EventType::ANNOTATION
30
31
  end
@@ -25,6 +25,7 @@ module Caliper
25
25
  class ViewEvent < Event
26
26
 
27
27
  def initialize
28
+ super
28
29
  @type = EventType::VIEW
29
30
  @context = EventContext::VIEW
30
31
  end
@@ -64,7 +64,8 @@ module Caliper
64
64
  end
65
65
 
66
66
  def eql?(other)
67
- @sensorId == other.sensorId && @apiKey == other.apiKey
67
+ @context == other.context && @apiKey == other.apiKey
68
+ # @context == other.context && @sensorId == other.sensorId && @apiKey == other.apiKey
68
69
  end
69
70
  end
70
71
  end
@@ -20,18 +20,18 @@
20
20
  #
21
21
  module Caliper
22
22
  class Options
23
- attr_accessor :api_key
24
23
  attr_accessor :host
25
- attr_accessor :time_out
24
+ attr_accessor :api_key
25
+ attr_accessor :connection_request_time_out
26
+ attr_accessor :connection_time_out
27
+ attr_accessor :socket_time_out
26
28
  end
27
29
 
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
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
37
37
  end
@@ -15,13 +15,35 @@
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
+
18
20
  #
19
21
  # Event store envelope. Contains event info.
20
22
  #
21
23
  module Caliper
22
- module Request
23
- class EventStoreEnvelope
24
- attr_accessor :id, :type, :time, :data
25
- end
26
- end
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
27
49
  end
@@ -0,0 +1,69 @@
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
@@ -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 './event_store_envelope'
19
+ require_relative './envelope'
20
20
 
21
21
  #
22
22
  # Event store requestor.
@@ -25,36 +25,25 @@ module Caliper
25
25
  module Request
26
26
  class EventStoreRequestor
27
27
 
28
- def get_payload_json(caliper_event, id, send_time)
29
-
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
41
-
42
- json_payload = JSON.generate(list_payload)
43
- return json_payload
28
+ def generate_payload(sensor, data)
29
+ return get_payload_json(sensor, data)
44
30
  end
45
31
 
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
32
+ def get_payload_json(sensor, data)
33
+ envelope = create_envelope(sensor, data)
34
+ return JSON.generate(envelope)
35
+ end
54
36
 
55
- json_payload = get_payload_json(caliper_event, id, send_time)
37
+ def create_envelope(sensor, data)
38
+ envelope = Envelope.new
39
+ envelope.sensor = sensor.id
40
+ envelope.data = to_array(data)
41
+ return envelope
42
+ end
56
43
 
44
+ def to_array(data)
45
+ return [data] if !(data.is_a?(Array))
57
46
  end
58
47
  end
59
48
  end
60
- end
49
+ end
@@ -15,10 +15,9 @@
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 "net/http"
19
- require "uri"
18
+ require 'rest-client'
19
+ require_relative './envelope'
20
20
  require_relative './event_store_requestor'
21
- require_relative './event_store_envelope'
22
21
 
23
22
  module Caliper
24
23
  module Request
@@ -28,34 +27,14 @@ module Caliper
28
27
 
29
28
  def initialize(options)
30
29
  @options = options
31
- end
30
+ end
32
31
 
33
- def send(event)
34
- status = false
32
+ def send(sensor, data)
33
+ payload = generate_payload(sensor, data)
35
34
 
36
- raise ArgumentError, "Expecting Caliper::Event but got #{event.class.to_s}" unless event.is_a?(Caliper::Event::Event)
37
-
38
- envelope = EventEnvelope.new
39
- envelope.apiKey = @options['apiKey']
40
- envelope.sensorId = @options['sensorId']
41
- envelope.event = event
42
-
43
- RestClient.post @options['host'], envelope.to_json, :content_type => :json, :accept => :json
44
-
45
-
46
- if (response.code != 200)
47
- status_code = response.code
48
-
49
- # failed call
50
- status = false
51
- fail "Failed: HTTP error code: " + status_code
52
- else
53
- # success call
54
- status = true
55
- end
56
-
57
- return status
58
- end
35
+ # What about the api key (authorization)?
36
+ RestClient.post @options['host'], payload, :content_type => :json, :accept => :json
37
+ end
59
38
  end
60
39
  end
61
40
  end
@@ -15,10 +15,9 @@
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 "./options"
20
- require_relative "./event_envelope"
21
- require_relative "./entity_envelope"
18
+
19
+ require_relative './options'
20
+ require_relative './request/http_requestor'
22
21
 
23
22
  #
24
23
  # Caliper Sensor.
@@ -26,33 +25,23 @@ require_relative "./entity_envelope"
26
25
  module Caliper
27
26
  class Sensor
28
27
 
29
- def initialize(options)
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
28
+ attr_accessor :id
43
29
 
30
+ def initialize(id, options)
31
+ @id = id
32
+ @options = options
44
33
  end
45
34
 
46
35
  def describe(entity)
47
36
  raise ArgumentError, "Expecting Caliper::Entity but got #{entity.class.to_s}" unless entity.is_a?(Caliper::Entities::Entity)
48
37
 
49
- envelope = EntityEnvelope.new
50
- envelope.apiKey = @options['apiKey']
51
- envelope.sensorId = @options['sensorId']
52
- envelope.entity = entity
38
+ HttpRequestor.new(@options).send(self, entity)
39
+ end
53
40
 
54
- RestClient.post @options['host'], envelope.to_json, :content_type => :json, :accept => :json
41
+ def send(event)
42
+ raise ArgumentError, "Expecting Caliper::Event but got #{event.class.to_s}" unless event.is_a?(Caliper::Event::Event)
55
43
 
44
+ HttpRequestor.new(@options).send(self, event)
56
45
  end
57
46
  end
58
47
  end
@@ -19,5 +19,5 @@
19
19
  # Version.
20
20
  #
21
21
  module Caliper
22
- VERSION = "0.9.1"
22
+ VERSION = "0.9.3"
23
23
  end
@@ -31,6 +31,7 @@ require_all 'lib/caliper/entities/assignable/attempt.rb'
31
31
  require_all 'lib/caliper/entities/assignable/assignable_digital_resource.rb'
32
32
  require_all 'lib/caliper/event/assessment_item_event.rb'
33
33
  require_all 'lib/caliper/profiles/assessment_item_profile.rb'
34
+ require_all 'lib/caliper/profiles/assessment_profile.rb'
34
35
  require 'json_spec'
35
36
 
36
37
  module Caliper
@@ -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'
28
29
  require_all 'lib/caliper/entities/session/session.rb'
29
30
  require_all 'lib/caliper/event/session_event.rb'
30
31
  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
@@ -0,0 +1,188 @@
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
@@ -26,36 +26,20 @@ module Caliper
26
26
 
27
27
  it "should ensure that we can create and send an event" do
28
28
 
29
- options = {
30
- 'host' => 'http://dev1.intellifylearning.com/v1custom/eventdata',
31
- 'sensorId' => '0945062D-C8A1-40D7-9834-C1659705EC5B',
32
- 'apiKey' => '_-kJMcjiSymICwhUaHULbg'
33
- }
34
-
35
- sensor = Sensor.new options
36
-
37
- # Load JSON from caliper-common-fixtures for comparison
38
- # NOTE - sym link to caliper-common-fixtures needs to exist under spec/fixtures
39
- file = File.read('spec/fixtures/caliperNavigationEvent.json')
40
- data_hash = JSON.parse(file)
41
- # puts "JSON from file = #{data_hash}"
42
- deser_session_event = Caliper::Event::SessionEvent.new
43
- deser_session_event.from_json data_hash
44
-
45
- # NOTE: To test sending events to an actual endpoint,
46
- # for now, uncomment the line below after setting options.host above
47
- # to a new/valid request bin or end point URL.
48
-
49
- response = sensor.send deser_session_event
50
-
51
- p response
52
-
53
-
54
- # NOTE: To test sending events to an actual endpoint,
29
+ id = 'http://learning-app.some-university.edu/sensor'
30
+ options = {
31
+ 'host' => 'http://requestb.in/1i7pr2i1',
32
+ 'apiKey' => 'test_api_key'
33
+ }
34
+
35
+ sensor = Sensor.new id, options
36
+ event = session_event
37
+
38
+ # NOTE: To test sending events to an actual endpoint,
55
39
  # for now, uncomment the line below after setting options.host above
56
40
  # to a new/valid request bin or end point URL.
57
41
 
58
42
  # sensor.send event
59
43
  end
60
44
  end
61
- end
45
+ 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.1
4
+ version: 0.9.3
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-04-29 00:00:00.000000000 Z
11
+ date: 2015-05-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: This is the implementation of IMSGlobal Caliper in Ruby
14
14
  email:
@@ -79,7 +79,6 @@ 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
83
82
  - lib/caliper/event/annotation_event.rb
84
83
  - lib/caliper/event/assessment_event.rb
85
84
  - lib/caliper/event/assessment_item_event.rb
@@ -91,7 +90,6 @@ files:
91
90
  - lib/caliper/event/outcome_event.rb
92
91
  - lib/caliper/event/session_event.rb
93
92
  - lib/caliper/event/view_event.rb
94
- - lib/caliper/event_envelope.rb
95
93
  - lib/caliper/jsonable.rb
96
94
  - lib/caliper/options.rb
97
95
  - lib/caliper/profiles/annotation_profile.rb
@@ -102,7 +100,8 @@ files:
102
100
  - lib/caliper/profiles/profile.rb
103
101
  - lib/caliper/profiles/reading_profile.rb
104
102
  - lib/caliper/profiles/session_profile.rb
105
- - lib/caliper/request/event_store_envelope.rb
103
+ - lib/caliper/request/envelope.rb
104
+ - lib/caliper/request/envelope_jsonable.rb
106
105
  - lib/caliper/request/event_store_requestor.rb
107
106
  - lib/caliper/request/http_requestor.rb
108
107
  - lib/caliper/sensor.rb
@@ -137,6 +136,7 @@ files:
137
136
  - spec/lib/event/session_event_timeout_spec.rb
138
137
  - spec/lib/event/viewed_event_spec.rb
139
138
  - 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,5 +183,6 @@ 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
186
187
  - spec/lib/sensor_spec.rb
187
188
  - spec/spec_helper.rb
@@ -1,33 +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 '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
@@ -1,33 +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 '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