ucengine 0.5.0 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ucengine (0.4.0)
4
+ ucengine (0.5.3)
5
5
  daemons (~> 1.1)
6
6
  json (~> 1.5)
7
7
  rest-client (~> 1.6)
@@ -9,12 +9,12 @@ PATH
9
9
  GEM
10
10
  remote: http://rubygems.org/
11
11
  specs:
12
- daemons (1.1.0)
12
+ daemons (1.1.3)
13
13
  diff-lcs (1.1.2)
14
- json (1.5.1)
14
+ json (1.5.3)
15
15
  mime-types (1.16)
16
16
  rack (1.2.2)
17
- rest-client (1.6.1)
17
+ rest-client (1.6.3)
18
18
  mime-types (>= 1.16)
19
19
  rspec (2.4.0)
20
20
  rspec-core (~> 2.4.0)
@@ -1,5 +1,6 @@
1
1
  require 'json'
2
2
  require 'yaml'
3
+ require 'logger'
3
4
 
4
5
  require 'rest-client'
5
6
 
@@ -28,18 +29,14 @@ require 'uri'
28
29
  # end
29
30
  class UCEngine
30
31
 
31
- DEBUG = 0 # Print every request and everything above.
32
- WARNING = 1 # Print everything that seems fishy.
33
- ERROR = 2 # Print regular errors, usually HTTP errors.
34
- CRITICAL = 3 # Only print critical errors (bad hostname or port, etc).
35
- QUIET = 4 # Don't print anything (default).
36
-
37
32
  # HTTP API conf.
38
33
  API_ROOT = '/api'
39
34
  API_VERSION = '0.5'
40
35
 
41
36
  attr_reader :sid, :uid, :connected
42
37
 
38
+ @@logger = nil
39
+
43
40
  # Load configuration file (default: config.yaml). The returned configuration
44
41
  # is a Hash, as returned by YAML.load_file().
45
42
  def self.load_config(path = 'config.yaml')
@@ -57,21 +54,26 @@ class UCEngine
57
54
  # end
58
55
  #
59
56
  #
60
- def self.run(name, &proc)
61
- Daemons.run_proc(name, &proc)
57
+ def self.run(name, options = {}, &proc)
58
+ Daemons.run_proc(name, options, &proc)
59
+ end
60
+
61
+ # Set the default logger.
62
+ def self.logger=(logger)
63
+ @@logger = logger
62
64
  end
63
65
 
64
66
  # Create a new U.C.Engine object. 'host' is the hostname of the U.C.Engine server
65
67
  # and 'port' is to TCP port to connect to. Note that this method doesn't create
66
- # a new connection, see the #connect method.
67
- # An additional 'debug' parameter set the debug level of the library, all the
68
- # debug information are written in the error output.
69
- def initialize(host, port, debug = UCEngine::QUIET)
68
+ # a new connection, see the #connect method. An optional parameter 'level' can be
69
+ # used to set the logging level (default: Logger::UNKNOWN).
70
+ def initialize(host, port, level = Logger::UNKNOWN)
70
71
  @host = host
71
72
  @port = port
72
73
  @http = Net::HTTP.new(host, port)
73
74
  @threads = []
74
- @debug = debug
75
+ @logger = @@logger || Logger.new($stderr)
76
+ @logger.level = level
75
77
  debug "Initialisation complete for #{host}:#{port}."
76
78
  end
77
79
 
@@ -109,6 +111,16 @@ class UCEngine
109
111
  end
110
112
  end
111
113
 
114
+ # List users in a meeting room.
115
+ #
116
+ #
117
+ # uce = UCEngine.new("localhost", 4567)
118
+ # users = uce.roster('demo')
119
+ #
120
+ def roster(name)
121
+ get("/meeting/all/#{name}/roster")['result']
122
+ end
123
+
112
124
  # Search events. The 'location' parameter is where you're expection the events to come:
113
125
  # * "meeting": event from a specific meeting.
114
126
  # * "": all events.
@@ -243,27 +255,17 @@ class UCEngine
243
255
  #
244
256
  # uce.upload(["demo_meeting"], File.new("/path/file_to_upload.pdf"))
245
257
  #
246
- def upload(location, file)
258
+ def upload(location, file, metadata={})
247
259
  url = "http://#{@host}:#{@port}#{API_ROOT}/#{API_VERSION}/file/#{location}?uid=#{@uid}&sid=#{@sid}"
248
260
  debug "Upload: #{file.path} to #{url}"
249
- result = JSON.parse(RestClient.post(url, {:upload => file}))
261
+ result = JSON.parse(RestClient.post(url, { :content => file,
262
+ :metadata => metadata }))
250
263
  debug 'Upload complete'
