icws 2.0.1 → 2.2.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.
- checksums.yaml +4 -4
- data/lib/icws/Queues/queue.rb +88 -0
- data/lib/icws/connection.rb +1 -1
- data/lib/icws/icwsclient.rb +12 -1
- data/lib/icws/interactions/interaction.rb +70 -0
- data/lib/icws/interactions/interactionmanager.rb +23 -0
- data/lib/icws/messages/messagequeue.rb +57 -53
- data/lib/icws/messages/messagesubscriber.rb +10 -8
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c6cae70aa27478d4b5705c903fcc9e732e4e342
|
4
|
+
data.tar.gz: f0e3f20f66a2c00f58e2daf06ed677016cf1bc7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d14231467ab62cdc15247bd309dd4681dd516e22d3f976c63910d3028b4f34dec7a4bf0678b051fbdf79d30fd69a8bb53a79fc74cfd2756b55e0483fbe14d12c
|
7
|
+
data.tar.gz: 8ddd16e583a172a2637fbb47c89ac61803a037eadea3704a4a82ff59da936b4dcc81841b767a99030a24a5ae9cc9b270db362126feab3f6975fa7235a5881063
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'icws/messages/messagesubscriber'
|
2
|
+
require 'icws/messages/messagequeue'
|
3
|
+
|
4
|
+
class ICWS
|
5
|
+
class Queues
|
6
|
+
|
7
|
+
|
8
|
+
class Queue < ICWS::Messages::MessageSubscriber
|
9
|
+
@addedHandler = nil
|
10
|
+
@changedHandler = nil
|
11
|
+
@removedHandler = nil
|
12
|
+
|
13
|
+
# @interactionMap = {}
|
14
|
+
|
15
|
+
def initialize(connection, messageQueue )
|
16
|
+
super(connection,messageQueue, "urn:inin.com:queues:queueContentsMessage")
|
17
|
+
end
|
18
|
+
|
19
|
+
def start_watching_workgroup_queue(queueName, attributes)
|
20
|
+
watchData = {
|
21
|
+
:queueIds=> [
|
22
|
+
{
|
23
|
+
:queueType=>2,
|
24
|
+
:queueName=> queueName
|
25
|
+
}
|
26
|
+
],
|
27
|
+
:attributeNames => attributes
|
28
|
+
}
|
29
|
+
|
30
|
+
@client.put "/messaging/subscriptions/queues/" + queueName, watchData
|
31
|
+
end
|
32
|
+
|
33
|
+
def event_received(message)
|
34
|
+
if @addedHandler != nil
|
35
|
+
if(message["interactionsAdded"] != nil && message["interactionsAdded"].length >0 )
|
36
|
+
puts 'interactions added '
|
37
|
+
interactions = []
|
38
|
+
for interaction in message["interactionsAdded"]
|
39
|
+
addedInteraction = ICWS::Interactions::Interaction.new interaction, @connection
|
40
|
+
interactions.push addedInteraction
|
41
|
+
|
42
|
+
# @interactionMap[addedInteraction.id] = addedInteraction;
|
43
|
+
end
|
44
|
+
|
45
|
+
@addedHandler.call interactions
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
if @changedHandler != nil
|
51
|
+
if(message["interactionsChanged"] != nil && message["interactionsChanged"].length >0 )
|
52
|
+
interactions = []
|
53
|
+
for interaction in message["interactionsChanged"]
|
54
|
+
interactions.push ICWS::Interactions::Interaction.new interaction["interactionId"], @connection
|
55
|
+
end
|
56
|
+
|
57
|
+
@changedHandler.call interactions
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
if @removedHandler != nil
|
63
|
+
if(message["interactionsRemoved"] != nil && message["interactionsRemoved"].length >0 )
|
64
|
+
for interaction in message["interactionsRemoved"]
|
65
|
+
@interactionMap.delete interaction;
|
66
|
+
end
|
67
|
+
|
68
|
+
@removedHandler.call message["interactionsRemoved"]
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def on_interactions_added(&block)
|
76
|
+
@addedHandler = block
|
77
|
+
end
|
78
|
+
|
79
|
+
def on_interactions_changed(&block)
|
80
|
+
@changedHandler = block
|
81
|
+
end
|
82
|
+
|
83
|
+
def on_interactions_removed(&block)
|
84
|
+
@removedHandler = block
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
data/lib/icws/connection.rb
CHANGED
data/lib/icws/icwsclient.rb
CHANGED
@@ -32,7 +32,18 @@ class ICWS
|
|
32
32
|
#
|
33
33
|
def post(url, body, headers={})
|
34
34
|
begin
|
35
|
-
|
35
|
+
result = nil
|
36
|
+
if body != nil
|
37
|
+
result = @http_resource[url].post body.to_json, headers
|
38
|
+
else
|
39
|
+
result = @http_resource[url].post "", headers
|
40
|
+
end
|
41
|
+
|
42
|
+
if(result != nil && result != '')
|
43
|
+
JSON.parse result
|
44
|
+
else
|
45
|
+
return nil
|
46
|
+
end
|
36
47
|
rescue => e
|
37
48
|
puts e.inspect
|
38
49
|
throw e
|
@@ -0,0 +1,70 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
class ICWS
|
4
|
+
class Interactions
|
5
|
+
class Interaction
|
6
|
+
attr_reader :id
|
7
|
+
|
8
|
+
@attributes = {}
|
9
|
+
|
10
|
+
def initialize(interactionDetails, connection)
|
11
|
+
if( connection != nil)
|
12
|
+
@client = ICWS::Client.new connection
|
13
|
+
end
|
14
|
+
|
15
|
+
@id = interactionDetails["interactionId"]
|
16
|
+
@attributes = interactionDetails["attributes"]
|
17
|
+
end
|
18
|
+
|
19
|
+
def update_attributes(newAttributes)
|
20
|
+
@attributes.merge! newAttributes
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_attributes(attributeArray)
|
24
|
+
attrs = attributeArray.join (",")
|
25
|
+
attributes = @client.get "/interactions/#@id?select=" + attrs
|
26
|
+
return attributes["attributes"]
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_attribute(attributeName)
|
30
|
+
|
31
|
+
if @attributes.key? attributeName
|
32
|
+
return @attributes[attributeName]
|
33
|
+
end
|
34
|
+
|
35
|
+
uri = "/interactions/#@id?select=" + attributeName
|
36
|
+
|
37
|
+
attributeResult = @client.get uri
|
38
|
+
|
39
|
+
return attributeResult["attributes"][attributeName]
|
40
|
+
end
|
41
|
+
|
42
|
+
def set_attributes(attributes)
|
43
|
+
body = {"attributes" => attributes}
|
44
|
+
@client.post "/interactions/#@id", body
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
def set_attribute(name, value)
|
49
|
+
attrs = {}
|
50
|
+
attrs[name] = value
|
51
|
+
return set_attributes attrs
|
52
|
+
end
|
53
|
+
|
54
|
+
def is_connected?
|
55
|
+
state = get_attribute("Eic_State")
|
56
|
+
return state == 'C'
|
57
|
+
end
|
58
|
+
|
59
|
+
def is_disconnected?
|
60
|
+
state = get_attribute("Eic_State")
|
61
|
+
return state == 'E' || state == "I"
|
62
|
+
end
|
63
|
+
|
64
|
+
def disconnect
|
65
|
+
@client.post "/interactions/#@id/disconnect", nil
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'icws/interactions/interaction'
|
2
|
+
|
3
|
+
class ICWS
|
4
|
+
class Interactions
|
5
|
+
class InteractionManager
|
6
|
+
def initialize(connection)
|
7
|
+
@client = ICWS::Client.new connection
|
8
|
+
end
|
9
|
+
|
10
|
+
def make_call (connection, number)
|
11
|
+
|
12
|
+
makeCallParams = {
|
13
|
+
"__type" => "urn:inin.com:interactions:createCallParameters",
|
14
|
+
:target => number
|
15
|
+
}
|
16
|
+
|
17
|
+
result = @client.post "/interactions", makeCallParams
|
18
|
+
|
19
|
+
return Interaction.new result, connection
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,67 +1,71 @@
|
|
1
|
+
require 'icws/icwsclient'
|
2
|
+
|
1
3
|
class ICWS
|
2
|
-
|
3
|
-
|
4
|
-
class
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
4
|
+
class Messages
|
5
|
+
#The message queue manages callbacks for different objects that are receiving messages from CIC.
|
6
|
+
class MessageQueue
|
7
|
+
class EventHandlerArray < Array
|
8
|
+
def add_handler(&block)
|
9
|
+
push(block)
|
10
|
+
end
|
11
|
+
def add
|
12
|
+
raise "error"
|
13
|
+
end
|
14
|
+
def remove_handler(code)
|
15
|
+
delete(code)
|
16
|
+
end
|
17
|
+
def fire(e)
|
18
|
+
reverse_each { |handler|
|
19
|
+
begin
|
20
|
+
handler.call(e)
|
21
|
+
rescue => e
|
22
|
+
puts e.inspect
|
23
|
+
end
|
24
|
+
}
|
25
|
+
end
|
22
26
|
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def initialize(connection)
|
26
|
-
@message_handlers = {}
|
27
|
-
@client = ICWS::Client.new connection
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
28
|
+
def initialize(connection)
|
29
|
+
@message_handlers = {}
|
30
|
+
@client = ICWS::Client.new connection
|
33
31
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
def register(messageType, &block)
|
38
|
-
if(@message_handlers[messageType] == nil)
|
39
|
-
@message_handlers[messageType] = EventHandlerArray.new
|
32
|
+
@pollingThread = Thread.new() {
|
33
|
+
poll_loop
|
34
|
+
}
|
40
35
|
end
|
41
|
-
callback = block
|
42
|
-
@message_handlers[messageType].add_handler {|e| callback.call(e)}
|
43
|
-
end
|
44
36
|
|
45
|
-
|
46
|
-
|
47
|
-
|
37
|
+
#register for a new message type.
|
38
|
+
# @param messageType [String] The type of messages to receive notifications for.
|
39
|
+
# @param block [&block] Block to call when a message of that type is received.
|
40
|
+
def register(messageType, &block)
|
41
|
+
if(@message_handlers[messageType] == nil)
|
42
|
+
@message_handlers[messageType] = EventHandlerArray.new
|
43
|
+
end
|
44
|
+
callback = block
|
45
|
+
@message_handlers[messageType].add_handler {|e| callback.call(e)}
|
48
46
|
end
|
49
47
|
|
50
|
-
|
51
|
-
|
48
|
+
def deregister(messageType, code)
|
49
|
+
if(@message_handlers[messageType] == nil)
|
50
|
+
return
|
51
|
+
end
|
52
|
+
|
53
|
+
@message_handlers[messageType].remove_handler(code)
|
54
|
+
end
|
52
55
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
56
|
+
private
|
57
|
+
def poll_loop
|
58
|
+
while true
|
59
|
+
messages = @client.get '/messaging/messages'
|
60
|
+
for message in messages
|
61
|
+
#puts message
|
62
|
+
type = message['__type']
|
63
|
+
if @message_handlers[type]
|
64
|
+
@message_handlers[type].fire(message)
|
65
|
+
end
|
62
66
|
end
|
67
|
+
sleep 1
|
63
68
|
end
|
64
|
-
sleep 1
|
65
69
|
end
|
66
70
|
end
|
67
71
|
end
|
@@ -1,15 +1,17 @@
|
|
1
1
|
class ICWS
|
2
2
|
#Base class to listen for events from the server.
|
3
|
-
class
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
class Messages
|
4
|
+
class MessageSubscriber
|
5
|
+
def initialize(connection, message_queue, messageId)
|
6
|
+
message_queue.register(messageId) {|e| event_received(e)}
|
7
|
+
@application_name = connection.application_name
|
8
|
+
@client = ICWS::Client.new connection
|
9
|
+
@connection = connection
|
10
|
+
end
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
def event_received(message)
|
12
|
+
def event_received(message)
|
12
13
|
|
14
|
+
end
|
13
15
|
end
|
14
16
|
end
|
15
17
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: icws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Glinski
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- RAKEFILE
|
64
64
|
- README.md
|
65
65
|
- RELEASING.md
|
66
|
+
- lib/icws/Queues/queue.rb
|
66
67
|
- lib/icws/configuration/configurationitem.rb
|
67
68
|
- lib/icws/configuration/roles.rb
|
68
69
|
- lib/icws/configuration/stations.rb
|
@@ -71,6 +72,8 @@ files:
|
|
71
72
|
- lib/icws/connection.rb
|
72
73
|
- lib/icws/feature.rb
|
73
74
|
- lib/icws/icwsclient.rb
|
75
|
+
- lib/icws/interactions/interaction.rb
|
76
|
+
- lib/icws/interactions/interactionmanager.rb
|
74
77
|
- lib/icws/messages/messagequeue.rb
|
75
78
|
- lib/icws/messages/messagesubscriber.rb
|
76
79
|
- lib/icws/statistics/statisticcategory.rb
|