ejabberd_rest 0.0.1

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: 208917e6e7d28b70ad4d67c8225c3151172a079f
4
+ data.tar.gz: d03b96ad1b9f7967fa5105c324bae3b284e1f332
5
+ SHA512:
6
+ metadata.gz: 8d9d4f928ef0d26fffba177e2a10f59d87fb5a0f6dbed7cda38ecf7e961ad1dafaac4b5e45525f05f0fc435dd6272b50e90cd362f1203dcd4f286ca30e8811a0
7
+ data.tar.gz: b1be8abe3c48b7902e991afd0f6302532986934e393094be40d734f1006b01b9891e72b1ab0ae10f50c13c4c77a2d98838a3d9540424aa4cf744ff4503dd95a9
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ejabberd_rest.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Fajar Budiprasetyo
2
+
3
+ MIT License
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,40 @@
1
+ # EjabberdRest
2
+
3
+ Ruby interface for ejabberd [mod_rest](https://github.com/processone/ejabberd-contrib/tree/master/mod_rest)
4
+
5
+ ## Implemented method
6
+
7
+ * Add user
8
+ * Delete user
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'ejabberd_rest'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install ejabberd_rest
23
+
24
+ ## Usage
25
+
26
+ ```ruby
27
+ client = EjabberdRest::Client.new(url: "http://dreamland:5285")
28
+ client.add_user("ruby1", "dreamland", "ruby1password")
29
+ => true
30
+ client.delete_user("ruby1", "dreamland")
31
+ => "0"
32
+ ```
33
+
34
+ ## Contributing
35
+
36
+ 1. Fork it ( http://github.com/<my-github-username>/ejabberd_rest/fork )
37
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
38
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
39
+ 4. Push to the branch (`git push origin my-new-feature`)
40
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ejabberd_rest/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ejabberd_rest"
8
+ spec.version = EjabberdRest::VERSION
9
+ spec.authors = ["Fajar Budiprasetyo"]
10
+ spec.email = ["fajar.ab@gmail.com"]
11
+ spec.summary = %q{Ruby interface for ejabberd mod_rest.}
12
+ spec.description = %q{Ruby interface to add and delete user using ejabberd mod_rest.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_runtime_dependency "faraday", "~> 0.9.0"
25
+ end
@@ -0,0 +1,51 @@
1
+ require "ejabberd_rest/errors"
2
+
3
+ module EjabberdRest
4
+ class Client
5
+ attr_accessor :http_adapter, :mod_rest_url
6
+
7
+ DEFAULT_MOD_REST_URL = "http://localhost:5285"
8
+
9
+ def initialize(attributes={})
10
+ @mod_rest_url = attributes[:url] || DEFAULT_MOD_REST_URL
11
+ @http_adapter = attributes[:http_adapter] || :net_http
12
+ end
13
+
14
+ def add_user(username, domain, password)
15
+ rbody = post("/rest", body: "register #{username} #{domain} #{password}")
16
+
17
+ if rbody.include?("successfully registered")
18
+ true
19
+ else
20
+ if rbody.include?("already registered")
21
+ raise Error::UserAlreadyRegistered
22
+ else
23
+ false
24
+ end
25
+ end
26
+ end
27
+
28
+ def delete_user(username, domain)
29
+ post("/rest", body: "unregister #{username} #{domain}")
30
+ end
31
+
32
+ private
33
+
34
+ def connection
35
+ connection = Faraday.new(@mod_rest_url) do |builder|
36
+ builder.request :url_encoded
37
+ builder.response :logger
38
+
39
+ builder.adapter @http_adapter
40
+ end
41
+ end
42
+
43
+ def post(path, options)
44
+ response = connection.send(:post, path) do |request|
45
+ request.body = options[:body] if options[:body]
46
+ end
47
+
48
+ response.body
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,5 @@
1
+ module EjabberdRest
2
+ class Error
3
+ class UserAlreadyRegistered < StandardError; end
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module EjabberdRest
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,3 @@
1
+ require "ejabberd_rest/version"
2
+ require "ejabberd_rest/client"
3
+ require "faraday"
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ejabberd_rest
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Fajar Budiprasetyo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-31 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.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
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: faraday
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.9.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.0
55
+ description: Ruby interface to add and delete user using ejabberd mod_rest.
56
+ email:
57
+ - fajar.ab@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - ejabberd_rest.gemspec
68
+ - lib/ejabberd_rest.rb
69
+ - lib/ejabberd_rest/client.rb
70
+ - lib/ejabberd_rest/errors.rb
71
+ - lib/ejabberd_rest/version.rb
72
+ homepage: ''
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.2.0.rc.1
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Ruby interface for ejabberd mod_rest.
96
+ test_files: []
97
+ has_rdoc: