public void SetServiceHookUrl(string token, string projectName, string projectId, string serviceHookUrl)
{
if (!ServiceHookExists(token, projectName, serviceHookUrl))
{
try
{
var url = string.Format(GetProject(token, projectName).ProjectUrl + "/servicehook", projectName);
var req = GetAuthenticatedWebRequest(token, url);
req.Accept = "application/json";
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
string parameters = "ServiceHook.Url=" + serviceHookUrl;
byte[] bytes = System.Text.Encoding.ASCII.GetBytes(parameters);
req.ContentLength = bytes.Length;
System.IO.Stream os = req.GetRequestStream();
os.Write(bytes, 0, bytes.Length); //Push it out there
os.Close();
System.Net.WebResponse resp = req.GetResponse();
System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
var respStr = sr.ReadToEnd().Trim();
var nvc = HttpUtility.ParseQueryString(respStr);
}
catch (WebException we)
{
//TODO: What is the "right" way to do this?
// We will swallow the 404 here because AppHarbor returns
// a 404 in the case that I am a collaborator on a project
// and not the owner, and I try to access the servicehook url
if (!we.Message.Contains("404"))
{
throw we;
}
}
catch (Exception e)
{
throw e;
}
}
}