public function ingestInput($vars, $skipValidate = false)
 {
     parent::ingestInput($vars, $skipValidate);
     //Prep file upload data
     if (isset($this->api_vars["file"])) {
         $this->method = "uploadFile";
         $this->endpoint = $this->job;
         if (!isset($this->api_vars["brand_name"])) {
             $this->api_vars["brand_name"] = $this->account->getName();
             if ($this->api_vars["brand_name"] == null) {
                 CliScriptAbstract::confirm("You need to provide a brand if you are not using a preconfigured account.\nContinue anyway?", "Add the '-h' option for more details on valid inputs.");
                 $this->api_vars["brand_name"] = "unknown";
             }
         }
         if (CliScriptAbstract::$flags["isValidateFile"]) {
             $this->api_vars["is_skip_check"] = true;
         }
     }
     //Correctly manage updates.
     if (isset($this->api_vars["vars"])) {
         if (!isset($this->api_vars["update"])) {
             $this->api_vars["update"] = array();
         }
         $this->api_vars["update"]["vars"] = $this->api_vars["vars"];
         unset($this->api_vars["vars"]);
     }
     if (isset($this->api_vars["lists"])) {
         if (!isset($this->api_vars["update"])) {
             $this->api_vars["update"] = array();
         }
         $this->api_vars["update"]["lists"] = $this->api_vars["lists"];
         unset($this->api_vars["lists"]);
     }
     if (isset($this->api_vars["optout"])) {
         if (!isset($this->api_vars["update"])) {
             $this->api_vars["update"] = array();
         }
         $this->api_vars["update"]["optout"] = $this->api_vars["optout"];
         unset($this->api_vars["optout"]);
     }
     if (isset($this->api_vars["delete_vars"])) {
         if (!isset($this->api_vars["update"])) {
             $this->api_vars["update"] = array();
         }
         $tmp = explode(",", $this->api_vars["delete_vars"]);
         foreach ($tmp as $i => $c) {
             $tmp[$i] = trim($c);
         }
         $this->api_vars["update"]["delete_vars"] = $tmp;
         unset($this->api_vars["delete_vars"]);
     }
     if (isset($this->api_vars["signup_date"])) {
         if (!isset($this->api_vars["update"])) {
             $this->api_vars["update"] = array();
         }
         $this->api_vars["update"]["signup_date"] = $this->api_vars["signup_date"];
         unset($this->api_vars["signup_date"]);
     }
 }
 public function ingestInput($vars, $skipValidate = false)
 {
     parent::ingestInput($vars, $skipValidate);
     if (isset($this->api_vars["file"])) {
         $this->method = "uploadFile";
         $this->endpoint = $this->job;
         $this->api_vars["file_type"] = "json";
         if (!isset($this->api_vars["brand_name"])) {
             $this->api_vars["brand_name"] = $this->account->getName();
             if ($this->api_vars["brand_name"] == null) {
                 CliScriptAbstract::confirm("You need to provide a brand if you are not using a preconfigured account.\nContinue anyway?", "Add the '-h' option for more details on valid inputs.");
                 $this->api_vars["brand_name"] = "unknown";
             }
         }
     }
 }
 public function ingestInput($vars, $skipValidate = false)
 {
     parent::ingestInput($vars, $skipValidate);
     //Prep file upload data
     if (isset($this->api_vars["file"])) {
         $this->method = "uploadFile";
         $this->endpoint = $this->job;
         if (!isset($this->api_vars["brand_name"])) {
             $this->api_vars["brand_name"] = $this->account->getName();
             if ($this->api_vars["brand_name"] == null) {
                 CliScriptAbstract::confirm("You need to provide a brand if you are not using a preconfigured account.\nContinue anyway?", "Add the '-h' option for more details on valid inputs.");
                 $this->api_vars["brand_name"] = "unknown";
             }
         }
         if (CliScriptAbstract::$flags["isValidateFile"]) {
             $this->api_vars["is_skip_check"] = true;
         }
         if (!isset($this->api_vars["file_type"])) {
             $this->api_vars["file_type"] = "json";
         }
     } else {
         echo "This isn't supported. How did you get here?\n\nSERIOUSLY!!!???\n\n";
     }
 }
