icws 0.0.3 → 1.0.0

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.
@@ -3,38 +3,93 @@ require 'rubygems'
3
3
  require 'json'
4
4
 
5
5
  class ICWS
6
- class Client
7
- def initialize(connection)
8
- @connection = connection
9
- headers = {:Cookie => @connection.cookie,"ININ-ICWS-CSRF-Token" => @connection.token}
10
- @http_resource = RestClient::Resource.new(@connection.base_uri, :headers => headers)
11
- end
12
-
13
- def post(url, body, headers={})
14
- begin
15
- JSON.parse @http_resource[url].post body.to_json, headers
16
- rescue => e
17
- puts e.inspect
18
- throw e
19
- end
20
- end
21
-
22
- def get(url, headers={})
23
- JSON.parse @http_resource[url].get headers
24
- end
25
-
26
- def delete(url, headers={})
27
- @http_resource[url].delete headers
28
- end
29
-
30
- def put(url, body, headers={})
31
- begin
32
- @http_resource[url].put body.to_json, headers
33
- rescue => e
34
- puts e.inspect
35
- throw e
36
- end
37
-
6
+ # REST wrapper around the ICWS connection. This class handles setting the proper cookies and headers for
7
+ # each request.
8
+
9
+ class Client
10
+ # Creates a new ICWS Client
11
+ #
12
+ # == Parameters:
13
+ # connection::
14
+ # ICWS::Connection instance
15
+ def initialize(connection)
16
+ @connection = connection
17
+ headers = {:Cookie => @connection.cookie,"ININ-ICWS-CSRF-Token" => @connection.token}
18
+ @http_resource = RestClient::Resource.new(@connection.base_uri, :headers => headers)
19
+ end
20
+
21
+ # Makes a POST call to the server.
22
+ #
23
+ # == Parameters:
24
+ # url::
25
+ # The Url to call the POST On
26
+ #
27
+ # headers::
28
+ # Optional additional headers to send
29
+ #
30
+ # == Returns:
31
+ # The response from the server
32
+ #
33
+ def post(url, body, headers={})
34
+ begin
35
+ JSON.parse @http_resource[url].post body.to_json, headers
36
+ rescue => e
37
+ puts e.inspect
38
+ throw e
39
+ end
40
+ end
41
+
42
+
43
+ # Makes a GET call to the server.
44
+ #
45
+ # == Parameters:
46
+ # url::
47
+ # The Url to call the GET On
48
+ #
49
+ # headers::
50
+ # Optional additional headers to send
51
+ #
52
+ # == Returns:
53
+ # The response from the server
54
+ #
55
+
56
+ def get(url, headers={})
57
+ JSON.parse @http_resource[url].get headers
58
+ end
59
+
60
+ # Makes a DELETE call to the server.
61
+ #
62
+ # == Parameters:
63
+ # url::
64
+ # The Url to call the DELETE On
65
+ #
66
+ # headers::
67
+ # Optional additional headers to send
68
+ #
69
+ def delete(url, headers={})
70
+ @http_resource[url].delete headers
71
+ end
72
+
73
+ # Makes a PUT call to the server.
74
+ #
75
+ # == Parameters:
76
+ # url::
77
+ # The Url to call the PUT On
78
+ #
79
+ # headers::
80
+ # Optional additional headers to send
81
+ #
82
+ # == Returns:
83
+ # The response from the server
84
+ #
85
+ def put(url, body, headers={})
86
+ begin
87
+ @http_resource[url].put body.to_json, headers
88
+ rescue => e
89
+ puts e.inspect
90
+ throw e
91
+ end
92
+
93
+ end
38
94
  end
39
- end
40
95
  end
@@ -1,65 +1,68 @@
1
1
  class ICWS
