ucengine 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
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/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = ucengine.rb
2
2
 
3
- ucengine.rb can connect, subscribe, and publish events to UCEngine.
3
+ ucengine.rb can connect, subscribe, and publish events to UC Engine.
4
4
 
5
5
  == Copyright
6
6
 
data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
+ require "rspec/core/rake_task"
3
4
 
4
5
  begin
5
6
  require 'jeweler'
@@ -33,11 +34,12 @@ rescue LoadError
33
34
  end
34
35
  end
35
36
 
36
- task :test => :check_dependencies do
37
- sh "rspec spec"
37
+ RSpec::Core::RakeTask.new(:spec) do |spec|
38
+ spec.pattern = 'spec/*_spec.rb'
39
+ spec.rspec_opts = ['--backtrace']
38
40
  end
39
41
 
40
- task :default => :test
42
+ task :default => :rspec
41
43
 
42
44
  require 'rake/rdoctask'
43
45
  Rake::RDocTask.new do |rdoc|
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.2.0
data/lib/ucengine.rb CHANGED
@@ -17,12 +17,12 @@ require 'daemons'
17
17
  # connections and request to the UCEngine server.
18
18
  #
19
19
  # uce = UCEngine.new("localhost", 4567)
20
- # uce.connect("bibi", :password => 'abcd') do |uce|
21
- # uce.subscribe(["af83"], :type => 'chat.message.new', :search => 'HTML5') do |event|
22
- # uce.push(:location => [event['org'], event['meeting']]
23
- # :from => 'bot',
24
- # :type => 'chat.message.new',
25
- # :metadata => {"text" => "Hey, you were talking about HTML5"})
20
+ # uce.connect("uce@example.com", :password => 'pwd') do |uce|
21
+ # uce.subscribe([], :type => 'chat.message.new', :search => 'HTML5') do |event|
22
+ # uce.publish(:location => [event['meeting']]
23
+ # :from => 'bot',
24
+ # :type => 'chat.message.new',
25
+ # :metadata => {"text" => "Hey, you were talking about HTML5"})
26
26
  # end
27
27
  # end
28
28
  class UCEngine
@@ -40,9 +40,9 @@ class UCEngine
40
40
 
41
41
  API_ROOT = "/api"
42
42
 
43
- API_VERSION = "0.1"
43
+ API_VERSION = "0.2"
44
44
 
45
- attr_reader :sid, :uid
45
+ attr_reader :sid, :uid, :connected
46
46
 
47
47
  # Load configuration file (default: config.yaml). The returned configuration
48
48
  # is a Hash, as returned by YAML.load_file().
@@ -79,6 +79,10 @@ class UCEngine
79
79
  debug(UCEngine::DEBUG, "Initialisation complete for #{host}:#{port}.")
80
80
  end
81
81
 
82
+ def connected?
83
+ @connected
84
+ end
85
+
82
86
  # Connect to the UCEngine server with the User ID 'uid' and the its credential.
83
87
  #
84
88
  #
@@ -89,10 +93,16 @@ class UCEngine
89
93
  #
90
94
  def connect(uid, params)
91
95
  @uid = uid
92
- response = put("/presence/#{@uid}", {:credential => params[:credential]})
93
- @sid = response['result']
94
- debug(UCEngine::DEBUG, "Authentification complete for #{@uid}/#{@sid}.")
95
- yield self
96
+ begin
97
+ response = put("/presence/#{@uid}", {:credential => params[:credential]})
98
+ @connected = true
99
+ @sid = response['result']
100
+ debug(UCEngine::DEBUG, "Authentification complete for #{@uid}/#{@sid}.")
101
+ rescue RestClient::Request::Unauthorized
102
+ debug(UCEngine::DEBUG, "Authentification error for #{@uid}.")
103
+ @connected = false
104
+ end
105
+ yield self if block_given?
96
106
  @threads.each do |thread|
97
107
  begin
98
108
  thread.join
@@ -104,8 +114,7 @@ class UCEngine
104
114
 
105
115
  # Subscribe to an event stream. The 'location' parameter is where you're expecting
106
116
  # the events to come:
107
- # * ["organisation", "meeting"]: events from a specific meeting.
108
- # * ["organisation"]: events from all meetings of the organisation and for the organisation itself.
117
+ # * ["meeting"]: events from a specific meeting.
109
118
  # * []: all events.
110
119
  #
111
120
  # The function takes extra parameters:
