Guest User

Untitled

a guest
Feb 18th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. // For each result in the data.
  2. foreach (var result in results["data"])
  3. {
  4. // ID for each Asana task in the data.
  5. string id = (string)result["id"];
  6.  
  7. // Deserialize the JSON data so we can use it with an object and its properties.
  8. deserialize.SetJsonData(requestAsana.getSingleAsanaTask(id));
  9.  
  10. // Add data to the list.
  11. asanaDataList.Add(deserialize.Data);
  12. }
  13.  
  14. private AsanaRootData root = new AsanaRootData();
  15. public string jsonData;
  16. public string SetJsonData(string json)
  17. {
  18. this.jsonData = json;
  19.  
  20. root = JsonConvert.DeserializeObject<AsanaRootData>(jsonData);
  21.  
  22. return json;
  23. }
  24.  
  25. public string getSingleAsanaTask(string taskID)
  26. {
  27. try
  28. {
  29. // Make a request variable with URL and ID.
  30. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(taskURL + taskID);
  31. // Speed up requests.
  32. request.Proxy = null;
  33.  
  34. // Encode authentication value.
  35. String encoded = Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes(auth));
  36.  
  37. // Add authentication to header.
  38. request.Headers.Add("Authorization", "Basic " + encoded);
  39.  
  40. // Response variable.
  41. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  42.  
  43. // Get the stream associated with the response.
  44. Stream receiveStream = response.GetResponseStream();
  45.  
  46. // Pipes the stream to a higher level stream reader with the required encoding format.
  47. StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
  48.  
  49. return readStream.ReadToEnd();
  50. }
  51. catch (WebException e)
  52. {
  53. Debug.WriteLine("nInvalid Asana task IDn");
  54. }
  55. return "";
  56. }
Add Comment
Please, Sign In to add comment