openfire_room_api 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c72a2b81197e2a4668af35a7c07650fd6ad9c1e0
4
+ data.tar.gz: 82e3d90e9886f15dc6ebd8f2ccbce46abca545f0
5
+ SHA512:
6
+ metadata.gz: b1ab53027b3a21d27a379553eaa4e36f5898b06dd4499170428c66f8e6c25a4bdaf8ca8e7f5d2a8530f74a20dd069b708513a99e3c50f558864702e4bc0b1f78
7
+ data.tar.gz: 8a0f4e8b5e3be9a7fcbbd8efc3e873630cc92c2e56875b7d58183e960b5ac41c55f8b193972045355f42325eb437c0fb6092e914dbff4844d20984286162ca82
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :development do
4
+ gem "rspec"
5
+ gem "shoulda"
6
+ gem "jeweler"
7
+ gem 'fakeweb'
8
+ end
@@ -0,0 +1,82 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (4.0.0)
5
+ i18n (~> 0.6, >= 0.6.4)
6
+ minitest (~> 4.2)
7
+ multi_json (~> 1.3)
8
+ thread_safe (~> 0.1)
9
+ tzinfo (~> 0.3.37)
10
+ addressable (2.3.5)
11
+ atomic (1.1.14)
12
+ builder (3.2.2)
13
+ diff-lcs (1.2.4)
14
+ fakeweb (1.3.0)
15
+ faraday (0.8.8)
16
+ multipart-post (~> 1.2.0)
17
+ git (1.2.6)
18
+ github_api (0.10.1)
19
+ addressable
20
+ faraday (~> 0.8.1)
21
+ hashie (>= 1.2)
22
+ multi_json (~> 1.4)
23
+ nokogiri (~> 1.5.2)
24
+ oauth2
25
+ hashie (2.0.5)
26
+ highline (1.6.19)
27
+ httpauth (0.2.0)
28
+ i18n (0.6.5)
29
+ jeweler (1.8.7)
30
+ builder
31
+ bundler (~> 1.0)
32
+ git (>= 1.2.5)
33
+ github_api (= 0.10.1)
34
+ highline (>= 1.6.15)
35
+ nokogiri (= 1.5.10)
36
+ rake
37
+ rdoc
38
+ json (1.8.0)
39
+ jwt (0.1.8)
40
+ multi_json (>= 1.5)
41
+ minitest (4.7.5)
42
+ multi_json (1.8.1)
43
+ multi_xml (0.5.5)
44
+ multipart-post (1.2.0)
45
+ nokogiri (1.5.10)
46
+ oauth2 (0.9.2)
47
+ faraday (~> 0.8)
48
+ httpauth (~> 0.2)
49
+ jwt (~> 0.1.4)
50
+ multi_json (~> 1.0)
51
+ multi_xml (~> 0.5)
52
+ rack (~> 1.2)
53
+ rack (1.5.2)
54
+ rake (10.1.0)
55
+ rdoc (4.0.1)
56
+ json (~> 1.4)
57
+ rspec (2.14.1)
58
+ rspec-core (~> 2.14.0)
59
+ rspec-expectations (~> 2.14.0)
60
+ rspec-mocks (~> 2.14.0)
61
+ rspec-core (2.14.5)
62
+ rspec-expectations (2.14.3)
63
+ diff-lcs (>= 1.1.3, < 2.0)
64
+ rspec-mocks (2.14.3)
65
+ shoulda (3.5.0)
66
+ shoulda-context (~> 1.0, >= 1.0.1)
67
+ shoulda-matchers (>= 1.4.1, < 3.0)
68
+ shoulda-context (1.1.5)
69
+ shoulda-matchers (2.4.0)
70
+ activesupport (>= 3.0.0)
71
+ thread_safe (0.1.3)
72
+ atomic
73
+ tzinfo (0.3.37)
74
+
75
+ PLATFORMS
76
+ ruby
77
+
78
+ DEPENDENCIES
79
+ fakeweb
80
+ jeweler
81
+ rspec
82
+ shoulda
@@ -0,0 +1,23 @@
1
+ # openfire_room_api
2
+
3
+ a ruby client for openfire's room_service api
4
+
5
+ ## Installation
6
+
7
+ In your Gemfile
8
+
9
+ gem "openfire_room_api"
10
+
11
+ ## Usage
12
+
13
+ create a new roomservice object
14
+
15
+ api = OpenfireRoomApi::RoomService.new(:url => "http://localhost:9090/", :secret => "BIGSECRET")
16
+
17
+ create a new room
18
+
19
+ api.add_room!(:roomname => "room", :jid => "jid", :subdomain => "groupchat")
20
+
21
+ delete a room
22
+
23
+ api.delete_room!(:roomname => "room", :subdomain => "groupchat")
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ gem.name = "openfire_room_api"
15
+ gem.homepage = "https://github.com/wecapslabs/openfire_room_api"
16
+ gem.summary = %Q{ruby client for the openfire roomservice api}
17
+ gem.description = %Q{ruby client for the openfire xmpp-server room_service api}
18
+ gem.email = "flyerhzm@gmail.com"
19
+ gem.authors = ["Richard Huang"]
20
+ end
21
+ Jeweler::RubygemsDotOrgTasks.new
22
+
23
+ require 'rspec'
24
+ require 'rspec/core/rake_task'
25
+ desc "Run all examples"
26
+ task RSpec::Core::RakeTask.new('spec')
27
+
28
+ task :default => :spec
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,6 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+
4
+ module OpenfireRoomApi; end
5
+
6
+ require 'openfire_room_api/room_service'
@@ -0,0 +1,64 @@
1
+ class OpenfireRoomApi::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)
48
+ http = Net::HTTP.new(uri.host, uri.port)
49
+ resp = http.get("#{uri.path}?#{params}")
50
+ return resp.body
51
+ rescue Exception => e
52
+ raise HTTPException, e.to_s
53
+ end
54
+
55
+ def parse_response(data)
56
+ error = data.match(/<error>(.*)<\/error>/)
57
+ if error && @@api_exceptions.include?(error[1])
58
+ raise eval("#{error[1].gsub('Exception', '')}Exception")
59
+ end
60
+ raise InvalidResponseException unless data.match(/<result>ok<\/result>/)
61
+ return true
62
+ end
63
+
64
+ end
@@ -0,0 +1,56 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "openfire_room_api"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Richard Huang"]
12
+ s.date = "2013-10-06"
13
+ s.description = "ruby client for the openfire xmpp-server room_service api"
14
+ s.email = "flyerhzm@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ "Gemfile",
20
+ "Gemfile.lock",
21
+ "README.md",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "lib/openfire_room_api.rb",
25
+ "lib/openfire_room_api/room_service.rb",
26
+ "openfire_room_api.gemspec",
27
+ "spec/room_service_spec.rb",
28
+ "spec/spec_helper.rb"
29
+ ]
30
+ s.homepage = "https://github.com/wecapslabs/openfire_room_api"
31
+ s.require_paths = ["lib"]
32
+ s.rubygems_version = "2.0.6"
33
+ s.summary = "ruby client for the openfire roomservice api"
34
+
35
+ if s.respond_to? :specification_version then
36
+ s.specification_version = 4
37
+
38
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
39
+ s.add_development_dependency(%q<rspec>, [">= 0"])
40
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
41
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
42
+ s.add_development_dependency(%q<fakeweb>, [">= 0"])
43
+ else
44
+ s.add_dependency(%q<rspec>, [">= 0"])
45
+ s.add_dependency(%q<shoulda>, [">= 0"])
46
+ s.add_dependency(%q<jeweler>, [">= 0"])
47
+ s.add_dependency(%q<fakeweb>, [">= 0"])
48
+ end
49
+ else
50
+ s.add_dependency(%q<rspec>, [">= 0"])
51
+ s.add_dependency(%q<shoulda>, [">= 0"])
52
+ s.add_dependency(%q<jeweler>, [">= 0"])
53
+ s.add_dependency(%q<fakeweb>, [">= 0"])
54
+ end
55
+ end
56
+
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Room Service" do
4
+
5
+ before :all do
6
+ @room_service = OpenfireRoomApi::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(OpenfireRoomApi::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(OpenfireRoomApi::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(OpenfireRoomApi::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(OpenfireRoomApi::RoomService::IllegalArgumentException)
64
+ end
65
+
66
+ end
67
+
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'rspec'
3
+ require 'fakeweb'
4
+
5
+ FakeWeb.allow_net_connect = false
6
+
7
+ $: << ::File.expand_path('../../lib', __FILE__)
8
+ require 'openfire_room_api'
9
+
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: openfire_room_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Richard Huang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: shoulda
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: jeweler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: fakeweb
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: ruby client for the openfire xmpp-server room_service api
70
+ email: flyerhzm@gmail.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files:
74
+ - README.md
75
+ files:
76
+ - Gemfile
77
+ - Gemfile.lock
78
+ - README.md
79
+ - Rakefile
80
+ - VERSION
81
+ - lib/openfire_room_api.rb
82
+ - lib/openfire_room_api/room_service.rb
83
+ - openfire_room_api.gemspec
84
+ - spec/room_service_spec.rb
85
+ - spec/spec_helper.rb
86
+ homepage: https://github.com/wecapslabs/openfire_room_api
87
+ licenses: []
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.0.6
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: ruby client for the openfire roomservice api
109
+ test_files: []