@@ -148,12 +157,12 @@ class UCEngine
148
157
  end
149
158
 
150
159
  # Publish an event. Publishing an event require a few mandatories parameters:
151
- # [:location] As described in the subscribe method: ["organisation", "meeting"] publish the event in a specific meeting, ["organisation"] publish the event in the organisation and []: publish the event in the server root.
160
+ # [:location] As described in the subscribe method: ["meeting"] publish the event in a specific meeting or []: publish the event in the server root.
152
161
  # [:type] The type of event to send, the format of this type is usually 'namespace.object.action', for example: 'chat.message.new', 'twitter.tweet.new', 'internal.user.update'
153
162
  # [:parent] The id of the parent, this parameter is useful to build event hierarchy.
154
163
  # [:metadata] A hash of freely defined values to append to the event.
155
164
  #
156
- # uce.publish(:location => ["af83", "WebWorkersCamp"],
165
+ # uce.publish(:location => ["WebWorkersCamp"],
157
166
  # :type => 'presentation.slide.add'
158
167
  # :metadata => {:url => 'http://myserver/slides/03.png',
159
168
  # :index => 3})
@@ -182,17 +191,17 @@ class UCEngine
182
191
  return time
183
192
  end
184
193
 
185
- # Download a file from UCEngine. The 'location' parameter is the couple [organisation, meeting]
194
+ # Download a file from UCEngine. The meeting parameter is
186
195
  # where the file sits. The 'id' parameters is the file idenfication number
187
196
  #
188
- # uce.download(["af83", "demo_meeting"], "file_43243243253253.pdf")
197
+ # uce.download(["demo_meeting"], "file_43243243253253.pdf")
189
198
  #
190
- def download(location, id)
199
+ def download(meeting, id)
191
200
  Net::HTTP.start(@host, @port) do |http|
192
201
  params = Hash.new
193
202
  params[:uid] = @uid if @uid
194
203
  params[:sid] = @sid if @sid
195
- url = "http://#{@host}:#{@port}#{API_ROOT}/#{API_VERSION}/file/#{location.join('/')}/#{id}"
204
+ url = "http://#{@host}:#{@port}#{API_ROOT}/#{API_VERSION}/file/#{meeting}/#{id}"
196
205
 
197
206
  debug(UCEngine::DEBUG, "Download: #{url}")
198
207
  result = RestClient.get(url, {:params => params})
@@ -201,15 +210,15 @@ class UCEngine
201
210
  end
202
211
  end
203
212
 
204
- # Upload a file to UCEngine. The 'location' parameter is the couple [organisation, meeting] where
213
+ # Upload a file to UCEngine. The meeting is where
205
214
  # you want the file to be uploaded. The 'file' parameter is a File object.
206
215
  # This function returns a JSON structure {'result': file_id} where 'file_id' is the identification
207
216
  # number of the file.
208
217
  #
209
- # uce.upload(["af83", "demo_meeting"], File.new("/path/file_to_upload.pdf"))
218
+ # uce.upload(["demo_meeting"], File.new("/path/file_to_upload.pdf"))
210
219
  #
211
- def upload(location, file)
212
- url = "http://#{@host}:#{@port}#{API_ROOT}/#{API_VERSION}/file/#{location.join('/')}?uid=#{@uid}&sid=#{@sid}"
220
+ def upload(meeting, file)
221
+ url = "http://#{@host}:#{@port}#{API_ROOT}/#{API_VERSION}/file/#{meeting}?uid=#{@uid}&sid=#{@sid}"
213
222
  debug(UCEngine::DEBUG, "Upload: #{file.path} to #{url}")
214
223
  result = JSON.parse(RestClient.post(url, {:upload => file}))
215
224
  debug(UCEngine::DEBUG, "Upload complete")
data/spec/spec_helper.rb CHANGED
@@ -2,7 +2,6 @@ require 'ucengine'
2
2
 
3
3
  UCE_HOST = "localhost"
4
4
  UCE_PORT = 5281
5
- UCE_ORG = "test_org"
6
5
  UCE_MEETING = "test_meeting"
7
6
  UCE_URL = "http://#{UCE_HOST}#{UCEngine::API_ROOT}/#{UCEngine::API_VERSION}"
8
7
  USER = "test_user@#{UCE_HOST}"
@@ -6,10 +6,10 @@ require 'spec_helper'
6
6
  class UCEngineMock < Sinatra::Base
7
7
  use Rack::MethodOverride
