Sha256: 5856191adebb9873054f39de218f1fd445282344a7e91fce118958b18850bdda

Contents?: true

Size: 1.92 KB

Versions: 1

Compression:

Stored size: 1.92 KB

Contents

module MooMoo
  module OpenSRS
    class Base
      include LookupCommands
      include ProvisioningCommands
      include TransferCommands
      include NameserverCommands
      include CookieCommands

      attr_reader :host, :key, :user, :pass, :port

      # Constructor
      #
      # === Required
      #  * <tt>:host</tt> - host of the OpenSRS server
      #  * <tt>:key</tt> - private key
      #  * <tt>:user</tt> - username of the reseller
      #  * <tt>:pass</tt> - password of the rseller
      #
      # === Optional
      #  * <tt>:port</tt> - port to connect on
      def initialize(host = nil, key = nil, user = nil, pass = nil, port = 55443)
        @host = host || MooMoo.config.host
        @key  = key  || MooMoo.config.key
        @user = user || MooMoo.config.user
        @pass = pass || MooMoo.config.pass
        @port = port || MooMoo.config.port
      end

      # Runs a command
      #
      # === Required
      #  * <tt>:command</tt> - command to run
      #  * <tt>:command</tt> - command to run
      #
      # === Optional
      #  * <tt>:params</tt> - parameters for the command
      #  * <tt>:cookie</tt> - cookie, if the command requires it
      def run_command(action, object, params = {}, cookie = nil)
        cmd = Command.new(action, object, params, cookie)

        try_opensrs do
          result = cmd.run(@host, @key, @user, @port)
          Response.new(result, params[:key])
        end
      end

      private

      # Indexes an array by building a hash with numeric keys
      #
      # === Required
      #  * <tt>:arr</tt> - array to build an indexed hash of
      def index_array(arr)
        arr_indexed = {}

        arr.each_with_index do |item, index|
          arr_indexed[index] = item
        end

        arr_indexed
      end

      def try_opensrs
        begin
          yield
        rescue Exception => e
          raise OpenSRSException, e.message
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
moo_moo-0.1.1 lib/moo_moo/opensrs/base.rb