//get the current account balance for a given user
public string getAccountBalance(string username, string apiKey, ref NotifyIcon notifyIcon)
{
string accountBalance = "0.0";
try
{
if (String.IsNullOrEmpty(username))
return "";
WebClient client = new WebClient();
string urlFormat = "http://marketplace.envato.com/api/v1/" + username + "/" + apiKey + "/account.json";
Uri url = new Uri(string.Format(urlFormat));
string data = client.DownloadString(url);
using (JsonReader reader = new JsonReader(new StringReader(data)))
{
while (reader.Read())
{
//users++;
if ((string)reader.Value == "balance")
{
reader.Read();
accountBalance = (string)reader.Value;
}
}
reader.Close(); //close the reader object
}
}
catch (WebException webex)
{
notifyIcon.ShowBalloonTip(180000000, "EnvatoTracker error!", "Error querying the api - invalid api key maybe?\n\nError:"+webex, ToolTipIcon.None);
}
return accountBalance;
}