jabber_admin 0.1.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +5 -5
  2. data/.editorconfig +30 -0
  3. data/.gitignore +4 -2
  4. data/.rubocop.yml +35 -0
  5. data/.simplecov +5 -0
  6. data/.travis.yml +8 -6
  7. data/.yardopts +4 -0
  8. data/CHANGELOG.md +49 -0
  9. data/Gemfile +4 -2
  10. data/Makefile +108 -0
  11. data/README.md +145 -21
  12. data/Rakefile +5 -3
  13. data/bin/config.rb +11 -0
  14. data/bin/console +3 -3
  15. data/docker-compose.yml +15 -0
  16. data/jabber_admin.gemspec +34 -27
  17. data/lib/jabber_admin.rb +97 -34
  18. data/lib/jabber_admin/api_call.rb +110 -20
  19. data/lib/jabber_admin/commands.rb +6 -12
  20. data/lib/jabber_admin/commands/ban_account.rb +11 -10
  21. data/lib/jabber_admin/commands/create_room.rb +15 -10
  22. data/lib/jabber_admin/commands/create_room_with_opts.rb +20 -14
  23. data/lib/jabber_admin/commands/get_vcard.rb +84 -0
  24. data/lib/jabber_admin/commands/muc_register_nick.rb +26 -0
  25. data/lib/jabber_admin/commands/register.rb +16 -11
  26. data/lib/jabber_admin/commands/registered_users.rb +18 -0
  27. data/lib/jabber_admin/commands/restart.rb +8 -5
  28. data/lib/jabber_admin/commands/send_direct_invitation.rb +19 -16
  29. data/lib/jabber_admin/commands/send_stanza.rb +21 -0
  30. data/lib/jabber_admin/commands/send_stanza_c2s.rb +28 -0
  31. data/lib/jabber_admin/commands/set_nickname.rb +22 -0
  32. data/lib/jabber_admin/commands/set_presence.rb +37 -0
  33. data/lib/jabber_admin/commands/set_room_affiliation.rb +26 -0
  34. data/lib/jabber_admin/commands/set_vcard.rb +68 -0
  35. data/lib/jabber_admin/commands/subscribe_room.rb +19 -12
  36. data/lib/jabber_admin/commands/unregister.rb +13 -7
  37. data/lib/jabber_admin/commands/unsubscribe_room.rb +10 -7
  38. data/lib/jabber_admin/configuration.rb +6 -1
  39. data/lib/jabber_admin/exceptions.rb +41 -0
  40. data/lib/jabber_admin/version.rb +19 -1
  41. metadata +120 -25
  42. data/lib/jabber_admin/initializer.rb +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 539a6c8f78226c54b34ef4fbba4a4efdab80070b
4
- data.tar.gz: c775b07759beeeb2b4db8b4cc66297d04e38d0b2
2
+ SHA256:
3
+ metadata.gz: 31b521fdd1da155402e58b436e83fcb22012648b601f543fd5e885f844fd019e
4
+ data.tar.gz: 9f14f04eaa52941167b0deaeb3322d1d1e947acf8ed2cc8e16cdc00dabeaa8a4
5
5
  SHA512:
