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.
Files changed (52) hide show
  1. checksums.yaml +5 -13
  2. data/lib/caliper/defaults.rb +2 -2
  3. data/lib/caliper/entities/agent/organization.rb +3 -3
  4. data/lib/caliper/entities/assessment/assessment.rb +0 -2
  5. data/lib/caliper/entities/entity.rb +0 -1
  6. data/lib/caliper/entities/foaf/agent.rb +1 -1
  7. data/lib/caliper/entities/lis/course_offering.rb +0 -1
  8. data/lib/caliper/entities/lis/group.rb +1 -2
  9. data/lib/caliper/entities/lis/{roles.rb → role.rb} +1 -1
  10. data/lib/caliper/entities/outcome/result.rb +3 -3
  11. data/lib/caliper/entities/response/fillin_blank_response.rb +1 -0
  12. data/lib/caliper/entities/response/multiple_choice_response.rb +1 -0
  13. data/lib/caliper/entities/response/multiple_response_response.rb +1 -0
  14. data/lib/caliper/entities/response/response.rb +1 -0
  15. data/lib/caliper/entities/response/select_type_response.rb +1 -0
  16. data/lib/caliper/entities/response/true_false_response.rb +1 -0
  17. data/lib/caliper/event/annotation_event.rb +1 -0
  18. data/lib/caliper/event/event.rb +28 -26
  19. data/lib/caliper/event/view_event.rb +1 -0
  20. data/lib/caliper/jsonable.rb +2 -1
  21. data/lib/caliper/options.rb +11 -11
  22. data/lib/caliper/profiles/assessment_profile.rb +0 -1
  23. data/lib/caliper/{event/grade_predict_event.rb → request/envelope.rb} +21 -11
  24. data/lib/caliper/request/envelope_jsonable.rb +69 -0
  25. data/lib/caliper/request/event_store_requestor.rb +16 -27
  26. data/lib/caliper/request/http_requestor.rb +8 -27
  27. data/lib/caliper/sensor.rb +12 -23
  28. data/lib/caliper/version.rb +1 -1
  29. data/spec/lib/entities/agent/person_spec.rb +1 -1
  30. data/spec/lib/entities/entity_spec.rb +1 -1
  31. data/spec/lib/event/annotation_event_bookmark_spec.rb +81 -98
  32. data/spec/lib/event/annotation_event_highlight_spec.rb +81 -98
  33. data/spec/lib/event/annotation_event_shared_spec.rb +81 -100
  34. data/spec/lib/event/annotation_event_tag_spec.rb +81 -98
  35. data/spec/lib/event/assessment_event_spec.rb +64 -124
  36. data/spec/lib/event/assessment_item_completed_event_spec.rb +93 -138
  37. data/spec/lib/event/assessment_item_started_event_spec.rb +92 -139
  38. data/spec/lib/event/assignable_event_spec.rb +65 -129
  39. data/spec/lib/event/media_event_spec.rb +77 -94
  40. data/spec/lib/event/navigated_event_spec.rb +90 -108
  41. data/spec/lib/event/session_event_login_spec.rb +98 -108
  42. data/spec/lib/event/session_event_logout_spec.rb +66 -81
  43. data/spec/lib/event/session_event_timeout_spec.rb +62 -88
  44. data/spec/lib/event/viewed_event_spec.rb +74 -92
  45. data/spec/lib/event_helper.rb +89 -109
  46. data/spec/lib/request/http_requestor_spec.rb +170 -0
  47. data/spec/lib/sensor_spec.rb +9 -29
  48. metadata +10 -11
  49. data/lib/caliper/entities/outcome/predicted_grade.rb +0 -43
  50. data/lib/caliper/entity_envelope.rb +0 -33
  51. data/lib/caliper/event_envelope.rb +0 -33
  52. data/lib/caliper/request/event_store_envelope.rb +0 -27
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YTFiNGQxYTJkOTcyNzBkZjAwNWVkZGNhN2UxNTg0YWRhM2ZkOTYxYQ==
5
- data.tar.gz: !binary |-
6
- Yjk4ZmU4Njg0YzQwMDdhYmJmYTA0YmRiZWRhMWM0Mjk3NmVmODBhNw==
2
+ SHA1:
3
+ metadata.gz: d787d10711e9df110e47808696cc7320a4d38fac
4
+ data.tar.gz: 829240aa1cfbc63aa8738b15f12f460da5f9b83a
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MWYwZjFmZGRhNDc2YmRhZDNhNjFkODY1MGIxZDgzOWI2ZTA3NTk4OTA1YzBj
10
- ZTRiMTAxNmIyN2NjNDc2YjYxM2NjZWE1ZDM2OWRhM2IyYmYzZGVkMmI0M2Vl
11
- YWNkYTIyOGEwYmJlM2U2N2EwN2I2YjQwZDc0Y2I4ZWExYzY4MjY=
12
- data.tar.gz: !binary |-
13
- MmZlOWU2ZTIyMjM1YzM0ZWEyMWVmMTg4MDViMTg4OWI1NzkzYWU5NDY5MzQx
14
- ODg5NDEzMTA0Yjc1ZTE1Zjk0ZTM3ZjFiNjVkMzQ5ZjIwZjRlZDc4NjJjZjE1
15
- NDYxNGUyODNkNzRlYWViZmFlYTJhZTYwODhiMmRjYzY4N2ExZTQ=
6
+ metadata.gz: 241b1e7dd90b7cb2fe680f1c4de7ef53576d4d3b1694593ed44c64116d4c7f9a7bc95804f3b231ac8f855b9e51d3025736923238ac47f2eb1df9d4ed02cebde9
7
+ data.tar.gz: 15fc41e4d02518ac66a10f7f1f790846377c7a8769f02b0d3bad81ec4d19ffb7397f25f8be2a4a06b9d001d5ebb866dd19a236144e7d9293321944ee95d366f7
@@ -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
@@ -25,10 +25,10 @@ module Caliper
25
25
  module Entities
