epp-client-base 0.14.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,5 @@
1
1
  module EPPClient
2
+ # This "strange" exception allows having more informative error messages.
2
3
  class EPPErrorResponse < StandardError
3
4
  attr_accessor :response_xml, :response_code, :message
4
5
 
@@ -1,8 +1,9 @@
1
1
  module EPPClient
2
+ # This implements the poll EPP commands.
2
3
  module Poll
3
4
  def poll_req_xml #:nodoc:
4
5
  command do |xml|
5
- xml.poll(:op => :req)
6
+ xml.poll(:op => :req)
6
7
  end
7
8
  end
8
9
 
@@ -28,33 +29,32 @@ module EPPClient
28
29
 
29
30
  def poll_req_process(xml) #:nodoc:
30
31
  ret = {}
31
- if (date = xml.xpath("epp:msgQ/epp:qDate", EPPClient::SCHEMAS_URL)).size > 0
32
- ret[:qDate] = DateTime.parse(date.text)
32
+ if (date = xml.xpath('epp:msgQ/epp:qDate', EPPClient::SCHEMAS_URL)).size > 0
33
+ ret[:qDate] = DateTime.parse(date.text)
33
34
  end
34
- if (msg = xml.xpath("epp:msgQ/epp:msg", EPPClient::SCHEMAS_URL)).size > 0
35
- ret[:msg] = msg.text
36
- ret[:msg_xml] = msg.to_s
35
+ if (msg = xml.xpath('epp:msgQ/epp:msg', EPPClient::SCHEMAS_URL)).size > 0
36
+ ret[:msg] = msg.text
37
+ ret[:msg_xml] = msg.to_s
37
38
  end
38
39
  if (obj = xml.xpath('epp:resData', EPPClient::SCHEMAS_URL)).size > 0 ||
39
- (obj = xml.xpath('epp:extension', EPPClient::SCHEMAS_URL)).size > 0
40
- ret[:obj_xml] = obj.to_s
41
- PARSERS.each do |xpath,parser|
42
- if obj.xpath(xpath, EPPClient::SCHEMAS_URL).size > 0
43
- ret[:obj] = case parser
44
- when Symbol
45
- send(parser, xml)
46
- else
47
- raise NotImplementedError
48
- end
49
- end
50
- end
40
+ (obj = xml.xpath('epp:extension', EPPClient::SCHEMAS_URL)).size > 0
41
+ ret[:obj_xml] = obj.to_s
42
+ PARSERS.each do |xpath, parser|
43
+ next unless obj.xpath(xpath, EPPClient::SCHEMAS_URL).size > 0
44
+ ret[:obj] = case parser
45
+ when Symbol
46
+ send(parser, xml)
47
+ else
48
+ fail NotImplementedError
49
+ end
50
+ end
51
51
  end
52
52
  ret
53
53
  end
54
54
 
55
55
  def poll_ack_xml(mid) #:nodoc:
56
56
  command do |xml|
57
- xml.poll(:op => :ack, :msgID => mid)
57
+ xml.poll(:op => :ack, :msgID => mid)
58
58
  end
59
59
  end
60
60
 
@@ -1,36 +1,34 @@
1
1
  module EPPClient
2
+ # This handles the basic session, login, logout, and hello.
2
3
  module Session
3
-
4
4
  # Sends an hello epp command.
5
5
  def hello
6
- send_request(command do |xml|
7
- xml.hello
8
- end)
6
+ send_request(command(&:hello))
9
7
  end
10
8
 
11
9
  def login_xml(new_pw = nil) #:nodoc:
12
10
  command do |xml|
13
- xml.login do
14
- xml.clID(@client_id)
15
- xml.pw(@password)
16
- xml.newPW(new_pw) unless new_pw.nil?
17
- xml.options do
18
- xml.version(@version)
19
- xml.lang(@lang)
20
- end
21
- xml.svcs do
22
- services.each do |s|
23
- xml.objURI(s)
24
- end
25
- unless extensions.empty?
26
- xml.svcExtension do
27
- extensions.each do |e|
28
- xml.extURI(e)
29
- end
30
- end
31
- end
32
- end
33
- end
11
+ xml.login do
12
+ xml.clID(@client_id)
13
+ xml.pw(@password)
14
+ xml.newPW(new_pw) unless new_pw.nil?
15
+ xml.options do
16
+ xml.version(@version)
17
+ xml.lang(@lang)
18
+ end
19
+ xml.svcs do
20
+ services.each do |s|
21
+ xml.objURI(s)
22
+ end
23
+ unless extensions.empty?
24
+ xml.svcExtension do
25
+ extensions.each do |e|
26
+ xml.extURI(e)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
34
32
  end
35
33
  end
36
34
  private :login_xml
@@ -46,9 +44,7 @@ module EPPClient
46
44
  # Performs the logout command, after it, the server terminates the