2
- class MessageQueue
3
- #http://stackoverflow.com/questions/605169/how-to-do-events-in-ruby
4
- class EventHandlerArray < Array
5
- def add_handler(&block)
6
- push(block)
7
- end
8
- def add
9
- raise "error"
10
- end
11
- def remove_handler(code)
12
- delete(code)
13
- end
14
- def fire(e)
15
- reverse_each { |handler|
16
- begin
17
- handler.call(e)
18
- rescue => e
19
- puts e.inspect
20
- end
21
- }
22
- end
2
+ #The message queue manages callbacks for different objects that are receiving messages from CIC.
3
+ class MessageQueue
4
+ class EventHandlerArray < Array
5
+ def add_handler(&block)
6
+ push(block)
7
+ end
8
+ def add
9
+ raise "error"
10
+ end
11
+ def remove_handler(code)
12
+ delete(code)
13
+ end
14
+ def fire(e)
15
+ reverse_each { |handler|
16
+ begin
17
+ handler.call(e)
18
+ rescue => e
19
+ puts e.inspect
20
+ end
21
+ }
22
+ end
23
+ end
24
+
25
+ def initialize(connection)
26
+ @message_handlers = {}
27
+ @client = ICWS::Client.new connection
28
+
29
+ @pollingThread = Thread.new() {
30
+ poll_loop
31
+ }
32
+ end
33
+
34
+ #register for a new message type.
35
+ # @param messageType [String] The type of messages to receive notifications for.
36
+ # @param block [&block] Block to call when a message of that type is received.
37
+ def register(messageType, &block)
38
+ if(@message_handlers[messageType] == nil)
39
+ @message_handlers[messageType] = EventHandlerArray.new
40
+ end
41
+ callback = block
42
+ @message_handlers[messageType].add_handler {|e| callback.call(e)}
43
+ end
44
+
45
+ def deregister(messageType, code)
46
+ if(@message_handlers[messageType] == nil)
47
+ return
48
+ end
49
+
50
+ @message_handlers[messageType].remove_handler(code)
51
+ end
52
+
53
+ private
54
+ def poll_loop
55
+ while true
56
+ messages = @client.get '/messaging/messages'
57
+ for message in messages
58
+ #puts message
59
+ type = message['__type']
60
+ if @message_handlers[type]
61
+ @message_handlers[type].fire(message)
62
+ end
63
+ end
64
+ sleep 1
65
+ end
66
+ end
23
67
  end
24
-
25
- def initialize(connection)
26
- @message_handlers = {}
27
- @client = ICWS::Client.new connection
28
-
29
- @pollingThread = Thread.new() {
30
- poll_loop
31
- }
32
- end
33
-
34
- def register(messageType, &block)
35
- if(@message_handlers[messageType] == nil)
36
- @message_handlers[messageType] = EventHandlerArray.new
37
- end
38
- callback = block
39
- @message_handlers[messageType].add_handler {|e| callback.call(e)}
40
- end
41
-
42
- def deregister(messageType, code)
43
- if(@message_handlers[messageType] == nil)
44
- return
45
- end
46
-
47
- @message_handlers[messageType].remove_handler(code)
48
- end
49
-
50
- private
51
- def poll_loop
52
- while true
53
- messages = @client.get '/messaging/messages'
54
- for message in messages
55
- #puts message
56
- type = message['__type']
57
- if @message_handlers[type]
58
- @message_handlers[type].fire(message)
59
- end
60
- end
61
- sleep 1
62
- end
63
- end
64
- end
65
- end
68
+ end
@@ -1,14 +1,15 @@
1
1
  class ICWS
2
- class MessageSubscriber
3
- def initialize(connection, message_queue, messageId)
4
- message_queue.register(messageId) {|e| event_received(e)}
5
- @application_name = connection.application_name
6
- @client = ICWS::Client.new connection
7
-
2
+ #Base class to listen for events from the server.
3
+ class MessageSubscriber
4
+ def initialize(connection, message_queue, messageId)
5
+ message_queue.register(messageId) {|e| event_received(e)}
6
+ @application_name = connection.application_name
7
+ @client = ICWS::Client.new connection
8
+
9
+ end
10
+
11
+ def event_received(message)
12
+
13
+ end
8
14
  end
9
-
10
- def event_received(message)
11
-
12
- end
13
- end
14
- end
15
+ end
@@ -1,22 +1,30 @@
1
1
  require '..\lib\statistics\statisticdefinition.rb'
