public async Task <List <Room> > GetRoomsForCurrentUser() { List <Room> rooms = new List <Room>(); HttpResponseMessage response = await RequestsBL.GETRequest("/room", Constants.BaseRequestStub); if (response != null) { if (response.IsSuccessStatusCode) { rooms = RequestsBL.DeserializeObjects <Room>(XDocument.Parse(await response.Content.ReadAsStringAsync()), elementPointer); } } return(rooms); }
public async Task <Bitmap> GetAvatar(string username, int pixelDesired) //to load anyone custom sized avatar { Bitmap avatar = null; HttpResponseMessage response = await RequestsBL.GETRequest(string.Format("/{0}/{1}", username, pixelDesired), Constants.AvatarRequestStub); if (response != null) { if (response.IsSuccessStatusCode) { avatar = new Bitmap(await response.Content.ReadAsStreamAsync()); } } return(avatar); }
public async Task <List <Contact> > SearchContacts(string searchText) { List <Contact> contacts = new List <Contact>(); HttpResponseMessage response = await RequestsBL.GETRequest (String.Format("/get?format=json&search={0}&itemType=call&itemId=new&shareTypes%5B%5D=0&shareTypes%5B%5D=1", searchText), Constants.ContactsRequestStub); if (response != null) { JObject jResponse = (JObject)JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync()); //sto coso era già un json e non un xml var contactsContainer = jResponse["ocs"]["data"].AsJEnumerable(); //non si sa perché il pointer non funziona, seleziono path a mano if (contactsContainer != null) //gli oggetti che trova finalmente li serializza { if (contactsContainer is JArray) { contacts = JsonConvert.DeserializeObject <List <Contact> >(contactsContainer.ToString()); //if multiple nodes (array) } else if (contactsContainer is JObject) { contacts.Add(JsonConvert.DeserializeObject <Contact>(contactsContainer.ToString())); //if single node } } } return(contacts); }
public async Task <UserInfo> GetUserInfo(string userId) { HttpResponseMessage response = await RequestsBL.GETRequest(string.Format("/{0}", userId), Constants.UsersRequestStub); UserInfo ui = new UserInfo(); if (response != null) { if (response.IsSuccessStatusCode) { ui = RequestsBL.DeserializeObjects <UserInfo>(XDocument.Parse(await response.Content.ReadAsStringAsync()), dataPointer)[0]; } } return(ui); }
public async Task <List <Chat> > GetChatsInRoom(Room Room) { List <Chat> chats = new List <Chat>(); HttpResponseMessage response = await RequestsBL.GETRequest(string.Format ("/chat/{0}?lastKnownMessageId=0&limit=100&lookIntoFuture=1", Room.token), Constants.BaseRequestStub); if (response != null) { if (response.IsSuccessStatusCode) { chats = RequestsBL.DeserializeObjects <Chat>(XDocument.Parse(await response.Content.ReadAsStringAsync()), elementPointer); } } return(chats); }