ucengine 0.1.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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/README.rdoc ADDED
@@ -0,0 +1,7 @@
1
+ = ucengine.rb
2
+
3
+ ucengine.rb can connect, subscribe, and publish events to UCEngine.
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2010 AF83. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "ucengine"
8
+ gem.summary = %Q{Ruby library for UCEngine}
9
+ gem.description = %Q{ucengine.rb is a Ruby library to consume the UCEngine API}
10
+ gem.email = "victor.goya@af83.com"
11
+ gem.homepage = "http://github.com/AF83/ucengine.rb"
12
+ gem.authors = ["AF83"]
13
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ gem.add_dependency "json", ">=0"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/test_*.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ begin
30
+ require 'rcov/rcovtask'
31
+ Rcov::RcovTask.new do |test|
32
+ test.libs << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+ rescue LoadError
37
+ task :rcov do
38
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
+ end
40
+ end
41
+
42
+ task :test => :check_dependencies
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "ucengine.rb #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/doc/UCEngine.html ADDED
@@ -0,0 +1,769 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
7
+
8
+ <title>Class: UCEngine</title>
9
+
10
+ <link rel="stylesheet" href="./rdoc.css" type="text/css" media="screen" />
11
+
12
+ <script src="./js/jquery.js" type="text/javascript"
13
+ charset="utf-8"></script>
14
+ <script src="./js/thickbox-compressed.js" type="text/javascript"
15
+ charset="utf-8"></script>
16
+ <script src="./js/quicksearch.js" type="text/javascript"
17
+ charset="utf-8"></script>
18
+ <script src="./js/darkfish.js" type="text/javascript"
19
+ charset="utf-8"></script>
20
+
21
+ </head>
22
+ <body class="class">
23
+
24
+ <div id="metadata">
25
+ <div id="home-metadata">
26
+ <div id="home-section" class="section">
27
+ <h3 class="section-header">
28
+ <a href="./index.html">Home</a>
29
+ <a href="./index.html#classes">Classes</a>
30
+ <a href="./index.html#methods">Methods</a>
31
+ </h3>
32
+ </div>
33
+ </div>
34
+
35
+ <div id="file-metadata">
36
+ <div id="file-list-section" class="section">
37
+ <h3 class="section-header">In Files</h3>
38
+ <div class="section-body">
39
+ <ul>
40
+
41
+ <li><a href="./lib/ucengine_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
42
+ class="thickbox" title="lib/ucengine.rb">lib/ucengine.rb</a></li>
43
+
44
+ </ul>
45
+ </div>
46
+ </div>
47
+
48
+
49
+ </div>
50
+
51
+ <div id="class-metadata">
52
+
53
+ <!-- Parent Class -->
54
+
55
+ <div id="parent-class-section" class="section">
56
+ <h3 class="section-header">Parent</h3>
57
+
58
+ <p class="link">Object</p>
59
+
60
+ </div>
61
+
62
+
63
+ <!-- Namespace Contents -->
64
+
65
+
66
+ <!-- Method Quickref -->
67
+
68
+ <div id="method-list-section" class="section">
69
+ <h3 class="section-header">Methods</h3>
70
+ <ul class="link-list">
71
+
72
+ <li><a href="#method-c-encode">::encode</a></li>
73
+
74
+ <li><a href="#method-c-new">::new</a></li>
75
+
76
+ <li><a href="#method-i-connect">#connect</a></li>
77
+
78
+ <li><a href="#method-i-debug">#debug</a></li>
79
+
80
+ <li><a href="#method-i-delete">#delete</a></li>
81
+
82
+ <li><a href="#method-i-get">#get</a></li>
83
+
84
+ <li><a href="#method-i-post">#post</a></li>
85
+
86
+ <li><a href="#method-i-publish">#publish</a></li>
87
+
88
+ <li><a href="#method-i-put">#put</a></li>
89
+
90
+ <li><a href="#method-i-subscribe">#subscribe</a></li>
91
+
92
+ <li><a href="#method-i-time">#time</a></li>
93
+
94
+ </ul>
95
+ </div>
96
+
97
+
98
+ <!-- Included Modules -->
99
+
100
+ </div>
101
+
102
+ <div id="project-metadata">
103
+
104
+
105
+
106
+ <div id="classindex-section" class="section project-section">
107
+ <h3 class="section-header">Class Index
108
+ <span class="search-toggle"><img src="./images/find.png"
109
+ height="16" width="16" alt="[+]"
110
+ title="show/hide quicksearch" /></span></h3>
111
+ <form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
112
+ <fieldset>
113
+ <legend>Quicksearch</legend>
114
+ <input type="text" name="quicksearch" value=""
115
+ class="quicksearch-field" />
116
+ </fieldset>
117
+ </form>
118
+
119
+ <ul class="link-list">
120
+
121
+ <li><a href="./UCEngine.html">UCEngine</a></li>
122
+
123
+ </ul>
124
+ <div id="no-class-search-results" style="display: none;">No matching classes.</div>
125
+ </div>
126
+
127
+
128
+ </div>
129
+ </div>
130
+
131
+ <div id="documentation">
132
+ <h1 class="class">UCEngine</h1>
133
+
134
+ <div id="description">
135
+ <p>
136
+ This class is the main and only class in ucengine.rb, it handles
137
+ connections and request to the <a href="UCEngine.html">UCEngine</a> server.
138
+ </p>
139
+ <pre>
140
+ uce = UCEngine.new(&quot;localhost&quot;, 4567)
141
+ uce.connect(&quot;bibi&quot;, :password =&gt; 'abcd') do |uce|
142
+ uce.subscribe([&quot;af83&quot;], :type =&gt; 'chat.message.new', :search =&gt; 'HTML5') do |event|
143
+ uce.push(:location =&gt; [event['org'], event['meeting']]
144
+ :from =&gt; 'bot',
145
+ :type =&gt; 'chat.message.new',
146
+ :metadata =&gt; {&quot;text&quot; =&gt; &quot;Hey, you were talking about HTML5&quot;})
147
+ end
148
+ end</pre>
149
+
150
+ </div>
151
+
152
+ <!-- Constants -->
153
+
154
+ <div id="constants-list" class="section">
155
+ <h3 class="section-header">Constants</h3>
156
+ <dl>
157
+
158
+ <dt><a name="DEBUG">DEBUG</a></dt>
159
+
160
+ <dd class="description"><p>
161
+ Print every request and everything above.
162
+ </p></dd>
163
+
164
+
165
+ <dt><a name="WARNING">WARNING</a></dt>
166
+
167
+ <dd class="description"><p>
168
+ Print everything that seems fishy.
169
+ </p></dd>
170
+
171
+
172
+ <dt><a name="ERROR">ERROR</a></dt>
173
+
174
+ <dd class="description"><p>
175
+ Print regular errors, usually HTTP errors.
176
+ </p></dd>
177
+
178
+
179
+ <dt><a name="CRITICAL">CRITICAL</a></dt>
180
+
181
+ <dd class="description"><p>
182
+ Only print critical errors (bad hostname or port, etc).
183
+ </p></dd>
184
+
185
+
186
+ <dt><a name="QUIET">QUIET</a></dt>
187
+
188
+ <dd class="description"><p>
189
+ Don&#8217;t print anything (default).
190
+ </p></dd>
191
+
192
+
193
+ </dl>
194
+ </div>
195
+
196
+
197
+ <!-- Attributes -->
198
+
199
+
200
+ <!-- Methods -->
201
+
202
+ <div id="public-class-method-details" class="method-section section">
203
+ <h3 class="section-header">Public Class Methods</h3>
204
+
205
+
206
+ <div id="new-method" class="method-detail ">
207
+ <a name="method-c-new"></a>
208
+
209
+ <div class="method-heading">
210
+
211
+ <span class="method-name">new</span><span
212
+ class="method-args">(host, port, debug = UCEngine::QUIET)</span>
213
+ <span class="method-click-advice">click to toggle source</span>
214
+
215
+ </div>
216
+
217
+ <div class="method-description">
218
+
219
+ <p>
220
+ Create a new <a href="UCEngine.html">UCEngine</a> object.
221
+ &#8216;host&#8217; is the hostname of the <a
222
+ href="UCEngine.html">UCEngine</a> server and &#8216;port&#8217; is to TCP
223
+ port to connect to. Note that this method doesn&#8217;t create a new
224
+ connection, see the <a href="UCEngine.html#method-i-connect">#</a> method.
225
+ An additional &#8216;debug&#8217; parameter set the debug level of the
226
+ library, all the debug information are written in the error output.
227
+ </p>
228
+
229
+
230
+
231
+ <div class="method-source-code"
232
+ id="new-source">
233
+ <pre>
234
+ <span class="ruby-comment cmt"># File lib/ucengine.rb, line 44</span>
235
+ 44: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">host</span>, <span class="ruby-identifier">port</span>, <span class="ruby-identifier">debug</span> = <span class="ruby-constant">UCEngine</span><span class="ruby-operator">::</span><span class="ruby-constant">QUIET</span>)
236
+ 45: <span class="ruby-ivar">@host</span> = <span class="ruby-identifier">host</span>
237
+ 46: <span class="ruby-ivar">@port</span> = <span class="ruby-identifier">port</span>
238
+ 47: <span class="ruby-ivar">@http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">host</span>, <span class="ruby-identifier">port</span>)
239
+ 48: <span class="ruby-ivar">@threads</span> = []
240
+ 49: <span class="ruby-ivar">@debug</span> = <span class="ruby-identifier">debug</span>
241
+ 50: <span class="ruby-identifier">debug</span>(<span class="ruby-constant">UCEngine</span><span class="ruby-operator">::</span><span class="ruby-constant">DEBUG</span>, <span class="ruby-node">&quot;Initialisation complete for #{host}:#{port}.&quot;</span>)
242
+ 51: <span class="ruby-keyword kw">end</span></pre>
243
+ </div>
244
+
245
+ </div>
246
+
247
+
248
+
249
+
250
+ </div>
251
+
252
+
253
+ </div>
254
+
255
+ <div id="protected-class-method-details" class="method-section section">
256
+ <h3 class="section-header">Protected Class Methods</h3>
257
+
258
+
259
+ <div id="encode-method" class="method-detail ">
260
+ <a name="method-c-encode"></a>
261
+
262
+ <div class="method-heading">
263
+
264
+ <span class="method-name">encode</span><span
265
+ class="method-args">(params)</span>
266
+ <span class="method-click-advice">click to toggle source</span>
267
+
268
+ </div>
269
+
270
+ <div class="method-description">
271
+
272
+ <p>
273
+ Encode parameters
274
+ </p>
275
+
276
+
277
+
278
+ <div class="method-source-code"
279
+ id="encode-source">
280
+ <pre>
281
+ <span class="ruby-comment cmt"># File lib/ucengine.rb, line 149</span>
282
+ 149: <span class="ruby-keyword kw">def</span> <span class="ruby-constant">UCEngine</span>.<span class="ruby-identifier">encode</span>(<span class="ruby-identifier">params</span>)
283
+ 150: <span class="ruby-identifier">params</span>.<span class="ruby-identifier">collect</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-node">&quot;#{k}=#{CGI::escape(v.to_s)}&quot;</span> }.<span class="ruby-identifier">join</span>(<span class="ruby-value str">'&amp;'</span>)
284
+ 151: <span class="ruby-keyword kw">end</span></pre>
285
+ </div>
286
+
287
+ </div>
288
+
289
+
290
+
291
+
292
+ </div>
293
+
294
+
295
+ </div>
296
+
297
+ <div id="public-instance-method-details" class="method-section section">
298
+ <h3 class="section-header">Public Instance Methods</h3>
299
+
300
+
301
+ <div id="connect-method" class="method-detail ">
302
+ <a name="method-i-connect"></a>
303
+
304
+ <div class="method-heading">
305
+
306
+ <span class="method-name">connect</span><span
307
+ class="method-args">(uid, credential)</span>
308
+ <span class="method-click-advice">click to toggle source</span>
309
+
310
+ </div>
311
+
312
+ <div class="method-description">
313
+
314
+ <p>
315
+ Connect to the <a href="UCEngine.html">UCEngine</a> server with the User ID
316
+ &#8216;uid&#8217; and the its credential.
317
+ </p>
318
+ <pre>
319
+ uce = UCEngine.new(&quot;localhost&quot;, 4567)
320
+ uce.connect(&quot;bibi&quot;, :password =&gt; 'abcd') do |uce|
321
+ ... your code goes here
322
+ end
323
+ </pre>
324
+ <p>
325
+ It is currently possible to use :token or :password as authentification
326
+ method.
327
+ </p>
328
+
329
+
330
+
331
+ <div class="method-source-code"
332
+ id="connect-source">
333
+ <pre>
334
+ <span class="ruby-comment cmt"># File lib/ucengine.rb, line 62</span>
335
+ 62: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">connect</span>(<span class="ruby-identifier">uid</span>, <span class="ruby-identifier">credential</span>)
336
+ 63: <span class="ruby-ivar">@uid</span> = <span class="ruby-identifier">uid</span>
337
+ 64: <span class="ruby-identifier">response</span> = <span class="ruby-identifier">put</span>(<span class="ruby-node">&quot;/presence/#{@uid}&quot;</span>, {<span class="ruby-value">:auth</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'token'</span>, <span class="ruby-value">:credential</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">credential</span>[<span class="ruby-value">:token</span>]})
338
+ 65: <span class="ruby-ivar">@sid</span> = <span class="ruby-identifier">response</span>[<span class="ruby-value str">'result'</span>]
339
+ 66: <span class="ruby-identifier">debug</span>(<span class="ruby-constant">UCEngine</span><span class="ruby-operator">::</span><span class="ruby-constant">DEBUG</span>, <span class="ruby-node">&quot;Authentification complete for #{@uid}/#{@sid}.&quot;</span>)
340
+ 67: <span class="ruby-keyword kw">yield</span> <span class="ruby-keyword kw">self</span>
341
+ 68: <span class="ruby-ivar">@threads</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">thread</span><span class="ruby-operator">|</span>
342
+ 69: <span class="ruby-identifier">thread</span>.<span class="ruby-identifier">join</span>
343
+ 70: <span class="ruby-keyword kw">end</span>
344
+ 71: <span class="ruby-keyword kw">end</span></pre>
345
+ </div>
346
+
347
+ </div>
348
+
349
+
350
+
351
+
352
+ </div>
353
+
354
+
355
+ <div id="publish-method" class="method-detail ">
356
+ <a name="method-i-publish"></a>
357
+
358
+ <div class="method-heading">
359
+
360
+ <span class="method-name">publish</span><span
361
+ class="method-args">(event)</span>
362
+ <span class="method-click-advice">click to toggle source</span>
363
+
364
+ </div>
365
+
366
+ <div class="method-description">
367
+
368
+ <p>
369
+ Publish an event. Publishing an event require a few mandatories parameters:
370
+ </p>
371
+ <dl>
372
+ <dt>:location</dt><dd><p>
373
+ As described in the subscribe method: [&#8220;organisation&#8221;,
374
+ &#8220;meeting&#8221;] publish the event in a specific meeting,
375
+ [&#8220;organisation&#8221;] publish the event in the organisation and []:
376
+ publish the event in the server root.
377
+ </p>
378
+ </dd>
379
+ <dt>:type</dt><dd><p>
380
+ The type of event to send, the format of this type is usually
381
+ &#8216;namespace.object.action&#8217;, for example:
382
+ &#8216;chat.message.new&#8217;, &#8216;twitter.tweet.new&#8217;,
383
+ &#8216;internal.user.update&#8216;
384
+ </p>
385
+ </dd>
386
+ <dt>:parent</dt><dd><p>
387
+ The id of the parent, this parameter is useful to build event hierarchy.
388
+ </p>
389
+ </dd>
390
+ <dt>:metadata</dt><dd><p>
391
+ A hash of freely defined values to append to the event.
392
+ </p>
393
+ </dd>
394
+ </dl>
395
+ <pre>
396
+ uce.publish(:location =&gt; [&quot;af83&quot;, &quot;WebWorkersCamp&quot;],
397
+ :type =&gt; 'presentation.slide.add'
398
+ :metadata =&gt; {:url =&gt; 'http://myserver/slides/03.png',
399
+ :index =&gt; 3})</pre>
400
+
401
+
402
+
403
+ <div class="method-source-code"
404
+ id="publish-source">
405
+ <pre>
406
+ <span class="ruby-comment cmt"># File lib/ucengine.rb, line 123</span>
407
+ 123: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">publish</span>(<span class="ruby-identifier">event</span>)
408
+ 124: <span class="ruby-identifier">debug</span>(<span class="ruby-constant">UCEngine</span><span class="ruby-operator">::</span><span class="ruby-constant">DEBUG</span>, <span class="ruby-node">&quot;Publish to #{event[:location]}, type: #{event[:type]}, parent: #{event[:parent]}, metadata: #{event[:metadata]}&quot;</span>)
409
+ 125: <span class="ruby-identifier">params</span> = <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>
410
+ 126: <span class="ruby-identifier">params</span>[<span class="ruby-value">:type</span>] = <span class="ruby-identifier">event</span>[<span class="ruby-value">:type</span>]
411
+ 127: <span class="ruby-identifier">params</span>[<span class="ruby-value">:parent</span>] = <span class="ruby-identifier">event</span>[<span class="ruby-value">:parent</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">event</span>[<span class="ruby-value">:parent</span>]
412
+ 128: <span class="ruby-identifier">metadata</span>.<span class="ruby-identifier">each_key</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span><span class="ruby-operator">|</span>
413
+ 129: <span class="ruby-identifier">params</span>[<span class="ruby-node">&quot;metadata[#{key}]&quot;</span>] = <span class="ruby-identifier">metadata</span>[<span class="ruby-identifier">key</span>]
414
+ 130: <span class="ruby-keyword kw">end</span>
415
+ 131: <span class="ruby-identifier">put</span>(<span class="ruby-node">&quot;/event/#{event[:location].join(&quot;/&quot;)}&quot;</span>, <span class="ruby-identifier">params</span>)
416
+ 132: <span class="ruby-keyword kw">end</span></pre>
417
+ </div>
418
+
419
+ </div>
420
+
421
+
422
+
423
+
424
+ </div>
425
+
426
+
427
+ <div id="subscribe-method" class="method-detail ">
428
+ <a name="method-i-subscribe"></a>
429
+
430
+ <div class="method-heading">
431
+
432
+ <span class="method-name">subscribe</span><span
433
+ class="method-args">(location, params = {})</span>
434
+ <span class="method-click-advice">click to toggle source</span>
435
+
436
+ </div>
437
+
438
+ <div class="method-description">
439
+
440
+ <p>
441
+ Subscribe to an event stream. The &#8216;location&#8217; parameter is where
442
+ you&#8217;re expecting the events to come:
443
+ </p>
444
+ <ul>
445
+ <li><p>
446
+ [&#8220;organisation&#8221;, &#8220;meeting&#8221;]: events from a specific
447
+ meeting.
448
+ </p>
449
+ </li>
450
+ <li><p>
451
+ [&#8220;organisation&#8221;]: events from all meetings of the organisation
452
+ and for the organisation itself.
453
+ </p>
454
+ </li>
455
+ <li><p>
456
+ []: all events.
457
+ </p>
458
+ </li>
459
+ </ul>
460
+ <p>
461
+ The function takes extra parameters: :type => the type of event (ex.
462
+ &#8216;chat.message.new&#8217;, &#8216;internal.user.add&#8217;, etc).
463
+ :from => the origin of the message, the value is an uid. :parent => the id
464
+ of the the parent event. :search => list of keywords that match the
465
+ metadata of the returned events
466
+ </p>
467
+ <pre>
468
+ uce.subscribe([&quot;af83&quot;], :type =&gt; 'internal.meeting.add', :search =&gt; 'HTML5') do |event|
469
+ puts &quot;A new meeting about HTML5 was created&quot;
470
+ end</pre>
471
+
472
+
473
+
474
+ <div class="method-source-code"
475
+ id="subscribe-source">
476
+ <pre>
477
+ <span class="ruby-comment cmt"># File lib/ucengine.rb, line 89</span>
478
+ 89: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">subscribe</span>(<span class="ruby-identifier">location</span>, <span class="ruby-identifier">params</span> = {})
479
+ 90: <span class="ruby-identifier">debug</span>(<span class="ruby-constant">UCEngine</span><span class="ruby-operator">::</span><span class="ruby-constant">DEBUG</span>, <span class="ruby-node">&quot;Subscribe to #{location} with #{params}.&quot;</span>)
480
+ 91: <span class="ruby-ivar">@threads</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span>
481
+ 92: <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">start</span>(<span class="ruby-ivar">@host</span>, <span class="ruby-ivar">@port</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">http</span><span class="ruby-operator">|</span>
482
+ 93: <span class="ruby-identifier">params</span>[<span class="ruby-value">:_async</span>] = <span class="ruby-value str">&quot;lp&quot;</span>
483
+ 94: <span class="ruby-identifier">params</span>[<span class="ruby-value">:start</span>] = <span class="ruby-value">0</span> <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">params</span>[<span class="ruby-value">:start</span>]
484
+ 95: <span class="ruby-keyword kw">while</span> <span class="ruby-keyword kw">true</span>
485
+ 96: <span class="ruby-keyword kw">begin</span>
486
+ 97: <span class="ruby-identifier">events</span> = <span class="ruby-identifier">get</span>(<span class="ruby-node">&quot;/event/#{location.join(&quot;/&quot;)}&quot;</span>, <span class="ruby-identifier">params</span>, <span class="ruby-identifier">http</span>)[<span class="ruby-value str">'result'</span>]
487
+ 98: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Timeout</span><span class="ruby-operator">::</span><span class="ruby-constant">Error</span>
488
+ 99: <span class="ruby-keyword kw">retry</span>
489
+ 100: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">EOFError</span>
490
+ 101: <span class="ruby-identifier">sleep</span> <span class="ruby-value">10</span>
491
+ 102: <span class="ruby-keyword kw">retry</span>
492
+ 103: <span class="ruby-keyword kw">end</span>
493
+ 104: <span class="ruby-identifier">events</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">event</span><span class="ruby-operator">|</span>
494
+ 105: <span class="ruby-keyword kw">yield</span> <span class="ruby-identifier">event</span>
495
+ 106: <span class="ruby-keyword kw">end</span>
496
+ 107: <span class="ruby-identifier">params</span>[<span class="ruby-value">:start</span>] = <span class="ruby-identifier">events</span>[<span class="ruby-value">1</span>][<span class="ruby-value str">'datetime'</span>] <span class="ruby-operator">+</span> <span class="ruby-value">1</span>
497
+ 108: <span class="ruby-keyword kw">end</span>
498
+ 109: <span class="ruby-keyword kw">end</span>
499
+ 110: <span class="ruby-keyword kw">end</span>
500
+ 111: <span class="ruby-keyword kw">end</span></pre>
501
+ </div>
502
+
503
+ </div>
504
+
505
+
506
+
507
+
508
+ </div>
509
+
510
+
511
+ <div id="time-method" class="method-detail ">
512
+ <a name="method-i-time"></a>
513
+
514
+ <div class="method-heading">
515
+
516
+ <span class="method-name">time</span><span
517
+ class="method-args">()</span>
518
+ <span class="method-click-advice">click to toggle source</span>
519
+
520
+ </div>
521
+
522
+ <div class="method-description">
523
+
524
+ <p>
525
+ Return the current timestamp from the server. The timestamp is expressed in
526
+ milliseconds from Epoch (january 1st 1970). This function can be useful if
527
+ you need to search for events from <em>now</em>.
528
+ </p>
529
+ <pre>
530
+ uce.time -&gt; 1240394032</pre>
531
+
532
+
533
+
534
+ <div class="method-source-code"
535
+ id="time-source">
536
+ <pre>
537
+ <span class="ruby-comment cmt"># File lib/ucengine.rb, line 140</span>
538
+ 140: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">time</span>
539
+ 141: <span class="ruby-identifier">time</span> = <span class="ruby-identifier">get</span>(<span class="ruby-value str">&quot;/time&quot;</span>, <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>)[<span class="ruby-value str">'result'</span>].<span class="ruby-identifier">to_i</span>
540
+ 142: <span class="ruby-identifier">debug</span>(<span class="ruby-constant">UCEngine</span><span class="ruby-operator">::</span><span class="ruby-constant">DEBUG</span>, <span class="ruby-node">&quot;Fecth timestamp from UCEngine: #{time}&quot;</span>)
541
+ 143: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">time</span>
542
+ 144: <span class="ruby-keyword kw">end</span></pre>
543
+ </div>
544
+
545
+ </div>
546
+
547
+
548
+
549
+
550
+ </div>
551
+
552
+
553
+ </div>
554
+
555
+ <div id="protected-instance-method-details" class="method-section section">
556
+ <h3 class="section-header">Protected Instance Methods</h3>
557
+
558
+
559
+ <div id="debug-method" class="method-detail ">
560
+ <a name="method-i-debug"></a>
561
+
562
+ <div class="method-heading">
563
+
564
+ <span class="method-name">debug</span><span
565
+ class="method-args">(level, message)</span>
566
+ <span class="method-click-advice">click to toggle source</span>
567
+
568
+ </div>
569
+
570
+ <div class="method-description">
571
+
572
+ <p>
573
+ Print debug messages
574
+ </p>
575
+
576
+
577
+
578
+ <div class="method-source-code"
579
+ id="debug-source">
580
+ <pre>
581
+ <span class="ruby-comment cmt"># File lib/ucengine.rb, line 154</span>
582
+ 154: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">debug</span>(<span class="ruby-identifier">level</span>, <span class="ruby-identifier">message</span>)
583
+ 155: <span class="ruby-identifier">$stderr</span>.<span class="ruby-identifier">write</span>(<span class="ruby-node">&quot;#{message}\n\n&quot;</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">level</span> <span class="ruby-operator">&gt;=</span> <span class="ruby-ivar">@debug</span>
584
+ 156: <span class="ruby-keyword kw">end</span></pre>
585
+ </div>
586
+
587
+ </div>
588
+
589
+
590
+
591
+
592
+ </div>
593
+
594
+
595
+ <div id="delete-method" class="method-detail ">
596
+ <a name="method-i-delete"></a>
597
+
598
+ <div class="method-heading">
599
+
600
+ <span class="method-name">delete</span><span
601
+ class="method-args">(path, params)</span>
602
+ <span class="method-click-advice">click to toggle source</span>
603
+
604
+ </div>
605
+
606
+ <div class="method-description">
607
+
608
+ <p>
609
+ Handle DELETE requests
610
+ </p>
611
+
612
+
613
+
614
+ <div class="method-source-code"
615
+ id="delete-source">
616
+ <pre>
617
+ <span class="ruby-comment cmt"># File lib/ucengine.rb, line 183</span>
618
+ 183: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">delete</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">params</span>)
619
+ 184: <span class="ruby-identifier">params</span>[<span class="ruby-value str">'_method'</span>] = <span class="ruby-value str">&quot;DELETE&quot;</span>
620
+ 185: <span class="ruby-identifier">post</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">params</span>)
621
+ 186: <span class="ruby-keyword kw">end</span></pre>
622
+ </div>
623
+
624
+ </div>
625
+
626
+
627
+
628
+
629
+ </div>
630
+
631
+
632
+ <div id="get-method" class="method-detail ">
633
+ <a name="method-i-get"></a>
634
+
635
+ <div class="method-heading">
636
+
637
+ <span class="method-name">get</span><span
638
+ class="method-args">(path, params, http = @http)</span>
639
+ <span class="method-click-advice">click to toggle source</span>
640
+
641
+ </div>
642
+
643
+ <div class="method-description">
644
+
645
+ <p>
646
+ Handle GET requests
647
+ </p>
648
+
649
+
650
+
651
+ <div class="method-source-code"
652
+ id="get-source">
653
+ <pre>
654
+ <span class="ruby-comment cmt"># File lib/ucengine.rb, line 159</span>
655
+ 159: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">params</span>, <span class="ruby-identifier">http</span> = <span class="ruby-ivar">@http</span>)
656
+ 160: <span class="ruby-identifier">params</span>[<span class="ruby-value">:uid</span>] = <span class="ruby-ivar">@uid</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@uid</span>
657
+ 161: <span class="ruby-identifier">params</span>[<span class="ruby-value">:sid</span>] = <span class="ruby-ivar">@sid</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@sid</span>
658
+ 162: <span class="ruby-identifier">result</span> = <span class="ruby-constant">JSON</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">http</span>.<span class="ruby-identifier">get</span>(<span class="ruby-node">&quot;/api/0.1/#{path}?#{UCEngine.encode(params)}&quot;</span>).<span class="ruby-identifier">body</span>)
659
+ 163: <span class="ruby-identifier">debug</span>(<span class="ruby-constant">UCEngine</span><span class="ruby-operator">::</span><span class="ruby-constant">DEBUG</span>, <span class="ruby-node">&quot;Request: GET /api/0.1/#{path}?#{UCEngine.encode(params)}\nResult: #{result}&quot;</span>)
660
+ 164: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">result</span>
661
+ 165: <span class="ruby-keyword kw">end</span></pre>
662
+ </div>
663
+
664
+ </div>
665
+
666
+
667
+
668
+
669
+ </div>
670
+
671
+
672
+ <div id="post-method" class="method-detail ">
673
+ <a name="method-i-post"></a>
674
+
675
+ <div class="method-heading">
676
+
677
+ <span class="method-name">post</span><span
678
+ class="method-args">(path, params, http = @http)</span>
679
+ <span class="method-click-advice">click to toggle source</span>
680
+
681
+ </div>
682
+
683
+ <div class="method-description">
684
+
685
+ <p>
686
+ Handle POST requests
687
+ </p>
688
+
689
+
690
+
691
+ <div class="method-source-code"
692
+ id="post-source">
693
+ <pre>
694
+ <span class="ruby-comment cmt"># File lib/ucengine.rb, line 168</span>
695
+ 168: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">post</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">params</span>, <span class="ruby-identifier">http</span> = <span class="ruby-ivar">@http</span>)
696
+ 169: <span class="ruby-identifier">params</span>[<span class="ruby-value">:uid</span>] = <span class="ruby-ivar">@uid</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@uid</span>
697
+ 170: <span class="ruby-identifier">params</span>[<span class="ruby-value">:sid</span>] = <span class="ruby-ivar">@sid</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@sid</span>
698
+ 171: <span class="ruby-identifier">result</span> = <span class="ruby-constant">JSON</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">http</span>.<span class="ruby-identifier">post</span>(<span class="ruby-node">&quot;/api/0.1/#{path}&quot;</span>, <span class="ruby-constant">UCEngine</span>.<span class="ruby-identifier">encode</span>(<span class="ruby-identifier">params</span>)).<span class="ruby-identifier">body</span>)
699
+ 172: <span class="ruby-identifier">debug</span>(<span class="ruby-constant">UCEngine</span><span class="ruby-operator">::</span><span class="ruby-constant">DEBUG</span>, <span class="ruby-node">&quot;Request: POST /api/0.1/#{path}?#{UCEngine.encode(params)}\nResult: #{result}&quot;</span>)
700
+ 173: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">result</span>
701
+ 174: <span class="ruby-keyword kw">end</span></pre>
702
+ </div>
703
+
704
+ </div>
705
+
706
+
707
+
708
+
709
+ </div>
710
+
711
+
712
+ <div id="put-method" class="method-detail ">
713
+ <a name="method-i-put"></a>
714
+
715
+ <div class="method-heading">
716
+
717
+ <span class="method-name">put</span><span
718
+ class="method-args">(path, params)</span>
719
+ <span class="method-click-advice">click to toggle source</span>
720
+
721
+ </div>
722
+
723
+ <div class="method-description">
724
+
725
+ <p>
726
+ Handle PUT requests
727
+ </p>
728
+
729
+
730
+
731
+ <div class="method-source-code"
732
+ id="put-source">
733
+ <pre>
734
+ <span class="ruby-comment cmt"># File lib/ucengine.rb, line 177</span>
735
+ 177: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">put</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">params</span>)
736
+ 178: <span class="ruby-identifier">params</span>[<span class="ruby-value str">'_method'</span>] = <span class="ruby-value str">&quot;PUT&quot;</span>
737
+ 179: <span class="ruby-identifier">post</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">params</span>)
738
+ 180: <span class="ruby-keyword kw">end</span></pre>
739
+ </div>
740
+
741
+ </div>
742
+
743
+
744
+
745
+
746
+ </div>
747
+
748
+
749
+ </div>
750
+
751
+
752
+ </div>
753
+
754
+
755
+ <div id="rdoc-debugging-section-dump" class="debugging-section">
756
+
757
+ <p>Disabled; run with --debug to generate this.</p>
758
+
759
+ </div>
760
+
761
+ <div id="validator-badges">
762
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
763
+ <p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
764
+ Rdoc Generator</a> 1.1.6</small>.</p>
765
+ </div>
766
+
767
+ </body>
768
+ </html>
769
+