switchvoxFix 0.1.3

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: 459f4e3771735faa173522402167f33ddb977999
4
+ data.tar.gz: 10d4c1ba90d526b6f8161d7dd6b8bf026217d056
5
+ SHA512:
6
+ metadata.gz: 50477ea89177a279ba4164f2302a52e0774cb60de5aae52b3d387a9e2f8a40d91a54552969d6b40007bbf5d6c346b682324256ee85fd04fb3b2b824c0f57a53a
7
+ data.tar.gz: 1898ba823262b2c7d284b7c535b7f27d303191d6c25555e19f81652a8e47cbd25f2cc9e01681fb469e50168c0872f19c93700e30afb43a7ceee5097d5db96ac4
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|switchvoxgem| "https://github.com/wrenchell/switchvoxgem" }
4
+
5
+ # Specify your gem's dependencies in switchvox.gemspec
6
+ gemspec
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ === 0.0.1 2010-04-22
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Mitchell Thompson
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/Manifest.txt ADDED
@@ -0,0 +1,16 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.md
4
+ Rakefile
5
+ lib/switchvoxFix.rb
6
+ lib/switchvoxFix/array.rb
7
+ lib/switchvoxFix/base.rb
8
+ lib/switchvoxFix/hash.rb
9
+ lib/switchvoxFix/net_http_digest_auth.rb
10
+ lib/switchvoxFix/object.rb
11
+ script/console
12
+ script/destroy
13
+ script/generate
14
+ test/test_helper.rb
15
+ test/test_json_to_obj.rb
16
+ test/test_switchvox.rb
data/README.md ADDED
@@ -0,0 +1,70 @@
1
+ = Switchvox
2
+
3
+ * http://github.com/chicks/switchvox
4
+
5
+ == SUMMARY:
6
+
7
+ Ruby Gem for interacting with Digium's Switchvox PBX via JSON
8
+
9
+ == DESCRIPTION:
10
+
11
+ Ruby Gem for interacting with Digium's Switchvox PBX via JSON.
12
+
13
+ There wasn't a gem out there, so I wrote one.
14
+
15
+ == FEATURES/PROBLEMS:
16
+
17
+ * The response hash gets converted into a Ruby object, via Hash#to_obj method.
18
+
19
+ == SYNOPSIS:
20
+
21
+ require 'switchvox'
22
+ switchvox = Switchvox::Base.new("pbx.foo.com", 'user', 'password', {:debug => false})
23
+
24
+ # Pull the software version of Switchvox
25
+ switchvox.request("switchvox.info.getSoftwareVersion")
26
+
27
+ # Pull a call report
28
+ call_log = switchvox.request("switchvox.callLogs.search", {
29
+ "start_date" => "2010-01-01 00:00:00",
30
+ "end_date" => "2010-01-02 23:59:59",
31
+ "account_ids" => [1001],
32
+ })
33
+ calls = call_log.calls.call
34
+ calls.each do |call|
35
+ c = call.to_obj
36
+ puts calls.index(call).to_s + ": " + c.start_time + ": " + c.from + " " + c.to
37
+ end
38
+
39
+ == REQUIREMENTS:
40
+
41
+ * json gem
42
+
43
+ == INSTALL:
44
+
45
+ * sudo gem install switchvox
46
+
47
+ == LICENSE:
48
+
49
+ (The MIT License)
50
+
51
+ Copyright (c) 2010 Carl Hicks
52
+
53
+ Permission is hereby granted, free of charge, to any person obtaining
54
+ a copy of this software and associated documentation files (the
55
+ 'Software'), to deal in the Software without restriction, including
56
+ without limitation the rights to use, copy, modify, merge, publish,
57
+ distribute, sublicense, and/or sell copies of the Software, and to
58
+ permit persons to whom the Software is furnished to do so, subject to
59
+ the following conditions:
60
+
61
+ The above copyright notice and this permission notice shall be
62
+ included in all copies or substantial portions of the Software.
63
+
64
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
65
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
66
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
67
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
68
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
69
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
70
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/switchvoxFix'
6
+
7
+ Hoe.plugin :newgem
8
+ Hoe.plugin :git
9
+ # Hoe.plugin :website
10
+ # Hoe.plugin :cucumberfeatures
11
+
12
+ # Generate all the Rake tasks
13
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
14
+ $hoe = Hoe.spec 'switchvoxFix' do
15
+ self.developer 'mthompson', 'mthompson@unitas-inc.com'
16
+ self.rubyforge_name = self.name # TODO this is default value
17
+ self.extra_deps = [['json']]
18
+
19
+ end
20
+
21
+ require 'newgem/tasks'
22
+ Dir['tasks/**/*.rake'].each { |t| load t }
23
+
24
+ # TODO - want other tests/tasks run by default? Add them to the list
25
+ # remove_task :default
26
+ # task :default => [:spec, :features]
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "switchvoxFix"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,14 @@
1
+ # A fancy way of iterating over an array and converting hashes to objects
2
+ class Array
3
+ def to_obj
4
+ # Make a deep copy of the array
5
+ a = Marshal.load(Marshal.dump(self))
6
+ a.each do |i|
7
+ case i.class.to_s
8
+ when "Hash" then i = i.to_obj
9
+ when "Array" then i = i.to_obj
10
+ end
11
+ end
12
+ a
13
+ end
14
+ end
@@ -0,0 +1,145 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ module SwitchvoxFix
4
+
5
+ require 'uri'
6
+ require 'net/https'
7
+ require 'openssl'
8
+ require 'digest/md5'
9
+ require 'rubygems'
10
+ require 'json'
11
+
12
+ # Raised when credentials are incorrect
13
+ class LoginError < RuntimeError
14
+ end
15
+
16
+ # Raised when the response.body is empty
17
+ class EmptyResponse < RuntimeError
18
+ end
19
+
20
+ # Raised when a response is returned that we don't know how to handle
21
+ class UnhandledResponse < RuntimeError
22
+ end
23
+
24
+ # The primary class used to interact with Switchvox.
25
+ class Base
26
+
27
+ URL = "/json"
28
+ attr :host, true
29
+ attr :url, true
30
+ attr :user, false
31
+ attr :pass, false
32
+ attr :connection, true
33
+ attr :session, true
34
+ attr :debug, true
35
+ attr :auth_header, true
36
+
37
+ def initialize(host, user, pass, options={})
38
+ {:debug => false}.merge! options
39
+ @debug = options[:debug]
40
+
41
+ @host = host
42
+ @user = user
43
+ @pass = pass
44
+ @url = URI.parse("https://" + @host + URL)
45
+ @ssl = false
46
+ @ssl = true if @url.scheme == "https"
47
+
48
+ @connection = false
49
+ @auth_header = false
50
+ login!
51
+ raise LoginError, "Invalid Username or Password" unless logged_in?
52
+ end
53
+
54
+ # A standard REST call to get a list of entries
55
+ def request(method, parameters={})
56
+ login! unless logged_in?
57
+ json = wrap_json(method, parameters)
58
+
59
+ # Send the request
60
+ header = {'Content-Type' => "application/json"}
61
+ request = Net::HTTP::Post.new(@url.path, header)
62
+ request.digest_auth(@user, @pass, @auth_header)
63
+ request.body = json
64
+ response = @connection.request(request)
65
+
66
+ if @debug
67
+ puts "#{method}: Request"
68
+ puts json
69
+ puts "\n"
70
+ end
71
+
72
+ case response
73
+ when Net::HTTPOK
74
+ raise EmptyResponse unless response.body
75
+ response_json = JSON.parse response.body
76
+ if @debug
77
+ puts "#{method}: Response:"
78
+ pp response_json
79
+ puts "\n\n"
80
+ end
81
+ response_obj = response_json["response"]["result"].to_obj
82
+ return response_obj
83
+ when Net::HTTPUnauthorized
84
+ login!
85
+ request(method, parameters)
86
+ when Net::HTTPForbidden
87
+ raise LoginError, "Invalid Username or Password"
88
+ else raise UnhandledResponse, "Can't handle response #{response}"
89
+ end
90
+ end
91
+
92
+ protected
93
+
94
+ # Check to see if we are logged in
95
+ def logged_in?
96
+ return false unless @auth_header
97
+ true
98
+ end
99
+
100
+ # Attempt HTTP Digest Authentication with Switchvox
101
+ def login!
102
+ connect! unless connected?
103
+ @auth_header = @connection.head(@url.path)
104
+ end
105
+
106
+ # Check to see if we have an HTTP/S Connection
107
+ def connected?
108
+ return false unless @connection
109
+ return false unless @connection.started?
110
+ true
111
+ end
112
+
113
+ # Connect to the remote Switchvox system. If SSL is enabled, ignore certificate checking.
114
+ def connect!
115
+ @connection = Net::HTTP.new(@url.host, @url.port)
116
+ if @ssl
117
+ @connection.use_ssl = true
118
+ @connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
119
+ end
120
+ if @debug
121
+ #@connection.set_debug_output $stderr
122
+ end
123
+ @connection.start
124
+ end
125
+
126
+ # Wrap a JSON method and parameters in a Switchvox compatible request body.
127
+ def wrap_json(method, parameters={})
128
+ json = <<-"EOF"
129
+ {
130
+ \"request\": {
131
+ \"method\": \"#{method}\",
132
+ \"parameters\": #{parameters.to_json}
133
+ }
134
+ }
135
+ EOF
136
+ json.gsub!(/^\s{8}/,'')
137
+ end
138
+
139
+ end
140
+
141
+ end
142
+
143
+
144
+
145
+
@@ -0,0 +1,17 @@
1
+ # A fancy way of iterating over a hash and converting hashes to objects
2
+ class Hash
3
+ def to_obj
4
+ o = Object.new
5
+ self.each do |k,v|
6
+ # If we're looking at a hash or array, we need to look through them and convert any hashes to objects as well
7
+ case v.class.to_s
8
+ when "Hash" then v = v.to_obj
9
+ when "Array" then v = v.to_obj
10
+ end
11
+ o.instance_variable_set("@#{k}", v) ## create and initialize an instance variable for this key/value pair
12
+ o.class.send(:define_method, k, proc{o.instance_variable_get("@#{k}")}) ## create the getter that returns the instance variable
13
+ o.class.send(:define_method, "#{k}=", proc{|v| o.instance_variable_set("@#{k}", v)}) ## create the setter that sets the instance variable
14
+ end
15
+ o
16
+ end
17
+ end
@@ -0,0 +1,34 @@
1
+ module Net
2
+ module HTTPHeader
3
+ require 'digest/md5'
4
+ require 'net/http'
5
+
6
+ @@nonce_count = -1
7
+ CNONCE = Digest::MD5.new.update("%x" % (Time.now.to_i + rand(65535))).hexdigest
8
+ def digest_auth(user, password, response)
9
+ # based on http://segment7.net/projects/ruby/snippets/digest_auth.rb
10
+ @@nonce_count += 1
11
+
12
+ response['www-authenticate'] =~ /^(\w+) (.*)/
13
+
14
+ params = {}
15
+ $2.gsub(/(\w+)="(.*?)"/) { params[$1] = $2 }
16
+
17
+ a_1 = "#{user}:#{params['realm']}:#{password}"
18
+ a_2 = "#{@method}:#{@path}"
19
+ request_digest = ''
20
+ request_digest << Digest::MD5.new.update(a_1).hexdigest
21
+ request_digest << ':' << params['nonce']
22
+ request_digest << ':' << Digest::MD5.new.update(a_2).hexdigest
23
+
24
+ header = []
25
+ header << "Digest username=\"#{user}\""
26
+ header << "realm=\"#{params['realm']}\""
27
+ header << "uri=\"#{@path}\""
28
+ header << "nonce=\"#{params['nonce']}\""
29
+ header << "response=\"#{Digest::MD5.new.update(request_digest).hexdigest}\""
30
+
31
+ @header['Authorization'] = header
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,5 @@
1
+ class Object
2
+ def to_obj
3
+ self
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module SwitchvoxFix
2
+ VERSION = "0.1.3"
3
+ end
@@ -0,0 +1,12 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'switchvoxFix/hash'
5
+ require 'switchvoxFix/array'
6
+ require 'switchvoxFix/object'
7
+ require 'switchvoxFix/net_http_digest_auth'
8
+ require 'switchvoxFix/base'
9
+
10
+ module SwitchvoxFix
11
+ VERSION = '0.1.3'
12
+ end
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/switchvoxFix.rb'}"
9
+ puts "Loading switchvoxFix gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "switchvoxFix/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "switchvoxFix"
8
+ spec.version = SwitchvoxFix::VERSION
9
+ spec.authors = ["Mitchell Thompson"]
10
+ spec.email = ["mthompson@unitas-inc.com"]
11
+ spec.summary = "Fixed issues with outdated gem"
12
+ spec.description = "Something Dumb here"
13
+ spec.homepage = "https://github.com/wrenchell/switchvoxFix"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+
19
+
20
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
21
+ f.match(%r{^(test|spec|features)/})
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.15"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: switchvoxFix
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Mitchell Thompson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-10-19 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.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Something Dumb here
42
+ email:
43
+ - mthompson@unitas-inc.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - History.txt
51
+ - LICENSE.txt
52
+ - Manifest.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/console
56
+ - bin/setup
57
+ - lib/switchvoxFix.rb
58
+ - lib/switchvoxFix/array.rb
59
+ - lib/switchvoxFix/base.rb
60
+ - lib/switchvoxFix/hash.rb
61
+ - lib/switchvoxFix/net_http_digest_auth.rb
62
+ - lib/switchvoxFix/object.rb
63
+ - lib/switchvoxFix/version.rb
64
+ - script/console
65
+ - script/destroy
66
+ - script/generate
67
+ - switchvoxFix.gemspec
68
+ homepage: https://github.com/wrenchell/switchvoxFix
69
+ licenses:
70
+ - MIT
71
+ metadata: {}
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 2.6.8
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: Fixed issues with outdated gem
92
+ test_files: []