public async void Login_Phase1() { #region Login Phase 1 var client = new WordPressClient("http://mm-app.co.za/wp-json/"); client.AuthMethod = AuthMethod.JWT; try { await client.RequestJWToken(Usernamelabel.Text, Password.Text); } catch (Exception e) { await App.Current.MainPage.DisplayAlert("Wrong Detail's", e.ToString(), "OK"); } var x = client; var isValidToken = await client.IsValidJWToken(); WpApiCredentials.token = client.GetToken(); if (isValidToken) { Login_Phase2(); } else { await App.Current.MainPage.DisplayAlert("Empty Values", "Token not Found", "OK"); } #endregion }
public WordPressService(SettingsService settingsService) { _settingsService = settingsService; _localSettings = ApplicationData.Current.LocalSettings; _client = new WordPressClient(Config.WordPressUri); Init(); }
public async Task <bool> CreatePost(string title, string content) { try { Console.WriteLine("Trying to post"); WordPressClient client = await GetClient(currentUser.UserName, currentUser.Password); if (await client.IsValidJWToken()) { var post = new Post { Title = new Title(title), Content = new Content(content) }; await client.Posts.Create(post); Console.WriteLine("Logging out of client."); client.Logout(); } } catch (Exception e) { Console.WriteLine("could not post"); Console.WriteLine("Error:" + e.Message); } Console.WriteLine("Post complete"); return(true); }
public async void TestPosts() { client = new WordPressClient(ApiCredentials.WordPressUri); client.Username = ApiCredentials.Username; client.Password = ApiCredentials.Password; var posts = await client.ListPosts(); var post = await client.GetPost("1"); var newpost = new Post() { Title = new Title() { Raw = "new test post" } }; //var newpostresponse = await client.CreatePost(newpost); var comments = await client.ListComments(); var comment = await client.GetComment("3"); var currentUser = await client.GetCurrentUser(); }
public async Task CustomHttpClient() { // Initialize var httpClient = new HttpClient { BaseAddress = new Uri(ApiCredentials.WordPressUri) }; httpClient.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0"); httpClient.DefaultRequestHeaders.Add("Referer", "https://github.com/wp-net/WordPressPCL"); var client = new WordPressClient(httpClient); var posts = await client.Posts.GetAll(); var post = await client.Posts.GetByID(posts.First().Id); Assert.IsTrue(posts.First().Id == post.Id); Assert.IsTrue(!string.IsNullOrEmpty(posts.First().Content.Rendered)); await client.RequestJWToken(ApiCredentials.Username, ApiCredentials.Password); var validToken = await client.IsValidJWToken(); Assert.IsTrue(validToken); }
public static async System.Threading.Tasks.Task connectAsync() { var client = new WordPressClient("http://localhost:81/wordpress/", "wp-josn/wc/v3/"); // Posts var posts = await client.Posts.GetAll(); //var postbyid = await client.Posts.GetById(id); // Comments var comments = await client.Comments.GetAll(); //var commentbyid = await client.Comments.GetById(id); //var commentsbypost = await client.Comments.GetCommentsForPost(postid, true, false); // Users // JWT authentication client.AuthMethod = AuthMethod.JWT; await client.RequestJWToken("user", "changeme"); // check if authentication has been successful var isValidToken = await client.IsValidJWToken(); // now you can send requests that require authentication //var response = client.Posts.Delete(postid); Console.WriteLine(posts); }
/// <summary> /// removes or changes posts with sale changes /// </summary> /// <param name="driver"></param> /// <returns></returns> public static async Task UpdatePosts() { WordPressClient client = await GetClient(); Dictionary <int, String> TagsIDtoName = SendGetTags(GetTags()).ToDictionary(k => k.Id, v => v.Name); Dictionary <int, Post> PostsDict = SendGetPosts(GetPosts()).ToDictionary(p => p.Tags[0]); foreach (Product update in Product.updates) { if (PostsDict.ContainsKey(update.tagID)) { Post post = PostsDict[update.tagID]; //if update is no longer on sale, delete from wordpress if (update.Change == 2) { client.Posts.Delete(post.Id).Wait(); client.Tags.Delete(post.Tags[0]).Wait(); client.Media.Delete(post.FeaturedMedia.Value).Wait(); tags.Remove(TagsIDtoName[update.tagID]); } else if (update.Change == 1) { //Otherwise update with the new prices Post updatePost = new Post { Id = post.Id, Content = new Content("$" + update.Xprice + "-->" + "$" + update.Price), }; client.Posts.Update(updatePost).Wait(); } } } }
/// <summary> /// Create the Wordpress PCL client. /// </summary> /// <returns></returns> private WordPressClient GetClient() { WordPressClient client = null; try { var wpUrl = _configService.Get(ConfigSettings.WordpressURL); if (!String.IsNullOrEmpty(wpUrl)) { var baseUrl = new Uri(wpUrl); var url = new Uri(baseUrl, "/wp-json/"); Logging.LogVerbose($"Initialising Wordpress Client for {url}..."); // JWT authentication client = new WordPressClient(url.ToString()); client.Auth.UseBearerAuth(JWTPlugin.JWTAuthByEnriqueChavez); Logging.Log($"JWT Auth token generated successfully."); } else { Logging.Log("Wordpress integration was not configured."); } } catch (Exception ex) { Logging.LogError($"Unable to create Wordpress Client: {ex.Message}"); client = null; } return(client); }
public static async Task Init(TestContext testContext) { _client = ClientHelper.GetWordPressClient(); _clientAuth = await ClientHelper.GetAuthenticatedWordPressClient(testContext); _testContext = testContext; }
//public static async Task ReadLastWeek2(IWebDriver driver, WebDriverWait wait) //{ // WordPressClient client = await GetClient(); // if (await client.IsValidJWToken()) // { // foreach (Post post in client.Posts.GetAll().Result) // { // Product.updates.Add(new Product( // post.Title.Rendered, // post.Categories[0], // Selenium.getLink(driver, wait, post), // post.Tags[0] // )); // } // tagIDtoID(Product.updates).Wait(); // } //} /// <summary> /// removes or changes posts with sale changes /// </summary> /// <param name="driver"></param> /// <returns></returns> public static async Task UpdatePosts() { WordPressClient client = await GetClient(); foreach (Post post in client.Posts.GetAll().Result) { foreach (Product update in Product.updates) { if (post.Tags[0] == update.tagID) { //if update is no longer on sale, delete from wordpress if (update.Price == -1 || update.Xprice == -1) { await client.Posts.Delete(post.Id); await client.Tags.Delete(post.Tags[0]); await client.Media.Delete(post.FeaturedMedia.Value); } else { //Otherwise update with the new prices Post updatePost = new Post { Id = post.Id, Content = new Content("$" + update.Xprice + "-->" + "$" + update.Price), }; await client.Posts.Update(updatePost); } } } } }
public async Task Application_Password_Auth() { // The old JWT Plugin results in issues when using Application Passwords for requests Console.WriteLine($"App Password info: {_testContext?.Properties["skipapppassword"]}"); if (_testContext?.Properties["skipapppassword"]?.ToString() == "true") { Console.WriteLine("Skip App Password Test"); Assert.Inconclusive(); return; } Console.WriteLine("Run App Password Test"); var appPassword = await _clientAuth.Users.CreateApplicationPassword(System.Guid.NewGuid().ToString()); var appPasswordClient = new WordPressClient(ApiCredentials.WordPressUri) { AuthMethod = AuthMethod.ApplicationPassword, UserName = ApiCredentials.Username }; appPasswordClient.SetApplicationPassword(appPassword.Password); var post = new Post() { Title = new Title("Title 1"), Content = new Content("Content PostCreate") }; var postCreated = await appPasswordClient.Posts.Create(post); Assert.IsNotNull(postCreated); Assert.AreEqual("Title 1", postCreated.Title.Raw); }
// should do some refactoring...also this checks every post seperately but should only happen once per update public Term[] GetRssCategory() { // from https://github.com/abrudtkuhl/WordPressSharp/issues/48#issuecomment-105643517 var keyword = new Term { Name = "RssFeedPosts", Slug = "Something, something...", Taxonomy = "category" }; var existingTerm = CheckForCategory(keyword); if (existingTerm == null) { using (var client = new WordPressClient(config)) { keyword.Id = client.NewTerm(keyword); } } else { keyword = existingTerm; } //create a terms list var terms = new List <Term>(); terms.Add(keyword); return(terms.ToArray()); }
public async Task Users_Authenticate() { var clientAuth = new WordPressClient(ApiCredentials.WordPressUri) { AuthMethod = AuthMethod.JWT }; await clientAuth.RequestJWToken(ApiCredentials.Username, ApiCredentials.Password); var isLoggedIn = await clientAuth.IsValidJWToken(); Assert.IsTrue(isLoggedIn); var clientNotAuth = new WordPressClient(ApiCredentials.WordPressUri) { AuthMethod = AuthMethod.JWT }; await Assert.ThrowsExceptionAsync <WPException>(async() => { await clientNotAuth.RequestJWToken(ApiCredentials.Username, "123"); }); isLoggedIn = await clientNotAuth.IsValidJWToken(); Assert.IsFalse(isLoggedIn); }
public async Task UpdatePage(int pageId, string neuerHtmlCode, WordPressCredentials credentials) { _logger.LogInformation("Starte WordPress-API"); var config = new WordPressSiteConfig { BaseUrl = credentials.BaseUrl, Username = credentials.Username, Password = credentials.Password }; using (var client = new WordPressClient(config)) { var post = new Post { Id = Convert.ToString(pageId), Content = neuerHtmlCode }; var sucess = await client.EditPostAsync(post); if (!sucess) { throw new Exception($"EditPostAsync gab false zurück :("); } } }
public static WordPressClient GetWordPressClient() { if (_client == null) { _client = new WordPressClient(ApiCredentials.WordPressUri, ""); } return(_client); }
private async void Button_Click(object sender, RoutedEventArgs e) { ShowLoading("loading..."); wordpressClient = new WordPressClient(); var response = await wordpressClient.GetCategoriesList("msicc.net"); HideLoading(); }
private async void Button_Click(object sender, RoutedEventArgs e) { ShowLoading("loading..."); wordpressClient = new WordPressClient(); var response = await wordpressClient.GetCategoryPostList("msicc.net", "wpdev", PostType.post, PostStatus.publish); HideLoading(); }
public DetailPageViewModel() { if (Windows.ApplicationModel.DesignMode.DesignModeEnabled) { //Value = "Designtime value"; } _client = new WordPressClient(ApiCredentials.WordPressUri); PostComments = new ObservableCollection <Comment>(); }
async void button_Click(object sender, EventArgs e) { ShowLoading("loading..."); wordpressclient = new WordPressClient(); var response = await wordpressclient.GetPostList("msicc.net", PostType.post, PostStatus.publish); HideLoading(); }
/// <summary> /// Reset the client - use this if the settings are updated. /// </summary> public void ResetClient() { _client = GetClient(); if (_client != null) { Logging.Log("Wordpress API client reset."); } }
public async Task GetFirstPostTest() { // Initialize var client = new WordPressClient(ApiCredentials.WordPressUri); var posts = await client.ListPosts(); var post = await client.GetPost(posts[0].Id); Assert.IsTrue(posts[0].Id == post.Id); }
public static async Task <WordPressClient> GetAuthenticatedWordPressClient(AuthMethod method = AuthMethod.JWT) { var clientAuth = new WordPressClient(ApiCredentials.WordPressUri) { AuthMethod = AuthMethod.JWT }; await clientAuth.RequestJWToken(ApiCredentials.Username, ApiCredentials.Password); return(clientAuth); }
private async Task <User> CreateRandomUser(WordPressClient client) { var random = new Random(); var r = random.Next(0, 1000); var username = $"Testuser{r}"; var email = $"testuser{r}@test.com"; var password = $"testpassword{r}"; return(await client.Users.Create(new User(username, email, password))); }
public WordPressClient GetClient() { if (URI == "") { return(null); } WordPressClient TheClient = new WordPressClient(URI); return(TheClient); }
private static async Task <WordPressClient> GetClient() { // JWT authentication var client = new WordPressClient("http://wordpress-domain.com/wp-json/"); client.AuthMethod = AuthMethod.JWT; await client.RequestJWToken("user", "password"); return(client); }
public async Task BasicSetupTest() { // Initialize var client = new WordPressClient(ApiCredentials.WordPressUri); Assert.IsNotNull(client); // Posts var posts = await client.ListPosts(); Assert.IsNotNull(posts); }
private Term CheckForCategory(Term keyword) { Term existingTerm; using (var client = new WordPressClient(config)) { var terms = client.GetTerms("category", new TermFilter()); existingTerm = terms.FirstOrDefault(x => x.Name.Equals(keyword.Name)); } return(existingTerm); }
private static async Task <WordPressClient> GetAuthenticatedWordPressClient() { var client = new WordPressClient(ApiCredentials.WordPressUri); client.Username = ApiCredentials.Username; client.Password = ApiCredentials.Password; client.AuthMethod = AuthMethod.JWT; await client.RequestJWToken(); return(client); }
public async Task Media_Read() { // Initialize var client = new WordPressClient(ApiCredentials.WordPressUri); Assert.IsNotNull(client); var media = await client.Media.GetAll(); Assert.IsNotNull(media); Assert.AreNotEqual(media.Count(), 0); }
public async Task GetStickyPosts() { // Initialize var client = new WordPressClient(ApiCredentials.WordPressUri); var posts = await client.ListStickyPosts(); foreach (Post post in posts) { Assert.IsTrue(post.Sticky); } }
/// <summary> /// returns client for wordpress site /// </summary> /// <returns></returns> public static async Task <WordPressClient> GetClient() { //JWT authentication var client = new WordPressClient("https://zed.exioite.com/wp-json/"); client.AuthMethod = AuthMethod.JWT; String[] creds = Formatting.getCreds(); client.RequestJWToken(creds[0], creds[1]).Wait(); //await client.RequestJWToken("*****@*****.**", "*xuFKWOX@t8Oc$8fgALK4HLh"); return(client); }