ultraspeed-epp 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +32 -0
- data/Rakefile +8 -0
- data/lib/epp.rb +12 -0
- data/lib/epp/server.rb +75 -0
- data/lib/require_parameters.rb +14 -0
- data/test/test_epp.rb +11 -0
- data/test/test_helper.rb +3 -0
- metadata +60 -0
data/README.rdoc
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
= EPP Version 1.0
|
2
|
+
|
3
|
+
http://github.com/ultraspeed/epp
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Basic functionality for connecting and making requests on EPP (Extensible Provisioning Protocol) servers.
|
8
|
+
|
9
|
+
== LICENSE:
|
10
|
+
|
11
|
+
(The MIT License)
|
12
|
+
|
13
|
+
Copyright (c) 2009 Josh Delsman (Ultraspeed)
|
14
|
+
|
15
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
16
|
+
a copy of this software and associated documentation files (the
|
17
|
+
'Software'), to deal in the Software without restriction, including
|
18
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
19
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
20
|
+
permit persons to whom the Software is furnished to do so, subject to
|
21
|
+
the following conditions:
|
22
|
+
|
23
|
+
The above copyright notice and this permission notice shall be
|
24
|
+
included in all copies or substantial portions of the Software.
|
25
|
+
|
26
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
27
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
28
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
29
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
30
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
31
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
32
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/lib/epp.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
require 'socket'
|
3
|
+
|
4
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
5
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
6
|
+
|
7
|
+
require 'require_parameters'
|
8
|
+
require 'epp/server.rb'
|
9
|
+
|
10
|
+
module Epp #:nodoc:
|
11
|
+
VERSION = '1.0'
|
12
|
+
end
|
data/lib/epp/server.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
module Epp #:nodoc:
|
2
|
+
class Server
|
3
|
+
include RequiresParameters
|
4
|
+
|
5
|
+
def initialize(attributes = {})
|
6
|
+
requires!(attributes, :server, :port)
|
7
|
+
|
8
|
+
@connection = open_connection(attributes[:server], attributes[:port])
|
9
|
+
@socket = open_socket(@connection)
|
10
|
+
|
11
|
+
# Initiate the connection to the server through the SSL socket
|
12
|
+
@socket.connect
|
13
|
+
|
14
|
+
# Receive the EPP <greeting> frame which is sent by the server
|
15
|
+
# upon initial connection
|
16
|
+
get_frame
|
17
|
+
end
|
18
|
+
|
19
|
+
# Sends an XML request to the EPP server, and receives an XML response
|
20
|
+
def request(xml)
|
21
|
+
send_frame(xml)
|
22
|
+
get_frame
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
# Opens a connection to the EPP server.
|
28
|
+
def open_connection(server, port)
|
29
|
+
TCPSocket.new(server, port)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Opens an SSL socket with the EPP server.
|
33
|
+
def open_socket(connection)
|
34
|
+
OpenSSL::SSL::SSLSocket.new(connection)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Closes the connection to the EPP server. It should be noted
|
38
|
+
# that the EPP specification indicates that clients should send
|
39
|
+
# a <logout> command before ending the session, so it is recommended
|
40
|
+
# that you do so.
|
41
|
+
def close_connection
|
42
|
+
@socket.close if defined?(@socket) && !@socket.closed?
|
43
|
+
@connection.close if defined?(@connection) && !@connection.closed?
|
44
|
+
end
|
45
|
+
|
46
|
+
# Receive an EPP frame from the server. Since the connection is blocking,
|
47
|
+
# this method will wait until the connection becomes available for use. If
|
48
|
+
# the connection is broken, a SocketError will be raised. Otherwise,
|
49
|
+
# it will return a string containing the XML from the server.
|
50
|
+
def get_frame
|
51
|
+
header = @socket.read(4)
|
52
|
+
|
53
|
+
if header.nil? and @socket.closed?
|
54
|
+
raise SocketError.new("Connection closed by remote server")
|
55
|
+
elsif header.nil?
|
56
|
+
raise SocketError.new("Error reading frame from remote server")
|
57
|
+
else
|
58
|
+
unpacked_header = header.unpack("N")
|
59
|
+
length = unpacked_header[0]
|
60
|
+
|
61
|
+
if length < 5
|
62
|
+
raise SocketError.new("Got bad frame header length of #{length} bytes from the server")
|
63
|
+
else
|
64
|
+
@socket.read(length - 4)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# Send an XML frame to the server. Should return the total byte
|
70
|
+
# size of the frame sent to the server.
|
71
|
+
def send_frame(xml)
|
72
|
+
@socket.write([xml.length].pack("N") + xml)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module RequiresParameters #:nodoc:
|
2
|
+
def requires!(hash, *params)
|
3
|
+
params.each do |param|
|
4
|
+
if param.is_a?(Array)
|
5
|
+
raise ArgumentError.new("Missing required parameter: #{param.first}") unless hash.has_key?(param.first)
|
6
|
+
|
7
|
+
valid_options = param[1..-1]
|
8
|
+
raise ArgumentError.new("Parameter: #{param.first} must be one of #{valid_options.to_sentence(:connector => 'or')}") unless valid_options.include?(hash[param.first])
|
9
|
+
else
|
10
|
+
raise ArgumentError.new("Missing required parameter: #{param}") unless hash.has_key?(param)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/test/test_epp.rb
ADDED
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ultraspeed-epp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Josh Delsman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-06-03 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Basic functionality for connecting and making requests on EPP (Extensible Provisioning Protocol) servers.
|
17
|
+
email: jdelsman@ultraspeed.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- lib/epp/server.rb
|
26
|
+
- lib/epp.rb
|
27
|
+
- lib/require_parameters.rb
|
28
|
+
- Rakefile
|
29
|
+
- README.rdoc
|
30
|
+
- test/test_epp.rb
|
31
|
+
- test/test_helper.rb
|
32
|
+
has_rdoc: true
|
33
|
+
homepage: http://github.com/ultraspeed/epp
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options:
|
36
|
+
- --inline-source
|
37
|
+
- --charset=UTF-8
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "0"
|
45
|
+
version:
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
requirements: []
|
53
|
+
|
54
|
+
rubyforge_project: epp
|
55
|
+
rubygems_version: 1.2.0
|
56
|
+
signing_key:
|
57
|
+
specification_version: 2
|
58
|
+
summary: Basic functionality for connecting and making requests on EPP (Extensible Provisioning Protocol) servers.
|
59
|
+
test_files: []
|
60
|
+
|