26
26
  module Agent
27
27
  class Organization < Entity
28
- include Caliper::Entities::W3C::Organization
28
+ include Caliper::Entities::FOAF::Agent,
29
+ Caliper::Entities::W3C::Organization
29
30
 
30
- attr_accessor :membership,
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"
@@ -24,7 +24,7 @@ module Caliper
24
24
  module Entities
25
25
  module FOAF
26
26
  module Agent
27
- attr_accessor :hasMembership # Membership
27
+
28
28
  end
29
29
  end
30
30
  end
@@ -29,7 +29,6 @@ module Caliper
29
29
 
30
30
  attr_accessor :courseNumber,
31
31
  :academicSession,
32
- :membership,
33
32
  :subOrganizationOf
34
33
  def initialize
35
34
  super
@@ -27,8 +27,7 @@ module Caliper
27
27
  class Group < Entity
28
28
  include Caliper::Entities::W3C::Organization
29
29
 
30
- attr_accessor :membership,
31
- :subOrganizationOf
30
+ attr_accessor :subOrganizationOf
32
31
 
33
32
  def initialize
34
33
  super
@@ -21,7 +21,7 @@
21
21
  module Caliper
22
22
  module Entities
23
23
  module LIS
24
- module Roles
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'
@@ -35,10 +35,10 @@ module Caliper
35
35
  :curve_factor,
36
36
  :comment,
37
37
  :scored_by
38
+ end
38
39
 
39
- def initialize
40
-
41
- end
40
+ def initialize
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
@@ -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
@@ -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, # String
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, # Agent
61
+ :actor,
70
62
 
71
- # Required - Action performed by Agent From Metric Profile
72
- :action, # String
63
+ # Required - Action performed by Agent From Metric Profile (String)
64
+ :action,
73
65
 
74
- # Required - "Activity Context" from Metric Profile
75
- :object, # Object
66
+ # Required - Object
67
+ :object,
76
68
 
77
- # Optional - "target" from Metric Profile
78
- :target, # Targetable
69
+ # Optional - Targeted object (Targetable)
70
+ :target,
79
71
 
80
- # Optional - entity "generated" as result of action - from Metric Profile
81
- :generated, # Generatable
72
+ # Optional - Generated object (Generatable)
73
+ :generated,
82
74
 
83
- # Required time that the event was started at
84
- :startedAtTime, # ISO-8601 date string
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, # ISO-8601 date string
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 # String
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
@@ -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
@@ -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 './event'
18
+ require_relative './envelope_jsonable'
19
19
 
20
20
  #
21
- # GradePredictEvent Event.
21
+ # Event store envelope. Contains event info.
22
22
  #
23
23
  module Caliper
24
- module Event
25
- class GradePredictEvent < Event
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
- :type,
28
- :action,
29
- :object,
30
- :generated
37
+ :sensor,
38
+ :sendTime,
39
+ :data
31
40
 
32
41
  def initialize
33
- super
34
- @context = EventContext::GRADE_PREDICT
35
- @type = EventType::GRADE_PREDICT
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 './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,32 +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
- # 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
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
@@ -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.3.14"
22
+ VERSION = "0.9.3.15"
23
23
  end
@@ -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.should be_json_eql(expected_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.should be_json_eql(expected_json)#.excluding("@class")
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