ims_caliper 0.9.3.14 → 0.9.3.15
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 +5 -13
- data/lib/caliper/defaults.rb +2 -2
- data/lib/caliper/entities/agent/organization.rb +3 -3
- data/lib/caliper/entities/assessment/assessment.rb +0 -2
- data/lib/caliper/entities/entity.rb +0 -1
- data/lib/caliper/entities/foaf/agent.rb +1 -1
- data/lib/caliper/entities/lis/course_offering.rb +0 -1
- data/lib/caliper/entities/lis/group.rb +1 -2
- data/lib/caliper/entities/lis/{roles.rb → role.rb} +1 -1
- data/lib/caliper/entities/outcome/result.rb +3 -3
- data/lib/caliper/entities/response/fillin_blank_response.rb +1 -0
- data/lib/caliper/entities/response/multiple_choice_response.rb +1 -0
- data/lib/caliper/entities/response/multiple_response_response.rb +1 -0
- data/lib/caliper/entities/response/response.rb +1 -0
- data/lib/caliper/entities/response/select_type_response.rb +1 -0
- data/lib/caliper/entities/response/true_false_response.rb +1 -0
- data/lib/caliper/event/annotation_event.rb +1 -0
- data/lib/caliper/event/event.rb +28 -26
- data/lib/caliper/event/view_event.rb +1 -0
- data/lib/caliper/jsonable.rb +2 -1
- data/lib/caliper/options.rb +11 -11
- data/lib/caliper/profiles/assessment_profile.rb +0 -1
- data/lib/caliper/{event/grade_predict_event.rb → request/envelope.rb} +21 -11
- data/lib/caliper/request/envelope_jsonable.rb +69 -0
- data/lib/caliper/request/event_store_requestor.rb +16 -27
- data/lib/caliper/request/http_requestor.rb +8 -27
- data/lib/caliper/sensor.rb +12 -23
- data/lib/caliper/version.rb +1 -1
- data/spec/lib/entities/agent/person_spec.rb +1 -1
- data/spec/lib/entities/entity_spec.rb +1 -1
- data/spec/lib/event/annotation_event_bookmark_spec.rb +81 -98
- data/spec/lib/event/annotation_event_highlight_spec.rb +81 -98
- data/spec/lib/event/annotation_event_shared_spec.rb +81 -100
- data/spec/lib/event/annotation_event_tag_spec.rb +81 -98
- data/spec/lib/event/assessment_event_spec.rb +64 -124
- data/spec/lib/event/assessment_item_completed_event_spec.rb +93 -138
- data/spec/lib/event/assessment_item_started_event_spec.rb +92 -139
- data/spec/lib/event/assignable_event_spec.rb +65 -129
- data/spec/lib/event/media_event_spec.rb +77 -94
- data/spec/lib/event/navigated_event_spec.rb +90 -108
- data/spec/lib/event/session_event_login_spec.rb +98 -108
- data/spec/lib/event/session_event_logout_spec.rb +66 -81
- data/spec/lib/event/session_event_timeout_spec.rb +62 -88
- data/spec/lib/event/viewed_event_spec.rb +74 -92
- data/spec/lib/event_helper.rb +89 -109
- data/spec/lib/request/http_requestor_spec.rb +170 -0
- data/spec/lib/sensor_spec.rb +9 -29
- metadata +10 -11
- data/lib/caliper/entities/outcome/predicted_grade.rb +0 -43
- data/lib/caliper/entity_envelope.rb +0 -33
- data/lib/caliper/event_envelope.rb +0 -33
- data/lib/caliper/request/event_store_envelope.rb +0 -27
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
Yjk4ZmU4Njg0YzQwMDdhYmJmYTA0YmRiZWRhMWM0Mjk3NmVmODBhNw==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d787d10711e9df110e47808696cc7320a4d38fac
|
4
|
+
data.tar.gz: 829240aa1cfbc63aa8738b15f12f460da5f9b83a
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
ZTRiMTAxNmIyN2NjNDc2YjYxM2NjZWE1ZDM2OWRhM2IyYmYzZGVkMmI0M2Vl
|
11
|
-
YWNkYTIyOGEwYmJlM2U2N2EwN2I2YjQwZDc0Y2I4ZWExYzY4MjY=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MmZlOWU2ZTIyMjM1YzM0ZWEyMWVmMTg4MDViMTg4OWI1NzkzYWU5NDY5MzQx
|
14
|
-
ODg5NDEzMTA0Yjc1ZTE1Zjk0ZTM3ZjFiNjVkMzQ5ZjIwZjRlZDc4NjJjZjE1
|
15
|
-
NDYxNGUyODNkNzRlYWViZmFlYTJhZTYwODhiMmRjYzY4N2ExZTQ=
|
6
|
+
metadata.gz: 241b1e7dd90b7cb2fe680f1c4de7ef53576d4d3b1694593ed44c64116d4c7f9a7bc95804f3b231ac8f855b9e51d3025736923238ac47f2eb1df9d4ed02cebde9
|
7
|
+
data.tar.gz: 15fc41e4d02518ac66a10f7f1f790846377c7a8769f02b0d3bad81ec4d19ffb7397f25f8be2a4a06b9d001d5ebb866dd19a236144e7d9293321944ee95d366f7
|
data/lib/caliper/defaults.rb
CHANGED
@@ -25,10 +25,10 @@ module Caliper
|
|
25
25
|
module Entities
|
26
26
|
module Agent
|
27
27
|
class Organization < Entity
|
28
|
-
include Caliper::Entities::
|
28
|
+
include Caliper::Entities::FOAF::Agent,
|
29
|
+
Caliper::Entities::W3C::Organization
|
29
30
|
|
30
|
-
attr_accessor :
|
31
|
-
:subOrganizationOf
|
31
|
+
attr_accessor :subOrganizationOf
|
32
32
|
|
33
33
|
def initialize
|
34
34
|
super
|
@@ -25,8 +25,6 @@ module Caliper
|
|
25
25
|
module Assessment
|
26
26
|
class Assessment < Caliper::Entities::Assignable::AssignableDigitalResource
|
27
27
|
|
28
|
-
attr_accessor :assessmentItems
|
29
|
-
|
30
28
|
def initialize
|
31
29
|
super
|
32
30
|
@type = Caliper::Entities::Assignable::AssignableDigitalResourceType::ASSESSMENT
|
@@ -40,7 +40,6 @@ module Caliper
|
|
40
40
|
PERSON = "http://purl.imsglobal.org/caliper/v1/lis/Person"
|
41
41
|
RESPONSE = "http://purl.imsglobal.org/caliper/v1/Response"
|
42
42
|
RESULT = "http://purl.imsglobal.org/caliper/v1/Result"
|
43
|
-
PREDICTED_GRADE = "http://purl.imsglobal.org/caliper/v1/PredictedGrade"
|
44
43
|
SESSION = "http://purl.imsglobal.org/caliper/v1/Session"
|
45
44
|
SOFTWARE_APPLICATION = "http://purl.imsglobal.org/caliper/v1/SoftwareApplication"
|
46
45
|
TARGET = "http://purl.imsglobal.org/caliper/v1/Target"
|
@@ -21,7 +21,7 @@
|
|
21
21
|
module Caliper
|
22
22
|
module Entities
|
23
23
|
module LIS
|
24
|
-
module
|
24
|
+
module Role
|
25
25
|
LEARNER = 'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
|
26
26
|
EXTERNAL_LEARNER = 'http://purl.imsglobal.org/vocab/lis/v2/membership/Learner#ExternalLearner'
|
27
27
|
GUEST_LEARNER = 'http://purl.imsglobal.org/vocab/lis/v2/membership/Learner#GuestLearner'
|
data/lib/caliper/event/event.rb
CHANGED
@@ -34,7 +34,6 @@ module Caliper
|
|
34
34
|
OUTCOME = "http://purl.imsglobal.org/ctx/caliper/v1/OutcomeEvent"
|
35
35
|
SESSION = "http://purl.imsglobal.org/ctx/caliper/v1/SessionEvent"
|
36
36
|
VIEW = "http://purl.imsglobal.org/ctx/caliper/v1/ViewEvent"
|
37
|
-
GRADE_PREDICT = "http://purl.imsglobal.org/ctx/caliper/v1/GradePredictEvent"
|
38
37
|
end
|
39
38
|
|
40
39
|
module EventType
|
@@ -46,7 +45,6 @@ module Caliper
|
|
46
45
|
MEDIA = "http://purl.imsglobal.org/caliper/v1/MediaEvent"
|
47
46
|
NAVIGATION = "http://purl.imsglobal.org/caliper/v1/NavigationEvent"
|
48
47
|
OUTCOME = "http://purl.imsglobal.org/caliper/v1/OutcomeEvent"
|
49
|
-
GRADE_PREDICT = "http://purl.imsglobal.org/caliper/v1/GradePredictEvent"
|
50
48
|
SESSION = "http://purl.imsglobal.org/caliper/v1/SessionEvent"
|
51
49
|
VIEW = "http://purl.imsglobal.org/caliper/v1/ViewEvent"
|
52
50
|
end
|
@@ -57,41 +55,44 @@ module Caliper
|
|
57
55
|
attr_accessor :context, # String Required - the JSON-LD context for the Event
|
58
56
|
|
59
57
|
# Required - the type of the Event
|
60
|
-
:type,
|
61
|
-
|
62
|
-
# Learning Context
|
63
|
-
:edApp, # SoftwareApplication
|
64
|
-
|
65
|
-
# LIS Group
|
66
|
-
:group, # Group
|
58
|
+
:type,
|
67
59
|
|
68
60
|
# Required - Agent (User, System) that performed the action
|
69
|
-
:actor,
|
61
|
+
:actor,
|
70
62
|
|
71
|
-
# Required - Action performed by Agent From Metric Profile
|
72
|
-
:action,
|
63
|
+
# Required - Action performed by Agent From Metric Profile (String)
|
64
|
+
:action,
|
73
65
|
|
74
|
-
# Required -
|
75
|
-
:object,
|
66
|
+
# Required - Object
|
67
|
+
:object,
|
76
68
|
|
77
|
-
# Optional -
|
78
|
-
:target,
|
69
|
+
# Optional - Targeted object (Targetable)
|
70
|
+
:target,
|
79
71
|
|
80
|
-
# Optional -
|
81
|
-
:generated,
|
72
|
+
# Optional - Generated object (Generatable)
|
73
|
+
:generated,
|
82
74
|
|
83
|
-
# Required time that the event was started at
|
84
|
-
:startedAtTime,
|
75
|
+
# Required time that the event was started at (ISO-8601 date string)
|
76
|
+
:startedAtTime,
|
85
77
|
|
86
|
-
# An optional time that the event ended at
|
87
|
-
:endedAtTime,
|
78
|
+
# An optional time that the event ended at (ISO-8601 date string)
|
79
|
+
:endedAtTime,
|
88
80
|
|
89
81
|
# An xsd:duration (http://books.xmlschemata.org/relaxng/ch19-77073.html)
|
90
|
-
# The format is expected to be PnYnMnDTnHnMnS
|
82
|
+
# The String format is expected to be PnYnMnDTnHnMnS
|
91
83
|
# Valid values include PT1004199059S, PT130S, PT2M10S, P1DT2S, -P1Y, or P1Y2M3DT5H20M30.123S.
|
92
84
|
# The following values are invalid: 1Y (leading P is missing), P1S (T separator is missing),
|
93
85
|
# 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). */
|
94
|
-
:duration
|
86
|
+
:duration,
|
87
|
+
|
88
|
+
# edApp
|
89
|
+
:edApp,
|
90
|
+
|
91
|
+
# Group
|
92
|
+
:group,
|
93
|
+
|
94
|
+
# Membership
|
95
|
+
:membership
|
95
96
|
|
96
97
|
def initialize()
|
97
98
|
@context = EventContext::EVENT
|
@@ -101,11 +102,12 @@ module Caliper
|
|
101
102
|
@object = nil
|
102
103
|
@target = nil
|
103
104
|
@generated = nil
|
104
|
-
@edApp = nil
|
105
|
-
@group = nil
|
106
105
|
@startedAtTime = Time.now.utc.iso8601(3)
|
107
106
|
@endedAtTime = nil
|
108
107
|
@duration = nil
|
108
|
+
@edApp = nil
|
109
|
+
@group = nil
|
110
|
+
@membership = nil
|
109
111
|
end
|
110
112
|
end
|
111
113
|
end
|
data/lib/caliper/jsonable.rb
CHANGED
@@ -64,7 +64,8 @@ module Caliper
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def eql?(other)
|
67
|
-
@
|
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
|
data/lib/caliper/options.rb
CHANGED
@@ -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 :
|
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
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
@@ -27,7 +27,6 @@ module Caliper
|
|
27
27
|
RESTARTED = "http://purl.imsglobal.org/vocab/caliper/v1/action#Restarted"
|
28
28
|
STARTED = "http://purl.imsglobal.org/vocab/caliper/v1/action#Started"
|
29
29
|
SUBMITTED = "http://purl.imsglobal.org/vocab/caliper/v1/action#Submitted"
|
30
|
-
GRADED = "http://purl.imsglobal.org/vocab/caliper/v1/action#Graded"
|
31
30
|
end
|
32
31
|
|
33
32
|
class AssessmentProfile < Caliper::Profiles::Profile
|
@@ -15,24 +15,34 @@
|
|
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 './
|
18
|
+
require_relative './envelope_jsonable'
|
19
19
|
|
20
20
|
#
|
21
|
-
#
|
21
|
+
# Event store envelope. Contains event info.
|
22
22
|
#
|
23
23
|
module Caliper
|
24
|
-
module
|
25
|
-
|
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
|
+
|
26
36
|
attr_accessor :context,
|
27
|
-
:
|
28
|
-
:
|
29
|
-
:
|
30
|
-
:generated
|
37
|
+
:sensor,
|
38
|
+
:sendTime,
|
39
|
+
:data
|
31
40
|
|
32
41
|
def initialize
|
33
|
-
|
34
|
-
|
35
|
-
|
42
|
+
@context = Context::CONTEXT
|
43
|
+
@sensor = ''
|
44
|
+
@sendTime = Time.now.utc.iso8601(3)
|
45
|
+
@data = []
|
36
46
|
end
|
37
47
|
end
|
38
48
|
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 './
|
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
|
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
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
-
|
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
|
19
|
-
|
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,32 +27,14 @@ module Caliper
|
|
28
27
|
|
29
28
|
def initialize(options)
|
30
29
|
@options = options
|
31
|
-
|
30
|
+
end
|
32
31
|
|
33
|
-
|
34
|
-
|
32
|
+
def send(sensor, data)
|
33
|
+
payload = generate_payload(sensor, data)
|
35
34
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
request = Net::HTTP::Post.new uri
|
40
|
-
|
41
|
-
response = http.request request # Net::HTTPResponse object
|
42
|
-
end
|
43
|
-
|
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
|
35
|
+
# What about the api key (authorization)?
|
36
|
+
RestClient.post @options['host'], payload, :content_type => :json, :accept => :json
|
37
|
+
end
|
57
38
|
end
|
58
39
|
end
|
59
40
|
end
|
data/lib/caliper/sensor.rb
CHANGED
@@ -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
|
-
|
19
|
-
require_relative
|
20
|
-
require_relative
|
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
|
-
|
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
|
-
|
50
|
-
|
51
|
-
envelope.sensorId = @options['sensorId']
|
52
|
-
envelope.entity = entity
|
38
|
+
HttpRequestor.new(@options).send(self, entity)
|
39
|
+
end
|
53
40
|
|
54
|
-
|
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
|
data/lib/caliper/version.rb
CHANGED
@@ -43,7 +43,7 @@ module Caliper
|
|
43
43
|
file = File.read('spec/lib/entities/agent/student.json')
|
44
44
|
data_hash = JSON.parse(file)
|
45
45
|
expected_json = data_hash.to_json # convert hash back to JSON string after parse
|
46
|
-
student.to_json.
|
46
|
+
expect(student.to_json).to be_json_eql(expected_json)
|
47
47
|
|
48
48
|
des_student = Person.new
|
49
49
|
des_student.from_json data_hash
|
@@ -39,7 +39,7 @@ module Caliper
|
|
39
39
|
file = File.read('spec/lib/entities/entity.json')
|
40
40
|
data_hash = JSON.parse(file)
|
41
41
|
expected_json = data_hash.to_json # convert hash back to JSON string after parse
|
42
|
-
entity.to_json.
|
42
|
+
expect(entity.to_json).to be_json_eql(expected_json)#.excluding("@class")
|
43
43
|
|
44
44
|
# Compare Deserialized JSON to desired Entity
|
45
45
|
des_entity = Entity.new
|