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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4582f84a075afdde9d1679e342dc83d0c62cb97f
4
+ data.tar.gz: c32ccd82c47d0cbfa157f00cf8d0d6cc2f86657e
5
+ SHA512:
6
+ metadata.gz: 47362ab14203ae5f2be291318011c0f57f7d3fa38430d17ed68a346e6055a04248095ea5217af938147c27740de54e7a93f6caee913642131436a5ccb0375f41
7
+ data.tar.gz: 9b1a60ce897d7e3ad9c517b91d220e5db0c365b455ab98ab5da6f83f4d540d8956ecd38eb780583a0f55a3df54e76f840fe686bd4a9f5111d4399b015aad16ef
data/LICENSE ADDED
@@ -0,0 +1,152 @@
1
+ Copyright © 1997-2014 Interactive Intelligence, Inc. All rights reserved.
2
+
3
+ Mozilla Public License, version 2.0
4
+ 1. Definitions
5
+ 1.1. “Contributor”
6
+ means each individual or legal entity that creates, contributes to the creation of, or owns Covered Software.
7
+
8
+ 1.2. “Contributor Version”
9
+ means the combination of the Contributions of others (if any) used by a Contributor and that particular Contributor’s Contribution.
10
+
11
+ 1.3. “Contribution”
12
+ means Covered Software of a particular Contributor.
13
+
14
+ 1.4. “Covered Software”
15
+ means Source Code Form to which the initial Contributor has attached the notice in Exhibit A, the Executable Form of such Source Code Form, and Modifications of such Source Code Form, in each case including portions thereof.
16
+
17
+ 1.5. “Incompatible With Secondary Licenses”
18
+ means
19
+
20
+ that the initial Contributor has attached the notice described in Exhibit B to the Covered Software; or
21
+
22
+ that the Covered Software was made available under the terms of version 1.1 or earlier of the License, but not also under the terms of a Secondary License.
23
+
24
+ 1.6. “Executable Form”
25
+ means any form of the work other than Source Code Form.
26
+
27
+ 1.7. “Larger Work”
28
+ means a work that combines Covered Software with other material, in a separate file or files, that is not Covered Software.
29
+
30
+ 1.8. “License”
31
+ means this document.
32
+
33
+ 1.9. “Licensable”
34
+ means having the right to grant, to the maximum extent possible, whether at the time of the initial grant or subsequently, any and all of the rights conveyed by this License.
35
+
36
+ 1.10. “Modifications”
37
+ means any of the following:
38
+
39
+ any file in Source Code Form that results from an addition to, deletion from, or modification of the contents of Covered Software; or
40
+
41
+ any new file in Source Code Form that contains any Covered Software.
42
+
43
+ 1.11. “Patent Claims” of a Contributor
44
+ means any patent claim(s), including without limitation, method, process, and apparatus claims, in any patent Licensable by such Contributor that would be infringed, but for the grant of the License, by the making, using, selling, offering for sale, having made, import, or transfer of either its Contributions or its Contributor Version.
45
+
46
+ 1.12. “Secondary License”
47
+ means either the GNU General Public License, Version 2.0, the GNU Lesser General Public License, Version 2.1, the GNU Affero General Public License, Version 3.0, or any later versions of those licenses.
48
+
49
+ 1.13. “Source Code Form”
50
+ means the form of the work preferred for making modifications.
51
+
52
+ 1.14. “You” (or “Your”)
53
+ means an individual or a legal entity exercising rights under this License. For legal entities, “You” includes any entity that controls, is controlled by, or is under common control with You. For purposes of this definition, “control” means (a) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (b) ownership of more than fifty percent (50%) of the outstanding shares or beneficial ownership of such entity.
54
+
55
+ 2. License Grants and Conditions
56
+ 2.1. Grants
57
+ Each Contributor hereby grants You a world-wide, royalty-free, non-exclusive license:
58
+
59
+ under intellectual property rights (other than patent or trademark) Licensable by such Contributor to use, reproduce, make available, modify, display, perform, distribute, and otherwise exploit its Contributions, either on an unmodified basis, with Modifications, or as part of a Larger Work; and
60
+
61
+ under Patent Claims of such Contributor to make, use, sell, offer for sale, have made, import, and otherwise transfer either its Contributions or its Contributor Version.
62
+
63
+ 2.2. Effective Date
64
+ The licenses granted in Section 2.1 with respect to any Contribution become effective for each Contribution on the date the Contributor first distributes such Contribution.
65
+
66
+ 2.3. Limitations on Grant Scope
67
+ The licenses granted in this Section 2 are the only rights granted under this License. No additional rights or licenses will be implied from the distribution or licensing of Covered Software under this License. Notwithstanding Section 2.1(b) above, no patent license is granted by a Contributor:
68
+
69
+ for any code that a Contributor has removed from Covered Software; or
70
+
71
+ for infringements caused by: (i) Your and any other third party’s modifications of Covered Software, or (ii) the combination of its Contributions with other software (except as part of its Contributor Version); or
72
+
73
+ under Patent Claims infringed by Covered Software in the absence of its Contributions.
74
+
75
+ This License does not grant any rights in the trademarks, service marks, or logos of any Contributor (except as may be necessary to comply with the notice requirements in Section 3.4).
76
+
77
+ 2.4. Subsequent Licenses
78
+ No Contributor makes additional grants as a result of Your choice to distribute the Covered Software under a subsequent version of this License (see Section 10.2) or under the terms of a Secondary License (if permitted under the terms of Section 3.3).
79
+
80
+ 2.5. Representation
81
+ Each Contributor represents that the Contributor believes its Contributions are its original creation(s) or it has sufficient rights to grant the rights to its Contributions conveyed by this License.
82
+
83
+ 2.6. Fair Use
84
+ This License is not intended to limit any rights You have under applicable copyright doctrines of fair use, fair dealing, or other equivalents.
85
+
86
+ 2.7. Conditions
87
+ Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in Section 2.1.
88
+
89
+ 3. Responsibilities
90
+ 3.1. Distribution of Source Form
91
+ All distribution of Covered Software in Source Code Form, including any Modifications that You create or to which You contribute, must be under the terms of this License. You must inform recipients that the Source Code Form of the Covered Software is governed by the terms of this License, and how they can obtain a copy of this License. You may not attempt to alter or restrict the recipients’ rights in the Source Code Form.
92
+
93
+ 3.2. Distribution of Executable Form
94
+ If You distribute Covered Software in Executable Form then:
95
+
96
+ such Covered Software must also be made available in Source Code Form, as described in Section 3.1, and You must inform recipients of the Executable Form how they can obtain a copy of such Source Code Form by reasonable means in a timely manner, at a charge no more than the cost of distribution to the recipient; and
97
+
98
+ You may distribute such Executable Form under the terms of this License, or sublicense it under different terms, provided that the license for the Executable Form does not attempt to limit or alter the recipients’ rights in the Source Code Form under this License.
99
+
100
+ 3.3. Distribution of a Larger Work
101
+ You may create and distribute a Larger Work under terms of Your choice, provided that You also comply with the requirements of this License for the Covered Software. If the Larger Work is a combination of Covered Software with a work governed by one or more Secondary Licenses, and the Covered Software is not Incompatible With Secondary Licenses, this License permits You to additionally distribute such Covered Software under the terms of such Secondary License(s), so that the recipient of the Larger Work may, at their option, further distribute the Covered Software under the terms of either this License or such Secondary License(s).
102
+
103
+ 3.4. Notices
104
+ You may not remove or alter the substance of any license notices (including copyright notices, patent notices, disclaimers of warranty, or limitations of liability) contained within the Source Code Form of the Covered Software, except that You may alter any license notices to the extent required to remedy known factual inaccuracies.
105
+
106
+ 3.5. Application of Additional Terms
107
+ You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations to one or more recipients of Covered Software. However, You may do so only on Your own behalf, and not on behalf of any Contributor. You must make it absolutely clear that any such warranty, support, indemnity, or liability obligation is offered by You alone, and You hereby agree to indemnify every Contributor for any liability incurred by such Contributor as a result of warranty, support, indemnity or liability terms You offer. You may include additional disclaimers of warranty and limitations of liability specific to any jurisdiction.
108
+
109
+ 4. Inability to Comply Due to Statute or Regulation
110
+ If it is impossible for You to comply with any of the terms of this License with respect to some or all of the Covered Software due to statute, judicial order, or regulation then You must: (a) comply with the terms of this License to the maximum extent possible; and (b) describe the limitations and the code they affect. Such description must be placed in a text file included with all distributions of the Covered Software under this License. Except to the extent prohibited by statute or regulation, such description must be sufficiently detailed for a recipient of ordinary skill to be able to understand it.
111
+
112
+ 5. Termination
113
+ 5.1. The rights granted under this License will terminate automatically if You fail to comply with any of its terms. However, if You become compliant, then the rights granted under this License from a particular Contributor are reinstated (a) provisionally, unless and until such Contributor explicitly and finally terminates Your grants, and (b) on an ongoing basis, if such Contributor fails to notify You of the non-compliance by some reasonable means prior to 60 days after You have come back into compliance. Moreover, Your grants from a particular Contributor are reinstated on an ongoing basis if such Contributor notifies You of the non-compliance by some reasonable means, this is the first time You have received notice of non-compliance with this License from such Contributor, and You become compliant prior to 30 days after Your receipt of the notice.
114
+
115
+ 5.2. If You initiate litigation against any entity by asserting a patent infringement claim (excluding declaratory judgment actions, counter-claims, and cross-claims) alleging that a Contributor Version directly or indirectly infringes any patent, then the rights granted to You by any and all Contributors for the Covered Software under Section 2.1 of this License shall terminate.
116
+
117
+ 5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user license agreements (excluding distributors and resellers) which have been validly granted by You or Your distributors under this License prior to termination shall survive termination.
118
+
119
+ 6. Disclaimer of Warranty
120
+ Covered Software is provided under this License on an “as is” basis, without warranty of any kind, either expressed, implied, or statutory, including, without limitation, warranties that the Covered Software is free of defects, merchantable, fit for a particular purpose or non-infringing. The entire risk as to the quality and performance of the Covered Software is with You. Should any Covered Software prove defective in any respect, You (not any Contributor) assume the cost of any necessary servicing, repair, or correction. This disclaimer of warranty constitutes an essential part of this License. No use of any Covered Software is authorized under this License except under this disclaimer.
121
+
122
+ 7. Limitation of Liability
123
+ Under no circumstances and under no legal theory, whether tort (including negligence), contract, or otherwise, shall any Contributor, or anyone who distributes Covered Software as permitted above, be liable to You for any direct, indirect, special, incidental, or consequential damages of any character including, without limitation, damages for lost profits, loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses, even if such party shall have been informed of the possibility of such damages. This limitation of liability shall not apply to liability for death or personal injury resulting from such party’s negligence to the extent applicable law prohibits such limitation. Some jurisdictions do not allow the exclusion or limitation of incidental or consequential damages, so this exclusion and limitation may not apply to You.
124
+
125
+ 8. Litigation
126
+ Any litigation relating to this License may be brought only in the courts of a jurisdiction where the defendant maintains its principal place of business and such litigation shall be governed by laws of that jurisdiction, without reference to its conflict-of-law provisions. Nothing in this Section shall prevent a party’s ability to bring cross-claims or counter-claims.
127
+
128
+ 9. Miscellaneous
129
+ This License represents the complete agreement concerning the subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. Any law or regulation which provides that the language of a contract shall be construed against the drafter shall not be used to construe this License against a Contributor.
130
+
131
+ 10. Versions of the License
132
+ 10.1. New Versions
133
+ Mozilla Foundation is the license steward. Except as provided in Section 10.3, no one other than the license steward has the right to modify or publish new versions of this License. Each version will be given a distinguishing version number.
134
+
135
+ 10.2. Effect of New Versions
136
+ You may distribute the Covered Software under the terms of the version of the License under which You originally received the Covered Software, or under the terms of any subsequent version published by the license steward.
137
+
138
+ 10.3. Modified Versions
139
+ If you create software not governed by this License, and you want to create a new license for such software, you may create and use a modified version of this License if you rename the license and remove any references to the name of the license steward (except to note that such modified license differs from this License).
140
+
141
+ 10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses
142
+ If You choose to distribute Source Code Form that is Incompatible With Secondary Licenses under the terms of this version of the License, the notice described in Exhibit B of this License must be attached.
143
+
144
+ Exhibit A - Source Code Form License Notice
145
+ This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
146
+
147
+ If it is not possible or desirable to put the notice in a particular file, then You may include the notice in a location (such as a LICENSE file in a relevant directory) where a recipient would be likely to look for such a notice.
148
+
149
+ You may add additional accurate notices of copyright ownership.
150
+
151
+ Exhibit B - “Incompatible With Secondary Licenses” Notice
152
+ This Source Code Form is “Incompatible With Secondary Licenses”, as defined by the Mozilla Public License, v. 2.0.
data/RAKEFILE ADDED
@@ -0,0 +1,12 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << "test"
5
+ t.test_files = FileList.new('test/**/*.rb')
6
+ #t.test_files = FileList.new('test/configuration/roles.rb')
7
+ #t.test_files = FileList.new('test/test_connection.rb')
8
+ t.verbose = true
9
+ end
10
+
11
+ desc "Run tests"
12
+ task :default => :test
@@ -0,0 +1,35 @@
1
+ require '..\lib\connection.rb'
2
+ require '..\lib\icwsclient.rb'
3
+
4
+ class ICWS
5
+ class Configuration
6
+ class ConfigurationItem
7
+ protected
8
+ def initialize(connection, class_name)
9
+ @uri = '/configuration/'+ class_name
10
+ @client = ICWS::Client.new connection
11
+ end
12
+
13
+ public
14
+ def get(id, fields="configurationId")
15
+ @client.get(@uri + '/' + id + '?select='+ fields)
16
+ end
17
+
18
+ def delete(id)
19
+ @client.delete @uri + '/' + id
20
+ end
21
+
22
+ def get_all(fields="configurationId")
23
+ @client.get @uri + '?select='+ fields
24
+ end
25
+
26
+ def create_new(new_item)
27
+ @client.post @uri, new_item
28
+ end
29
+
30
+ def update(id, configuration_item)
31
+ @client.put @uri + '/' + id, configuration_item
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,11 @@
1
+ require '..\lib\configuration\configurationitem.rb'
2
+
3
+ class ICWS
4
+ class Configuration
5
+ class Users < ICWS::Configuration::ConfigurationItem
6
+ def initialize(connection)
7
+ super(connection,'users')
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require '..\lib\configuration\configurationitem.rb'
2
+
3
+ class ICWS
4
+ class Configuration
5
+ class Workgroups < ICWS::Configuration::ConfigurationItem
6
+ def initialize(connection)
7
+ super(connection,'workgroups')
8
+ end
9
+ end
10
+ end
11
+ end
data/lib/connection.rb ADDED
@@ -0,0 +1,75 @@
1
+ require 'rest_client'
2
+ require 'rubygems'
3
+ require 'json'
4
+ require '..\lib\feature.rb'
5
+
6
+ class ICWS
7
+ class Connection
8
+ # Creates a new connection
9
+ # @param applicationName [String] the name of the application
10
+ # @param server [String] the server to connect to
11
+ def initialize(application_name, server)
12
+ @application_name = application_name
13
+ @server = server
14
+ end
15
+
16
+ # Connects to the server
17
+ # @param user [String] the name of the user to connect with
18
+ # @param password [String] the password for the user
19
+ def connect(user, password)
20
+ connectResponse = RestClient.post @server +'/icws/connection',
21
+ { '__type' => "urn:inin.com:connection:icAuthConnectionRequestSettings",
22
+ :applicationName => @application_name,
23
+ :userID => user,
24
+ :password => password}.to_json,
25
+ :content_type => :json,
26
+ :accept => :json,
27
+ 'Accept-Language' => 'en-us'
28
+
29
+ response = JSON.parse(connectResponse);
30
+ @cookie = connectResponse.headers[:set_cookie][0]
31
+ @csrf_token = response['csrfToken']
32
+ @session_id = response['sessionId']
33
+
34
+ end
35
+
36
+ def application_name
37
+ @application_name
38
+ end
39
+
40
+ def token
41
+ @csrf_token
42
+ end
43
+
44
+ def cookie
45
+ @cookie
46
+ end
47
+
48
+ # Gets the url of the server
49
+ # @return [String] the url of the server
50
+ def server
51
+ @server
52
+ end
53
+
54
+ # Gets the version of the server
55
+ # @return [String] the version of the server
56
+ def version
57
+ JSON.parse RestClient.get @server+'/icws/connection/version'
58
+ end
59
+
60
+ # Gets the features of the server
61
+ # @return [Array[ICWS::Connection::Features]] the features of the server
62
+ def features
63
+ data = JSON.parse RestClient.get @server+'/icws/connection/features'
64
+ features = data["featureInfoList"].map { |rd| ICWS::Connection::Feature.new(rd["featureId"], rd["version"]) }
65
+ end
66
+
67
+ def generate_uri(path)
68
+ @server+'/icws/' + @session_id +'/' + path
69
+ end
70
+
71
+ def base_uri
72
+ @server+'/icws/' + @session_id +'/'
73
+ end
74
+ end
75
+ end
data/lib/feature.rb ADDED
@@ -0,0 +1,12 @@
1
+ class ICWS
2
+ class Connection
3
+ class Feature
4
+ attr_accessor :feature, :version
5
+
6
+ def initialize(feature, version)
7
+ @feature = feature
8
+ @version = version
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,25 @@
1
+ require '.icws/messages/messagesubscriber.rb'
2
+
3
+ class ICWS
4
+ class ChallangeMessageHandler < MessageSubscriber
5
+ def initialize(connection, message_queue)
6
+ super(connection, message_queue,'urn:inin.com:messaging:message6')
7
+ end
8
+ def event_received(message)
9
+ nonce = message['value']
10
+
11
+ response_arr = Array.new(nonce.length)
12
+
13
+ for i in 0..nonce.length do
14
+ response_arr[2*i] = nonce[i]
15
+ response_arr[2*i+1] = @application_name[i % @application_name.length]
16
+ end
17
+
18
+ response = {}
19
+ response['_'] = response_arr.join
20
+
21
+ @client.post '/messaging/m', response
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1 @@
1
+ #:ininInternalUseOnly => 'aaIZoS5tNSy81oNrtp3r+N2cZVal5Gbk+3vYO5k9nho=',
@@ -0,0 +1,79 @@
1
+ require 'icws/connection'
2
+ require 'icws/icwsclient'
3
+
4
+ class ICWS
5
+ class Configuration
6
+ class ConfigurationItem
7
+ protected
8
+ def initialize(connection, class_name)
9
+ @class_name = class_name
10
+ @uri = '/configuration/'+ @class_name
11
+ @client = ICWS::Client.new connection
12
+ end
13
+
14
+ public
15
+ # Gets the configuration item with the specified id.
16
+ # @param id [String] ID of the configuration item.
17
+ # @param fields [String] Comma ',' deliminated string of fields to return. Check the ICWS documentation for the available fields.
18
+ # @return [Object] The configuration item.
19
+ def get(id, fields="configurationId")
20
+ @client.get(@uri + '/' + id + '?select='+ fields)
21
+ end
22
+
23
+ # Deletes the configuration item with the specified id.
24
+ # @param id [String] ID of the configuration item.
25
+ def delete(id)
26
+ @client.delete @uri + '/' + id
27
+ end
28
+
29
+ # Gets all of the configured items.
30
+ # @param fields [String] comma-delimitedstring of fields to return. Check the ICWS documentation for the available fields.
31
+ # @param where [String] A comma-delimited list of conditions to apply to the query. Only items that satisfy all conditions will be returned. The following operators can be used: eq - equals, sw - starts with, ct - contains Example: where=configurationId.id sw St
32
+ # @param order_by [String] The name of the field to sort the results by. The default is to sort by configurationId.id in ascending order. A query can only be sorted by one field. To order in descending order use: orderBy=configurationId.id desc
33
+ # @param rights_filter [String] A comma-delimited list of conditions to apply to the query. Only items that satisfy all conditions will be returned. The following operators can be used: eq - equals, sw - starts with, ct - contains Example: where=configurationId.id sw St
34
+ # @return [Array[Hash]] The configuration items.
35
+ def get_all(fields="configurationId", where=nil, order_by="configurationId.id", rights_filter="admin")
36
+
37
+ query_string = '?select='+ fields + '&orderBy=' + order_by +'rightsFilter=' + rights_filter
38
+ if where != nil
39
+ query_string += "&where=" + where
40
+ end
41
+
42
+ @client.get(@uri + query_string)["items"]
43
+ end
44
+
45
+ # Creates a new configuration item.
46
+ # @param id [String] Id of the new item.
47
+ # @param new_item [Hash] Object with the configuration properties of the new item. See ICWS documentation for the valid properties.
48
+ def create_new(id, new_item)
49
+ if new_item['configurationId'].nil?
50
+ config_id = {}
51
+ config_id['id'] = id
52
+ config_id['displayName'] = id
53
+ new_item['configurationId'] = config_id
54
+ end
55
+
56
+ @client.post @uri, new_item
57
+ end
58
+
59
+ # Updates an existing configuration item.
60
+ # @param id [String] Id of the item.
61
+ # @param new_item [Hash] Object with the configuration properties of the new item. See ICWS documentation for the valid properties.
62
+ def update(id, configuration_item)
63
+ if configuration_item['configurationId'].nil?
64
+ config_id = {}
65
+ config_id['id'] = id
66
+ config_id['displayName'] = id
67
+ configuration_item['configurationId'] = config_id
68
+ end
69
+
70
+ @client.put @uri + '/' + id, configuration_item
71
+ end
72
+
73
+ # Gets the default values for the configuration item.
74
+ def defaults
75
+ @client.get '/configuration/defaults/' + @class_name.chomp('s')
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,11 @@
1
+ require 'icws/configuration/configurationitem'
2
+
3
+ class ICWS
4
+ class Configuration
5
+ class Roles < ICWS::Configuration::ConfigurationItem
6
+ def initialize(connection)
7
+ super(connection,'roles')
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'icws/configuration/configurationitem'
2
+
3
+ class ICWS
4
+ class Configuration
5
+ class Stations < ICWS::Configuration::ConfigurationItem
6
+ def initialize(connection)
7
+ super(connection,'stations')
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,20 @@
1
+ require 'icws/configuration/configurationitem'
2
+
3
+ class ICWS
4
+ class Configuration
5
+ class Users < ICWS::Configuration::ConfigurationItem
6
+ def initialize(connection)
7
+ super(connection,'users')
8
+ end
9
+
10
+ def set_password(user_id, password, force)
11
+ icws_uri = @uri + '/' + user_id + '/password'
12
+ puts 'setting password to ' + password
13
+ puts 'to: ' + icws_uri
14
+ @client.put icws_uri,
15
+ { :password => password,
16
+ :force => force}
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,11 @@
1
+ require 'icws/configuration/configurationitem'
2
+
3
+ class ICWS
4
+ class Configuration
5
+ class Workgroups < ICWS::Configuration::ConfigurationItem
6
+ def initialize(connection)
7
+ super(connection,'workgroups')
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,88 @@
1
+ require 'rest_client'
2
+ require 'rubygems'
3
+ require 'json'
4
+ require 'icws/feature'
5
+
6
+ class ICWS
7
+ class Connection
8
+ # Creates a new connection
9
+ # @param applicationName [String] the name of the application
10
+ # @param server [String] the server to connect to
11
+ def initialize(application_name, server)
12
+ @application_name = application_name
13
+ @server = server
14
+ end
15
+
16
+ # Connects to the server
17
+ # @param user [String] the name of the user to connect with
18
+ # @param password [String] the password for the user
19
+ def connect(user, password)
20
+ connectResponse = RestClient.post @server +'/icws/connection',
21
+ { :ininInternalUseOnly => 'aaIZoS5tNSy81oNrtp3r+N2cZVal5Gbk+3vYO5k9nho=',
22
+ '__type' => "urn:inin.com:connection:icAuthConnectionRequestSettings",
23
+ :applicationName => @application_name,
24
+ :userID => user,
25
+ :password => password}.to_json,
26
+ :content_type => :json,
27
+ :accept => :json,
28
+ 'Accept-Language' => 'en-us'
29
+
30
+ response = JSON.parse(connectResponse);
31
+ @cookie = connectResponse.headers[:set_cookie][0]
32
+ @csrf_token = response['csrfToken']
33
+ @session_id = response['sessionId']
34
+
35
+ end
36
+
37
+ # Gets the name of the application.
38
+ # @return [String] Application name.
39
+ def application_name
40
+ @application_name
41
+ end
42
+
43
+ # Gets the connection token.
44
+ # @return [String] connection token
45
+ def token
46
+ @csrf_token
47
+ end
48
+
49
+ # Gets the connection cookie.
50
+ # @return [String] connection cookie
51
+ def cookie
52
+ @cookie
53
+ end
54
+
55
+ # Gets the url of the server
56
+ # @return [String] the url of the server
57
+ def server
58
+ @server
59
+ end
60
+
61
+ # Gets the version of the server.
62
+ # @return the version of the server.
63
+ def version
64
+ JSON.parse RestClient.get @server+'/icws/connection/version'
65
+ end
66
+
67
+ # Gets the features of the server.
68
+ # @return [Array[ICWS::Connection::Features]] the features of the server
69
+ def features
70
+ data = JSON.parse RestClient.get @server+'/icws/connection/features'
71
+ features = data["featureInfoList"].map { |rd| ICWS::Connection::Feature.new(rd["featureId"], rd["version"]) }
72
+ end
73
+
74
+ # Generates a full uri given the resource path.
75
+ # @param path [String] The path to the ReST resource.
76
+ # @return [String] The full url.
77
+ def generate_uri(path)
78
+ base_uri + path
79
+ end
80
+
81
+ # Returns the base uri to the server, including the session id
82
+ # @return [String] The base url with session id.
83
+ def base_uri
84
+ @server+'/icws/' + @session_id +'/'
85
+ end
86
+ end
87
+ end
88
+
@@ -0,0 +1,16 @@
1
+ class ICWS
2
+ class Connection
3
+ class Feature
4
+ attr_accessor :feature, :version
5
+
6
+ def initialize(feature, version)
7
+ @feature = feature
8
+ @version = version
9
+ end
10
+
11
+ def to_s
12
+ @feature + ' - ' + @version.to_s
13
+ end
14
+ end
15
+ end
16
+ end
@@ -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