8
8
 
9
- VERSION = '0.1'
9
+ VERSION = '0.2'
10
10
 
11
11
  put "/api/#{VERSION}/presence/:uid" do
12
- if params[:uid] == USER
12
+ if params[:uid] == USER && params[:credential] == PASSWORD
13
13
  status 200
14
14
  {:result => "test_sid"}.to_json
15
15
  else
@@ -23,8 +23,8 @@ class UCEngineMock < Sinatra::Base
23
23
  {:result => 1234}.to_json
24
24
  end
25
25
 
26
- put "/api/#{VERSION}/event/:org/:meeting" do
27
- if params[:org] == UCE_ORG && params[:meeting] == UCE_MEETING
26
+ put "/api/#{VERSION}/event/:meeting" do
27
+ if params[:meeting] == UCE_MEETING
28
28
  if params[:type] == "test_type" &&
29
29
  params[:parent] == "test_parent" &&
30
30
  params[:metadata]["a"] == "b" &&
@@ -41,14 +41,13 @@ class UCEngineMock < Sinatra::Base
41
41
  end
42
42
  end
43
43
 
44
- get "/api/#{VERSION}/event/:org/:meeting" do
45
- if params[:org] == UCE_ORG && params[:meeting] == UCE_MEETING
44
+ get "/api/#{VERSION}/event/:meeting" do
45
+ if params[:meeting] == UCE_MEETING
46
46
  if params[:type] == "test.event"
47
47
  status 200
