public async Task CreateArticle(string blogId, string author, string title, string description = null) { if (string.IsNullOrWhiteSpace(blogId)) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(blogId)); } if (string.IsNullOrWhiteSpace(author)) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(author)); } if (string.IsNullOrWhiteSpace(title)) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(title)); } if (_fileProvider.CheckMetaFileExists(MetaFileNameValues.ARTICLE)) { Console.WriteLine("An Article already exists within the current context"); return; } var response = await _client.PostMessage(BogApiRouteValues.ARTICLE, new ArticleRequest { Author = author, Title = title, Description = description, BlogId = Guid.Parse(blogId) }); if (!response.IsSuccessStatusCode) { throw new HttpRequestException($"failed HTTP request: {response.StatusCode}\n{response.ReasonPhrase}"); } var blogContentTask = response.Content.ReadAsStringAsync(); await _fileProvider.WriteMetaFile(MetaFileNameValues.ARTICLE, blogContentTask); var contents = await blogContentTask; contents = JsonUtility.Prettify <ArticleResponse>(contents); Console.WriteLine(contents); }
public async Task UpdateEntry(string entryFilePath) { entryFilePath = Path.GetFullPath(entryFilePath); Console.WriteLine($"attempting to load entry file: {entryFilePath}"); if (!File.Exists(entryFilePath)) { throw new FileNotFoundException($"Could not load entry file: {entryFilePath}"); } var articleContext = await _getArticleContextWorkflow.GetArticleContext(); if (articleContext == null) { return; } var entryFileBytes = await File.ReadAllBytesAsync(entryFilePath); var entryContentsUtf8 = Encoding.UTF8.GetString(entryFileBytes); var entry = new ArticleEntry { Content = entryContentsUtf8 }; var updateEntryResponse = await _client.PostMessage(articleContext.GetApiLink(LinkRelValueObject.ENTRY), entry); if (!updateEntryResponse.IsSuccessStatusCode) { throw new HttpRequestException($"failed HTTP request: {updateEntryResponse.StatusCode}\n{updateEntryResponse.ReasonPhrase}"); } var entryResponseContents = await updateEntryResponse.Content.ReadAsStringAsync(); entryResponseContents = JsonUtility.Prettify <ArticleEntryResponse>(entryResponseContents); Console.WriteLine(entryResponseContents); await Task.CompletedTask; }
public async Task UpdateMetaTags(params string[] tags) { var articleContext = await _getArticleContextWorkflow.GetArticleContext(); if (articleContext == null) { return; } var tagRequests = tags.Select(tag => new MetaTagRequest { Name = tag }).ToArray(); var metaRequestLink = articleContext.GetApiLink(LinkRelValueObject.META_TAG); var response = await _client.PostMessage(metaRequestLink, tagRequests); if (!response.IsSuccessStatusCode) { throw new HttpRequestException($"failed HTTP request: {response.StatusCode}\n{response.ReasonPhrase}"); } }