internal Request(Uri requestUri, Func <string, bool> validationDelegate, string endpoint, CancellationToken token, WordpressAuthorization auth, HttpMethod method, IDictionary <string, string> headers, HttpContent formBody, int perPageCount = 10, Callback callback = null) { RequestUri = requestUri; Callback = callback; Endpoint = endpoint; Token = token; RequestMethod = method; Headers = headers; FormBody = formBody; Authorization = auth; PerPageCount = perPageCount; ValidationDelegate = validationDelegate; }
private static async Task <int> Main(string[] args) { CookieContainer container = new CookieContainer(); CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); WordpressClient client = new WordpressClient("https://www.example.com/wp-json/", maxConcurrentRequestsPerInstance: 8, timeout: 60) .WithCookieContainer(ref container) .WithActivityCallback((type) => { Console.WriteLine(type); return(Task.CompletedTask); }) .WithJsonSerializerSetting(new JsonSerializerSettings() { ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor, MissingMemberHandling = MissingMemberHandling.Ignore }) .WithGlobalResponseProcessor((response) => { Console.WriteLine(response); return(true); }); redo: WordpressAuthorization auth = new WordpressAuthorization("username", "password", WordpressClient.AuthorizationType.Jwt); if (await client.IsLoggedInAsync()) { Console.WriteLine("Already logged in."); } else { if (await client.LoginAsync(auth).ConfigureAwait(false)) { Console.WriteLine("Logged in now"); } } var currentUser = await client.GetCurrentUserAsync((builder) => builder.Create()); Console.WriteLine(currentUser.Message); Console.ReadKey(); goto redo; Console.ReadKey(); return(0); }