6
- metadata.gz: d5378a4478def4b3d76915f56e446cbbe522b2e89446908150bc25bc30a1308c76c046cfbd4f506f7c9114a4a87aa5c5884ce703c78a70e43f3e6199dfc81988
7
- data.tar.gz: 9fe1f23a6679d11299d9d73bfd07b8523b4c88b016b1d04e9c03881380dcc6b03086682b9d68755dbbb2f0114c37ff452f7b0e3eb6479cfe93b7b4e6cc8b48cc
6
+ metadata.gz: 57e645f24f358c679b841cde89b8d8ee9fc978d5497a979ce5e87217f936af0438f9e8a75a1bcb94f9d2f195ea469fdc3be1f55137d8b20c66e5b04e0a61bf9d
7
+ data.tar.gz: b26205f1387f7b50c2ac30407402017f5ab70aa89d64d34905f6c2ddddb26e3d05fa48b6a49f418eb9716c20ec2ce95327e97155f6ab0be9d2c88ff930a732bf
@@ -0,0 +1,30 @@
1
+ # http://editorconfig.org
2
+ root = true
3
+
4
+ [*]
5
+ indent_style = space
6
+ indent_size = 2
7
+ end_of_line = lf
8
+ charset = utf-8
9
+ trim_trailing_whitespace = true
10
+ insert_final_newline = true
11
+
12
+ [*.md]
13
+ trim_trailing_whitespace = true
14
+
15
+ [*.json]
16
+ indent_style = space
17
+ indent_size = 2
18
+
19
+ [*.yml]
20
+ indent_style = space
21
+ indent_size = 2
22
+
23
+ [Makefile]
24
+ trim_trailing_whitespace = true
25
+ indent_style = tab
26
+ indent_size = 4
27
+
28
+ [*.sh]
29
+ indent_style = space
30
+ indent_size = 2
data/.gitignore CHANGED
@@ -3,11 +3,13 @@
3
3
  /Gemfile.lock
4
4
  /_yardoc/
5
5
  /coverage/
6
+ /doc/
6
7
  /pkg/
7
8
  /spec/reports/
8
9
  /tmp/
10
+ /vendor/
11
+ /gemfiles/vendor/
12
+ *.gemfile.lock
9
13
 
10
14
  # rspec failure tracking
11
15
  .rspec_status
12
-
13
- *.gem
@@ -0,0 +1,35 @@
1
+ require: rubocop-rspec
2
+
3
+ Documentation:
4
+ Enabled: true
5
+
6
+ AllCops:
7
+ DisplayCopNames: true
8
+ TargetRubyVersion: 2.5
9
+
10
+ Metrics/BlockLength:
11
+ Exclude:
12
+ - Rakefile
13
+ - spec/**/*.rb
14
+ - '**/*.rake'
15
+ - '*.gemspec'
16
+
17
+ # Document all the things.
18
+ Style/DocumentationMethod:
19
+ Enabled: true
20
+ RequireForNonPublicMethods: true
21
+
22
+ # Because +expect_any_instance_of().to have_received()+ is not
23
+ # supported with the +with(hash_including)+ matchers
24
+ RSpec/MessageSpies:
25
+ EnforcedStyle: receive
26
+
27
+ # Allow deeper nesting because of the predefined/non-predefined -
28
+ # bang/non-bang cases.
29
+ RSpec/NestedGroups:
30
+ Max: 4
31
+
32
+ # We stay at 80 characters per line.
33
+ # See: https://rubystyle.guide/#max-line-length
34
+ Metrics/LineLength:
35
+ Max: 80
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ SimpleCov.start 'test_frameworks' do
4
+ add_filter '/vendor/bundle/'
5
+ end
@@ -1,16 +1,18 @@
1
+ sudo: false
1
2
  env:
2
3
  global:
3
- - CC_TEST_REPORTER_ID=02d696c72627e730a3db553884276acf15672466e32e66a788672d3b167629ca
4
- sudo: false
4
+ - CC_TEST_REPORTER_ID=05f9944a34899135739ab519c57a179a3f4677999fd832fa87da25d3643702b7
5
5
  language: ruby
6
6
  rvm:
7
- - 2.2
8
- - 2.3
9
- - 2.4
10
- before_install: gem install bundler -v 1.15.1
7
+ - 2.6
8
+ - 2.6
9
+ - 2.5
10
+ before_install: gem install bundler
11
11
  before_script:
12
12
  - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
13
13
  - chmod +x ./cc-test-reporter
14
14
  - ./cc-test-reporter before-build
15
+ script:
16
+ - bundle exec rspec
15
17
  after_script:
