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 # * :host - host of the OpenSRS server # * :key - private key # * :user - username of the reseller # * :pass - password of the rseller # # === Optional # * :port - 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 # * :command - command to run # * :command - command to run # # === Optional # * :params - parameters for the command # * :cookie - 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 # * :arr - 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