static void Main(string[] args)
{
string secret = null;
string clientToken = null;
string accessToken = null;
string apiurl = null;
List<string> headers = new List<string>();
string httpMethod = "GET";
string contentType = "application/json";
string outputfile = null;
string uploadfile = null;
string data = null;
int maxBodySize = 2048;
bool verbose = false;
string firstarg = null;
foreach (string arg in args)
{
if (firstarg != null)
{
switch (firstarg)
{
case "-a":
accessToken = arg;
break;
case "-c":
clientToken = arg;
break;
case "-d":
if (httpMethod == "GET") httpMethod = "POST";
data = arg;
break;
case "-f":
if (httpMethod == "GET") httpMethod = "PUT";
uploadfile = arg;
break;
case "-H":
headers.Add(arg);
break;
case "-m":
maxBodySize = Convert.ToInt32(arg);
break;
case "-o":
outputfile = arg;
break;
case "-s":
secret = arg;
break;
case "-T":
contentType = arg;
break;
case "-X":
httpMethod = arg;
break;
}
firstarg = null;
}
else if (arg == "-h" || arg == "--help" || arg == "/?")
{
help();
return;
}
else if (arg == "-v" || arg == "-vv")
verbose = true;
else if (!arg.StartsWith("-"))
apiurl = arg;
else
firstarg = arg;
}
if (verbose)
{
Console.WriteLine("{0} {1}", httpMethod, apiurl);
Console.WriteLine("ClientToken: {0}", clientToken);
Console.WriteLine("AccessToken: {0}", accessToken);
Console.WriteLine("Secret: {0}", secret);
if (data != null) Console.WriteLine("Data: [{0}]", data);
if (uploadfile != null) Console.WriteLine("UploadFile: {0}", uploadfile);
if (outputfile != null) Console.WriteLine("OutputFile: {0}", outputfile);
foreach (string header in headers)
Console.WriteLine("{0}", header);
Console.WriteLine("Content-Type: {0}", contentType);
}
execute(httpMethod, apiurl, headers, clientToken, accessToken, secret, data, uploadfile, outputfile, maxBodySize, contentType, verbose);
}