2
2
 
3
3
  class ICWS
4
+ #Defines a category for supervisor statistics
4
5
  class StatisticCategory
5
- attr_reader :statistic_category_id
6
- attr_reader :display_string
7
- attr_reader :description
8
- attr_reader :statistic_definitions
9
-
10
- def initialize(propertyMap)
11
- @statistic_category_id = propertyMap['statisticCategoryId']
12
- @display_string = propertyMap['displayString']
13
- @description = propertyMap['description']
14
- @statistic_definitions = []
15
- propertyMap['statisticDefinitions'].each {|s| @statistic_definitions.push ICWS::StatisticDefinition.new(s)}
16
- end
17
-
18
- def to_s
19
- @display_string + '(' + @statistic_category_id + ')'
20
- end
21
- end
22
- end
6
+ #Category Id
7
+ attr_reader :statistic_category_id
8
+ #Category display string
9
+ attr_reader :display_string
10
+ #Category Description
11
+ attr_reader :description
12
+ #List of StatisticDefinition
13
+ attr_reader :statistic_definitions
14
+
15
+ #Creates a new Statistic category.
16
+ # @param propertyMap [Hash] Map or properties that define the statistic.
17
+ def initialize(propertyMap)
18
+ @statistic_category_id = propertyMap['statisticCategoryId']
19
+ @display_string = propertyMap['displayString']
20
+ @description = propertyMap['description']
21
+ @statistic_definitions = []
22
+ propertyMap['statisticDefinitions'].each {|s| @statistic_definitions.push ICWS::StatisticDefinition.new(s)}
23
+ end
24
+
25
+ #String reporesentation - DisplayString (Category Id)
26
+ def to_s
27
+ @display_string + '(' + @statistic_category_id + ')'
28
+ end
29
+ end
30
+ end
@@ -1,20 +1,28 @@
1
1
 
2
2
  class ICWS
3
+ #Definition of a supervisor statistic
3
4
  class StatisticDefinition
4
- attr_reader :statistic_identifier
5
- attr_reader :display_string
6
- attr_reader :description
7
- attr_reader :units_display
8
-
9
- def initialize(propertyMap)
10
- @statistic_identifier = propertyMap['statisticIdentifier']
11
- @display_string = propertyMap['displayString']
12
- @description = propertyMap['description']
13
- @units_display = propertyMap['unitsDisplay']
14
- end
15
-
16
- def to_s
17
- ' ' + @display_string + '(' + @statistic_identifier + ')'
18
- end
19
- end
20
- end
5
+ #ID of the statistic
6
+ attr_reader :statistic_identifier
7
+ #Display String of the statistic
8
+ attr_reader :display_string
9
+ #Description of the statistic
10
+ attr_reader :description
11
+ #Statistic Units
12
+ attr_reader :units_display
13
+
14
+ #Creates a new Statistic category.
15
+ # @param propertyMap [Hash] Map or properties that define the statistic.
16
+ def initialize(propertyMap)
17
+ @statistic_identifier = propertyMap['statisticIdentifier']
18
+ @display_string = propertyMap['displayString']
19
+ @description = propertyMap['description']
20
+ @units_display = propertyMap['unitsDisplay']
21
+ end
22
+
23
+ #String reporesentation - DisplayString (Stat Id)
24
+ def to_s
25
+ ' ' + @display_string + '(' + @statistic_identifier + ')'
26
+ end
27
+ end
28
+ end
@@ -2,23 +2,27 @@ require '..\lib\messages\messagesubscriber.rb'
2
2
  require '..\lib\statistics\statisticcategory.rb'
3
3
 
4
4
  class ICWS
