Module: Pepper::Commands::ClassMethods

Defined in:
lib/pepper/commands.rb

Instance Method Summary collapse

Instance Method Details

#check(*domains) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/pepper/commands.rb', line 35

def check(*domains)
   unless @logged_in
  builder = Nokogiri::XML::Builder.new do |xml|
    xml.epp("xmlns"              => "urn:ietf:params:xml:ns:epp-1.0", 
            "xmlns:xsi"          => "http://www.w3.org/2001/XMLSchema-instance",
            "xsi:schemaLocation" => "urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd" ) {
      xml.command {
        xml.check {
          xml.check("xmlns:domain"       => "http://www.nominet.org.uk/epp/xml/nom-domain-2.0",
                    "xsi:schemaLocation" => "http://www.nominet.org.uk/epp/xml/nom-domain-2.0 nom-domain-2.0.xsd") {
            xml.parent.namespace = xml.parent.namespace_definitions.first
            domains.each {|d|
              xml["domain"].name d
            }
          }
        }
      }
    }
  end
  r = self.write( builder.to_xml )
  r.response.resdata.chkdata.domain_names.inject({}){|hash,domain|
    hash.merge( domain => r.response.resdata.chkdata.domain_names_avail.shift == "1")
  }
end

#create(opts = {}) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/pepper/commands.rb', line 81

def create(opts = {})
  # OPTIMIZE: Break this up - it's way to clunky
   unless @logged_in
  builder = Nokogiri::XML::Builder.new do |xml|
    xml.epp("xmlns"              => "urn:ietf:params:xml:ns:epp-1.0", 
            "xmlns:xsi"          => "http://www.w3.org/2001/XMLSchema-instance",
            "xsi:schemaLocation" => "urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd" ) {
      xml.command {
        xml.create {
          xml.create("xmlns:domain"       => "http://www.nominet.org.uk/epp/xml/nom-domain-2.0",
                     "xsi:schemaLocation" => "http://www.nominet.org.uk/epp/xml/nom-domain-2.0 nom-domain-2.0.xsd") {
            xml.parent.namespace = xml.parent.namespace_definitions.first
            xml["domain"].send(:"name",       opts["name"])
            xml["domain"].send(:"period",     opts["period"])     if opts.has_key? "period"
            xml["domain"].send(:"first-bill", opts["first_bill"]) if opts.has_key? "first_bill"
            xml["domain"].send(:"recur-bill", opts["recur_bill"]) if opts.has_key? "recur_bill"
            xml["domain"].send(:"auto-bill",  opts["auto_bill"])  if opts.has_key? "auto_bill"
            xml["domain"].send(:"next-bill",  opts["next_bill"])  if opts.has_key? "next_bill"
            xml["domain"].send(:"notes",      opts["notes"])      if opts.has_key? "notes"
            xml["domain"]. {
              xml.create("xmlns:account" => "http://www.nominet.org.uk/epp/xml/nom-account-2.0",
                         "xmlns:contact" => "http://www.nominet.org.uk/epp/xml/nom-contact-2.0"){
                 = opts["account"]
                xml.parent.namespace = xml.parent.namespace_definitions.select{|ns| ns.prefix == "account"}.first
                xml["account"].send(:"name",      ["name"])      if .has_key? "name"
                xml["account"].send(:"trad-name", ["trad_name"]) if .has_key? "trad_name"
                xml["account"].send(:"type_",     ["type"])      if .has_key? "type"
                xml["account"].send(:"co-no",     ["co_no"])     if .has_key? "co_no"
                xml["account"].send(:"opt-out",   ["opt_out"])   if .has_key? "opt_out"
                xml["account"].addr {
                  addr = ["addr"]
                  Array[*opts["account"]["addr"]["street"]].each{|s| # Allows either a single string passed in or an array to work
                    xml.street s
                  }
                  %w(locality city county postcode country).each {|f|
                    xml.send(f.to_sym, addr[f]) if addr.has_key?(f)
                  }
                }
                ["contacts"].each_with_index {|c,i|
                  xml["account"].contact(:order => i+1) {
                    xml["contact"].create {
                      %w(name phone email mobile).each {|f|
                        xml["contact"].send(f.to_sym, c[f]) if c.has_key?(f)
                      }
                    }
                  }
                }            
              }
            }
            if opts.has_key? "ns"
              xml["domain"].ns {
                opts["ns"]["hosts"].each {|host|
                  xml["domain"].host {
                    xml["domain"].hostName               host["hostname"]           if host.has_key? "hostname"
                    xml["domain"].hostAddr(:ip => "v4"){ host["hostaddress_ipv4"] } if host.has_key? "hostaddress_ipv4"
                    xml["domain"].hostAddr(:ip => "v6"){ host["hostaddress_ipv6"] } if host.has_key? "hostaddress_ipv6"
                  }
                }
              }
            end
          }
        }
      }
    }
  end
  r = self.write( builder.to_xml )
  r.response.to_hash
end

#info(name) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/pepper/commands.rb', line 60

def info(name)
   unless @logged_in
  builder = Nokogiri::XML::Builder.new do |xml|
    xml.epp("xmlns"              => "urn:ietf:params:xml:ns:epp-1.0", 
            "xmlns:xsi"          => "http://www.w3.org/2001/XMLSchema-instance",
            "xsi:schemaLocation" => "urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd" ) {
      xml.command {
        xml.info {
          xml.info("xmlns:domain"       => "http://www.nominet.org.uk/epp/xml/nom-domain-2.0",
                   "xsi:schemaLocation" => "urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd") {
            xml.parent.namespace = xml.parent.namespace_definitions.first
            xml["domain"].name name
          }
        }
      }
    }
  end
  r = self.write( builder.to_xml )
  r.response.resdata.infdata.to_hash
end

#loginObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/pepper/commands.rb', line 9

def 
  unless @logged_in
    builder = Nokogiri::XML::Builder.new do |xml|
      xml.epp("xmlns"              => "urn:ietf:params:xml:ns:epp-1.0", 
              "xmlns:xsi"          => "http://www.w3.org/2001/XMLSchema-instance",
              "xsi:schemaLocation" => "urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd" ) {
        xml.command {
          xml. {
            xml.clID @tag
            xml.pw   @password
            xml.options {
              xml.version "1.0"
              xml.lang    "en"
            }
            xml.svcs {
              xml.objURI "http://www.nominet.org.uk/epp/xml/nom-domain-2.0"
            }
          }
        }
      }
    end
    r = self.write( builder.to_xml )
  end
  @logged_in = true
end