public WR pJSON(string qTxt) { //list<string> qTxts JiraResource resource = new JiraResource(); string bURL = "https://redacted.atlassian.net/rest/api/latest/search?jql="; //base url, update to run string JSONdata = null; int statusCode = 0; Stream s; StreamReader r; HttpWebResponse webRes; HttpWebRequest WebReq = WebRequest.Create(bURL + qTxt) as HttpWebRequest; WebReq.ContentType = "application/json"; WebReq.Method = "GET"; WebReq.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes(resource.m_Username + ":" + resource.m_Password)); try { webRes = (HttpWebResponse)WebReq.GetResponse(); s = webRes.GetResponseStream(); r = new StreamReader(s); JSONdata = r.ReadToEnd(); statusCode = (int)webRes.StatusCode; s.Close(); r.Close(); } catch (WebException e) { s = e.Response.GetResponseStream(); r = new StreamReader(s); JSONdata = r.ReadToEnd(); statusCode = (int)((HttpWebResponse)e.Response).StatusCode; s.Close(); r.Close(); } try { //JavaScriptSerializer jss = new JavaScriptSerializer(); //jss.RegisterConverters = unnull; WR tem = new JavaScriptSerializer().Deserialize<WR>(JSONdata); return tem; } catch (Exception e) { string m = e.Message; } return null; }
public static int getJIRAtotal(string jqry) { JiraResource resource = new JiraResource(); string bURL = "https://redacted.atlassian.net/rest/api/latest/search?jql="; //base url, update to run string JSONdata = null; int statusCode = 0; Stream s; StreamReader r; HttpWebResponse webRes; HttpWebRequest WebReq = WebRequest.Create(bURL + jqry+"&startAt=0&maxResults=0") as HttpWebRequest; WebReq.ContentType = "application/json"; WebReq.Method = "GET"; WebReq.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes(resource.m_Username + ":" + resource.m_Password)); try { webRes = (HttpWebResponse)WebReq.GetResponse(); s = webRes.GetResponseStream(); r = new StreamReader(s); JSONdata = r.ReadToEnd(); statusCode = (int)webRes.StatusCode; s.Close(); r.Close(); } catch (WebException e) { s = e.Response.GetResponseStream(); r = new StreamReader(s); JSONdata = r.ReadToEnd(); statusCode = (int)((HttpWebResponse)e.Response).StatusCode; s.Close(); r.Close(); } try { //"{\"startAt\":0,\"maxResults\":0,\"total\":549,\"issues\":[]}" //{"startAt":0,"maxResults":0,"total":549,"issues":[]} //pos 36 int x = JSONdata.LastIndexOf(','); int i = Convert.ToInt32(JSONdata.Substring(36, JSONdata.LastIndexOf(',') - 36)); return i; } catch (Exception e) { string m = e.Message; } return 0; }