ucengine 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/doc/UCEngine.html DELETED
@@ -1,769 +0,0 @@
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
-