48
48
  {:result => [{:id => "12345",
49
49
  :type => "test.event",
50
50
  :datetime => 1234,
51
- :org => UCE_ORG,
52
51
  :meeting => UCE_MEETING,
53
52
  :metadata => {},
54
53
  :from => "frank"
@@ -64,8 +63,8 @@ class UCEngineMock < Sinatra::Base
64
63
  end
65
64
 
66
65
  # Download
67
- get "/api/#{VERSION}/file/:org/:meeting/:id" do
68
- if params[:org] == UCE_ORG && params[:meeting] == UCE_MEETING && params[:id] == "test_file"
66
+ get "/api/#{VERSION}/file/:meeting/:id" do
67
+ if params[:meeting] == UCE_MEETING && params[:id] == "test_file"
69
68
  status 200
70
69
  FILE_CONTENT
71
70
  else
@@ -75,8 +74,8 @@ class UCEngineMock < Sinatra::Base
75
74
  end
76
75
 
77
76
  # Upload
78
- post "/api/#{VERSION}/file/:org/:meeting" do
79
- if params[:org] == UCE_ORG && params[:meeting] == UCE_MEETING
77
+ post "/api/#{VERSION}/file/:meeting" do
78
+ if params[:meeting] == UCE_MEETING
80
79
  if params[:upload][:tempfile].read == FILE_CONTENT
81
80
  status 200
82
81
  {:result => "test_upload"}.to_json
@@ -3,6 +3,10 @@ require 'ucengine_mock'
3
3
 
4
4
  describe UCEngine do
5
5
 
6
+ before do
7
+ @uce = UCEngine.new(UCE_HOST, UCE_PORT)
8
+ end
9
+
6
10
  before(:all) do
7
11
  Thread.new do
8
12
  UCEngineMock.run! :host => UCE_HOST, :port => UCE_PORT
@@ -10,41 +14,46 @@ describe UCEngine do
10
14
  sleep 5
11
15
  end
12
16
 
13
- after do
14
- end
15
-
16
17
  it "connects to the UCEngine server" do
17
- uce = UCEngine.new(UCE_HOST, UCE_PORT)
18
- uce.connect(USER, :credential => PASSWORD) do |uce|
18
+ @uce.connect(USER, :credential => PASSWORD) do |uce|
19
19
  uce.sid.should eql("test_sid")
20
+ uce.should be_connected
21
+ end
22
+ end
23
+
24
+ it "connect with bad credential" do
25
+ @uce.connect(USER, :credential => PASSWORD + "toto") do |uce|
26
+ uce.should_not be_connected
27
+ end
28
+ end
29
+
30
+ it "should respond to connected?" do
31
+ @uce.connect(USER, :credential => PASSWORD) do |uce|
32
+ uce.respond_to?(:connected?).should eql true
20
33
  end
21
34
  end
22
35
 
23
36
  it "fails to connect to the UCEngine server" do
24
37
  begin
25
- did_connect = false
26
- uce = UCEngine.new("localhost", 65000)
38
+ uce = UCEngine.new("localhost", UCE_PORT + 1)
27
39
  uce.connect(USER, :credential => PASSWORD) do |uce|
28
- did_connect = true
29
40
  break
30
41
  end
31
42
  rescue
32
43
  ensure
33
- did_connect.should eql(false)
44
+ uce.should_not be_connected
34
45
  end
35
46
  end
36
47
 
37
48
  it "returns the current datetime of the server" do
38
- uce = UCEngine.new(UCE_HOST, UCE_PORT)
39
- uce.connect(USER, :credential => PASSWORD) do |uce|
40
- uce.time.should eql(1234)
49
+ @uce.connect(USER, :credential => PASSWORD) do |uce|
50
+ uce.time.should eql 1234
41
51
  end
42
- end
52
+ end
43
53
 
44
54
  it "publishes an event" do
45
- uce = UCEngine.new(UCE_HOST, UCE_PORT)
46
- uce.connect(USER, :credential => PASSWORD) do |uce|
47
- result = uce.publish(:location => [UCE_ORG, UCE_MEETING],
55
+ @uce.connect(USER, :credential => PASSWORD) do |uce|
56
+ result = uce.publish(:location => [UCE_MEETING],
48
57
  :type => "test_type",
49
58
  :parent => "test_parent",
50
59
  :metadata => {"a" => "b", "c" => "d"})
@@ -53,13 +62,11 @@ describe UCEngine do
53
62
  end
54
63
 
55
64
  it "subscribes to all events" do
56
- uce = UCEngine.new(UCE_HOST, UCE_PORT)
57
- uce.connect(USER, :credential => PASSWORD) do |uce|
58
- uce.subscribe([UCE_ORG, UCE_MEETING], :type => "test.event") do |event|
65
+ @uce.connect(USER, :credential => PASSWORD) do |uce|
66
+ uce.subscribe([UCE_MEETING], :type => "test.event") do |event|
59
67
  event['id'].should eql("12345")
60
68
  event['type'].should eql("test.event")
61
69
  event['datetime'].should eql(1234)
62
- event['org'].should eql(UCE_ORG)
63
70
  event['meeting'].should eql(UCE_MEETING)
64
71
  event['metadata'].should eql({})
65
72
  event['from'].should eql("frank")
@@ -69,19 +76,17 @@ describe UCEngine do
69
76
  end
70
77
 
71
78
  it "downloads a file" do
72
- uce = UCEngine.new(UCE_HOST, UCE_PORT)
73
- uce.connect(USER, :credential => PASSWORD) do |uce|
74
- result = uce.download([UCE_ORG, UCE_MEETING], "test_file")
79
+ @uce.connect(USER, :credential => PASSWORD) do |uce|
80
+ result = uce.download(UCE_MEETING, "test_file")
75
81
  result.should eql(FILE_CONTENT)
76
82
  end
77
83
  end
78
84
 
79
85
  it "uploads a file" do
80
- uce = UCEngine.new(UCE_HOST, UCE_PORT)
81
- uce.connect(USER, :credential => PASSWORD) do |uce|
86
+ @uce.connect(USER, :credential => PASSWORD) do |uce|
82
87
  file = Tempfile.open("test_file")
83
88
  file.write(FILE_CONTENT)
84
- result = uce.upload([UCE_ORG, UCE_MEETING], file.open)
89
+ result = uce.upload(UCE_MEETING, file.open)
85
90
  result['result'].should eql("test_upload")
86
91
  break
87
92
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
7
  - 2
9
- version: 0.1.2
8
+ - 0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - AF83
@@ -14,52 +14,35 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-31 00:00:00 +01:00
17
+ date: 2010-12-01 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: json
21
+ name: thoughtbot-shoulda
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
25
25
  requirements:
26
- - - ~>
26
+ - - ">="
27
27
  - !ruby/object:Gem::Version
28
28
  segments:
29
- - 1
30
- - 4
31
- version: "1.4"
32
- type: :runtime
29
+ - 0
30
+ version: "0"
31
+ type: :development
33
32
  version_requirements: *id001
34
33
  - !ruby/object:Gem::Dependency
35
- name: rest-client
34
+ name: json
36
35
  prerelease: false
37
36
  requirement: &id002 !ruby/object:Gem::Requirement
38
37
  none: false
39
38
  requirements:
40
- - - ~>
39
+ - - ">="
41
40
  - !ruby/object:Gem::Version
42
41
  segments:
43
- - 1
44
- - 6
45
- version: "1.6"
46
- type: :runtime
47
- version_requirements: *id002
48
- - !ruby/object:Gem::Dependency
49
- name: daemons
50
- prerelease: false
51
- requirement: &id003 !ruby/object:Gem::Requirement
52
- none: false
53
- requirements:
54
- - - ~>
55
- - !ruby/object:Gem::Version
56
- segments:
57
- - 1
58
- - 1
59
42
  - 0
60
- version: 1.1.0
43
+ version: "0"
61
44
  type: :runtime
62
- version_requirements: *id003
45
+ version_requirements: *id002
63
46
  description: ucengine.rb is a Ruby library to consume the UCEngine API
64
47
  email: victor.goya@af83.com
65
48
  executables: []
@@ -71,6 +54,7 @@ extra_rdoc_files:
71
54
  - README.rdoc
72
55
  files:
73
56
  - .document
57
+ - .gitignore
74
58
  - LICENSE
75
59
  - README.rdoc
76
60
  - Rakefile
@@ -109,15 +93,14 @@ files:
109
93
  - spec/spec_helper.rb
110
94
  - spec/ucengine_mock.rb
111
95
  - spec/ucengine_spec.rb
112
- - ucengine.gemspec
113
96
  - ucengine.rb.gemspec
114
97
  has_rdoc: true
115
98
  homepage: http://github.com/AF83/ucengine.rb
116
99
  licenses: []
117
100
 
118
101
  post_install_message:
119
- rdoc_options: []
120
-
102
+ rdoc_options:
103
+ - --charset=UTF-8
121
104
  require_paths:
122
105
  - lib
123
106
  required_ruby_version: !ruby/object:Gem::Requirement
data/ucengine.gemspec DELETED
@@ -1,87 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{ucengine}
8
- s.version = "0.1.2"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["AF83"]
12
- s.date = %q{2010-12-01}
13
- s.description = %q{ucengine.rb is a Ruby library to consume the UCEngine API}
14
- s.email = %q{victor.goya@af83.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "doc/UCEngine.html",
27
- "doc/UCEngine/Debug.html",
28
- "doc/created.rid",
29
- "doc/images/brick.png",
30
- "doc/images/brick_link.png",
31
- "doc/images/bug.png",
32
- "doc/images/bullet_black.png",
33
- "doc/images/bullet_toggle_minus.png",
34
- "doc/images/bullet_toggle_plus.png",
35
- "doc/images/date.png",
36
- "doc/images/find.png",
37
- "doc/images/loadingAnimation.gif",
38
- "doc/images/macFFBgHack.png",
39
- "doc/images/package.png",
40
- "doc/images/page_green.png",
41
- "doc/images/page_white_text.png",
42
- "doc/images/page_white_width.png",
43
- "doc/images/plugin.png",
44
- "doc/images/ruby.png",
45
- "doc/images/tag_green.png",
46
- "doc/images/wrench.png",
47
- "doc/images/wrench_orange.png",
48
- "doc/images/zoom.png",
49
- "doc/index.html",
50
- "doc/js/darkfish.js",
51
- "doc/js/jquery.js",
52
- "doc/js/quicksearch.js",
53
- "doc/js/thickbox-compressed.js",
54
- "doc/lib/ucengine_rb.html",
55
- "doc/rdoc.css",
56
- "lib/ucengine.rb",
57
- "test/helper.rb",
58
- "test/test_ucengine.rb",
59
- "ucengine.rb.gemspec"
60
- ]
61
- s.homepage = %q{http://github.com/AF83/ucengine.rb}
62
- s.rdoc_options = ["--charset=UTF-8"]
63
- s.require_paths = ["lib"]
64
- s.rubygems_version = %q{1.3.7}
65
- s.summary = %q{Ruby library for UCEngine}
66
- s.test_files = [
67
- "test/helper.rb",
68
- "test/test_ucengine.rb"
69
- ]
70
-
71
- if s.respond_to? :specification_version then
72
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
73
- s.specification_version = 3
74
-
75
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
76
- s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
77
- s.add_runtime_dependency(%q<json>, [">= 0"])
78
- else
79
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
80
- s.add_dependency(%q<json>, [">= 0"])
81
- end
82
- else
83
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
84
- s.add_dependency(%q<json>, [">= 0"])
85
- end
86
- end
87
-