elastix 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +51 -0
- data/Rakefile +1 -0
- data/elastix.gemspec +22 -0
- data/lib/elastix.rb +7 -0
- data/lib/elastix/base.rb +25 -0
- data/lib/elastix/extension.rb +117 -0
- data/lib/elastix/version.rb +3 -0
- data/spec/base_spec.rb +31 -0
- data/spec/extension_spec.rb +105 -0
- data/spec/spec_helper.rb +7 -0
- metadata +77 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZmY3ZWE4YzIzZjcwZTk3OGUzOTczYzM3NmQ2NGIwYjYwYzkzOTNjMg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
OWZmMjIyOTZiODkyNTMyNWI4NjI1NjRmN2JjMzAzNzBlYWMwNDBkNQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZDgzMTgyOTQ4ODA4NjdkNzJmODZlNjQ5MzMzZDExMzViYjdjODc4OTUwYzFh
|
10
|
+
N2UyNTNlYmNjMDQ5YmY3NzZmYjQ2NjY3OTViZDg0ZGNhNDZiM2NmOTVlZTcy
|
11
|
+
ODBmMjU2Nzg1MTkzMjI3OGVhZWM0NDllM2QzYjlkN2U4NDdjOGU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YzU2ZTUxMGU2MWQ1ZTc4NzgyNjVjNTcxNDZlMjE4NjM4ZDNjNzM1MDA2MWI2
|
14
|
+
ZDVlZjMzZjJiYzhjMDRhOGEyNzVhNjhhNGE5YmQ5YjQ4MmMyYTI5N2RhNzQ0
|
15
|
+
ZmEwZDZhNDFjNDlhMzhlMzdkMTkyYTg4ZTEzZGE4ZjEyZWY2YTk=
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 David Hahn
|
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,51 @@
|
|
1
|
+
# Elastix
|
2
|
+
|
3
|
+
This rubygem is an integration of the Elastix Call Center Module. So far it only includes functionality for managing extensions. It was built on top of ruby mechanize and for some reason I was having issues with symbols in the hashes so in the meantime you must use strings in the hashes passed into these methods. I apologize if this is inconvenient.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'elastix'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install elastix
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
This gem models the Active Record implementation. If you are familiar with Active Record
|
22
|
+
this gem should come pretty easy to you. For instance:
|
23
|
+
|
24
|
+
options = {
|
25
|
+
"extension" => "4555", "sipname" => "3333",
|
26
|
+
"outboundcid" => "3333333333", "name" => "David Hahn", "devinfo_secret" => "secret"
|
27
|
+
}
|
28
|
+
Elastix::Base.establish_connection "192.168.1.253", "user", "password"
|
29
|
+
ext = Elastix::Extension.new options
|
30
|
+
ext.save
|
31
|
+
e = Elastix::Extension.find options["extension"]
|
32
|
+
e.destroy
|
33
|
+
Elastix::Base.close_connection
|
34
|
+
|
35
|
+
Here is a list of methods that have been implemented:
|
36
|
+
* create
|
37
|
+
* save
|
38
|
+
* find
|
39
|
+
* destroy
|
40
|
+
* all
|
41
|
+
* ==
|
42
|
+
* to\_hash
|
43
|
+
* update\_attributes
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
1. Fork it
|
48
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
49
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
50
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
51
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/elastix.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'elastix/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "elastix"
|
8
|
+
spec.version = Elastix::VERSION
|
9
|
+
spec.authors = ["David Hahn"]
|
10
|
+
spec.email = ["dhahn@ctatechs.com"]
|
11
|
+
spec.description = %q{ A wrapper of the Elastix Call Center Module that deals primarily with extension management.}
|
12
|
+
spec.summary = %q{ Elastix is a gem that simplifies the process of creating, removing and changing extensions in the elastix web interface.}
|
13
|
+
spec.homepage = "https://github.com/CTA/elastix"
|
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_dependency 'mechanize', '~> 2.7'
|
22
|
+
end
|
data/lib/elastix.rb
ADDED
data/lib/elastix/base.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'mechanize'
|
2
|
+
module Elastix
|
3
|
+
attr_accessor :elastix
|
4
|
+
class Base
|
5
|
+
def self.establish_connection( ip, username, password)
|
6
|
+
$elastix = Mechanize.new
|
7
|
+
$elastix.agent.http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
8
|
+
$base_address = "https://#{ip}"
|
9
|
+
$elastix.get($base_address)
|
10
|
+
login_form = $elastix.page.forms[0]
|
11
|
+
login_form.input_user = username
|
12
|
+
login_form.input_pass = password
|
13
|
+
$elastix.submit(login_form,login_form.button_with("submit_login"))
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.close_connection
|
17
|
+
$base_address = nil
|
18
|
+
$elastix = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.reload
|
22
|
+
$elastix.get("#{$base_address}/config.php?handler=reload")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
module Elastix
|
2
|
+
class Extension
|
3
|
+
attr_accessor :extension, :name, :sipname, :outboundcid, :devinfo_secret
|
4
|
+
|
5
|
+
def initialize(params)
|
6
|
+
params.each_pair{|key,value| instance_variable_set "@#{key}", value}
|
7
|
+
end
|
8
|
+
|
9
|
+
def destroy
|
10
|
+
$elastix.get("#{$base_address}/config.php?type=setup&display=extensions&extdisplay=#{self.extension}&action=del")
|
11
|
+
Base.reload
|
12
|
+
end
|
13
|
+
|
14
|
+
def save
|
15
|
+
raise "Extension already exists" if Extension.exist? self.extension
|
16
|
+
Extension.new_extension_object(self.to_hash)
|
17
|
+
Base.reload
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.create(params)
|
21
|
+
e = Extension.new(params)
|
22
|
+
e.save
|
23
|
+
e
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.all
|
27
|
+
#TODO abstract this method
|
28
|
+
page = $elastix.get("#{$base_address}/index.php?menu=pbxconfig")
|
29
|
+
extensions = []
|
30
|
+
page.links.each do |link|
|
31
|
+
extensions << Extension.find(get_extension_from_link_text(link.text)) if href_is_acceptable? link.href
|
32
|
+
end
|
33
|
+
extensions
|
34
|
+
end
|
35
|
+
|
36
|
+
def update_attributes!(params)
|
37
|
+
params[:extension] = self.extension
|
38
|
+
Extension.update_extension_object(params)
|
39
|
+
Base.reload
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.find(extension)
|
43
|
+
get_extension_object(extension) if exist?(extension)
|
44
|
+
end
|
45
|
+
|
46
|
+
def ==(extension)
|
47
|
+
self.to_hash == extension.to_hash
|
48
|
+
end
|
49
|
+
|
50
|
+
def to_hash
|
51
|
+
Hash[self.instance_variables.map{|var| [var.to_s.delete("@"), self.instance_variable_get(var)]}]
|
52
|
+
#my_hash.symbolize_keys
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
def self.get_extension_object(extension)
|
57
|
+
Extension.new(get_extension_attributes(get_extension_display_page(extension).forms.first))
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.update_extension_object(params)
|
61
|
+
page = get_extension_display_page(params[:extension])
|
62
|
+
update_and_submit_form(page, params)
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.new_extension_object(params)
|
66
|
+
page = get_extension_display_page(params[:extension])
|
67
|
+
#This is necessary for new objects. It would be nice to figure out why.
|
68
|
+
page.encoding = "utf-8"
|
69
|
+
form = page.form("frm_extensions")
|
70
|
+
page = form.submit(form.button_with("Submit"))
|
71
|
+
update_and_submit_form(page, params)
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.update_and_submit_form(page, params)
|
75
|
+
form = page.form("frm_extensions")
|
76
|
+
form.encoding = "utf-8"
|
77
|
+
params.each{|key,value| form[key.to_s] = value unless value.nil?}
|
78
|
+
$elastix.submit(form, form.button_with("Submit"))
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.get_extension_display_page(extension)
|
82
|
+
$elastix.get "#{$base_address}/config.php?type=setup&display=extensions&extdisplay=#{extension}"
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.get_extension_attributes(form)
|
86
|
+
Hash[form.fields.map{|field| [field.name, field.value] if is_a_class_attribute(field.name) and not field.value.empty?}]
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.is_a_class_attribute attr
|
90
|
+
Extension.instance_methods.grep(/\w=$/).include? "#{attr}=".to_sym
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.exist? extension
|
94
|
+
if $elastix.get("#{$base_address}/index.php?menu=pbxconfig")
|
95
|
+
.body.match(/#{extension}/) then true else false end
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.href_is_acceptable?(href)
|
99
|
+
href.include? "config.php?type=setup&display=extensions&extdisplay=" unless href.nil?
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.get_extension_from_link_text(link_text)
|
103
|
+
link_text.scan(/<(.*)>/).first.first
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
class Hash
|
109
|
+
#TODO figure out why symbols break the code. For now everything has to be in strings.
|
110
|
+
def symbolize_keys
|
111
|
+
self.keys.each do |key|
|
112
|
+
self[(key.to_sym rescue key) || key] = self.delete(key)
|
113
|
+
end
|
114
|
+
self
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
data/spec/base_spec.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Base do
|
4
|
+
describe ".establish_connection" do
|
5
|
+
before { Base.establish_connection $auth_options[:ip], $auth_options[:username], $auth_options[:password] }
|
6
|
+
it "should assign an address to $base_address" do
|
7
|
+
$base_address.should eq "https://192.168.1.237"
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should assign a mechanize agent to $elastix" do
|
11
|
+
$elastix.class.should eq Mechanize
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should log into the webform" do
|
15
|
+
$elastix.page.title.should eq "Elastix"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe ".close_connection" do
|
20
|
+
before{ Base.close_connection }
|
21
|
+
it "should assign $base_address to nil" do
|
22
|
+
$base_address.should be_nil
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should assign $elastix to nil" do
|
26
|
+
$elastix.should be_nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
pending "it should apply the configuration changes"
|
31
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Extension do
|
4
|
+
let(:params) {
|
5
|
+
{
|
6
|
+
"extension" => "4555", "sipname" => "3333",
|
7
|
+
"outboundcid" => "3333333333", "name" => "David Hahn", "devinfo_secret" => "secret"
|
8
|
+
}
|
9
|
+
}
|
10
|
+
|
11
|
+
before { Base.establish_connection $auth_options[:ip], $auth_options[:username], $auth_options[:password] }
|
12
|
+
after(:all){ Base.close_connection }
|
13
|
+
after(:each) do
|
14
|
+
Extension.new(params).destroy if Extension.find(params["extension"])
|
15
|
+
end
|
16
|
+
|
17
|
+
describe ".initialize" do
|
18
|
+
it "should assign all params to their attribute equivalents" do
|
19
|
+
e = Extension.new(params)
|
20
|
+
params.each_pair {|key,value| e.send(key).should eq value}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe ".create" do
|
25
|
+
it "should create an extension" do
|
26
|
+
e = Extension.create(params)
|
27
|
+
Extension.find(params["extension"]).to_hash.should eq e.to_hash
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should return an Extension object" do
|
31
|
+
Extension.create(params).class.should eq Elastix::Extension
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe ".save" do
|
36
|
+
it "should create an extension" do
|
37
|
+
e = Extension.new(params)
|
38
|
+
e.save
|
39
|
+
Extension.find(params["extension"]).should_not be_nil
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should raise error if extension already exists" do
|
43
|
+
Extension.create(params)
|
44
|
+
Extension.new(params)
|
45
|
+
expect{Extension.save(params)}.to raise_error
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe ".find" do
|
50
|
+
it "should return nil if extension doesn't exist" do
|
51
|
+
Extension.find("-9999999").should be_nil
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should return the extension object if extension does exist" do
|
55
|
+
e = Extension.new(params)
|
56
|
+
e.save
|
57
|
+
Extension.find(params["extension"]).to_hash.should eq e.to_hash
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe ".destroy" do
|
62
|
+
it "should remove the extension from the interface" do
|
63
|
+
e = Extension.create(params)
|
64
|
+
e.destroy
|
65
|
+
Extension.find(params["extension"]).should be_nil
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe ".all" do
|
70
|
+
it "should return all extensions" do
|
71
|
+
e = Extension.create(params)
|
72
|
+
Extension.all.should include e
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe ".==" do
|
77
|
+
it "should return true if method contain the same attributes" do
|
78
|
+
e = Extension.new(params)
|
79
|
+
e2 = Extension.new(params)
|
80
|
+
(e == e2).should be_true
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should return true if method contain the same attributes" do
|
84
|
+
e = Extension.new(params)
|
85
|
+
e2 = Extension.new({"extension" => "333333"})
|
86
|
+
(e == e2).should be_false
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe ".to_hash" do
|
91
|
+
it "should output the attributes of an extension to a hash" do
|
92
|
+
e = Extension.create(params)
|
93
|
+
e.to_hash.should eq params
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe ".update_attributes" do
|
98
|
+
it "should only update the attributes that are input" do
|
99
|
+
e = Extension.create(params)
|
100
|
+
e.update_attributes!("sipname" => "testing")
|
101
|
+
new_ext = Extension.find(e.extension)
|
102
|
+
e.to_hash.should eq new_ext.to_hash
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: elastix
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Hahn
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mechanize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.7'
|
27
|
+
description: ! ' A wrapper of the Elastix Call Center Module that deals primarily
|
28
|
+
with extension management.'
|
29
|
+
email:
|
30
|
+
- dhahn@ctatechs.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- .gitignore
|
36
|
+
- .rspec
|
37
|
+
- Gemfile
|
38
|
+
- LICENSE.txt
|
39
|
+
- README.md
|
40
|
+
- Rakefile
|
41
|
+
- elastix.gemspec
|
42
|
+
- lib/elastix.rb
|
43
|
+
- lib/elastix/base.rb
|
44
|
+
- lib/elastix/extension.rb
|
45
|
+
- lib/elastix/version.rb
|
46
|
+
- spec/base_spec.rb
|
47
|
+
- spec/extension_spec.rb
|
48
|
+
- spec/spec_helper.rb
|
49
|
+
homepage: https://github.com/CTA/elastix
|
50
|
+
licenses:
|
51
|
+
- MIT
|
52
|
+
metadata: {}
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 2.0.5
|
70
|
+
signing_key:
|
71
|
+
specification_version: 4
|
72
|
+
summary: Elastix is a gem that simplifies the process of creating, removing and changing
|
73
|
+
extensions in the elastix web interface.
|
74
|
+
test_files:
|
75
|
+
- spec/base_spec.rb
|
76
|
+
- spec/extension_spec.rb
|
77
|
+
- spec/spec_helper.rb
|