5
- class Statistics < MessageSubscriber
6
- attr_reader :statistic_catalog
7
-
8
- def initialize(connection, message_queue)
9
- super(connection, message_queue,'urn:inin.com:statistics:statisticCatalogMessage')
10
- @client = ICWS::Client.new connection
11
- @client.put '/messaging/subscriptions/statistics/statistic-catalog', {}
12
-
13
- end
14
-
15
- def event_received(message)
16
- if message['__type'] == 'urn:inin.com:statistics:statisticCatalogMessage'
17
- @statistic_catalog = []
18
- message['statisticCategoryList'].each {|s| @statistic_catalog.push ICWS::StatisticCategory.new(s)}
19
-
20
- end
5
+ #Subscribes to Statistics from CIC
6
+ class Statistics < MessageSubscriber
7
+ #Hash of Statistics catalogs
8
+ attr_reader :statistic_catalog
9
+
10
+ #Constructor which sets up a new watcher on the statistics catalog
11
+ def initialize(connection, message_queue)
12
+ super(connection, message_queue,'urn:inin.com:statistics:statisticCatalogMessage')
13
+ @client = ICWS::Client.new connection
14
+ @client.put '/messaging/subscriptions/statistics/statistic-catalog', {}
15
+
16
+ end
17
+
18
+ #block for when a new stat catalog message comes in
19
+ def event_received(message)
20
+ if message['__type'] == 'urn:inin.com:statistics:statisticCatalogMessage'
21
+ @statistic_catalog = []
22
+ message['statisticCategoryList'].each {|s| @statistic_catalog.push ICWS::StatisticCategory.new(s)}
23
+
24
+ end
25
+ end
26
+
21
27
  end
22
-
23
- end
24
- end
28
+ end
@@ -2,34 +2,45 @@ require 'icws/status/statusmessage'
2
2
  require 'icws/status/userstatus'
3
3
 
4
4
  class ICWS
5
- class ICWS::Status
6
-
7
- def initialize(connection)
8
- @client = ICWS::Client.new connection
9
- end
10
-
11
- def all_system_statuses
12
- status_list = @client.get '/status/status-messages'
13
- statuses = []
14
- status_list['statusMessageList'].each {|s| statuses.push ICWS::StatusMessage.new(s)}
15
- return statuses
16
- end
17
-
18
- def allowable_statuses (user_id)
19
- status = @client.get '/status/status-messages-user-access/' + user_id
20
- status['statusMessages']
21
- end
22
-
23
- def get_user_status(user_id)
24
- status = @client.get '/status/user-statuses/' + user_id
25
- ICWS::Status::UserStatus.new(status )
26
- end
27
-
28
- def set_user_status(user_id, status_id)
29
- status_data = {}
30
- status_data[:statusId] = status_id
31
-
32
- @client.put '/status/user-statuses/' + user_id, status_data
5
+ #Status message handler
6
+ class Status
7
+ #Creates a new instance
8
+ def initialize(connection)
9
+ @client = ICWS::Client.new connection
10
+ end
11
+ #Retreives all the statuses configured in the system
12
+ # @return [Array[StatusMessage]] The status messages.
13
+ def all_system_statuses
14
+ status_list = @client.get '/status/status-messages'
15
+ statuses = []
16
+ status_list['statusMessageList'].each {|s| statuses.push ICWS::StatusMessage.new(s)}
17
+ return statuses
18
+ end
19
+
20
+ #Retreives all the statuses for a given user.
21
+ # @param user_id [String] The user Id
22
+ # @return [Array[StatusMessage]] The status messages.
23
+ def allowable_statuses (user_id)
24
+ status = @client.get '/status/status-messages-user-access/' + user_id
25
+ status['statusMessages']
26
+ end
27
+
28
+ #Retreives the current status for a given user.
29
+ # @param user_id [String] The user Id
30
+ # @return [StatusMessage] The user's status.
31
+ def get_user_status(user_id)
32
+ status = @client.get '/status/user-statuses/' + user_id
33
+ ICWS::Status::UserStatus.new(status )
34
+ end
35
+
36
+ #Sets the current status for a given user.
37
+ # @param user_id [String] The user Id
38
+ # @param status_id [String] The Id of the status to set to.
39
+ def set_user_status(user_id, status_id)
40
+ status_data = {}
41
+ status_data[:statusId] = status_id
42
+
43
+ @client.put '/status/user-statuses/' + user_id, status_data
44
+ end
33
45
  end
34
- end
35
- end
46
+ end