16
18
  - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
@@ -0,0 +1,4 @@
1
+ --output-dir=doc/app
2
+ -
3
+ README.md
4
+ lib/**/*.rb
@@ -0,0 +1,49 @@
1
+ ### 1.0.0
2
+
3
+ * All `JabberAdmin` errors `[UnknownCommandError, CommandError, RequestError]`
4
+ now ship the response object correctly (was always set to `nil` previously)
5
+ (#6)
6
+ * Improved the default exceptions messages with the response body (#6)
7
+ * Added support for setting/fetching vCard details (`JabberAdmin.set_vcard`,
8
+ `JabberAdmin.get_vcard`) (#6)
9
+ * Dropped support for Ruby <2.5 (#6)
10
+ * Added some versioning helpers (eg. `JabberAdmin.version`)
11
+
12
+ ### 0.2.0
13
+
14
+ * [BC] The configuration has changed
15
+ * `api_host` => `url`, we require now the full base URL of the REST API, this
16
+ allows custom mod_http_api paths (See: https://bit.ly/2rBxatJ)
17
+ * `admin` => `username`, we want to be use common sense API client jargon
18
+ here
19
+ * We support from now on predefined AND freestyle commands on the `JabberAdmin`
20
+ module
21
+ * We support from now on bang and non-bang command variants (for both
22
+ predefined and freestyle commands) which allows the client to use builtin
23
+ error handling or not
24
+ * [BC] Previously only bang variants were possible, without response checking,
25
+ look out for more exceptions when you migrate
26
+ * New predefined commands:
27
+ * muc_register_nick
28
+ * send_stanza_c2s
29
+ * set_nickname
30
+ * set_presence
31
+ * The documentation was greatly improved
32
+ * The testcases were rewritten and tested with VCR against a real ejabberd
33
+ server (18.01)
34
+
35
+ ### 0.1.4
36
+
37
+ * Added support for predefined commands
38
+ * ban_account
39
+ * create_room
40
+ * create_room_with_opts
41
+ * register
42
+ * registered_users
43
+ * restart
44
+ * send_direct_invitation
45
+ * send_stanza
46
+ * set_room_affiliation
47
+ * subscribe_room
48
+ * unregister
49
+ * unsubscribe_room
data/Gemfile CHANGED
@@ -1,6 +1,8 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
6
 
5
7
  # Specify your gem's dependencies in jabber_admin.gemspec
6
8
  gemspec
@@ -0,0 +1,108 @@
1
+ MAKEFLAGS += --warn-undefined-variables -j1
2
+ SHELL := bash
3
+ .SHELLFLAGS := -eu -o pipefail -c
4
+ .DEFAULT_GOAL := all
5
+ .DELETE_ON_ERROR:
6
+ .SUFFIXES:
7
+ .PHONY:
8
+
9
+ # Environment switches
10
+ MAKE_ENV ?= docker
11
+ COMPOSE_RUN_SHELL_FLAGS ?= --rm
12
+
13
+ # Directories
14
+ VENDOR_DIR ?= vendor/bundle
15
+
16
+ # Host binaries
17
+ BASH ?= bash
18
+ COMPOSE ?= docker-compose
19
+ ECHO ?= echo
20
+ GREP ?= grep
21
+ ID ?= id
22
+ MKDIR ?= mkdir
23
+ RM ?= rm
24
+ SED ?= sed
25
+ SORT ?= sort
26
+
27
+ # Container binaries
28
+ BUNDLE ?= bundle
29
+ RAKE ?= rake
30
+ RUBOCOP ?= rubocop
31
+
32
+ all:
33
+ # jabber_admin
34
+ #
35
+ # install Install the dependencies
36
+ # test Run the whole test suite
37
+ # test-style Check the coding styles
38
+ # clean Clean the dependencies
39
+ #
40
+ # shell Run an interactive shell on the container
41
+ # shell-irb Run an interactive IRB shell on the container
42
+ #
43
+ # supported-commands-list Generate the supported commands list
44
+
45
+ # Define a generic shell run wrapper
46
+ # $1 - The command to run
47
+ ifeq ($(MAKE_ENV),docker)
48
+ define run-shell
49
+ $(COMPOSE) run $(COMPOSE_RUN_SHELL_FLAGS) \
50
+ -e LANG=en_US.UTF-8 -e LANGUAGE=en_US.UTF-8 -e LC_ALL=en_US.UTF-8 \
51
+ -e HOME=/tmp -e BUNDLE_APP_CONFIG=/app/.bundle \
52
+ -u `$(ID) -u` test bash -c 'sleep 0.1; echo; $(1)'
53
+ endef
54
+ else ifeq ($(MAKE_ENV),baremetal)
55
+ define run-shell
56
+ $(1)
57
+ endef
58
+ endif
59
+
60
+ install:
61
+ # Install the dependencies
62
+ @$(MKDIR) -p $(VENDOR_DIR)
63
+ @$(call run-shell,$(BUNDLE) check || $(BUNDLE) install --path $(VENDOR_DIR))
64
+
65
+ test: install
66
+ # Run the whole test suite
67
+ @$(call run-shell,$(BUNDLE) exec $(RAKE))
68
+
69
+ test-style: test-style-ruby
70
+
71
+ test-style-ruby:
72
+ # Run the static code analyzer (rubocop)
73
+ @$(call run-shell,$(BUNDLE) exec $(RUBOCOP) -a)
74
+
75
+ clean:
76
+ # Clean the dependencies
77
+ @$(RM) -rf $(VENDOR_DIR)
78
+
79
+ clean-containers:
80
+ # Clean running containers
81
+ ifeq ($(MAKE_ENV),docker)
82
+ @$(COMPOSE) down
83
+ endif
84
+
85
+ distclean: clean clean-containers
86
+
87
+ shell: install
88
+ # Run an interactive shell on the container
89
+ @$(call run-shell,$(BASH) -i)
90
+
91
+ shell-irb: install
92
+ # Run an interactive IRB shell on the container
93
+ @$(call run-shell,bin/console)
94
+
95
+ release:
96
+ # Release a new gem version
97
+ @$(RAKE) release
98
+
99
+ supported-commands-list:
100
+ # Generate the supported commands list
101
+ @$(ECHO)
102
+ @$(GREP) -oP '@see https?://.*' -R lib/jabber_admin/commands/ \
103
+ | $(SED) \
104
+ -e 's/@see //g' \
105
+ -e 's/.rb:/](/g' \
106
+ -e 's/$$/)/g' \
107
+ -e 's#^lib/jabber_admin/commands/#- [#g' \
108
+ | $(SORT)
data/README.md CHANGED
@@ -1,10 +1,21 @@
1
- # JabberAdmin
1
+ ![jabber_admin](doc/assets/project.svg)
2
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)
3
+ [![Build Status](https://travis-ci.com/hausgold/jabber_admin.svg?branch=master)](https://travis-ci.com/hausgold/jabber_admin)
4
+ [![Gem Version](https://badge.fury.io/rb/jabber_admin.svg)](https://badge.fury.io/rb/jabber_admin)
5
+ [![Maintainability](https://api.codeclimate.com/v1/badges/dd51c4668e97771baaba/maintainability)](https://codeclimate.com/repos/5cac8bcb6969c376ed007c70/maintainability)
6
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/dd51c4668e97771baaba/test_coverage)](https://codeclimate.com/repos/5cac8bcb6969c376ed007c70/test_coverage)
7
+ [![API docs](https://img.shields.io/badge/docs-API-blue.svg)](https://www.rubydoc.info/gems/jabber_admin)
5
8
 
6
- JabberAdmin is a small library to easily communicate with the Ejabberd
7
- admin API.
9
+ jabber_admin is a small library to easily communicate with the [ejabberd
10
+ admin API](https://docs.ejabberd.im/developer/ejabberd-api/admin-api).
11
+
12
+ - [Installation](#installation)
13
+ - [Configuration](#configuration)
14
+ - [Usage](#usage)
15
+ - [Predefined commands](#predefined-commands)
16
+ - [Freestyle commands](#freestyle-commands)
17
+ - [Development](#development)
18
+ - [Contributing](#contributing)
8
19
 
9
20
  ## Installation
10
21
 
@@ -16,36 +27,149 @@ gem 'jabber_admin'
16
27
 
17
28
  And then execute:
18
29
 
19
- $ bundle
30
+ ```bash
31
+ $ bundle
32
+ ```
20
33
 
21
34
  Or install it yourself as:
22
35
 
23
- $ gem install jabber_admin
36
+ ```bash
37
+ $ gem install jabber_admin
38
+ ```
39
+
40
+ ## Configuration
41
+
42
+ You can configure the jabber_admin gem in a global initializer way with the
43
+ `JabberAdmin.configure` method which yields the configuration directly.
44
+
45
+ ```ruby
46
+ JabberAdmin.configure do |config|
47
+ # The ejabberd REST API endpoint as a full URL.
48
+ # Take care of the path part, because this is individually
49
+ # configured on ejabberd. (See: https://bit.ly/2rBxatJ)
50
+ config.url = 'http://jabber.local/api'
51
+ # Provide here the full user JID in order to authenticate as
52
+ # a administrator.
53
+ config.username = 'admin@jabber.local'
54
+ # The password of the administrator account.
55
+ config.password = 'password'
56
+ end
57
+ ```
58
+
59
+ In case this is not cool for you, you can get and modify the configuration
60
+ directly with the help of the `JabberAdmin.configuration` getter.
61
+
62
+ ```ruby
63
+ JabberAdmin.configuration.url = 'http://jabber.local/api'
64
+ JabberAdmin.configuration.username = 'admin@jabber.local'
65
+ JabberAdmin.configuration.password = 'password'
66
+ ```
24
67
 
25
68
  ## Usage
26
69
 
27
- ``` ruby
70
+ ### Predefined commands
71
+
72
+ We support some handy predefined commands out of the box which ease the quick
73
+ start usage. These predefined commands comes with a good documentation
74
+ (including valid example data) and a nifty interface. When it is possible to
75
+ fill up missing data from a full user/room JID we do so. Say while sending a
76
+ direct invitation, you just pass the full room JID and we take care of
77
+ splitting it up to fulfill the separate room name and the separate MUC service
78
+ domain.
79
+
80
+ All our predefined commands are available directly underneath the `JabberAdmin`
81
+ module as methods. Just call them like this:
82
+
83
+ ```ruby
28
84
  JabberAdmin.restart!
29
- JabberAdmin.create_room!(name: 'room1', host: '...')
85
+ JabberAdmin.register(user: 'peter@example.com', password: '123')
30
86
  ```
31
87
 
32
- Currently these basic commands are supported:
88
+ Have a close look at the method names. We support bang and non-bang variants.
89
+ The bang variants perform in-deep response validation and raise children of
90
+ `JabberAdmin::Error` in case of detected issues. These issues can be
91
+ unpermitted API requests, or invalid payload values, etc. The predefined
92
+ commands also perform response body checks when it is appropriate. (Eg. many
93
+ commands respond a single zero as a success indicator)
94
+
95
+ The non-bang variants will just fire the request and do not perform any checks
96
+ on the response. You can implement your own error handling or response analysis
97
+ if you like. You could also just fire and forget them. It's up to you.
98
+
99
+ Here comes a list of all supported predefined commands:
100
+
101
+ - [ban_account](https://bit.ly/2KW9xVt)
102
+ - [create_room](https://bit.ly/2rB8DFR)
103
+ - [create_room_with_opts](https://bit.ly/2IBEfVO)
104
+ - [muc_register_nick](https://bit.ly/2G9EBNQ)
105
+ - [registered_users](https://bit.ly/2KhwT6Z)
106
+ - [register](https://bit.ly/2wyhAox)
107
+ - [restart](https://bit.ly/2G7YEwd)
108
+ - [send_direct_invitation](https://bit.ly/2wuTpr2)
109
+ - [send_stanza_c2s](https://bit.ly/2wwUcYr)
110
+ - [send_stanza](https://bit.ly/2rzxyK1)
111
+ - [set_nickname](https://bit.ly/2rBdyqc)
112
+ - [set_presence](https://bit.ly/2rzxyK1)
113
+ - [set_room_affiliation](https://bit.ly/2G5MfbW)
114
+ - [subscribe_room](https://bit.ly/2Ke7Zoy)
115
+ - [unregister](https://bit.ly/2wwYnDE)
116
+ - [unsubscribe_room](https://bit.ly/2G5zcrj)
117
+
118
+ If you want to contribute more, we accept pull requests!
119
+
120
+ ### Freestyle commands
121
+
122
+ In case you want to send commands easily without delivering new predefined
123
+ commands with documentation and some nifty tricks, you can simply call the
124
+ ejabberd REST API with your custom commands like this:
125
+
126
+ ```ruby
127
+ JabberAdmin.status
128
+ JabberAdmin.get_last(user: 'tom', host: 'ejabberd.local')
129
+ JabberAdmin.set_presence!(...)
130
+ ```
131
+
132
+ The `JabberAdmin` is smart enough to detect that the given command is not a
133
+ predefined command and therefore it assembles a new `JabberAdmin::ApiCall`
134
+ instance and passes down all arguments. If you look closely you see again that
135
+ we support a bang and non-bang variant. The error handling works the same as on
136
+ predefined commands.
137
+
138
+ By default the `JabberAdmin::ApiCall` instance assumes it should perform body
139
+ checks on the response which is not clever on data fetching commands, due to
140
+ the fact that they do not deliver `0` as body. The body validation can be
141
+ turned off with the additional `check_res_body: false` argument.
33
142
 
34
- - ban_account
35
- - create_room
36
- - register
37
- - restart
38
- - send_direct_invitation
39
- - subscribe_room
40
- - unregister
41
- - unsubscribe_room
143
+ ```ruby
144
+ JabberAdmin.get_last! \
145
+ check_res_body: false, user: 'tom', host: 'ejabberd.local'
146
+ ```
147
+
148
+ In case you want to make use of the memorize feature of each
149
+ `JabberAdmin::ApiCall` instance, just build it up directly.
150
+
151
+ ```ruby
152
+ command = JabberAdmin::ApiCall.new('get_last'
153
+ user: 'tom',
154
+ host: 'ejabberd.local')
155
+ # Get the response and memorize it
156
+ command.response.object_id # => 21934400
157
+ # A second call to the response method will not perform a request again
158
+ command.response.object_id # => 21934400
159
+ ```
42
160
 
43
161
  ## Development
44
162
 
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.
163
+ After checking out the repo, run `make install` to install dependencies. Then,
164
+ run `make test` to run the tests. You can also run `make shell-irb` for an
165
+ interactive prompt that will allow you to experiment.
46
166
 
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).
167
+ To release a new version, update the version number in `version.rb`, and then
168
+ run `make release`, which will create a git tag for the version, push git
169
+ commits and tags, and push the `.gem` file to
170
+ [rubygems.org](https://rubygems.org).
48
171
 
49
172
  ## Contributing
50
173
 
51
- Bug reports and pull requests are welcome on GitHub at https://github.com/hausgold/jabber_admin.
174
+ Bug reports and pull requests are welcome on GitHub at
175
+ https://github.com/hausgold/jabber_admin.