switchvoxFix 0.1.4 → 0.1.6
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 +4 -4
- data/lib/switchvoxFix.rb +1 -1
- data/lib/switchvoxFix/version.rb +1 -1
- metadata +2 -12
- data/History.txt +0 -4
- data/Manifest.txt +0 -16
- data/lib/switchvoxFix/array.rb +0 -14
- data/lib/switchvoxFix/base.rb +0 -146
- data/lib/switchvoxFix/hash.rb +0 -17
- data/lib/switchvoxFix/net_http_digest_auth.rb +0 -34
- data/lib/switchvoxFix/object.rb +0 -5
- data/script/console +0 -10
- data/script/destroy +0 -14
- data/script/generate +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d01113df5ddc4d4075d53c4df153c38c741795c
|
4
|
+
data.tar.gz: a009db4e203fcc92c028d62c3def9ee236ba180d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c587468b85cfcf57b5f34cd319b162f57e6e6f2bd915f89af7b72168248dc587e1592e2f6876067dee3cd4835687ca124e636ca0becf84a653a03cd16ae66d33
|
7
|
+
data.tar.gz: 5bebde59c6a0357b10904dd00d315adfb283689657af11aa77acab7872e1068a78eafe4b6db97df613f53c76f84837dae3d073ce86d4c67ef8f8819d2429a179
|
data/lib/switchvoxFix.rb
CHANGED
data/lib/switchvoxFix/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: switchvoxFix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mitchell Thompson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -48,23 +48,13 @@ extra_rdoc_files: []
|
|
48
48
|
files:
|
49
49
|
- ".gitignore"
|
50
50
|
- Gemfile
|
51
|
-
- History.txt
|
52
51
|
- LICENSE.txt
|
53
|
-
- Manifest.txt
|
54
52
|
- README.md
|
55
53
|
- Rakefile
|
56
54
|
- bin/console
|
57
55
|
- bin/setup
|
58
56
|
- lib/switchvoxFix.rb
|
59
|
-
- lib/switchvoxFix/array.rb
|
60
|
-
- lib/switchvoxFix/base.rb
|
61
|
-
- lib/switchvoxFix/hash.rb
|
62
|
-
- lib/switchvoxFix/net_http_digest_auth.rb
|
63
|
-
- lib/switchvoxFix/object.rb
|
64
57
|
- lib/switchvoxFix/version.rb
|
65
|
-
- script/console
|
66
|
-
- script/destroy
|
67
|
-
- script/generate
|
68
58
|
- switchvoxFix.gemspec
|
69
59
|
homepage: https://github.com/wrenchell/switchvoxFix
|
70
60
|
licenses:
|
data/History.txt
DELETED
data/Manifest.txt
DELETED
@@ -1,16 +0,0 @@
|
|
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/lib/switchvoxFix/array.rb
DELETED
@@ -1,14 +0,0 @@
|
|
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
|
data/lib/switchvoxFix/base.rb
DELETED
@@ -1,146 +0,0 @@
|
|
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, port, 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
|
-
@url.port = port
|
46
|
-
@ssl = false
|
47
|
-
@ssl = true if @url.scheme == "https"
|
48
|
-
|
49
|
-
@connection = false
|
50
|
-
@auth_header = false
|
51
|
-
login!
|
52
|
-
raise LoginError, "Invalid Username or Password" unless logged_in?
|
53
|
-
end
|
54
|
-
|
55
|
-
# A standard REST call to get a list of entries
|
56
|
-
def request(method, parameters={})
|
57
|
-
login! unless logged_in?
|
58
|
-
json = wrap_json(method, parameters)
|
59
|
-
|
60
|
-
# Send the request
|
61
|
-
header = {'Content-Type' => "application/json"}
|
62
|
-
request = Net::HTTP::Post.new(@url.path, header)
|
63
|
-
request.digest_auth(@user, @pass, @auth_header)
|
64
|
-
request.body = json
|
65
|
-
response = @connection.request(request)
|
66
|
-
|
67
|
-
if @debug
|
68
|
-
puts "#{method}: Request"
|
69
|
-
puts json
|
70
|
-
puts "\n"
|
71
|
-
end
|
72
|
-
|
73
|
-
case response
|
74
|
-
when Net::HTTPOK
|
75
|
-
raise EmptyResponse unless response.body
|
76
|
-
response_json = JSON.parse response.body
|
77
|
-
if @debug
|
78
|
-
puts "#{method}: Response:"
|
79
|
-
pp response_json
|
80
|
-
puts "\n\n"
|
81
|
-
end
|
82
|
-
response_obj = response_json["response"]["result"].to_obj
|
83
|
-
return response_obj
|
84
|
-
when Net::HTTPUnauthorized
|
85
|
-
login!
|
86
|
-
request(method, parameters)
|
87
|
-
when Net::HTTPForbidden
|
88
|
-
raise LoginError, "Invalid Username or Password"
|
89
|
-
else raise UnhandledResponse, "Can't handle response #{response}"
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
protected
|
94
|
-
|
95
|
-
# Check to see if we are logged in
|
96
|
-
def logged_in?
|
97
|
-
return false unless @auth_header
|
98
|
-
true
|
99
|
-
end
|
100
|
-
|
101
|
-
# Attempt HTTP Digest Authentication with Switchvox
|
102
|
-
def login!
|
103
|
-
connect! unless connected?
|
104
|
-
@auth_header = @connection.head(@url.path)
|
105
|
-
end
|
106
|
-
|
107
|
-
# Check to see if we have an HTTP/S Connection
|
108
|
-
def connected?
|
109
|
-
return false unless @connection
|
110
|
-
return false unless @connection.started?
|
111
|
-
true
|
112
|
-
end
|
113
|
-
|
114
|
-
# Connect to the remote Switchvox system. If SSL is enabled, ignore certificate checking.
|
115
|
-
def connect!
|
116
|
-
@connection = Net::HTTP.new(@url.host, @url.port)
|
117
|
-
if @ssl
|
118
|
-
@connection.use_ssl = true
|
119
|
-
@connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
120
|
-
end
|
121
|
-
if @debug
|
122
|
-
#@connection.set_debug_output $stderr
|
123
|
-
end
|
124
|
-
@connection.start
|
125
|
-
end
|
126
|
-
|
127
|
-
# Wrap a JSON method and parameters in a Switchvox compatible request body.
|
128
|
-
def wrap_json(method, parameters={})
|
129
|
-
json = <<-"EOF"
|
130
|
-
{
|
131
|
-
\"request\": {
|
132
|
-
\"method\": \"#{method}\",
|
133
|
-
\"parameters\": #{parameters.to_json}
|
134
|
-
}
|
135
|
-
}
|
136
|
-
EOF
|
137
|
-
json.gsub!(/^\s{8}/,'')
|
138
|
-
end
|
139
|
-
|
140
|
-
end
|
141
|
-
|
142
|
-
end
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
data/lib/switchvoxFix/hash.rb
DELETED
@@ -1,17 +0,0 @@
|
|
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
|
@@ -1,34 +0,0 @@
|
|
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
|
data/lib/switchvoxFix/object.rb
DELETED
data/script/console
DELETED
@@ -1,10 +0,0 @@
|
|
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
DELETED
@@ -1,14 +0,0 @@
|
|
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
DELETED
@@ -1,14 +0,0 @@
|
|
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)
|