openfire_rest_api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/LICENSE.md +21 -0
- data/README.md +41 -0
- data/lib/openfire/api.rb +137 -0
- data/lib/openfire/group.rb +11 -0
- data/lib/openfire/user.rb +11 -0
- data/lib/openfire_rest_api.rb +10 -0
- data/lib/openfire_rest_api/version.rb +3 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8a9575f1e7b1c21354175b39005219d5fb9a4152
|
4
|
+
data.tar.gz: ce785b38cd08773faee8dc87738c9f87e25bf055
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9090e6000137d7b2310c48f4a3b426b1fc40063225c9086a7cad9331759436b2d3ab0702f404d26833aad3c7b0e322c18e3f57fdb170032ae05f3575bf22b7c4
|
7
|
+
data.tar.gz: fdd81077e7db4d5b8749e6428fd080916aa44de8caa8b06cb54c987c7ca75eb50bd9c7949c1a8e572101ba89cff2177cdc33aa7070b6095a49df16ae47058782
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at unformatt@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 unformatt
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# OpenfireRestApi
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/openfire_rest_api`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'openfire_rest_api'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install openfire_rest_api
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
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).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/openfire_rest_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/lib/openfire/api.rb
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
module Openfire
|
2
|
+
class Api
|
3
|
+
def initialize(endpoint_url, access_token)
|
4
|
+
@endpoint_url = endpoint_url
|
5
|
+
@access_token = access_token
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_users
|
9
|
+
request = web_request('GET', '/users', { }, default_headers)
|
10
|
+
request[:body]['user'].map { |x| Openfire::User.new(x) }
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_user(username)
|
14
|
+
request = web_request('GET', "/users/#{username}", { }, default_headers)
|
15
|
+
Openfire::User.new(request[:body])
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_user(user_data={})
|
19
|
+
request = web_request('POST', '/users', user_data.to_json, default_headers)
|
20
|
+
(request[:status_code] == 201)
|
21
|
+
end
|
22
|
+
|
23
|
+
def update_user(username, user_data={})
|
24
|
+
request = web_request('PUT', "/users/#{username}", user_data.to_json, default_headers)
|
25
|
+
(request[:status_code] == 200)
|
26
|
+
end
|
27
|
+
|
28
|
+
def delete_user(username)
|
29
|
+
request = web_request('DELETE', "/users/#{username}", { }, default_headers)
|
30
|
+
(request[:status_code] == 200)
|
31
|
+
end
|
32
|
+
|
33
|
+
def lock_user(username)
|
34
|
+
request = web_request('POST', "/lockouts/#{username}", { }, default_headers)
|
35
|
+
(request[:status_code] == 200)
|
36
|
+
end
|
37
|
+
|
38
|
+
def unlock_user(username)
|
39
|
+
request = web_request('DELETE', "/lockouts/#{username}", { }, default_headers)
|
40
|
+
(request[:status_code] == 200)
|
41
|
+
end
|
42
|
+
|
43
|
+
def get_user_groups(username)
|
44
|
+
request = web_request('GET', "/users/#{username}/groups", { }, default_headers)
|
45
|
+
body = request[:body]['groupname']
|
46
|
+
|
47
|
+
body.is_a?(Array) ? body : [body]
|
48
|
+
end
|
49
|
+
|
50
|
+
def add_user_to_group(username, groupname)
|
51
|
+
request = web_request('POST', "/users/#{username}/groups/#{groupname}", { }, default_headers)
|
52
|
+
|
53
|
+
(request[:status_code] == 201)
|
54
|
+
end
|
55
|
+
|
56
|
+
def add_user_to_groups(username, groupnames)
|
57
|
+
payload = { groupname: groupnames }.to_json
|
58
|
+
|
59
|
+
request = web_request('POST', "/users/#{username}/groups", payload, default_headers)
|
60
|
+
|
61
|
+
(request[:status_code] == 201)
|
62
|
+
end
|
63
|
+
|
64
|
+
def delete_user_from_group(username, groupname)
|
65
|
+
request = web_request('DELETE', "/users/#{username}/groups/#{groupname}", { }, default_headers)
|
66
|
+
|
67
|
+
(request[:status_code] == 200)
|
68
|
+
end
|
69
|
+
|
70
|
+
def delete_user_from_groups(username, groupnames)
|
71
|
+
payload = { groupname: groupnames }.to_json
|
72
|
+
|
73
|
+
request = web_request('DELETE', "/users/#{username}/groups", payload, default_headers)
|
74
|
+
|
75
|
+
(request[:status_code] == 200)
|
76
|
+
end
|
77
|
+
|
78
|
+
def get_groups
|
79
|
+
request = web_request('GET', '/groups', { }, default_headers)
|
80
|
+
request[:body]['group'].map { |x| Openfire::Group.new(x) }
|
81
|
+
end
|
82
|
+
|
83
|
+
def get_group(groupname)
|
84
|
+
request = web_request('GET', "/groups/#{groupname}", { }, default_headers)
|
85
|
+
Openfire::Group.new(request[:body])
|
86
|
+
end
|
87
|
+
|
88
|
+
def create_group(group_data)
|
89
|
+
request = web_request('POST', '/groups', group_data.to_json, default_headers)
|
90
|
+
(request[:status_code] == 201)
|
91
|
+
end
|
92
|
+
|
93
|
+
def update_group(groupname, group_data={})
|
94
|
+
request = web_request('PUT', "/groups/#{groupname}", group_data.to_json, default_headers)
|
95
|
+
(request[:status_code] == 200)
|
96
|
+
end
|
97
|
+
|
98
|
+
def delete_group(groupname)
|
99
|
+
request = web_request('DELETE', "/groups/#{groupname}", { }, default_headers)
|
100
|
+
(request[:status_code] == 200)
|
101
|
+
end
|
102
|
+
|
103
|
+
private
|
104
|
+
|
105
|
+
def default_headers
|
106
|
+
{
|
107
|
+
content_type: :json,
|
108
|
+
accept: :json,
|
109
|
+
authorization: @access_token
|
110
|
+
}
|
111
|
+
end
|
112
|
+
|
113
|
+
def web_request(uri_method, action, params={}, headers={})
|
114
|
+
begin
|
115
|
+
parse_response(RestClient::Request.execute({
|
116
|
+
method: uri_method,
|
117
|
+
url: "#{@endpoint_url}#{action}",
|
118
|
+
payload: params,
|
119
|
+
headers: headers
|
120
|
+
}))
|
121
|
+
rescue => e
|
122
|
+
parse_response(e.response)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def parse_response(response)
|
127
|
+
result = {
|
128
|
+
headers: response.headers,
|
129
|
+
body: (JSON.parse(response.body) rescue response.body),
|
130
|
+
status_code: response.code
|
131
|
+
}
|
132
|
+
|
133
|
+
result
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: openfire_rest_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matias Hick
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
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: rest-client
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.6.7
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.6.7
|
55
|
+
description: Connect with openfire through rest api plugin
|
56
|
+
email:
|
57
|
+
- unformatt@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- CHANGELOG.md
|
63
|
+
- CODE_OF_CONDUCT.md
|
64
|
+
- LICENSE.md
|
65
|
+
- README.md
|
66
|
+
- lib/openfire/api.rb
|
67
|
+
- lib/openfire/group.rb
|
68
|
+
- lib/openfire/user.rb
|
69
|
+
- lib/openfire_rest_api.rb
|
70
|
+
- lib/openfire_rest_api/version.rb
|
71
|
+
homepage: https://github.com/unformattmh/openfire_rest_api
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.2.5
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: Connect with openfire through rest api plugin
|
95
|
+
test_files: []
|