47
45
  # connection.
48
46
  def logout
49
- response = send_request(command do |xml|
50
- xml.logout
51
- end)
47
+ response = send_request(command(&:logout))
52
48
 
53
49
  get_result(response)
54
50
  end
@@ -1,32 +1,29 @@
1
1
  module EPPClient
2
+ # This module handles the SSL strangeness that happens with EPP.
2
3
  module SSL
3
4
  attr_reader :ssl_cert, :ssl_key
4
5
 
5
6
  def ssl_key=(key) #:nodoc:
6
7
  case key
7
8
  when OpenSSL::PKey::RSA
8
- @ssl_key = key
9
+ @ssl_key = key
9
10
  when String
10
- unless key =~ /-----BEGIN RSA PRIVATE KEY-----/
11
- key = File.read(key)
12
- end
13
- @ssl_key = OpenSSL::PKey::RSA.new(key)
11
+ key = File.read(key) unless key =~ /-----BEGIN RSA PRIVATE KEY-----/
12
+ @ssl_key = OpenSSL::PKey::RSA.new(key)
14
13
  else
15
- raise ArgumentError, "Must either be an OpenSSL::PKey::RSA object, a filename or a key"
14
+ fail ArgumentError, 'Must either be an OpenSSL::PKey::RSA object, a filename or a key'
16
15
  end
17
16
  end
18
17
 
19
18
  def ssl_cert=(cert) #:nodoc:
20
19
  case cert
21
20
  when OpenSSL::X509::Certificate
22
- @ssl_cert = cert
21
+ @ssl_cert = cert
23
22
  when String
24
- unless cert =~ /-----BEGIN CERTIFICATE-----/
25
- cert = File.read(cert)
26
- end
27
- @ssl_cert = OpenSSL::X509::Certificate.new(cert)
23
+ cert = File.read(cert) unless cert =~ /-----BEGIN CERTIFICATE-----/
24
+ @ssl_cert = OpenSSL::X509::Certificate.new(cert)
28
25
  else
29
- raise ArgumentError, "Must either be an OpenSSL::X509::Certificate object, a filename or a certificate"
26
+ fail ArgumentError, 'Must either be an OpenSSL::X509::Certificate object, a filename or a certificate'
30
27
  end
31
28
  end
32
29
 
@@ -1,3 +1,3 @@
1
1
  module EPPClient
2
- VERSION = "0.14.0"
2
+ VERSION = '0.15.0'.freeze
3
3
  end
@@ -1,13 +1,13 @@
1
1
  module EPPClient
2
+ # This handles all the XML I/O
2
3
  module XML
3
-
4
4
  attr_reader :sent_xml, :recv_xml, :msgQ_count, :msgQ_id, :trID
5
5
 
6
6
  # Parses a frame and returns a Nokogiri::XML::Document.
7
7
  def parse_xml(string) #:doc:
8
8
  Nokogiri::XML::Document.parse(string) do |opts|
9
- opts.options = 0
10
- opts.noblanks
9
+ opts.options = 0
10
+ opts.noblanks
11
11
  end
12
12
  end
13
13
  private :parse_xml
@@ -15,13 +15,13 @@ module EPPClient
15
15
  def recv_frame_to_xml #:nodoc:
16
16
  @recv_xml = parse_xml(@recv_frame)
17
17
  puts @recv_xml.to_s.gsub(/^/, '<< ') if debug
18
- return @recv_xml
18
+ @recv_xml
19
19
  end
20
20
 
21
21
  def sent_frame_to_xml #:nodoc:
22
22
  @send_xml = parse_xml(@sent_frame)
23
23
  puts @send_xml.to_s.gsub(/^/, '>> ') if debug
24
- return @send_xml
24
+ @send_xml
25
25
  end
26
26
 
27
27
  def raw_builder(opts = {}) #:nodoc:
@@ -32,10 +32,10 @@ module EPPClient
32
32
  # creates a Builder::XmlMarkup object, mostly only used by +command+
33
33
  def builder(opts = {})
34
34
  raw_builder(opts) do |xml|
35
- xml.instruct! :xml, :version =>"1.0", :encoding => "UTF-8"
36
- xml.epp('xmlns' => EPPClient::SCHEMAS_URL['epp'], 'xmlns:epp' => EPPClient::SCHEMAS_URL['epp']) do
37
- yield xml
38
- end
35
+ xml.instruct! :xml, :version => '1.0', :encoding => 'UTF-8'
36
+ xml.epp('xmlns' => EPPClient::SCHEMAS_URL['epp'], 'xmlns:epp' => EPPClient::SCHEMAS_URL['epp']) do
37
+ yield xml
38
+ end
39
39
  end
40
40
  end
41
41
 
@@ -49,51 +49,48 @@ module EPPClient
49
49
  # In case there was a problem, an EPPErrorResponse exception is raised.
