jabber_admin 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e4cebb5bfc66b3d12539e9f8c338cc049cfcc92f
4
+ data.tar.gz: 9fdd9fc1237d6124d2d69a6f7f252c1c6b72fb3e
5
+ SHA512:
6
+ metadata.gz: d5efa557ffb0608dfdb83b17e8db173feb563c77203d8c29ecf6df868867be1c0d0928da3c9dd69891957fcee90f930b97b25545810625a091b16a19595bd8bc
7
+ data.tar.gz: 50a2a5e468057f57a8474091788105c1e2dead917bdc8b77cb04996558f43ad9188c6ef0e90fb1a8bc9b55c77e021f313dc71b1aaa9375d099c570bd960c21ee
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,16 @@
1
+ env:
2
+ global:
3
+ - CC_TEST_REPORTER_ID=02d696c72627e730a3db553884276acf15672466e32e66a788672d3b167629ca
4
+ sudo: false
5
+ language: ruby
6
+ rvm:
7
+ - 2.2
8
+ - 2.3
9
+ - 2.4
10
+ before_install: gem install bundler -v 1.15.1
11
+ before_script:
12
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
13
+ - chmod +x ./cc-test-reporter
14
+ - ./cc-test-reporter before-build
15
+ after_script:
16
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in jabber_admin.gemspec
6
+ gemspec
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # JabberAdmin
2
+
3
+ [![Maintainability](https://api.codeclimate.com/v1/badges/0b3c444d8db8acaaba97/maintainability)](https://codeclimate.com/github/hausgold/jabber_admin/maintainability)
4
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/0b3c444d8db8acaaba97/test_coverage)](https://codeclimate.com/github/hausgold/jabber_admin/test_coverage)
5
+
6
+ JabberAdmin is a small library to easily communicate with the Ejabberd
7
+ admin API.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'jabber_admin'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install jabber_admin
24
+
25
+ ## Usage
26
+
27
+ ``` ruby
28
+ JabberAdmin.restart!
29
+ JabberAdmin.create_room!(name: 'room1', host: '...')
30
+ ```
31
+
32
+ Currently these basic commands are supported:
33
+
34
+ - ban_account
35
+ - create_room
36
+ - register
37
+ - restart
38
+ - send_direct_invitation
39
+ - subscribe_room
40
+ - unregister
41
+ - unsubscribe_room
42
+
43
+ ## Development
44
+
45
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
46
+
47
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
48
+
49
+ ## Contributing
50
+
51
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hausgold/jabber_admin.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "jabber_admin"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,42 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "jabber_admin/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jabber_admin"
8
+ spec.version = JabberAdmin::VERSION
9
+ spec.authors = ["Henning Vogt"]
10
+ spec.licenses = ['MIT']
11
+ spec.email = ["henning.vogt@hausgold.de"]
12
+
13
+ spec.summary = %q{Library for the Ejabberd RESTful admin API}
14
+ spec.description = %q{Library for the Ejabberd RESTful admin API}
15
+ spec.homepage = "https://github.com/hausgold/jabber_admin"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_dependency 'rest-client', '~> 2.0', '>= 2.0.2'
34
+ spec.add_dependency "activesupport", ">= 5"
35
+
36
+ spec.required_ruby_version = '>= 2.2'
37
+
38
+ spec.add_development_dependency "bundler", "~> 1.16"
39
+ spec.add_development_dependency "rake", "~> 10.0"
40
+ spec.add_development_dependency "rspec", "~> 3.0"
41
+ spec.add_development_dependency "simplecov", "~> 0.15"
42
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JabberAdmin
4
+ # Error that will be raised when API call is not successful
5
+ class ApiError < StandardError; end
6
+
7
+ # Handles the communication with the API
8
+ class ApiCall
9
+ attr_reader :command, :payload
10
+
11
+ def self.perform(command, payload = {})
12
+ new(command, payload).perform
13
+ end
14
+
15
+ def initialize(command, payload)
16
+ @command = command
17
+ @payload = payload
18
+ end
19
+
20
+ def perform
21
+ raise(ApiError, response.to_s) if response.code != 200
22
+
23
+ response
24
+ end
25
+
26
+ private
27
+
28
+ def response
29
+ @res ||= RestClient::Request.execute(
30
+ method: :post,
31
+ url: url,
32
+ user: JabberAdmin.configuration.admin,
33
+ password: JabberAdmin.configuration.password,
34
+ payload: payload.to_json
35
+ )
36
+ end
37
+
38
+ def url
39
+ "#{JabberAdmin.configuration.api_host}/api/#{@command}"
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JabberAdmin
4
+ module Commands
5
+ ##
6
+ # Ban an account: kick sessions and set random password
7
+ # https://docs.ejabberd.im/developer/ejabberd-api/admin-api/#ban-account-ban-an-account-kick-sessions-and-set-random-password
8
+ class BanAccount
9
+ # @param [user] The user
10
+ # @param [host] Server name
11
+ # @param [reason] Reason for banning user
12
+ def self.call(user:, host:, reason:)
13
+ JabberAdmin::ApiCall.perform(
14
+ 'ban_account', user: user, host: host, reason: reason
15
+ )
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JabberAdmin
4
+ module Commands
5
+ ##
6
+ # Create a MUC room name@service in host
7
+ # https://docs.ejabberd.im/developer/ejabberd-api/admin-api/#create-room-create-a-muc-room-name-service-in-host
8
+ class CreateRoom
9
+ # @param [name] The room name
10
+ # @param [service] MUC service
11
+ # @param [host] Server host
12
+ def self.call(name:, service:, host:)
13
+ JabberAdmin::ApiCall.perform(
14
+ 'create_room', name: name, service: service, host: host
15
+ )
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JabberAdmin
4
+ module Commands
5
+ ##
6
+ # Create a MUC room name@service in host
7
+ # https://docs.ejabberd.im/developer/ejabberd-api/admin-api/#create-room-with-opts-create-a-muc-room-name-service-in-host-with-given-options
8
+ class CreateRoomWithOpts
9
+ # @param [name] The room name
10
+ # @param [service] MUC service
11
+ # @param [host] Server host
12
+ # @param [options] [{ Name::String, Value::String }] List of options
13
+ def self.call(name:, service:, host:, options:)
14
+ JabberAdmin::ApiCall.perform(
15
+ 'create_room_with_opts', name: name,
16
+ service: service,
17
+ host: host,
18
+ options: options
19
+ )
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JabberAdmin
4
+ module Commands
5
+ ##
6
+ # Register a user
7
+ # https://docs.ejabberd.im/developer/ejabberd-api/admin-api/#register-register-a-user
8
+ class Register
9
+ # @param [user] The username
10
+ # @param [host] Local vhost served by ejabberd
11
+ # @param [password] The password
12
+ def self.call(user:, host:, password:)
13
+ JabberAdmin::ApiCall.perform(
14
+ 'register',
15
+ user: user, host: host, password: password
16
+ )
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JabberAdmin
4
+ module Commands
5
+ ##
6
+ # Restart ejabberd gracefully
7
+ # https://docs.ejabberd.im/developer/ejabberd-api/admin-api/#restart-restart-ejabberd-gracefully
8
+ class Restart
9
+ def self.call
10
+ JabberAdmin::ApiCall.perform 'restart'
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JabberAdmin
4
+ module Commands
5
+ ##
6
+ # Password and Message can also be: none. Users JIDs are separated with :
7
+ # https://docs.ejabberd.im/developer/ejabberd-api/admin-api/#send-direct-invitation-send-a-direct-invitation-to-several-destinations
8
+ class SendDirectInvitation
9
+ # @param [name] The room name
10
+ # @param [service] MUC service
11
+ # @param [password] Password, or none
12
+ # @param [reason] The reason text, or none
13
+ # @param [users] Users JIDs
14
+ def self.call(name:, service:, password:, reason:, users:)
15
+ joined_users = users.join(':')
16
+
17
+ JabberAdmin::ApiCall.perform(
18
+ 'send_direct_invitation',
19
+ name: name, service: service, password: password, reason: reason,
20
+ users: joined_users
21
+ )
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JabberAdmin
4
+ module Commands
5
+ ##
6
+ # Subscribe to a MUC conference
7
+ # https://docs.ejabberd.im/developer/ejabberd-api/admin-api/#subscribe-room-subscribe-to-a-muc-conference
8
+ class SubscribeRoom
9
+ # @param [user] Full JID, including some resource
10
+ # @param [nick] A user's nick
11
+ # @param [room] The room to subscribe
12
+ # @param [nodes] nodes
13
+ def self.call(user:, nick:, room:, nodes:)
14
+ JabberAdmin::ApiCall.perform(
15
+ 'subscribe_room',
16
+ user: user, nick: nick, room: room, nodes: nodes
17
+ )
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JabberAdmin
4
+ module Commands
5
+ ##
6
+ # Unregister a user
7
+ # https://docs.ejabberd.im/developer/ejabberd-api/admin-api/#unregister-unregister-a-user
8
+ class Unregister
9
+ # @param [user] The username
10
+ # @param [host] Local vhost served by ejabberd
11
+ def self.call(user:, host:)
12
+ JabberAdmin::ApiCall.perform 'unregister', user: user, host: host
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JabberAdmin
4
+ module Commands
5
+ ##
6
+ # Subscribe to a MUC conference
7
+ # https://docs.ejabberd.im/developer/ejabberd-api/admin-api/#unsubscribe-room-unsubscribe-from-a-muc-conference
8
+ class UnsubscribeRoom
9
+ # @param [user] Full JID, including some resource
10
+ # @param [room] The room to subscribe
11
+ def self.call(user:, room:)
12
+ JabberAdmin::ApiCall.perform 'unsubscribe_room', user: user, room: room
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'jabber_admin/commands/ban_account'
4
+ require 'jabber_admin/commands/create_room'
5
+ require 'jabber_admin/commands/create_room_with_opts'
6
+ require 'jabber_admin/commands/register'
7
+ require 'jabber_admin/commands/restart'
8
+ require 'jabber_admin/commands/send_direct_invitation'
9
+ require 'jabber_admin/commands/subscribe_room'
10
+ require 'jabber_admin/commands/unsubscribe_room'
11
+ require 'jabber_admin/commands/unregister'
12
+
13
+ ##
14
+ # Contains alle commands that are supported
15
+ module JabberAdmin
16
+ module Commands; end
17
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JabberAdmin
4
+ class Configuration
5
+ attr_accessor :admin, :password, :api_host
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JabberAdmin
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/inflector"
4
+ require "rest-client"
5
+
6
+ require "jabber_admin/configuration"
7
+ require "jabber_admin/commands"
8
+ require "jabber_admin/api_call"
9
+ require "jabber_admin/version"
10
+
11
+ ##
12
+ # Jabber Admin Library
13
+ #
14
+ # allows making API calls to the ejabberd RESTful admin backend
15
+ # All supported commands are available in /lib/jabber_admin/commands/
16
+ #
17
+ # Usage:
18
+ # All commands can be called via JabberAdmin.[method_name]!
19
+ # (Do not forget the bang at the end)
20
+ #
21
+ # @example:
22
+ # JabberAdmin.register!(user: 'peter', 'host': 'example.com', password: '123')
23
+ # JabberAdmin.unregister!(user: 'peter', 'host': 'example.com')
24
+ # JabberAdmin.restart!
25
+ #
26
+ module JabberAdmin
27
+ class << self
28
+ attr_writer :configuration
29
+ end
30
+
31
+ # @return [JabberAdmin::Configuration] The global JabberAdmin configuration
32
+ def self.configuration
33
+ @configuration ||= JabberAdmin::Configuration.new
34
+ end
35
+
36
+ # Class method to set and change the global configuration
37
+ #
38
+ # @example
39
+ # JabberAdmin.configure do |config|
40
+ # config.api_host = 'xmpp.example.com'
41
+ # config.admin = 'admin'
42
+ # config.password = 'password'
43
+ # end
44
+ def self.configure
45
+ yield(configuration)
46
+ end
47
+
48
+ def self.method_missing(method, *args, &block)
49
+ command = "jabber_admin/commands/#{method[0..-2]}".classify.constantize
50
+ args.empty? ? command.call : command.call(*args)
51
+ rescue NameError
52
+ super
53
+ end
54
+
55
+ def self.respond_to_missing?(method, include_private = false)
56
+ "jabber_admin/commands/#{method[0..-2]}".classify.constantize && true
57
+ rescue NameError
58
+ super
59
+ end
60
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jabber_admin
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Henning Vogt
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-01-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.0.2
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '2.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.0.2
33
+ - !ruby/object:Gem::Dependency
34
+ name: activesupport
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '5'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '5'
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.16'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.16'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '10.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '10.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '3.0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '3.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: simplecov
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '0.15'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '0.15'
103
+ description: Library for the Ejabberd RESTful admin API
104
+ email:
105
+ - henning.vogt@hausgold.de
106
+ executables: []
107
+ extensions: []
108
+ extra_rdoc_files: []
109
+ files:
110
+ - ".gitignore"
111
+ - ".rspec"
112
+ - ".travis.yml"
113
+ - Gemfile
114
+ - README.md
115
+ - Rakefile
116
+ - bin/console
117
+ - bin/setup
118
+ - jabber_admin.gemspec
119
+ - lib/jabber_admin.rb
120
+ - lib/jabber_admin/api_call.rb
121
+ - lib/jabber_admin/commands.rb
122
+ - lib/jabber_admin/commands/ban_account.rb
123
+ - lib/jabber_admin/commands/create_room.rb
124
+ - lib/jabber_admin/commands/create_room_with_opts.rb
125
+ - lib/jabber_admin/commands/register.rb
126
+ - lib/jabber_admin/commands/restart.rb
127
+ - lib/jabber_admin/commands/send_direct_invitation.rb
128
+ - lib/jabber_admin/commands/subscribe_room.rb
129
+ - lib/jabber_admin/commands/unregister.rb
130
+ - lib/jabber_admin/commands/unsubscribe_room.rb
131
+ - lib/jabber_admin/configuration.rb
132
+ - lib/jabber_admin/version.rb
133
+ homepage: https://github.com/hausgold/jabber_admin
134
+ licenses:
135
+ - MIT
136
+ metadata:
137
+ allowed_push_host: https://rubygems.org
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '2.2'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.6.11
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: Library for the Ejabberd RESTful admin API
158
+ test_files: []