251
264
  return result
252
265
  end
253
266
 
254
- protected
255
-
256
- # Print debug messages
257
- def log_message(level, message)
258
- $stderr.write "#{message}\n\n" if level >= @debug
259
- end
260
- def debug(message) ; log_message UCEngine::DEBUG, message ; end
261
- def warn(message) ; log_message UCEngine::WARNING, message ; end
262
- def error(message) ; log_message UCEngine::ERROR, message ; end
263
- def critical(message) ; log_message UCEngine::CRITICAL, message ; end
264
-
265
267
  # Handle GET requests
266
- def get(path, params, http = @http)
268
+ def get(path, params = {}, http = @http)
267
269
  params[:uid] = @uid if @uid
268
270
  params[:sid] = @sid if @sid
269
271
  url = "http://#{@host}:#{@port}#{API_ROOT}/#{API_VERSION}#{path}"
@@ -274,7 +276,7 @@ class UCEngine
274
276
  end
275
277
 
276
278
  # Handle POST requests
277
- def post(path, params, http = @http)
279
+ def post(path, params = {}, http = @http)
278
280
  params[:uid] = @uid if @uid
279
281
  params[:sid] = @sid if @sid
280
282
  url = "http://#{@host}:#{@port}#{API_ROOT}/#{API_VERSION}#{path}"
@@ -285,15 +287,21 @@ class UCEngine
285
287
  end
286
288
 
287
289
  # Handle PUT requests
288
- def put(path, params)
290
+ def put(path, params = {})
289
291
  params['_method'] = 'PUT'
290
292
  post path, params
291
293
  end
292
294
 
293
295
  # Handle DELETE requests
294
- def delete(path, params)
296
+ def delete(path, params = {})
295
297
  params['_method'] = 'DELETE'
296
298
  post path, params
297
299
  end
298
300
 
301
+ protected
302
+
303
+ def debug(message) ; @logger.debug message ; end
304
+ def warn(message) ; @logger.warn message ; end
305
+ def error(message) ; @logger.error message ; end
306
+ def critical(message) ; @logger.fatal message ; end
299
307
  end
@@ -1,3 +1,3 @@
1
1
  class UCEngine
2
- VERSION = '0.5.0'
2
+ VERSION = '0.5.3'
3
3
  end
@@ -23,6 +23,25 @@ class UCEngineMock < Sinatra::Base
23
23
  {:result => 1234}.to_json
24
24
  end
25
25
 
26
+ get "/api/#{VERSION}/meeting/all/:meeting/roster" do
27
+ status 200
28
+ users = [{:id => 34334839681323313178318538371527,
29
+ :name => 'jeffrey.lebowski@bathtub.com',
30
+ :domain => 'ucengine.org',
31
+ :auth => 'password',
32
+ :metadata => {
33
+ :nickname => "The Dude"
34
+ }},
35
+ {:id => 18519526811067452830480557737028,
36
+ :name => 'walter.sobchak@bowling.org',
37
+ :domain => 'ucengine.org',
38
+ :auth => 'password',
39
+ :metadata => {
40
+ :nickname => "The Veteran"
41
+ }}]
42
+ {:result => users}.to_json
43
+ end
44
+
26
45
  post "/api/#{VERSION}/event/:meeting" do
27
46
  if params[:meeting] == UCE_MEETING
28
47
  if params[:type] == "test_type" &&
@@ -76,7 +95,7 @@ class UCEngineMock < Sinatra::Base
76
95
  # Upload
77
96
  post "/api/#{VERSION}/file/:meeting" do
78
97
  if params[:meeting] == UCE_MEETING
79
- if params[:upload][:tempfile].read == FILE_CONTENT
98
+ if params[:content][:tempfile].read == FILE_CONTENT
80
99
  status 200
81
100
  {:result => "test_upload"}.to_json
82
101
  else
@@ -52,6 +52,15 @@ describe UCEngine do
52
52
  end
53
53
  end
54
54
 
55
+ it "returns the list of connected users" do
56
+ @uce.connect(USER, :credential => PASSWORD) do |uce|
57
+ roster = uce.roster('demo')
58
+ roster.length.should eql(2)
59
+ roster[0]['name'].should eql('jeffrey.lebowski@bathtub.com')
60
+ roster[1]['name'].should eql('walter.sobchak@bowling.org')
61
+ end
62
+ end
63
+
55
64
  it "publishes an event" do
56
65
  @uce.connect(USER, :credential => PASSWORD) do |uce|
