Class: Registrar::Provider::OpenSRS::Operation

Inherits:
Object
  • Object
show all
Defined in:
lib/registrar/provider/opensrs/operation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action, attributes) ⇒ Operation

Returns a new instance of Operation.



6
7
8
9
10
# File 'lib/registrar/provider/opensrs/operation.rb', line 6

def initialize(action, attributes)
  @action = action
  @object = :domain
  @attributes = attributes
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



5
6
7
# File 'lib/registrar/provider/opensrs/operation.rb', line 5

def action
  @action
end

#attributesObject (readonly)

Returns the value of attribute attributes.



5
6
7
# File 'lib/registrar/provider/opensrs/operation.rb', line 5

def attributes
  @attributes
end

#objectObject (readonly)

Returns the value of attribute object.



5
6
7
# File 'lib/registrar/provider/opensrs/operation.rb', line 5

def object
  @object
end

Instance Method Details

#to_xmlObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/registrar/provider/opensrs/operation.rb', line 11

def to_xml
  builder = Builder::XmlMarkup.new
  builder.OPS_envelope { |b| 
    b.header { |b| b.version('0.9') }
    b.body { |b| 
      b.data_block { |b|
        b.dt_assoc { |b|
          b.item("XCP", :key => "protocol")
          b.item(action.to_s.upcase, :key => "action")
          b.item(object.to_s.upcase, :key => "object")
          b.item(:key => "attributes") { |b|
            b.dt_assoc { |b|
              attributes.each do |key, value|
                if (value.respond_to?(:to_xml))
                  b.item(:key => key.to_s) {
                    value.to_xml(b)
                  }
                else
                  b.item(value.to_s, :key => key.to_s)
                end
              end
            }
          }
        }
      }
    }
  }
end