public string URLGetAuthor(string url, AlchemyAPI_BaseParams parameters) { CheckURL(url); parameters.setUrl(url); return GET("URLGetAuthor", "url", parameters); }
public string HTMLGetAuthor(string html, string url, AlchemyAPI_BaseParams parameters) { CheckHTML(html, url); parameters.setHtml(html); parameters.setUrl(url); return POST("HTMLGetAuthor", "html", parameters); }
private string DoRequest(HttpWebRequest wreq, AlchemyAPI_BaseParams.OutputMode outputMode) { using (HttpWebResponse wres = wreq.GetResponse() as HttpWebResponse) { StreamReader r = new StreamReader(wres.GetResponseStream()); string xml = r.ReadToEnd(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xml); XmlElement root = xmlDoc.DocumentElement; if (AlchemyAPI_BaseParams.OutputMode.XML == outputMode) { XmlNode status = root.SelectSingleNode("/results/status"); if (status.InnerText != "OK") { System.ApplicationException ex = new System.ApplicationException("Error making API call."); throw ex; } } else if (AlchemyAPI_BaseParams.OutputMode.RDF == outputMode) { XmlNamespaceManager nm = new XmlNamespaceManager(xmlDoc.NameTable); nm.AddNamespace("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); nm.AddNamespace("aapi", "http://rdf.alchemyapi.com/rdf/v1/s/aapi-schema#"); XmlNode status = root.SelectSingleNode("/rdf:RDF/rdf:Description/aapi:ResultStatus", nm); if (status.InnerText != "OK") { System.ApplicationException ex = new System.ApplicationException("Error making API call."); throw ex; } } return xml; } }
private string POST(string callName, string callPrefix, AlchemyAPI_BaseParams parameters) { // callMethod, callPrefix, ... params Uri address = new Uri(_requestUri + callPrefix + "/" + callName); HttpWebRequest wreq = WebRequest.Create(address) as HttpWebRequest; wreq.Proxy = GlobalProxySelection.GetEmptyWebProxy(); wreq.Method = "POST"; wreq.ContentType = "application/x-www-form-urlencoded"; StringBuilder d = new StringBuilder(); d.Append("apikey=").Append(_apiKey).Append(parameters.getParameterString()); parameters.resetBaseParams(); byte[] bd = UTF8Encoding.UTF8.GetBytes(d.ToString()); wreq.ContentLength = bd.Length; using (Stream ps = wreq.GetRequestStream()) { ps.Write(bd, 0, bd.Length); } return DoRequest(wreq, parameters.getOutputMode()); }
private string GET(string callName, string callPrefix, AlchemyAPI_BaseParams parameters) { // callMethod, callPrefix, ... params StringBuilder uri = new StringBuilder(); uri.Append(_requestUri).Append(callPrefix).Append("/").Append(callName); uri.Append("?apikey=").Append(_apiKey).Append(parameters.getParameterString()); parameters.resetBaseParams(); Uri address = new Uri(uri.ToString()); HttpWebRequest wreq = WebRequest.Create(address) as HttpWebRequest; wreq.Proxy = GlobalProxySelection.GetEmptyWebProxy(); wreq.Method = "GET"; return DoRequest(wreq, parameters.getOutputMode()); }
public string TextGetTextSentiment(string text, AlchemyAPI_BaseParams parameters) { CheckText(text); parameters.setText(text); return POST("TextGetTextSentiment", "text", parameters); }
public string URLGetTextSentiment(string url, AlchemyAPI_BaseParams parameters) { CheckURL(url); parameters.setUrl(url); return GET("URLGetTextSentiment", "url", parameters); }
public string HTMLGetMicroformats(string html, string url, AlchemyAPI_BaseParams parameters) { CheckHTML(html, url); parameters.setHtml(html); parameters.setUrl(url); return POST("HTMLGetMicroformatData", "html", parameters); }
public string URLGetMicroformats(string url, AlchemyAPI_BaseParams parameters) { CheckURL(url); parameters.setUrl(url); return GET("URLGetMicroformatData", "url", parameters); }