openfire_api_ruby 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b989f93996d043b4923147d0bff52689609202ce
4
- data.tar.gz: c57316b6b942cc68772ca7d69f06d792001286b3
3
+ metadata.gz: 0665f2a6e0f332baf868a0c3a7adbca72d5bdbfb
4
+ data.tar.gz: 4b9084eafbdb32fe81bc3a95314773a3518fea00
5
5
  SHA512:
6
- metadata.gz: 218a3cd3d0e0e62bab1aa87e0cef725977dac402e4a77b5b1290c95a06b9a14f612adcdfae4e45c50f2b93c8727e9adab3681d548f3f1f29a1eca1c8da5cbc11
7
- data.tar.gz: 05cb717e6f584b855b3c14b521377b82461e5fccf748abedae47ec20cd2204e3af6aee87d4f23a15f858c7038c4e1fb4e030a8125952438d5ab86324dbd835eb
6
+ metadata.gz: 8d8a2590d433ba465408cc951e09620baa78accf1ef8a3d693dbaaeebfe03d7d249315403d8b579e99cfb3b9b7db584a59f03e2d8245fadf83defcb62fce22a8
7
+ data.tar.gz: eb772d67448822d22d4768ffbac746498756bfb34081c6bd6b77ebc70d29f07a0f059fdafaf2d4d81c17ac577fc740e8f4474a6be6380bdb87b43ce7415f75b4
@@ -0,0 +1,65 @@
1
+ class OpenfireApiRuby::RoomService
2
+
3
+ @@api_path = "plugins/roomService/roomservice"
4
+ @@api_exceptions = %w(RoomServiceDisabled RequestNotAuthorised NotAllowedException IllegalArgumentException)
5
+
6
+ class HTTPException < StandardError; end
7
+ class InvalidResponseException < StandardError; end
8
+ class RoomServiceDisabledException < StandardError; end
9
+ class RequestNotAuthorisedException < StandardError; end
10
+ class NotAllowedException < StandardError; end
11
+ class IllegalArgumentException < StandardError; end
12
+
13
+ def initialize(options=Hash.new)
14
+ @options = { :path => @@api_path }.merge(options)
15
+ end
16
+
17
+ def add_room!(opts)
18
+ submit_request(opts.merge(:type => :add))
19
+ end
20
+
21
+ def delete_room!(opts)
22
+ submit_request(opts.merge(:type => :delete))
23
+ end
24
+
25
+ private
26
+
27
+ def build_query(params)
28
+ "#{build_query_uri.to_s}?#{build_query_params(params)}"
29
+ end
30
+
31
+ def build_query_uri
32
+ uri = URI.parse(@options[:url])
33
+ uri.path = File.join(uri.path, @@api_path)
34
+ uri
35
+ end
36
+
37
+ def build_query_params(params)
38
+ params.merge!(:secret => @options[:secret])
39
+ params.to_a.map{ |p| "#{p[0]}=#{p[1]}" }.join('&')
40
+ end
41
+
42
+ def submit_request(params)
43
+ data = submit_http_request(build_query_uri, build_query_params(params))
44
+ parse_response(data)
45
+ end
46
+
47
+ def submit_http_request(uri, params_as_string)
48
+ uri.query = URI.encode(params_as_string)
49
+ res = Net::HTTP.get_response(uri)
50
+
51
+ return res.body
52
+ rescue Exception => e
53
+ raise HTTPException, e.to_s
54
+ end
55
+
56
+ def parse_response(data)
57
+ error = data.match(/<error>(.*)<\/error>/)
58
+ if error && @@api_exceptions.include?(error[1])
59
+ raise eval("#{error[1].gsub('Exception', '')}Exception")
60
+ end
61
+ raise InvalidResponseException unless data.match(/<result>ok<\/result>/)
62
+ return true
63
+ end
64
+
65
+ end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{openfire_api_ruby}
8
- s.version = "0.3.1"
8
+ s.version = "0.3.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Babu"]
@@ -20,10 +20,12 @@ Gem::Specification.new do |s|
20
20
  "lib/openfire_api_ruby.rb",
21
21
  "lib/openfire_api_ruby/user_service.rb",
22
22
  "lib/openfire_api_ruby/group_service.rb",
23
+ "lib/openfire_api_ruby/room_service.rb",
23
24
  "openfire_api_ruby.gemspec",
24
25
  "readme.rdoc",
25
26
  "spec/spec_helper.rb",
26
- "spec/user_service_spec.rb"
27
+ "spec/user_service_spec.rb",
28
+ "spec/room_service_spec.rb"
27
29
  ]