57
66
  result = uce.publish(:location => UCE_MEETING,
@@ -99,7 +108,7 @@ describe UCEngine do
99
108
  @uce.connect(USER, :credential => PASSWORD) do |uce|
100
109
  file = Tempfile.open("test_file")
101
110
  file.write(FILE_CONTENT)
102
- result = uce.upload(UCE_MEETING, file.open)
111
+ result = uce.upload(UCE_MEETING, file.open, :description => "a file")
103
112
  result['result'].should eql("test_upload")
104
113
  break
105
114
  end
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
8
8
  s.authors = ['AF83']
9
9
  s.email = ['victor.goya@af83.com', 'arnaud.berthomier@af83.com']
10
10
  s.homepage = "https://github.com/AF83/ucengine.rb"
11
- s.summary = "A ruby library to consume the UCEngine API"
12
- s.description = "A ruby library to consume the UCEngine API"
11
+ s.summary = "A ruby library to consume the U.C.Engine API"
12
+ s.description = "A ruby library to consume the U.C.Engine API"
13
13
 
14
14
  s.required_rubygems_version = ">= 1.3.6"
15
15
  s.rubyforge_project = "ucengine"
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ucengine
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 5
9
- - 0
10
- version: 0.5.0
4
+ prerelease:
5
+ version: 0.5.3
11
6
  platform: ruby
12
7
  authors:
13
8
  - AF83
@@ -15,7 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-04-14 00:00:00 +02:00
13
+ date: 2011-07-04 00:00:00 +02:00
19
14
  default_executable:
20
15
  dependencies:
21
16
  - !ruby/object:Gem::Dependency
@@ -26,10 +21,6 @@ dependencies:
26
21
  requirements:
27
22
  - - ~>
28
23
  - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 1
32
- - 6
33
24
  version: "1.6"
34
25
  type: :runtime
35
26
  version_requirements: *id001
@@ -41,10 +32,6 @@ dependencies:
41
32
  requirements:
42
33
  - - ~>
43
34
  - !ruby/object:Gem::Version
44
- hash: 13
45
- segments:
46
- - 1
47
- - 1
48
35
  version: "1.1"
49
36
  type: :runtime
50
37
  version_requirements: *id002
@@ -56,10 +43,6 @@ dependencies:
56
43
  requirements:
57
44
  - - ~>
58
45
  - !ruby/object:Gem::Version
59
- hash: 5
60
- segments:
61
- - 1
62
- - 5
63
46
  version: "1.5"
64
47
  type: :runtime
65
48
  version_requirements: *id003
@@ -71,10 +54,6 @@ dependencies:
71
54
  requirements:
72
55
  - - ">="
73
56
  - !ruby/object:Gem::Version
74
- hash: 15
75
- segments:
76
- - 1
77
- - 0
78
57
  version: "1.0"
79
58
  type: :development
80
59
  version_requirements: *id004
@@ -86,10 +65,6 @@ dependencies:
86
65
  requirements:
87
66
  - - ~>
88
67
  - !ruby/object:Gem::Version
89
- hash: 11
90
- segments:
91
- - 2
92
- - 4
93
68
  version: "2.4"
94
69
  type: :development
95
70
  version_requirements: *id005
@@ -101,14 +76,10 @@ dependencies:
101
76
  requirements:
102
77
  - - ~>
103
78
  - !ruby/object:Gem::Version
104
- hash: 11
105
- segments:
106
- - 1
107
- - 2
108
79
  version: "1.2"
109
80
  type: :development
110
81
  version_requirements: *id006
111
- description: A ruby library to consume the UCEngine API
82
+ description: A ruby library to consume the U.C.Engine API
112
83
  email:
113
84
  - victor.goya@af83.com
114
85
  - arnaud.berthomier@af83.com
@@ -146,27 +117,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
146
117
  requirements:
147
118
  - - ">="
148
119
  - !ruby/object:Gem::Version
149
- hash: 3
150
- segments:
151
- - 0
152
120
  version: "0"
153
121
  required_rubygems_version: !ruby/object:Gem::Requirement
154
122
  none: false
155
123
  requirements:
156
124
  - - ">="
157
125
  - !ruby/object:Gem::Version
158
- hash: 23
159
- segments:
160
- - 1
161
- - 3
162
- - 6
163
126
  version: 1.3.6
164
127
  requirements: []
165
128
 
166
129
  rubyforge_project: ucengine
167
- rubygems_version: 1.3.7
130
+ rubygems_version: 1.6.2
168
131
  signing_key:
169
132
  specification_version: 3
170
- summary: A ruby library to consume the UCEngine API
133
+ summary: A ruby library to consume the U.C.Engine API
171
134
  test_files: []
172
135