pepper 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pepper/commands.rb +91 -0
- data/lib/pepper/connection.rb +0 -1
- data/lib/pepper/stanzas.rb +0 -5
- data/lib/pepper/stanzas/account_addr.rb +17 -0
- data/lib/pepper/stanzas/account_infdata.rb +27 -0
- data/lib/pepper/stanzas/chkdata.rb +3 -1
- data/lib/pepper/stanzas/contact_infdata.rb +21 -0
- data/lib/pepper/stanzas/domain_infdata.rb +31 -0
- data/lib/pepper/stanzas/epp.rb +3 -0
- data/lib/pepper/stanzas/host.rb +14 -0
- data/lib/pepper/stanzas/ns.rb +13 -0
- data/lib/pepper/stanzas/resdata.rb +5 -0
- data/lib/pepper/stanzas/response.rb +7 -3
- data/lib/pepper/stanzas/result.rb +2 -0
- data/lib/pepper/stanzas/sax_machinery.rb +20 -0
- data/test/live_pepper_test.rb +85 -0
- data/test/test_helper.rb +1 -1
- metadata +9 -2
data/lib/pepper/commands.rb
CHANGED
@@ -56,6 +56,97 @@ module Pepper
|
|
56
56
|
hash.merge( domain => r.response.resdata.chkdata.domain_names_avail.shift == "1")
|
57
57
|
}
|
58
58
|
end
|
59
|
+
|
60
|
+
def info(name)
|
61
|
+
login unless @logged_in
|
62
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
63
|
+
xml.epp("xmlns" => "urn:ietf:params:xml:ns:epp-1.0",
|
64
|
+
"xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
|
65
|
+
"xsi:schemaLocation" => "urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd" ) {
|
66
|
+
xml.command {
|
67
|
+
xml.info {
|
68
|
+
xml.info("xmlns:domain" => "http://www.nominet.org.uk/epp/xml/nom-domain-2.0",
|
69
|
+
"xsi:schemaLocation" => "urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd") {
|
70
|
+
xml.parent.namespace = xml.parent.namespace_definitions.first
|
71
|
+
xml["domain"].name name
|
72
|
+
}
|
73
|
+
}
|
74
|
+
}
|
75
|
+
}
|
76
|
+
end
|
77
|
+
r = self.write( builder.to_xml )
|
78
|
+
r.response.resdata.infdata.to_hash
|
79
|
+
end
|
80
|
+
|
81
|
+
def create(opts = {})
|
82
|
+
# OPTIMIZE: Break this up - it's way to clunky
|
83
|
+
login unless @logged_in
|
84
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
85
|
+
xml.epp("xmlns" => "urn:ietf:params:xml:ns:epp-1.0",
|
86
|
+
"xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
|
87
|
+
"xsi:schemaLocation" => "urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd" ) {
|
88
|
+
xml.command {
|
89
|
+
xml.create {
|
90
|
+
xml.create("xmlns:domain" => "http://www.nominet.org.uk/epp/xml/nom-domain-2.0",
|
91
|
+
"xsi:schemaLocation" => "http://www.nominet.org.uk/epp/xml/nom-domain-2.0 nom-domain-2.0.xsd") {
|
92
|
+
xml.parent.namespace = xml.parent.namespace_definitions.first
|
93
|
+
xml["domain"].send(:"name", opts["name"])
|
94
|
+
xml["domain"].send(:"period", opts["period"]) if opts.has_key? "period"
|
95
|
+
xml["domain"].send(:"first-bill", opts["first_bill"]) if opts.has_key? "first_bill"
|
96
|
+
xml["domain"].send(:"recur-bill", opts["recur_bill"]) if opts.has_key? "recur_bill"
|
97
|
+
xml["domain"].send(:"auto-bill", opts["auto_bill"]) if opts.has_key? "auto_bill"
|
98
|
+
xml["domain"].send(:"next-bill", opts["next_bill"]) if opts.has_key? "next_bill"
|
99
|
+
xml["domain"].send(:"notes", opts["notes"]) if opts.has_key? "notes"
|
100
|
+
xml["domain"].account {
|
101
|
+
xml.create("xmlns:account" => "http://www.nominet.org.uk/epp/xml/nom-account-2.0",
|
102
|
+
"xmlns:contact" => "http://www.nominet.org.uk/epp/xml/nom-contact-2.0"){
|
103
|
+
account = opts["account"]
|
104
|
+
xml.parent.namespace = xml.parent.namespace_definitions.select{|ns| ns.prefix == "account"}.first
|
105
|
+
xml["account"].send(:"name", account["name"]) if account.has_key? "name"
|
106
|
+
xml["account"].send(:"trad-name", account["trad_name"]) if account.has_key? "trad_name"
|
107
|
+
xml["account"].send(:"type_", account["type"]) if account.has_key? "type"
|
108
|
+
xml["account"].send(:"co-no", account["co_no"]) if account.has_key? "co_no"
|
109
|
+
xml["account"].send(:"opt-out", account["opt_out"]) if account.has_key? "opt_out"
|
110
|
+
xml["account"].addr {
|
111
|
+
addr = account["addr"]
|
112
|
+
Array[*opts["account"]["addr"]["street"]].each{|s| # Allows either a single string passed in or an array to work
|
113
|
+
xml.street s
|
114
|
+
}
|
115
|
+
%w(locality city county postcode country).each {|f|
|
116
|
+
xml.send(f.to_sym, addr[f]) if addr.has_key?(f)
|
117
|
+
}
|
118
|
+
}
|
119
|
+
account["contacts"].each_with_index {|c,i|
|
120
|
+
xml["account"].contact(:order => i+1) {
|
121
|
+
xml["contact"].create {
|
122
|
+
%w(name phone email mobile).each {|f|
|
123
|
+
xml["contact"].send(f.to_sym, c[f]) if c.has_key?(f)
|
124
|
+
}
|
125
|
+
}
|
126
|
+
}
|
127
|
+
}
|
128
|
+
}
|
129
|
+
}
|
130
|
+
if opts.has_key? "ns"
|
131
|
+
xml["domain"].ns {
|
132
|
+
opts["ns"]["hosts"].each {|host|
|
133
|
+
xml["domain"].host {
|
134
|
+
xml["domain"].hostName host["hostname"] if host.has_key? "hostname"
|
135
|
+
xml["domain"].hostAddr(:ip => "v4"){ host["hostaddress_ipv4"] } if host.has_key? "hostaddress_ipv4"
|
136
|
+
xml["domain"].hostAddr(:ip => "v6"){ host["hostaddress_ipv6"] } if host.has_key? "hostaddress_ipv6"
|
137
|
+
}
|
138
|
+
}
|
139
|
+
}
|
140
|
+
end
|
141
|
+
}
|
142
|
+
}
|
143
|
+
}
|
144
|
+
}
|
145
|
+
end
|
146
|
+
r = self.write( builder.to_xml )
|
147
|
+
r.response.to_hash
|
148
|
+
end
|
149
|
+
|
59
150
|
end
|
60
151
|
end
|
61
152
|
end
|
data/lib/pepper/connection.rb
CHANGED
data/lib/pepper/stanzas.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "pepper/stanzas/sax_machinery"
|
2
|
+
|
3
|
+
module Pepper
|
4
|
+
module Stanzas
|
5
|
+
class AccountAddr
|
6
|
+
include SAXMachine
|
7
|
+
|
8
|
+
elements "account:street", :as => :street
|
9
|
+
element "account:locality", :as => :locality
|
10
|
+
element "account:city", :as => :city
|
11
|
+
element "account:county", :as => :county
|
12
|
+
element "account:postcode", :as => :postcode
|
13
|
+
element "account:country", :as => :country
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "pepper/stanzas/sax_machinery"
|
2
|
+
require "pepper/stanzas/account_addr"
|
3
|
+
require "pepper/stanzas/contact_infdata"
|
4
|
+
|
5
|
+
module Pepper
|
6
|
+
module Stanzas
|
7
|
+
class AccountInfdata
|
8
|
+
include SAXMachine
|
9
|
+
|
10
|
+
element "account:roid", :as => :roid
|
11
|
+
element "account:name", :as => :name
|
12
|
+
element "account:trad-name", :as => :trad_name
|
13
|
+
element "account:type", :as => :type
|
14
|
+
element "account:co-no", :as => :co_no
|
15
|
+
element "account:opt-out", :as => :opt_out
|
16
|
+
element "account:addr", :as => :addr, :class => AccountAddr
|
17
|
+
|
18
|
+
element "account:clID", :as => :cl_id
|
19
|
+
element "account:crID", :as => :cr_id
|
20
|
+
element "account:crDate", :as => :cr_date
|
21
|
+
element "account:upID", :as => :up_id
|
22
|
+
element "account:upDate", :as => :up_date
|
23
|
+
|
24
|
+
elements "contact:infData", :as => :contacts, :class => ContactInfdata
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,10 +1,12 @@
|
|
1
|
+
require "pepper/stanzas/sax_machinery"
|
2
|
+
|
1
3
|
module Pepper
|
2
4
|
module Stanzas
|
3
5
|
class Chkdata
|
4
6
|
include SAXMachine
|
5
7
|
|
6
8
|
elements "domain:name", :as => :domain_names
|
7
|
-
elements "domain:name", :
|
9
|
+
elements "domain:name", :as => :domain_names_avail, :value => :avail
|
8
10
|
|
9
11
|
end
|
10
12
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "pepper/stanzas/sax_machinery"
|
2
|
+
|
3
|
+
module Pepper
|
4
|
+
module Stanzas
|
5
|
+
class ContactInfdata
|
6
|
+
include SAXMachine
|
7
|
+
|
8
|
+
element "contact:roid", :as => :roid
|
9
|
+
element "contact:name", :as => :name
|
10
|
+
element "contact:phone", :as => :phone
|
11
|
+
element "contact:email", :as => :email
|
12
|
+
|
13
|
+
element "contact:clID", :as => :cl_id
|
14
|
+
element "contact:crID", :as => :cr_id
|
15
|
+
element "contact:crDate", :as => :cr_date
|
16
|
+
element "contact:upID", :as => :up_id
|
17
|
+
element "contact:upDate", :as => :up_date
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "pepper/stanzas/sax_machinery"
|
2
|
+
require "pepper/stanzas/account_infdata"
|
3
|
+
require "pepper/stanzas/ns"
|
4
|
+
|
5
|
+
module Pepper
|
6
|
+
module Stanzas
|
7
|
+
class DomainInfdata
|
8
|
+
include SAXMachine
|
9
|
+
|
10
|
+
element "domain:name", :as => :name
|
11
|
+
element "domain:reg-status", :as => :reg_status
|
12
|
+
element "account:infData", :as => :account, :class => AccountInfdata
|
13
|
+
element "domain:ns", :as => :ns, :class => Ns
|
14
|
+
element "domain:reg-status", :as => :reg_status
|
15
|
+
element "domain:clID", :as => :cl_id
|
16
|
+
element "domain:crID", :as => :cr_id
|
17
|
+
element "domain:crDate", :as => :cr_date
|
18
|
+
element "domain:upID", :as => :up_id
|
19
|
+
element "domain:upDate", :as => :up_date
|
20
|
+
element "domain:exDate", :as => :ex_date
|
21
|
+
|
22
|
+
element "domain:first-bill", :as => :first_bill
|
23
|
+
element "domain:recur-bill", :as => :recur_bill
|
24
|
+
element "domain:auto-bill", :as => :auto_bill
|
25
|
+
element "domain:next-bill", :as => :next_bill
|
26
|
+
element "domain:notes", :as => :notes
|
27
|
+
element "domain:renew-not-required", :as => :renew_not_required
|
28
|
+
element "domain:reseller", :as => :reseller
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/pepper/stanzas/epp.rb
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "pepper/stanzas/sax_machinery"
|
2
|
+
|
3
|
+
module Pepper
|
4
|
+
module Stanzas
|
5
|
+
class Host
|
6
|
+
include SAXMachine
|
7
|
+
|
8
|
+
element "domain:hostName", :as => :hostname
|
9
|
+
element "domain:hostAddr", :as => :hostaddress_ipv4, :with => {:ip => "v4"}
|
10
|
+
element "domain:hostAddr", :as => :hostaddress_ipv6, :with => {:ip => "v6"}
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,9 +1,14 @@
|
|
1
|
+
require "pepper/stanzas/sax_machinery"
|
2
|
+
require "pepper/stanzas/chkdata"
|
3
|
+
require "pepper/stanzas/domain_infdata"
|
4
|
+
|
1
5
|
module Pepper
|
2
6
|
module Stanzas
|
3
7
|
class Resdata
|
4
8
|
include SAXMachine
|
5
9
|
|
6
10
|
element "domain:chkData", :as => :chkdata, :class => Chkdata
|
11
|
+
element "domain:infData", :as => :infdata, :class => DomainInfdata
|
7
12
|
end
|
8
13
|
end
|
9
14
|
end
|
@@ -1,11 +1,15 @@
|
|
1
|
+
require "pepper/stanzas/sax_machinery"
|
2
|
+
require "pepper/stanzas/result"
|
3
|
+
require "pepper/stanzas/resdata"
|
4
|
+
|
1
5
|
module Pepper
|
2
6
|
module Stanzas
|
3
7
|
class Response
|
4
8
|
include SAXMachine
|
5
9
|
|
6
|
-
element :result,
|
7
|
-
element :result,
|
8
|
-
element :resData, :as => :resdata,
|
10
|
+
element :result, :class => Result
|
11
|
+
element :result, :as => :result_code, :value => :code
|
12
|
+
element :resData, :as => :resdata, :class => Resdata
|
9
13
|
end
|
10
14
|
end
|
11
15
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "sax-machine"
|
2
|
+
|
3
|
+
# Mixup the mixin - to add functionality for simplifying results down to a hash
|
4
|
+
module SAXMachine
|
5
|
+
def to_hash
|
6
|
+
convert = Proc.new {|v|
|
7
|
+
if v.methods.include? "to_hash"
|
8
|
+
v.to_hash
|
9
|
+
elsif v.is_a? Array
|
10
|
+
v.map {|e| convert.call e }
|
11
|
+
else
|
12
|
+
v
|
13
|
+
end
|
14
|
+
}
|
15
|
+
|
16
|
+
instance_variables.inject({}) do |h,v|
|
17
|
+
h.merge v.gsub("@","") => convert.call( instance_variable_get v )
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/test/live_pepper_test.rb
CHANGED
@@ -46,6 +46,91 @@ class LivePepperTest < Test::Unit::TestCase
|
|
46
46
|
assert_equal domains, Pepper.check( *domains.keys )
|
47
47
|
end
|
48
48
|
end
|
49
|
+
|
50
|
+
context "'info'" do
|
51
|
+
should "return correct hash for 'adriana-TAG.co.uk'" do
|
52
|
+
# We cannot predict exactly when it was created at
|
53
|
+
info = Pepper.info( "adriana-#{@hash[:tag]}.co.uk" )
|
54
|
+
created_at = Time.xmlschema(info["cr_date"])
|
55
|
+
|
56
|
+
expected = {
|
57
|
+
"reg_status" => "Registered until expiry date.",
|
58
|
+
"name" => "adriana-#{@hash[:tag].downcase}.co.uk",
|
59
|
+
"cr_id" => "psamathe@nominet.org.uk",
|
60
|
+
"first_bill" => "th",
|
61
|
+
"recur_bill" => "th",
|
62
|
+
"cl_id" => @hash[:tag],
|
63
|
+
"ex_date" => (created_at + 2 * 60*60*24*365).strftime("%FT%T"), # 2 years
|
64
|
+
"cr_date" => created_at.strftime("%FT%T"),
|
65
|
+
"account" => {
|
66
|
+
"trad_name" => "Simple Registrant Trading Ltd",
|
67
|
+
"name" => "Simple Registrant-#{@hash[:tag]}",
|
68
|
+
"cr_id" => "psamathe@nominet.org.uk",
|
69
|
+
"cl_id" => @hash[:tag],
|
70
|
+
"type" => "LTD",
|
71
|
+
"opt_out" => "N",
|
72
|
+
"roid" => "105097-UK",
|
73
|
+
"cr_date" => (created_at + 1 * 60*60*24*365).strftime("%FT%T"), # 1 year
|
74
|
+
"contacts" => [{
|
75
|
+
"name" => "Mary Smith",
|
76
|
+
"up_id" => "psamathe@nominet.org.uk",
|
77
|
+
"cl_id" => @hash[:tag],
|
78
|
+
"roid" => "C112040-UK",
|
79
|
+
"phone" => "01234 567890",
|
80
|
+
"up_date" => (created_at + 1 * 60*60*24*365).strftime("%FT%T"), # 1 year
|
81
|
+
"email" => "mary.smith@ariel-#{@hash[:tag].downcase}.co.uk"
|
82
|
+
}],
|
83
|
+
"addr" => {
|
84
|
+
"city" => "Test City",
|
85
|
+
"country" => "GB",
|
86
|
+
"postcode" => "TE57 1NG",
|
87
|
+
"street" => [ "2 Test Street" ],
|
88
|
+
"county" => "Testshire"
|
89
|
+
}
|
90
|
+
},
|
91
|
+
"ns" => {
|
92
|
+
"hosts" => [{
|
93
|
+
"hostname" => "ns1.ariel-#{@hash[:tag].downcase}.co.uk."
|
94
|
+
}]
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
assert_equal( expected, Pepper.info( "adriana-#{@hash[:tag]}.co.uk" ))
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context "'create'" do
|
103
|
+
should "register a domain" do
|
104
|
+
expected = {
|
105
|
+
"result" => { "msg" => "Command completed successfully" },
|
106
|
+
"resdata" => { },
|
107
|
+
"result_code" => "1000"
|
108
|
+
}
|
109
|
+
options = {
|
110
|
+
"name" => "#{Time.now.to_i}-testingdomain-#{@hash[:tag]}.co.uk",
|
111
|
+
"account" => {
|
112
|
+
"name" => "Foo Bar",
|
113
|
+
"type" => "LTD",
|
114
|
+
"co_no" => "NI123456",
|
115
|
+
"opt_out" => "N",
|
116
|
+
"addr" => {
|
117
|
+
"street" => "1 Test",
|
118
|
+
"locality" => "Testville",
|
119
|
+
"city" => "Test",
|
120
|
+
"county" => "Testshire",
|
121
|
+
"postcode" => "TE57 7ES",
|
122
|
+
"country" => "GB"
|
123
|
+
},
|
124
|
+
"contacts" => [{
|
125
|
+
"name" => "Joe Test",
|
126
|
+
"phone" => "01234 567890",
|
127
|
+
"email" => "joe@test.com"
|
128
|
+
}]
|
129
|
+
}
|
130
|
+
}
|
131
|
+
assert_equal( expected, Pepper.create( options ) )
|
132
|
+
end
|
133
|
+
end
|
49
134
|
end
|
50
135
|
|
51
136
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pepper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Theo Cushion
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-01-24 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -65,11 +65,18 @@ files:
|
|
65
65
|
- lib/pepper/commands.rb
|
66
66
|
- lib/pepper/connection.rb
|
67
67
|
- lib/pepper/error.rb
|
68
|
+
- lib/pepper/stanzas/account_addr.rb
|
69
|
+
- lib/pepper/stanzas/account_infdata.rb
|
68
70
|
- lib/pepper/stanzas/chkdata.rb
|
71
|
+
- lib/pepper/stanzas/contact_infdata.rb
|
72
|
+
- lib/pepper/stanzas/domain_infdata.rb
|
69
73
|
- lib/pepper/stanzas/epp.rb
|
74
|
+
- lib/pepper/stanzas/host.rb
|
75
|
+
- lib/pepper/stanzas/ns.rb
|
70
76
|
- lib/pepper/stanzas/resdata.rb
|
71
77
|
- lib/pepper/stanzas/response.rb
|
72
78
|
- lib/pepper/stanzas/result.rb
|
79
|
+
- lib/pepper/stanzas/sax_machinery.rb
|
73
80
|
- lib/pepper/stanzas.rb
|
74
81
|
- lib/pepper/stream_parser.rb
|
75
82
|
- lib/pepper.rb
|