Sha256: 29d0c1b274db53e6e34321eab3cf770e5c4a57ee84db5eba6b49f8a5d99bd563

Contents?: true

Size: 1005 Bytes

Versions: 1

Compression:

Stored size: 1005 Bytes

Contents

require 'nokogiri'
require 'meac_control/xml/exceptions'

module MEACControl
  module XML
    class AbstractRequest
      attr_reader :devices, :commands

      def initialize(devices, commands)
        @devices = [devices].compact.flatten
        @commands = [commands].compact.flatten

        raise MEACControl::XML::Request::EmptyDeviceList if @devices.empty?
        raise MEACControl::XML::Request::EmptyCommandList if @commands.empty?
      end

      private
        def xml_template(command, mode)
          ::Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do
            Packet do
              Command command
              DatabaseManager do
                devices.each do |dev|
                  attributes = {:Group => dev.id}
                  commands.each do |cmd|
                    attributes.merge!(cmd.hash_for(mode))
                  end
                  Mnet(attributes)
                end
              end
            end
          end.to_xml
        end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
meac_control-1.0.0 lib/meac_control/xml/abstract_request.rb