50
50
  def get_result(args)
51
51
  xml = case args
52
- when Hash
53
- args.delete(:xml)
54
- else
55
- xml = args
56
- args = {}
57
- xml
58
- end
52
+ when Hash
53
+ args.delete(:xml)
54
+ else
55
+ xml = args
56
+ args = {}
57
+ xml
58
+ end
59
59
 
60
60
  args[:range] ||= 1000..1999
61
61
 
62
62
  if (mq = xml.xpath('epp:epp/epp:response/epp:msgQ', EPPClient::SCHEMAS_URL)).size > 0
63
- @msgQ_count = mq.attribute('count').value.to_i
64
- @msgQ_id = mq.attribute('id').value
65
- puts "DEBUG: MSGQ : count=#{@msgQ_count}, id=#{@msgQ_id}\n" if debug
63
+ @msgQ_count = mq.attribute('count').value.to_i
64
+ @msgQ_id = mq.attribute('id').value
65
+ puts "DEBUG: MSGQ : count=#{@msgQ_count}, id=#{@msgQ_id}\n" if debug
66
66
  else
67
- @msgQ_count = 0
68
- @msgQ_id = nil
67
+ @msgQ_count = 0
68
+ @msgQ_id = nil
69
69
  end
70
70
 
71
71
  if (trID = xml.xpath('epp:epp/epp:response/epp:trID', EPPClient::SCHEMAS_URL)).size > 0
72
- @trID = get_trid(trID)
72
+ @trID = get_trid(trID)
73
73
  end
74
74
 
75
75
  res = xml.xpath('epp:epp/epp:response/epp:result', EPPClient::SCHEMAS_URL)
76
76
  code = res.attribute('code').value.to_i
77
- if args[:range].include?(code)
78
- if args.key?(:callback)
79
- case cb = args[:callback]
80
- when Symbol
81
- return send(cb, xml.xpath('epp:epp/epp:response', EPPClient::SCHEMAS_URL))
82
- else
83
- raise ArgumentError, "Invalid callback type"
84
- end
85
- else
86
- return true
87
- end
77
+
78
+ fail EPPClient::EPPErrorResponse.new(:xml => xml, :code => code, :message => res.xpath('epp:msg', EPPClient::SCHEMAS_URL).text) unless args[:range].include?(code)
79
+
80
+ return true unless args.key?(:callback)
81
+
82
+ case cb = args[:callback]
83
+ when Symbol
84
+ return send(cb, xml.xpath('epp:epp/epp:response', EPPClient::SCHEMAS_URL))
88
85
  else
89
- raise EPPClient::EPPErrorResponse.new(:xml => xml, :code => code, :message => res.xpath('epp:msg', EPPClient::SCHEMAS_URL).text)
86
+ fail ArgumentError, 'Invalid callback type'
90
87
  end
91
88
  end
92
89
 
93
90
  def get_trid(xml)
94
91
  {
95
- :clTRID => xml.xpath('epp:clTRID', EPPClient::SCHEMAS_URL).text,
96
- :svTRID => xml.xpath('epp:svTRID', EPPClient::SCHEMAS_URL).text,
92
+ :clTRID => xml.xpath('epp:clTRID', EPPClient::SCHEMAS_URL).text,
93
+ :svTRID => xml.xpath('epp:svTRID', EPPClient::SCHEMAS_URL).text,
97
94
  }
98
95
  end
99
96
 
@@ -114,31 +111,31 @@ module EPPClient
114
111
  # end, lambda do |xml|
115
112
  # xml.extension
116
113
  # end)
117
- def command(*args, &block)
114
+ def command(*args, &_block)
118
115
  builder do |xml|
119
- xml.command do
120
- if block_given?
121
- yield xml
122
- else
123
- command = args.shift
124
- command.call(xml)
125
- args.each do |ext|
126
- xml.extension do
127
- ext.call(xml)
128
- end
129
- end
130
- end
131
- xml.clTRID(clTRID)
132
- end
116
+ xml.command do
117
+ if block_given?
118
+ yield xml
119
+ else
120
+ command = args.shift
121
+ command.call(xml)
122
+ args.each do |ext|
123
+ xml.extension do
124
+ ext.call(xml)
125
+ end
126
+ end
127
+ end
128
+ xml.clTRID(clTRID)
129
+ end
133
130
  end
134
131
  end
135
132
 
136
133
  # Wraps the content in an epp:extension.
137
134
  def extension
138
135
  raw_builder do |xml|
139
- xml.extension do
140
- yield(xml)
141
- end
136
+ xml.extension do
137
+ yield(xml)
138
+ end
142
139
  end
143
140
  end
144
141
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epp-client-base
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathieu Arnold
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2016-02-10 00:00:00 Z
12
+ date: 2016-02-17 00:00:00 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler