Since no language is specified, this covers the C # side.
This includes quick & dirty (current as of 2013-12-05) XML parsing to extract the amount of Microsoft Translator resources.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.Xml; using System.IO; namespace translation_testing { class Class1 { public static int GetUsage() { string uri = "https://api.datamarket.azure.com/Services/My/Datasets"; string general_accountkey = "your account key"; string accountkeyraw = general_accountkey + ":" + general_accountkey; byte[] accountkeybytes = Encoding.UTF8.GetBytes(accountkeyraw); string accountkeystring = Convert.ToBase64String(accountkeybytes); HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(uri); httpWebRequest.Headers.Add("Authorization", "Basic " + accountkeystring); WebResponse response = null; try { response = httpWebRequest.GetResponse(); using (Stream stream = response.GetResponseStream()) { StringBuilder sbresponse = new StringBuilder(); int len = 1; while (stream.CanRead && len > 0) { byte[] chunk = new byte[4096]; len = stream.Read(chunk, 0, 4096); sbresponse.Append(Encoding.UTF8.GetString(chunk, 0, len)); } return translator_resource_count(sbresponse.ToString()); } } catch { throw; } finally { if (response != null) { response.Close(); response = null; } } } private static int translator_resource_count(string input) { bool isentry = false; bool iscontent = false; bool istitle = false; bool isbalance = false; string title = null; string balance = null; using (XmlReader reader = XmlReader.Create(new StringReader(input))) { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Text) { if (istitle) title = reader.Value; if (isbalance) balance = reader.Value; } else if (reader.NodeType == XmlNodeType.Element) { if (reader.Name == "entry") isentry = true; if (isentry && reader.Name == "content") iscontent = true; if (isentry && !iscontent && reader.Name == "title") istitle = true; if (isentry && iscontent && title == "Microsoft Translator" && reader.Name == "d:ResourceBalance") isbalance = true; } else if (reader.NodeType == XmlNodeType.EndElement) { if (reader.Name == "entry") isentry = false; if (isentry && reader.Name == "content") iscontent = false; if (isentry && !iscontent && reader.Name == "title") istitle = false; if (isentry && iscontent && title == "Microsoft Translator" && reader.Name == "d:ResourceBalance") isbalance = false; } } } return int.Parse(balance); } } }
source share