icws 0.0.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.
@@ -0,0 +1,65 @@
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
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
+ 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
@@ -0,0 +1,14 @@
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
+
8
+ end
9
+
10
+ def event_received(message)
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ require '..\lib\statistics\statisticdefinition.rb'
2
+
3
+ class ICWS
4
+ 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
@@ -0,0 +1,20 @@
1
+
2
+ class ICWS
3
+ 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
@@ -0,0 +1,24 @@
1
+ require '..\lib\messages\messagesubscriber.rb'
2
+ require '..\lib\statistics\statisticcategory.rb'
3
+
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
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,35 @@
1
+ require 'icws/status/statusmessage'
2
+ require 'icws/status/userstatus'
3
+
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
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,41 @@
1
+ class ICWS
2
+ class StatusMessage
3
+ attr_reader :status_id
4
+ attr_reader :message_text
5
+ attr_reader :icon_uri
6
+ attr_reader :group_tag
7
+ attr_reader :can_have_date
8
+ attr_reader :can_have_time
9
+ attr_reader :is_do_not_disturb_status
10
+ attr_reader :is_selectable_status
11
+ attr_reader :is_persistent_status
12
+ attr_reader :is_forward_status
13
+ attr_reader :is_after_call_work_status
14
+ attr_reader :is_acd_status
15
+ attr_reader :is_allow_follow_up_status
16
+ attr_reader :system_id
17
+
18
+ def initialize(property_map)
19
+ @status_id = property_map['statusId']
20
+ @message_text = property_map['messageText']
21
+ @icon_uri = property_map['iconUri']
22
+ @group_tag = property_map['groupTag']
23
+ @can_have_date = property_map['canHaveDate']
24
+ @can_have_time = property_map['canHaveTime']
25
+ @is_do_not_disturb_status = property_map['isDoNotDisturbStatus']
26
+ @is_selectable_status = property_map['isSelectableStatus']
27
+ @is_fersistent_status = property_map['isPersistentStatus']
28
+ @is_forward_status = property_map['isForwardStatus']
29
+ @is_after_call_work_status = property_map['isAfterCallWorkStatus']
30
+ @is_acd_status = property_map['isAcdStatus']
31
+ @is_allow_follow_up_status = property_map['isAllowFollowUpStatus']
32
+ @system_id = property_map['systemId']
33
+ end
34
+
35
+ def to_s
36
+ status_id + ', ' + message_text + ',' + icon_uri
37
+ end
38
+ end
39
+ end
40
+
41
+
@@ -0,0 +1,33 @@
1
+ #require 'Date'
2
+
3
+ class ICWS
4
+ class Status
5
+ class UserStatus
6
+ attr_reader :user_id
7
+ attr_reader :status_id
8
+ attr_reader :status_changed #"=>"20130808T211625Z",
9
+ attr_reader :notes
10
+ attr_reader :ic_servers
11
+ attr_reader :stations
12
+ attr_reader :logged_in
13
+ attr_reader :on_phone
14
+ attr_reader :on_phone_changed
15
+
16
+ def initialize(property_map)
17
+ @status_id = property_map['statusId']
18
+ @user_id = property_map['userId']
19
+ @notes = property_map['notes']
20
+ @ic_servers = property_map['icServers']
21
+ @stations = property_map['stations']
22
+ @logged_in = property_map['loggedIn']
23
+ @on_phone = property_map['onPhone']
24
+ @status_changed = property_map['statusChanged'] #DateTime.parse property_map['statusChanged']
25
+ @system_id = property_map['onPhoneChanged']#DateTime.parse property_map['onPhoneChanged']
26
+ end
27
+
28
+ def to_s
29
+ @user_id + ' - ' + @status_id
30
+ end
31
+ end
32
+ end
33
+ end
data/lib/icwsclient.rb ADDED
@@ -0,0 +1,40 @@
1
+ require 'rest_client'
2
+ require 'rubygems'
3
+ require 'json'
4
+
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
+
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,65 @@
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
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
+ 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
@@ -0,0 +1,14 @@
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
+
8
+ end
9
+
10
+ def event_received(message)
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ require '..\lib\statistics\statisticdefinition.rb'
2
+
3
+ class ICWS
4
+ 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
@@ -0,0 +1,20 @@
1
+
2
+ class ICWS
3
+ 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
@@ -0,0 +1,24 @@
1
+ require '..\lib\messages\messagesubscriber.rb'
2
+ require '..\lib\statistics\statisticcategory.rb'
3
+
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
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,35 @@
1
+ require '..\lib\status\statusmessage.rb'
2
+ require '..\lib\status\userstatus.rb'
3
+
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
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,41 @@
1
+ class ICWS
2
+ class StatusMessage
3
+ attr_reader :status_id
4
+ attr_reader :message_text
5
+ attr_reader :icon_uri
6
+ attr_reader :group_tag
7
+ attr_reader :can_have_date
8
+ attr_reader :can_have_time
9
+ attr_reader :is_do_not_disturb_status
10
+ attr_reader :is_selectable_status
11
+ attr_reader :is_persistent_status
12
+ attr_reader :is_forward_status
13
+ attr_reader :is_after_call_work_status
14
+ attr_reader :is_acd_status
15
+ attr_reader :is_allow_follow_up_status
16
+ attr_reader :system_id
17
+
18
+ def initialize(property_map)
19
+ @status_id = property_map['statusId']
20
+ @message_text = property_map['messageText']
21
+ @icon_uri = property_map['iconUri']
22
+ @group_tag = property_map['groupTag']
23
+ @can_have_date = property_map['canHaveDate']
24
+ @can_have_time = property_map['canHaveTime']
25
+ @is_do_not_disturb_status = property_map['isDoNotDisturbStatus']
26
+ @is_selectable_status = property_map['isSelectableStatus']
27
+ @is_fersistent_status = property_map['isPersistentStatus']
28
+ @is_forward_status = property_map['isForwardStatus']
29
+ @is_after_call_work_status = property_map['isAfterCallWorkStatus']
30
+ @is_acd_status = property_map['isAcdStatus']
31
+ @is_allow_follow_up_status = property_map['isAllowFollowUpStatus']
32
+ @system_id = property_map['systemId']
33
+ end
34
+
35
+ def to_s
36
+ status_id + ', ' + message_text + ',' + icon_uri
37
+ end
38
+ end
39
+ end
40
+
41
+
@@ -0,0 +1,33 @@
1
+ require 'Date'
2
+
3
+ class ICWS
4
+ class Status
5
+ class UserStatus
6
+ attr_reader :user_id
7
+ attr_reader :status_id
8
+ attr_reader :status_changed #"=>"20130808T211625Z",
9
+ attr_reader :notes
10
+ attr_reader :ic_servers
11
+ attr_reader :stations
12
+ attr_reader :logged_in
13
+ attr_reader :on_phone
14
+ attr_reader :on_phone_changed
15
+
16
+ def initialize(property_map)
17
+ @status_id = property_map['statusId']
18
+ @user_id = property_map['userId']
19
+ @notes = property_map['notes']
20
+ @ic_servers = property_map['icServers']
21
+ @stations = property_map['stations']
22
+ @logged_in = property_map['loggedIn']
23
+ @on_phone = property_map['onPhone']
24
+ @status_changed = DateTime.parse property_map['statusChanged']
25
+ @system_id = DateTime.parse property_map['onPhoneChanged']
26
+ end
27
+
28
+ def to_s
29
+ @user_id + ' - ' + @status_id
30
+ end
31
+ end
32
+ end
33
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: icws
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Kevin Glinski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Ruby wrapper around ICWS
42
+ email: kevin.glinski@inin.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - LICENSE
48
+ - RAKEFILE
49
+ - lib/configuration/configurationitem.rb
50
+ - lib/configuration/users.rb
51
+ - lib/configuration/workgroups.rb
52
+ - lib/connection.rb
53
+ - lib/feature.rb
54
+ - lib/icws/INTERNAL/challangemessagehandler.rb
55
+ - lib/icws/INTERNAL/internalconnection.rb
56
+ - lib/icws/configuration/configurationitem.rb
57
+ - lib/icws/configuration/roles.rb
58
+ - lib/icws/configuration/stations.rb
59
+ - lib/icws/configuration/users.rb
60
+ - lib/icws/configuration/workgroups.rb
61
+ - lib/icws/connection.rb
62
+ - lib/icws/feature.rb
63
+ - lib/icws/icwsclient.rb
64
+ - lib/icws/messages/messagequeue.rb
65
+ - lib/icws/messages/messagesubscriber.rb
66
+ - lib/icws/statistics/statisticcategory.rb
67
+ - lib/icws/statistics/statisticdefinition.rb
68
+ - lib/icws/statistics/statistics.rb
69
+ - lib/icws/status/status.rb
70
+ - lib/icws/status/statusmessage.rb
71
+ - lib/icws/status/userstatus.rb
72
+ - lib/icwsclient.rb
73
+ - lib/messages/messagequeue.rb
74
+ - lib/messages/messagesubscriber.rb
75
+ - lib/statistics/statisticcategory.rb
76
+ - lib/statistics/statisticdefinition.rb
77
+ - lib/statistics/statistics.rb
78
+ - lib/status/status.rb
79
+ - lib/status/statusmessage.rb
80
+ - lib/status/userstatus.rb
81
+ homepage: https://github.com/InteractiveIntelligence/ICWSRubyGem
82
+ licenses: []
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.4.1
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: open source Ruby wrapper around ICWS
104
+ test_files: []