postfixman 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2cb8ad744350960850b05dd36bc90974b2e2f8dc
4
+ data.tar.gz: 5ff916383bbb2a064a97bc7b6aae80114704fd4b
5
+ SHA512:
6
+ metadata.gz: aea7cc91c773e55185514162450f71d98ae1db4097a8e0a529e4f3b39ec7e30c33834bcb002ec2b76e6f54173ccf5a91d4ef3565e655ede86c250f16410a93e4
7
+ data.tar.gz: 8b6527c0d7a5aa08787f39bace822ed4f368fe322a60d6f987f741885a3b27c1f54054a79d451696cd8f196456fd5f05b41da3d1c326e7fcc24c486363689125
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## v0.0.1
2
+
3
+ * Initial release
@@ -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,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 unformatt
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Postfixman
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'postfixman'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install postfixman
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/postfixman/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
@@ -0,0 +1,11 @@
1
+ module Postfixman
2
+ class Alias
3
+ attr_accessor :id, :name, :from, :recipients, :enabled
4
+
5
+ def initialize(attributes={})
6
+ attributes.each do |k,v|
7
+ self.send("#{k}=", v) if self.respond_to?(k)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,338 @@
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_domains
9
+ request = web_request('GET', '/domains', { }, default_headers)
10
+ request[:body].map { |x| Openfire::Domain.new(x) }
11
+ end
12
+
13
+ def get_users(domain_id)
14
+ request = web_request('GET', "/domains/#{domain_id}/users", { }, default_headers)
15
+ request[:body].map { |x| Openfire::User.new(x) }
16
+ end
17
+
18
+ def create_user(params)
19
+ request = web_request('POST', '/users', params, default_headers)
20
+ Openfire::User.new(request[:body])
21
+ end
22
+
23
+ def update_user(user_id, params)
24
+ request = web_request('PUT', "/users/#{user_id}", params, default_headers)
25
+ Openfire::User.new(request[:body])
26
+ end
27
+
28
+ def delete_user(user_id)
29
+ request = web_request('DELETE', "/users/#{user_id}", params, default_headers)
30
+ request[:body]['success'] == true
31
+ end
32
+
33
+ def get_aliases(domain_id)
34
+ request = web_request('GET', "/domains/#{domain_id}/aliases", { }, default_headers)
35
+ request[:body].map { |x| Openfire::Alias.new(x) }
36
+ end
37
+
38
+ def create_alias(params)
39
+ request = web_request('POST', '/aliases', params, default_headers)
40
+ Openfire::User.new(request[:body])
41
+ end
42
+
43
+ def update_alias(alias_id, params)
44
+ request = web_request('PUT', "/aliases/#{user_id}", params, default_headers)
45
+ Openfire::User.new(request[:body])
46
+ end
47
+
48
+ def delete_alias(alias_id)
49
+ request = web_request('DELETE', "/aliases/#{user_id}", params, default_headers)
50
+ request[:body]['success'] == true
51
+ end
52
+
53
+ def get_recipient_bccs
54
+ request = web_request('GET', "/domains/#{domain_id}/recipient_bccs", { }, default_headers)
55
+ request[:body].map { |x| Openfire::RecipientBcc.new(x) }
56
+ end
57
+
58
+ def create_recipient_bccs(params)
59
+ request = web_request('POST', '/recipient_bccs', params, default_headers)
60
+ Openfire::User.new(request[:body])
61
+ end
62
+
63
+ def update_sender_bccs(sender_bcc_id, params)
64
+ request = web_request('PUT', "/recipient_bccs/#{user_id}", params, default_headers)
65
+ Openfire::User.new(request[:body])
66
+ end
67
+
68
+ def delete_recipient_bccs(sender_bcc_id)
69
+ request = web_request('DELETE', "/recipient_bccs/#{user_id}", params, default_headers)
70
+ request[:body]['success'] == true
71
+ end
72
+
73
+ def get_sender_bccs
74
+ request = web_request('GET', "/domains/#{domain_id}/sender_bccs", { }, default_headers)
75
+ request[:body].map { |x| Openfire::SenderBcc.new(x) }
76
+ end
77
+
78
+ def create_sender_bccs(params)
79
+ request = web_request('POST', '/sender_bccs', params, default_headers)
80
+ Openfire::User.new(request[:body])
81
+ end
82
+
83
+ def update_sender_bccs(sender_bcc_id)
84
+ request = web_request('PUT', "/sender_bccs/#{user_id}", params, default_headers)
85
+ Openfire::User.new(request[:body])
86
+ end
87
+
88
+ def delete_sender_bccs(sender_bcc_id)
89
+ request = web_request('DELETE', "/sender_bccs/#{user_id}", params, default_headers)
90
+ request[:body]['success'] == true
91
+ end
92
+
93
+ def get_user(username)
94
+ request = web_request('GET', "/users/#{username}", { }, default_headers)
95
+ Openfire::User.new(request[:body])
96
+ end
97
+
98
+ def create_user(user_data={})
99
+ request = web_request('POST', '/users', user_data.to_json, default_headers)
100
+ (request[:status_code] == 201)
101
+ end
102
+
103
+ def update_user(username, user_data={})
104
+ request = web_request('PUT', "/users/#{username}", user_data.to_json, default_headers)
105
+ (request[:status_code] == 200)
106
+ end
107
+
108
+ def delete_user(username)
109
+ request = web_request('DELETE', "/users/#{username}", { }, default_headers)
110
+ (request[:status_code] == 200)
111
+ end
112
+
113
+ def lock_user(username)
114
+ request = web_request('POST', "/lockouts/#{username}", { }, default_headers)
115
+ (request[:status_code] == 200)
116
+ end
117
+
118
+ def unlock_user(username)
119
+ request = web_request('DELETE', "/lockouts/#{username}", { }, default_headers)
120
+ (request[:status_code] == 200)
121
+ end
122
+
123
+ def get_user_groups(username)
124
+ request = web_request('GET', "/users/#{username}/groups", { }, default_headers)
125
+ body = request[:body]['groupname']
126
+
127
+ body.is_a?(Array) ? body : [body]
128
+ end
129
+
130
+ def add_user_to_group(username, groupname)
131
+ request = web_request('POST', "/users/#{username}/groups/#{groupname}", { }, default_headers)
132
+
133
+ (request[:status_code] == 201)
134
+ end
135
+
136
+ def add_user_to_groups(username, groupnames)
137
+ payload = { groupname: groupnames }.to_json
138
+
139
+ request = web_request('POST', "/users/#{username}/groups", payload, default_headers)
140
+
141
+ (request[:status_code] == 201)
142
+ end
143
+
144
+ def delete_user_from_group(username, groupname)
145
+ request = web_request('DELETE', "/users/#{username}/groups/#{groupname}", { }, default_headers)
146
+
147
+ (request[:status_code] == 200)
148
+ end
149
+
150
+ def delete_user_from_groups(username, groupnames)
151
+ payload = { groupname: groupnames }.to_json
152
+
153
+ request = web_request('DELETE', "/users/#{username}/groups", payload, default_headers)
154
+
155
+ (request[:status_code] == 200)
156
+ end
157
+
158
+ def get_user_roster(username)
159
+ raise 'not implemented'
160
+ end
161
+
162
+ def create_user_roster(username, roster_data={})
163
+ raise 'not implemented'
164
+ end
165
+
166
+ def delete_user_roster(username, jid)
167
+ raise 'not implemented'
168
+ end
169
+
170
+ def update_user_roster(username, jid, roster_data={})
171
+ raise 'not implemented'
172
+ end
173
+
174
+ def get_chatrooms
175
+ raise 'not implemented'
176
+ end
177
+
178
+ def get_chatroom(room_name)
179
+ raise 'not implemented'
180
+ end
181
+
182
+ def get_chatroom_participants(room_name)
183
+ raise 'not implemented'
184
+ end
185
+
186
+ def create_chatroom(room_data={})
187
+ raise 'not implemented'
188
+ end
189
+
190
+ def delete_chatroom(room_name)
191
+ raise 'not implemented'
192
+ end
193
+
194
+ def update_chatroom(room_name, room_data={})
195
+ raise 'not implemented'
196
+ end
197
+
198
+ def add_user_to_chatroom(room_name, username_or_jid, role)
199
+ raise 'not implemented'
200
+ end
201
+
202
+ def delete_user_from_chatroom(room_name, username_or_jid, role)
203
+ raise 'not implemented'
204
+ end
205
+
206
+ def get_system_properties
207
+ request = web_request('GET', '/system/properties', { }, default_headers)
208
+ request[:body]['property'].map { |x| Openfire::SystemProperty.new(x) }
209
+ end
210
+
211
+ def get_system_property(property_name)
212
+ request = web_request('GET', "/system/properties/#{property_name}", { }, default_headers)
213
+ Openfire::SystemProperty.new(request[:body])
214
+ end
215
+
216
+ def create_system_property(property_name, value)
217
+ payload = {
218
+ '@key' => property_name,
219
+ '@value' => value
220
+ }.to_json
221
+
222
+ request = web_request('POST', '/system/properties', payload, default_headers)
223
+ (request[:status_code] == 201)
224
+ end
225
+
226
+ def delete_system_property(property_name)
227
+ request = web_request('DELETE', "/system/properties/#{property_name}", { }, default_headers)
228
+ (request[:status_code] == 200)
229
+ end
230
+
231
+ def update_system_property(property_name, value)
232
+ payload = {
233
+ '@key' => property_name,
234
+ '@value' => value
235
+ }.to_json
236
+
237
+ request = web_request('PUT', "/system/properties/#{property_name}", payload, default_headers)
238
+ (request[:status_code] == 200)
239
+ end
240
+
241
+ def get_concurrent_sessions_count
242
+ request = web_request('GET', '/system/statistics/sessions', { }, default_headers)
243
+ Openfire::SessionsCount.new(request[:body])
244
+ end
245
+
246
+ def get_groups
247
+ request = web_request('GET', '/groups', { }, default_headers)
248
+ request[:body]['group'].map { |x| Openfire::Group.new(x) }
249
+ end
250
+
251
+ def get_group(groupname)
252
+ request = web_request('GET', "/groups/#{groupname}", { }, default_headers)
253
+ Openfire::Group.new(request[:body])
254
+ end
255
+
256
+ def create_group(group_data)
257
+ request = web_request('POST', '/groups', group_data.to_json, default_headers)
258
+ (request[:status_code] == 201)
259
+ end
260
+
261
+ def update_group(groupname, group_data={})
262
+ request = web_request('PUT', "/groups/#{groupname}", group_data.to_json, default_headers)
263
+ (request[:status_code] == 200)
264
+ end
265
+
266
+ def delete_group(groupname)
267
+ request = web_request('DELETE', "/groups/#{groupname}", { }, default_headers)
268
+ (request[:status_code] == 200)
269
+ end
270
+
271
+ def get_sessions
272
+ request = web_request('GET', '/sessions', { }, default_headers)
273
+ data = request[:body]['session']
274
+
275
+ if data.is_a?(Array)
276
+ data.map { |x| Openfire::Session.new(x) }
277
+ else
278
+ [Openfire::Session.new(data)]
279
+ end
280
+ end
281
+
282
+ def get_user_sessions(username)
283
+ request = web_request('GET', "/sessions/#{username}", { }, default_headers)
284
+ data = request[:body]['session']
285
+
286
+ if data.is_a?(Array)
287
+ data.map { |x| Openfire::Session.new(x) }
288
+ else
289
+ [Openfire::Session.new(data)]
290
+ end
291
+ end
292
+
293
+ def close_user_sessions(username)
294
+ request = web_request('DELETE', "/sessions/#{username}", { }, default_headers)
295
+ (request[:status_code] == 200)
296
+ end
297
+
298
+ def send_broadcast_message(message_text)
299
+ payload = { body: message_text }.to_json
300
+
301
+ request = web_request('POST', '/messages/users', payload, default_headers)
302
+ end
303
+
304
+ private
305
+
306
+ def default_headers
307
+ {
308
+ content_type: :json,
309
+ accept: :json,
310
+ authorization: "Token token=\"#{@access_token}\""
311
+ }
312
+ end
313
+
314
+ def web_request(uri_method, action, params={}, headers={})
315
+ begin
316
+ parse_response(RestClient::Request.execute({
317
+ method: uri_method,
318
+ url: "#{@endpoint_url}#{action}",
319
+ payload: params,
320
+ headers: headers
321
+ }))
322
+ rescue => e
323
+ parse_response(e.response)
324
+ end
325
+ end
326
+
327
+ def parse_response(response)
328
+ result = {
329
+ headers: response.headers,
330
+ body: (JSON.parse(response.body) rescue response.body),
331
+ status_code: response.code
332
+ }
333
+
334
+ result
335
+ end
336
+ end
337
+ end
338
+
@@ -0,0 +1,11 @@
1
+ module Postfixman
2
+ class Domain
3
+ attr_accessor :id, :name, :from, :recipients, :enabled
4
+
5
+ def initialize(attributes={})
6
+ attributes.each do |k,v|
7
+ self.send("#{k}=", v) if self.respond_to?(k)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Postfixman
2
+ class RecipientBcc
3
+ attr_accessor :id, :from, :to, :enabled
4
+
5
+ def initialize(attributes={})
6
+ attributes.each do |k,v|
7
+ self.send("#{k}=", v) if self.respond_to?(k)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Postfixman
2
+ class SenderBcc
3
+ attr_accessor :id, :from, :to, :enabled
4
+
5
+ def initialize(attributes={})
6
+ attributes.each do |k,v|
7
+ self.send("#{k}=", v) if self.respond_to?(k)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Postfixman
2
+ class User
3
+ attr_accessor :id, :name, :email, :enabled
4
+
5
+ def initialize(attributes={})
6
+ attributes.each do |k,v|
7
+ self.send("#{k}=", v) if self.respond_to?(k)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Postfixman
2
+ VERSION = "0.0.1"
3
+ end
data/lib/postfixman.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'postfixman/version'
2
+
3
+ require 'postfixman/alias'
4
+ require 'postfixman/api'
5
+ require 'postfixman/domain'
6
+ require 'postfixman/recipient_bcc'
7
+ require 'postfixman/sender_bcc'
8
+ require 'postfixman/user'
9
+
10
+ # external dependencies
11
+ require 'rest-client'
12
+ require 'singleton'
13
+ require 'time'
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: postfixman
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Matias Hick
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-24 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: Access to Postfixman REST API
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/postfixman.rb
67
+ - lib/postfixman/alias.rb
68
+ - lib/postfixman/api.rb
69
+ - lib/postfixman/domain.rb
70
+ - lib/postfixman/recipient_bcc.rb
71
+ - lib/postfixman/sender_bcc.rb
72
+ - lib/postfixman/user.rb
73
+ - lib/postfixman/version.rb
74
+ homepage: https://github.com/unformattmh/postfixman
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.2.5
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Access to Postfixman REST API
98
+ test_files: []