elastix 0.0.3 → 0.0.5
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 +8 -8
- data/README.md +1 -1
- data/elastix.gemspec +2 -0
- data/lib/elastix.rb +2 -0
- data/lib/elastix/base.rb +42 -14
- data/lib/elastix/extension.rb +45 -58
- data/lib/elastix/sip.rb +7 -0
- data/lib/elastix/user.rb +4 -0
- data/lib/elastix/version.rb +1 -1
- data/spec/extension_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -1
- metadata +32 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MTExMDJiNmNjNjM3NmZhMTE1MmEwYzdkODAwODExODFlY2ZiZTI5Yg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YmE3ZmVkZWFmMWUxZTAxYTgzMDEwYWJjOWRiMTIyOGE2NGIxOGNiZg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OWE3OGRjYjgxYmRlYTVkNzRmNTVhYzBlMGZiYzAzNjViNGEyNzk2ODUxZjcz
|
10
|
+
YzBhODQ1YjUyYzViMzM0MmYwYWM0OTE3NDdlZjU4MjNmMjQzZDA1NmRlOWNk
|
11
|
+
MDEyOWI4MTYyNTk5NDJiMzQ5YWIxNGQyM2Q2ZjM1ZmUxM2RmYjI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZWU3OTJhMWI2OTkzYzU1ZWJmYWM4YWE3ZDI2MjBjOTNlOTliNWMzNDUyMTFj
|
14
|
+
MTYxOTZkMWVmZTRmMjBkM2Q5OWE3NmE2ZWQ1YWQ4ODA3OTAwNzczNzE2NjEx
|
15
|
+
YzNkZTE5NjJiMWQ5ZDEyZDJmMWVmZWIxZjIyNWJjNTIzMGZhNDU=
|
data/README.md
CHANGED
data/elastix.gemspec
CHANGED
data/lib/elastix.rb
CHANGED
data/lib/elastix/base.rb
CHANGED
@@ -1,25 +1,53 @@
|
|
1
1
|
require 'mechanize'
|
2
2
|
module Elastix
|
3
|
-
attr_accessor :elastix
|
4
3
|
class Base
|
5
|
-
def self.
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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"))
|
4
|
+
def self.establish_web_connection host, username, password
|
5
|
+
@@elastix = Mechanize.new
|
6
|
+
@@elastix.agent.http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
7
|
+
@@base_address = "https://#{host}"
|
8
|
+
login username, password
|
14
9
|
end
|
10
|
+
|
15
11
|
|
16
|
-
def self.
|
17
|
-
|
18
|
-
|
12
|
+
def self.establish_db_connection(host, username, password)
|
13
|
+
ActiveRecord::Base.establish_connection(
|
14
|
+
:adapter => "mysql2",
|
15
|
+
:host => host,
|
16
|
+
:database => "asterisk",
|
17
|
+
:username => username,
|
18
|
+
:password => password,
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.establish_connection(web_options={}, db_options={})
|
23
|
+
establish_web_connection(web_options[:host], web_options[:username], web_options[:password])
|
24
|
+
establish_db_connection(db_options[:host], db_options[:username], db_options[:password])
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.close_db_connection
|
28
|
+
ActiveRecord::Base.connection.close
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.use_existing_db_connection connection
|
32
|
+
establish_connection connection
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.close_db_connection
|
36
|
+
@@base_address = nil
|
37
|
+
@@elastix = nil
|
19
38
|
end
|
20
39
|
|
21
40
|
def self.reload
|
22
|
-
|
41
|
+
@@elastix.get("#{@@base_address}/config.php?handler=reload")
|
23
42
|
end
|
43
|
+
|
44
|
+
private
|
45
|
+
def self.login username, password
|
46
|
+
@@elastix.get(@@base_address)
|
47
|
+
login_form = @@elastix.page.forms[0]
|
48
|
+
login_form.input_user = username
|
49
|
+
login_form.input_pass = password
|
50
|
+
@@elastix.submit(login_form,login_form.button_with("submit_login"))
|
51
|
+
end
|
24
52
|
end
|
25
53
|
end
|
data/lib/elastix/extension.rb
CHANGED
@@ -1,106 +1,93 @@
|
|
1
1
|
module Elastix
|
2
|
-
class Extension
|
2
|
+
class Extension < Base
|
3
3
|
attr_accessor :extension, :name, :sipname, :outboundcid, :devinfo_secret
|
4
4
|
|
5
|
-
def initialize
|
5
|
+
def initialize params
|
6
6
|
params.each_pair{|key,value| instance_variable_set "@#{key}", value}
|
7
7
|
end
|
8
8
|
|
9
9
|
def destroy
|
10
|
-
|
10
|
+
@@elastix.get("#{@@base_address}/config.php?type=setup&display=extensions&extdisplay=#{self.extension}&action=del")
|
11
11
|
Base.reload
|
12
12
|
end
|
13
13
|
|
14
14
|
def save
|
15
|
-
|
16
|
-
|
15
|
+
if Extension.exist? extension
|
16
|
+
update_extension_object
|
17
|
+
else
|
18
|
+
new_extension_object
|
19
|
+
end
|
17
20
|
Base.reload
|
18
21
|
end
|
19
22
|
|
20
|
-
def
|
21
|
-
|
22
|
-
|
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)
|
23
|
+
def update_attributes params
|
24
|
+
params.each_pair{|key,value| instance_variable_set "@#{key}", value}
|
25
|
+
self.update_extension_object
|
39
26
|
Base.reload
|
40
27
|
end
|
41
28
|
|
42
|
-
def
|
43
|
-
get_extension_object(extension) if exist?(extension)
|
44
|
-
end
|
45
|
-
|
46
|
-
def ==(extension)
|
29
|
+
def == extension
|
47
30
|
self.to_hash == extension.to_hash
|
48
31
|
end
|
49
32
|
|
50
33
|
def to_hash
|
51
34
|
Hash[self.instance_variables.map{|var| [var.to_s.delete("@"), self.instance_variable_get(var)]}]
|
52
|
-
#my_hash.symbolize_keys
|
53
35
|
end
|
54
36
|
|
37
|
+
|
38
|
+
def self.find extension
|
39
|
+
get_extension_object(extension) if exist?(extension)
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.create params
|
43
|
+
e = Extension.new(params)
|
44
|
+
e.save
|
45
|
+
e
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.all
|
49
|
+
Sip.uniq.pluck(:id)
|
50
|
+
end
|
51
|
+
|
55
52
|
private
|
56
|
-
def
|
57
|
-
Extension.
|
58
|
-
|
59
|
-
|
60
|
-
def self.update_extension_object(params)
|
61
|
-
page = get_extension_display_page(params[:extension])
|
62
|
-
update_and_submit_form(page, params)
|
53
|
+
def update_extension_object
|
54
|
+
page = Extension.get_extension_display_page(self.extension)
|
55
|
+
update_and_submit_form(page, self.to_hash)
|
63
56
|
end
|
64
57
|
|
65
|
-
def
|
66
|
-
page = get_extension_display_page(params[:extension])
|
58
|
+
def new_extension_object
|
67
59
|
#This is necessary for new objects. It would be nice to figure out why.
|
60
|
+
page = @@elastix.get("#{@@base_address}/index.php?menu=pbxconfig")
|
68
61
|
page.encoding = "utf-8"
|
69
62
|
form = page.form("frm_extensions")
|
70
63
|
page = form.submit(form.button_with("Submit"))
|
71
|
-
update_and_submit_form(page,
|
64
|
+
update_and_submit_form(page, self.to_hash)
|
72
65
|
end
|
73
66
|
|
74
|
-
def
|
67
|
+
def update_and_submit_form(page, params)
|
75
68
|
form = page.form("frm_extensions")
|
76
69
|
form.encoding = "utf-8"
|
77
70
|
params.each{|key,value| form[key.to_s] = value unless value.nil?}
|
78
|
-
|
71
|
+
@@elastix.submit(form, form.button_with("Submit"))
|
79
72
|
end
|
80
73
|
|
81
|
-
def self.
|
82
|
-
|
74
|
+
def self.get_extension_object(extension)
|
75
|
+
Extension.new(get_extension_attributes(extension))
|
83
76
|
end
|
84
77
|
|
85
|
-
def self.
|
86
|
-
|
78
|
+
def self.get_extension_display_page(extension)
|
79
|
+
@@elastix.get "#{@@base_address}/config.php?type=setup&display=extensions&extdisplay=#{extension}"
|
87
80
|
end
|
88
81
|
|
89
|
-
|
90
|
-
|
82
|
+
#TODO make it easier to add fields. Right now it's just hardcoded what is returned.
|
83
|
+
def self.get_extension_attributes extension
|
84
|
+
secret = Sip.where(id: extension, keyword: "secret").first.data
|
85
|
+
user_fields = User.find_by_extension(extension)
|
86
|
+
{extension: extension, name: user_fields.name, sipname: user_fields.sipname, outboundcid: user_fields.outboundcid, devinfo_secret: secret}
|
91
87
|
end
|
92
88
|
|
93
89
|
def self.exist? extension
|
94
|
-
|
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
|
90
|
+
!!Sip.find_by_id(extension)
|
104
91
|
end
|
105
92
|
end
|
106
93
|
end
|
data/lib/elastix/sip.rb
ADDED
data/lib/elastix/user.rb
ADDED
data/lib/elastix/version.rb
CHANGED
data/spec/extension_spec.rb
CHANGED
@@ -8,7 +8,7 @@ describe Extension do
|
|
8
8
|
}
|
9
9
|
}
|
10
10
|
|
11
|
-
before { Base.establish_connection $auth_options[:ip], $auth_options[:username], $auth_options[:password] }
|
11
|
+
before(:all) { Base.establish_connection $auth_options[:ip], $auth_options[:username], $auth_options[:password] }
|
12
12
|
after(:all){ Base.close_connection }
|
13
13
|
after(:each) do
|
14
14
|
Extension.new(params).destroy if Extension.find(params["extension"])
|
@@ -97,7 +97,7 @@ describe Extension do
|
|
97
97
|
describe ".update_attributes" do
|
98
98
|
it "should only update the attributes that are input" do
|
99
99
|
e = Extension.create(params)
|
100
|
-
e.update_attributes
|
100
|
+
e.update_attributes("sipname" => "testing")
|
101
101
|
new_ext = Extension.find(e.extension)
|
102
102
|
e.to_hash.should eq new_ext.to_hash
|
103
103
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elastix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Hahn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mechanize
|
@@ -24,6 +24,34 @@ dependencies:
|
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activerecord
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mysql2
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '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'
|
27
55
|
description: ! ' A wrapper of the Elastix Call Center Module that deals primarily
|
28
56
|
with extension management.'
|
29
57
|
email:
|
@@ -42,6 +70,8 @@ files:
|
|
42
70
|
- lib/elastix.rb
|
43
71
|
- lib/elastix/base.rb
|
44
72
|
- lib/elastix/extension.rb
|
73
|
+
- lib/elastix/sip.rb
|
74
|
+
- lib/elastix/user.rb
|
45
75
|
- lib/elastix/version.rb
|
46
76
|
- spec/base_spec.rb
|
47
77
|
- spec/extension_spec.rb
|