public async Task <bool> AddAdmin(long userId, AccessLevel accessLevel) { string token = await tokenBotAuthorizer.GetToken(); Globals.Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); var jsonData = new UserData(userId, accessLevel); var json = JsonSerializer.Serialize <UserData>(jsonData); //Console.WriteLine(json); var response = await Globals.Client.PostAsync(this.usersBotUrl, new StringContent(json, Encoding.UTF8, "application/json")); bool status = response.StatusCode == HttpStatusCode.OK; return(status); }
public async Task <int> AddPost(WallPostData wallPostData, string[] tags) { string token = await tokenBotAuthorizer.GetToken(); Globals.Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); int idOriginal = -1; if (wallPostData.IsRepost()) { PostDTO original = new PostDTO(wallPostData.Original, new string[] {}); original.IsShared = true; string originalJson = JsonSerializer.Serialize <PostDTO>(original); var responseOriginal = await Globals.Client.PostAsync(feedUrl, new StringContent(originalJson, Encoding.UTF8, "application/json")); string contentOriginal = await responseOriginal.Content.ReadAsStringAsync(); var dictOriginal = JsonSerializer.Deserialize <Dictionary <string, object> >(contentOriginal); idOriginal = ((JsonElement)dictOriginal["id"]).GetInt32(); } PostDTO jsonData = new PostDTO(wallPostData, tags); jsonData.OriginalPostId = idOriginal; string json = JsonSerializer.Serialize <PostDTO>(jsonData); Console.WriteLine(json); var response = await Globals.Client.PostAsync(feedUrl, new StringContent(json, Encoding.UTF8, "application/json")); string content = await response.Content.ReadAsStringAsync(); //Console.WriteLine(content); var dict = JsonSerializer.Deserialize <Dictionary <string, object> >(content); return(((JsonElement)dict["id"]).GetInt32()); }