28
30
  s.homepage = %q{http://github.com/babu3009/openfire_api_ruby}
29
31
  s.require_paths = ["lib"]
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Room Service" do
4
+
5
+ before :all do
6
+ @room_service = OpenfireApiRuby::RoomService.new(:url => "http://fakehost.int:2323/", :secret => "bigsecret")
7
+ end
8
+
9
+ it "should build query urls" do
10
+ url = @room_service.send(:build_query_uri)
11
+ url.to_s.should == "http://fakehost.int:2323/plugins/roomService/roomservice"
12
+ end
13
+
14
+ it "should build query params" do
15
+ params = @room_service.send(:build_query_params, :type => :add, :roomname => "room", :subdomain => "groupchat")
16
+ params.should include("type=add")
17
+ params.should include("roomname=room")
18
+ params.should include("subdomain=groupchat")
19
+ params.should include("secret=bigsecret")
20
+ end
21
+
22
+ it "should build queries" do
23
+ url = @room_service.send(:build_query, :type => :add, :roomname => "room", :subdomain => "groupchat")
24
+ url.should include("http://fakehost.int:2323/plugins/roomService/roomservice?")
25
+ url.should include("type=add")
26
+ url.should include("roomname=room")
27
+ url.should include("subdomain=groupchat")
28
+ url.should include("secret=bigsecret")
29
+ end
30
+
31
+ it "should submit requests" do
32
+ FakeWeb.register_uri(:get, "http://fakehost.int:2323/plugins/roomService/roomservice?type=add&roomname=room&subdomain=groupchat&secret=bigsecret", :body => "<result>ok</result>")
33
+ @room_service.send(:submit_request, :type => :add, :roomname => "room", :subdomain => "groupchat").should == true
34
+ end
35
+
36
+ it "should add rooms" do
37
+ FakeWeb.register_uri(:get, "http://fakehost.int:2323/plugins/roomService/roomservice?type=add&roomname=room&subdomain=groupchat&secret=bigsecret", :body => "<result>ok</result>")
38
+ @room_service.add_room!(:roomname => "room", :subdomain => "groupchat").should == true
39
+ end
40
+
41
+ it "should delete rooms" do
42
+ FakeWeb.register_uri(:get, "http://fakehost.int:2323/plugins/roomService/roomservice?type=delete&roomname=room&subdomain=groupchat&secret=bigsecret", :body => "<result>ok</result>")
43
+ @room_service.delete_room!(:roomname => "room", :subdomain => "groupchat").should == true
44
+ end
45
+
46
+ it "should handle the error: room service disabled" do
47
+ FakeWeb.register_uri(:get, "http://fakehost.int:2323/plugins/roomService/roomservice?roomname=room1&type=add&secret=bigsecret", :body => "<error>RoomServiceDisabled</error>")
48
+ lambda{ @room_service.add_room!(:roomname => "room1") }.should raise_error(OpenfireApiRuby::RoomService::RoomServiceDisabledException)
49
+ end
50
+
51
+ it "should handle the error: request not authorized" do
52
+ FakeWeb.register_uri(:get, "http://fakehost.int:2323/plugins/roomService/roomservice?roomname=room1&type=add&secret=bigsecret", :body => "<error>RequestNotAuthorised</error>")
53
+ lambda{ @room_service.add_room!(:roomname => "room1") }.should raise_error(OpenfireApiRuby::RoomService::RequestNotAuthorisedException)
54
+ end
55
+
56
+ it "should handle the error: not allowed" do
57
+ FakeWeb.register_uri(:get, "http://fakehost.int:2323/plugins/roomService/roomservice?roomname=room1&type=add&secret=bigsecret", :body => "<error>NotAllowedException</error>")
58
+ lambda{ @room_service.add_room!(:roomname => "room1") }.should raise_error(OpenfireApiRuby::RoomService::NotAllowedException)
59
+ end
60
+
61
+ it "should handle the error: illegal argument" do
62
+ FakeWeb.register_uri(:get, "http://fakehost.int:2323/plugins/roomService/roomservice?roomname=room1&type=add&secret=bigsecret", :body => "<error>IllegalArgumentException</error>")
63
+ lambda{ @room_service.add_room!(:roomname => "room1") }.should raise_error(OpenfireApiRuby::RoomService::IllegalArgumentException)
64
+ end
65
+
66
+ end
67
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openfire_api_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Babu
@@ -92,9 +92,11 @@ files:
92
92
  - VERSION
93
93
  - lib/openfire_api_ruby.rb
94
94
  - lib/openfire_api_ruby/group_service.rb
95
+ - lib/openfire_api_ruby/room_service.rb
95
96
  - lib/openfire_api_ruby/user_service.rb
96
97
  - openfire_api_ruby.gemspec
97
98
  - readme.rdoc
99
+ - spec/room_service_spec.rb
98
100
  - spec/spec_helper.rb
99
101
  - spec/user_service_spec.rb
100
102
  homepage: http://github.com/babu3009/openfire_api_ruby