em-ucengine 0.1.1

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.
Files changed (5) hide show
  1. data/Gemfile +3 -0
  2. data/LICENSE +165 -0
  3. data/README.md +57 -0
  4. data/lib/em-ucengine.rb +188 -0
  5. metadata +135 -0
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
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.
@@ -0,0 +1,57 @@
1
+ EventMachine library for U.C.Engine
2
+ ===================================
3
+
4
+ em-ucengine is a Ruby library for [U.C.Engine](http://ucengine.org/) powered
5
+ by [EventMachine](https://github.com/eventmachine/eventmachine). It can
6
+ connect, subscribe and publish events to U.C.Engine.
7
+
8
+
9
+ How to use it
10
+ -------------
11
+
12
+ Install with Rubygems:
13
+
14
+ gem install em-ucengine
15
+
16
+ If you use bundler, add it to your `Gemfile`:
17
+
18
+ gem "em-ucengine", "~>0.1"
19
+
20
+ Then, you can use it in your code:
21
+
22
+ require "em-ucengine"
23
+ EventMachine::UCEngine.run do |uce|
24
+ uce.connect("participant", "pwd") do |session|
25
+ EM.add_periodic_timer(1) { session.publish("em-ucengine.example.ping", "demo") }
26
+ session.subscribe("demo") do |event|
27
+ puts "Hey, we received an event: #{event.inspect}"
28
+ end
29
+ end
30
+ end
31
+
32
+ Don't hesitate to look at the specs for more examples ;-)
33
+
34
+
35
+ TODO
36
+ ----
37
+
38
+ * Files API
39
+ * ACL or Roles API
40
+ * Better error handling
41
+ * Complete the specs
42
+ * Compatibility with em-synchrony
43
+ * Yard documentation
44
+
45
+
46
+ Issues or Suggestions
47
+ ---------------------
48
+
49
+ Found an issue or have a suggestion? Please report it on
50
+ [Github's issue tracker](http://github.com/af83/ucengine.em/issues).
51
+
52
+ If you wants to make a pull request, please check the specs before:
53
+
54
+ ./spec/em-ucengine_spec.rb
55
+
56
+
57
+ Copyright (c) 2011 af83, released under the LGPL license
@@ -0,0 +1,188 @@
1
+ require "eventmachine"
2
+ require "em-http-request"
3
+ require "yajl"
4
+
5
+
6
+ module EventMachine
7
+ class UCEngine
8
+
9
+ def self.run(*args)
10
+ EM.run { yield self.new(*args) }
11
+ end
12
+
13
+ def initialize(host="localhost", port=5280, api_root="/api", api_version="0.4")
14
+ @host = host
15
+ @port = port
16
+ @root = api_root
17
+ @version = api_version
18
+ end
19
+
20
+ def time
21
+ Session.new(self, nil, nil).time { |time| yield time }
22
+ end
23
+
24
+ def connect(user, password, metadata=nil)
25
+ body = { "name" => user, "credential" => password }
26
+ body["metadata"] = metadata if metadata
27
+ http = EM::HttpRequest.new(url "presence").post :body => body
28
+ http.errback { yield nil }
29
+ http.callback do
30
+ data = Yajl::Parser.parse(http.response)
31
+ data = data["result"] if data
32
+ yield Session.new(self, data["uid"], data["sid"])
33
+ end
34
+ end
35
+
36
+ def url(path)
37
+ "http://#{@host}:#{@port}#{@root}/#{@version}/#{path}"
38
+ end
39
+
40
+ class Session < Struct.new(:uce, :uid, :sid)
41
+
42
+ ### Time - http://docs.ucengine.org/api.html#time ###
43
+
44
+ def time
45
+ get("/time") { |result| yield result if block_given? }
46
+ end
47
+
48
+ ### Presence - http://docs.ucengine.org/api.html#authentication ###
49
+
50
+ def presence(sid)
51
+ get("/presence/#{sid}") { |result| yield result if block_given? }
52
+ end
53
+
54
+ def disconnect
55
+ delete("/presence/#{sid}") { |result| yield result if block_given? }
56
+ end
57
+
58
+ ### Users - http://docs.ucengine.org/api.html#user ###
59
+
60
+ def users
61
+ get("/user") { |result| yield result if block_given? }
62
+ end
63
+
64
+ def user(uid)
65
+ get("/user/#{uid}") { |result| yield result if block_given? }
66
+ end
67
+
68
+ def create_user(data)
69
+ post("/user", data) { |result| yield result && result.to_i if block_given? }
70
+ end
71
+
72
+ def update_user(uid, data)
73
+ put("/user/#{uid}", data) { |result| yield result if block_given? }
74
+ end
75
+
76
+ def delete_user(uid)
77
+ delete("/user/#{uid}") { |result| yield result if block_given? }
78
+ end
79
+
80
+ ### General infos - http://docs.ucengine.org/api.html#infos ###
81
+
82
+ def infos
83
+ get("/infos") { |result| yield result if block_given? }
84
+ end
85
+
86
+ def update_infos(metadata)
87
+ put("/infos", :metadata => metadata) { |result| yield result if block_given? }
88
+ end
89
+
90
+ ### Meetings - http://docs.ucengine.org/api.html#meeting ###
91
+
92
+ def meetings(status=nil)
93
+ get("/meeting/#{status}") { |result| yield result if block_given? }
94
+ end
95
+
96
+ def meeting(meeting)
97
+ get("/meeting/all/#{meeting}") { |result| yield result if block_given? }
98
+ end
99
+
100
+ def create_meeting(meeting, body={})
101
+ body.merge!(:meeting => meeting)
102
+ post("/meeting/all", body) { |result| yield result if block_given? }
103
+ end
104
+
105
+ def update_meeting(meeting, body={})
106
+ put("/meeting/all/#{meeting}", body) { |result| yield result if block_given? }
107
+ end
108
+
109
+ def delete_meeting(meeting)
110
+ delete("/meeting/all/#{meeting}") { |result| yield result if block_given? }
111
+ end
112
+
113
+ ### Rosters - http://docs.ucengine.org/api.html#join-a-meeting ###
114
+
115
+ def roster(meeting)
116
+ get("/meeting/all/#{meeting}/roster") { |result| yield result if block_given? }
117
+ end
118
+
119
+ def join_roster(meeting)
120
+ post("/meeting/all/#{meeting}/roster") { |result| yield result if block_given? }
121
+ end
122
+
123
+ def quit_roster(meeting, uid=nil)
124
+ delete("/meeting/all/#{meeting}/roster/#{uid || @uid}") { |result| yield result if block_given? }
125
+ end
126
+
127
+ ### Events - http://docs.ucengine.org/api.html#events ###
128
+
129
+ def events(meeting, params={})
130
+ params[:_async] = "no"
131
+ get("/event/#{meeting}", params) { |result| yield result if block_given? }
132
+ end
133
+
134
+ def subscribe(meeting, params={}, &blk)
135
+ params[:_async] = "lp"
136
+ recurse = Proc.new do |result|
137
+ next unless result
138
+ blk.call(result)
139
+ params[:start] = result.last["datetime"].to_i + 1
140
+ get("/event/#{meeting}", params, &recurse) if EM.reactor_running?
141
+ end
142
+ time do |time|
143
+ params[:start] = time
144
+ get("/event/#{meeting}", params, &recurse)
145
+ end
146
+ end
147
+
148
+ def publish(type, meeting=nil, metadata=nil)
149
+ body = { :type => type }
150
+ body[:metadata] = metadata if metadata
151
+ post("/event/#{meeting}", body) { |result| yield result if block_given? }
152
+ end
153
+
154
+ def search(params)
155
+ get("/search/event/", params) { |result| yield result if block_given? }
156
+ end
157
+
158
+ protected
159
+
160
+ def get(path, params={})
161
+ http_request(:get, path, :query => params) { |result| yield result }
162
+ end
163
+
164
+ def post(path, body=nil)
165
+ http_request(:post, path, :body => body) { |result| yield result }
166
+ end
167
+
168
+ def put(path, body=nil)
169
+ http_request(:put, path, :body => body) { |result| yield result }
170
+ end
171
+
172
+ def delete(path)
173
+ http_request(:delete, path) { |result| yield result }
174
+ end
175
+
176
+ def http_request(method, path, opts={})
177
+ opts[:query] ||= {}
178
+ opts[:query].merge!(:uid => uid, :sid => sid)
179
+ http = EM::HttpRequest.new(uce.url path).send(method, opts)
180
+ http.errback { yield nil }
181
+ http.callback do
182
+ data = Yajl::Parser.parse(http.response)
183
+ yield data && data.has_key?("result") && data["result"]
184
+ end
185
+ end
186
+ end
187
+ end
188
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: em-ucengine
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - Bruno Michel
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-04-14 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: eventmachine
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - "="
28
+ - !ruby/object:Gem::Version
29
+ hash: 62196357
30
+ segments:
31
+ - 1
32
+ - 0
33
+ - 0
34
+ - beta
35
+ - 3
36
+ version: 1.0.0.beta3
37
+ type: :runtime
38
+ version_requirements: *id001
39
+ - !ruby/object:Gem::Dependency
40
+ name: em-http-request
41
+ prerelease: false
42
+ requirement: &id002 !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - "="
46
+ - !ruby/object:Gem::Version
47
+ hash: 62196357
48
+ segments:
49
+ - 1
50
+ - 0
51
+ - 0
52
+ - beta
53
+ - 3
54
+ version: 1.0.0.beta3
55
+ type: :runtime
56
+ version_requirements: *id002
57
+ - !ruby/object:Gem::Dependency
58
+ name: yajl-ruby
59
+ prerelease: false
60
+ requirement: &id003 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ hash: 27
66
+ segments:
67
+ - 0
68
+ - 8
69
+ version: "0.8"
70
+ type: :runtime
71
+ version_requirements: *id003
72
+ - !ruby/object:Gem::Dependency
73
+ name: minitest
74
+ prerelease: false
75
+ requirement: &id004 !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ~>
79
+ - !ruby/object:Gem::Version
80
+ hash: 3
81
+ segments:
82
+ - 2
83
+ - 0
84
+ version: "2.0"
85
+ type: :development
86
+ version_requirements: *id004
87
+ description: A library for U.C.Engine, powered by EventMachine
88
+ email: bruno.michel@af83.com
89
+ executables: []
90
+
91
+ extensions: []
92
+
93
+ extra_rdoc_files:
94
+ - README.md
95
+ files:
96
+ - LICENSE
97
+ - README.md
98
+ - Gemfile
99
+ - lib/em-ucengine.rb
100
+ has_rdoc: true
101
+ homepage: http://github.com/af83/ucengine.em
102
+ licenses: []
103
+
104
+ post_install_message:
105
+ rdoc_options: []
106
+
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ hash: 3
124
+ segments:
125
+ - 0
126
+ version: "0"
127
+ requirements: []
128
+
129
+ rubyforge_project:
130
+ rubygems_version: 1.5.2
131
+ signing_key:
132
+ specification_version: 3
133
+ summary: A library for U.C.Engine, powered by EventMachine
134
+ test_files: []
135
+