/** * 새로운 대화방을 만듬 */ public bool CreateRoom(string teamId, string title, out WebexTeamsRoom room, out Int32 errorCode, out string errorMessage) { bool status = true; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(ROOM_ENDPOINT); request.Headers.Add("Authorization", string.Format("Bearer {0}", WebexTeamsClient.accessToken)); request.ContentType = "application/json;charset=utf-8"; request.Method = "POST"; try { WebexTeamsRoom input = new WebexTeamsRoom(); input.Title = title; if (!string.IsNullOrEmpty(teamId)) { input.TeamId = teamId; } string payload = JsonConvert.SerializeObject(input); Stream inputStream = request.GetRequestStream(); byte[] buff = System.Text.Encoding.UTF8.GetBytes(payload); inputStream.Write(buff, 0, buff.Length); inputStream.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode == HttpStatusCode.OK) { Stream stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream, Encoding.UTF8); WebexTeamsRoom result = JsonConvert.DeserializeObject <WebexTeamsRoom>(reader.ReadToEnd()); errorCode = (int)HttpStatusCode.OK; errorMessage = "OK"; room = result; } else { Stream stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream, Encoding.UTF8); JObject resp = JObject.Parse(reader.ReadToEnd()); errorCode = (int)response.StatusCode; errorMessage = resp["message"].ToString(); room = null; status = false; } } catch (System.Exception e) { System.Console.WriteLine("Error Message : " + e.Message); errorCode = -1; errorMessage = e.Message; room = null; status = false; } return(status); }
/** * 전체 Room List를 요청 함 */ public bool ListRooms(out List <WebexTeamsRoom> roomList, out Int32 errorCode, out string errorMessage) { bool status = true; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(ROOM_ENDPOINT); //request.Headers.Clear(); request.Headers.Add("Authorization", string.Format("Bearer {0}", WebexTeamsClient.accessToken)); request.ContentType = "application/json;charset=utf-8"; request.Method = "GET"; List <WebexTeamsRoom> rooms = new List <WebexTeamsRoom>(); try { HttpWebResponse response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode == HttpStatusCode.OK) { Stream stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream, Encoding.UTF8); JObject roomsResponse = JObject.Parse(reader.ReadToEnd()); IList <JToken> items = roomsResponse["items"].Children().ToList(); foreach (JToken item in items) { // JToken.ToObject is a helper method that uses JsonSerializer internally WebexTeamsRoom room = item.ToObject <WebexTeamsRoom>(); rooms.Add(room); } errorCode = (int)HttpStatusCode.OK; errorMessage = "OK"; roomList = rooms; } else { Stream stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream, Encoding.UTF8); JObject resp = JObject.Parse(reader.ReadToEnd()); errorCode = (int)response.StatusCode; errorMessage = resp["message"].ToString(); roomList = null; status = false; } } catch (System.Exception e) { System.Console.WriteLine("Error Message : " + e.Message); errorCode = -1; errorMessage = e.Message; roomList = null; status = false; } return(status); }