////Designate Call Parameters
$call_data = $api_object->getCallData();
$endpoint = $api_object->getEndpoint();
$method = $api_object->getMethod();
////Status Output
CliScriptAbstract::$flags["isSilent"] ?: (print "Starting\n");
if ((CliScriptAbstract::$flags["isVerbose"] || CliScriptAbstract::$flags["isInteractive"]) && (!CliScriptAbstract::$flags["isQuiet"] && !CliScriptAbstract::$flags["isSilent"])) {
    if ($account_credentials->getNumber() && $account_credentials->getKey() == $account_credentials->getKey($account_credentials->getNumber())) {
        print "Account " . $account_credentials->getNumber() . ": " . $account_credentials->getName() . "\n";
    }
    print "Key: " . $account_credentials->getKey() . "\n";
    print "Secret: " . $account_credentials->getSecret() . "\nValues:";
    print json_encode($call_data, JSON_PRETTY_PRINT) . "\n";
    if (CliScriptAbstract::$flags["isInteractive"]) {
        //Confirm + screen output if user decides to kills the script.
        $script->confirm("Proceed?", "Add the '-h' option for more details on valid inputs.");
    }
    //Seperate input from output
    print "\n\nCall Response\n";
}
////Api Call
echo "Method: " . $method;
echo "\n";
echo "Endpoint: " . $endpoint;
$response = $client->{$method}($endpoint, $call_data);
////Status Output
if (!CliScriptAbstract::$flags["isQuiet"] && !CliScriptAbstract::$flags["isSilent"]) {
    print json_encode($response, JSON_PRETTY_PRINT) . "\n";
}
CliScriptAbstract::$flags["isSilent"] ?: (print "\nFinished\n");
////Successful Output
 public static function readCliArguments(array $argv, CliScriptInterface $cli_interface)
 {
     ////Read in flags first.
     //Get flag options (I'm being annoying here so the flags from this file over ride any others but still display last.)
     $cli_options = CliScriptAbstract::$script_cli_options + array_reverse($cli_interface->getCliOptions());
     $cli_options = array_reverse($cli_options);
     //read in, save, then remove flags from argv.
     $argv = CliScriptAbstract::processFlags($argv, $cli_options, CliScriptAbstract::getFlagModifications($cli_interface));
     //make the flags easier to access here by giving them local scope.
     extract(CliScriptAbstract::$flags);
     //Read in all other vars.
     $cli_description = $cli_interface->getCliDescription();
     $cli_params = $cli_interface->getCliParameters();
     $cli_extras = $cli_interface->getOtherInputsDescription();
     //I want the full help menu to have precedence over the brief window.
     if (!$isRun && (count($argv) == 1 || $isHelp)) {
         CliScriptAbstract::print_help($cli_description, $cli_params, $cli_options, $cli_extras);
         die("\n");
     } else {
         if (!$isRun && ($isBriefHelp || $isBashHelp)) {
             $brief = $isBriefHelp ? "brief" : "bash";
             CliScriptAbstract::print_help($cli_description, $cli_params, $cli_options, $cli_extras, $brief);
             die("\n");
         }
     }
     //Past the help Menu, lets read in some vars
     $vars = array();
     //Named Vars sent through in the config as expected
     $flags = array();
     //Flags sent through in the config as expected
     $wildcards = array();
     //Named vars that were not expected
     $other_inputs = array();
     //Catch all for other input.
     $exploded_args = array();
     foreach ($argv as $arg) {
         if (strpos($arg, "=") !== FALSE) {
             $e = explode("=", $arg);
             $param_key = $e[0];
             if ($e[1][0] == "{") {
                 $e[1] = CliScriptAbstract::convertSmartQuotes($e[1]);
                 $exploded_args[$param_key] = json_decode($e[1], true);
                 if (json_last_error() !== JSON_ERROR_NONE) {
                     CliScriptAbstract::$last_error = $e[0];
                     CliScriptAbstract::confirm("JSON Object, " . $e[0] . ", was not successfully decoded: " . json_last_error_msg() . "\nContinue anyway?", "Try 'http://www.jsoneditoronline.org/' if you don't know what is wrong.");
                     unset($exploded_args[$param_key]);
                 }
             } else {
                 if (strpos($e[1], "(string)") !== false) {
                     $exploded_args[$param_key] = substr($e[1], 0, -8);
                 } else {
                     if (is_numeric($e[1])) {
                         $exploded_args[$param_key] = $e[1] + 0;
                     } else {
                         $exploded_args[$param_key] = $e[1];
                     }
                 }
             }
         } else {
             array_push($other_inputs, $arg);
         }
     }
     foreach ($cli_params as $param_var => $rest) {
         if (isset($exploded_args[$rest[0]])) {
             $vars[$param_var] = $exploded_args[$rest[0]];
             unset($exploded_args[$rest[0]]);
         }
     }
     CliScriptAbstract::processVars($exploded_args, $cli_params);
     return array("config_vars" => $vars, "wildcard_vars" => $exploded_args, "other_inputs" => $other_inputs);
 }
 private function confirm($question, $failText)
 {
     CliScriptAbstract::confirm($question, $failText);
 }
 protected function validateVars()
 {
     $criteria = $this->api_params_validation;
     $display = $this->cli_params;
     foreach ($criteria as $key => $value) {
         if (isset($this->api_vars[$key]) || $key == "always_required") {
             //Proceed to validate if the key is set, or the key is the required parameters key. Unlike below, the "always_required" naming is important.
             foreach ($value as $negation => $dependencies) {
                 if (!isset($this->api_vars[$negation]) && $negation != "require_one" && $negation != "value_specifics") {
                     //As "always_required" (or any other arbitrary name) won't be set, any dependencies of a nonsense name will always run. Unless some asshole submits always_required as a param.. Edit: If passed as a 0, now works as a feature.
                     foreach ($dependencies as $dependency) {
                         if (!isset($this->api_vars[$dependency])) {
                             if ($key == "always_required") {
                                 CliScriptAbstract::confirm("You are missing a required parameter: " . $display[$dependency][0] . ".\nContinue anyway?", "Add the '-h' option for more details on valid inputs.");
                             } else {
                                 CliScriptAbstract::confirm("To use " . $display[$key][0] . " you should also provide " . $display[$dependency][0] . ".\nContinue anyway?", "Add the '-h' option for more details on valid inputs.");
                             }
                         }
                     }
                 } else {
                     if ($negation == "require_one") {
                         $mix = array_intersect($dependencies, array_keys($this->api_vars));
                         if (count($mix) > 1 || count($mix) == 0) {
                             CliScriptAbstract::confirm("One, and only one, of the following must be submitted: " . implode(", ", $dependencies) . ".\nContinue anyway?", "Add the '-h' option for more details on valid inputs.");
                         }
                     } else {
                         if ($negation == "value_specifics") {
                             foreach ($dependencies as $value => $value_dependencies) {
                                 if ($this->api_vars[$key] == $value) {
                                     foreach ($value_dependencies as $dependency) {
                                         if (!isset($this->api_vars[$dependency])) {
                                             CliScriptAbstract::confirm("To use " . $display[$key][0] . " as " . $value . " you should also provide " . $display[$dependency][0] . ".\nContinue anyway?", "Add the '-h' option for more details on valid inputs.");
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }