Skip to content

Commit

Permalink
Merge pull request #12 from bb-io/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
vitalii-bezuhlyi authored Jul 9, 2024
2 parents ca0a130 + 870d6d5 commit 9b872da
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
17 changes: 10 additions & 7 deletions Apps.Wordpress/Actions/PageActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using Blackbird.Applications.Sdk.Utils.Extensions.System;
using Blackbird.Applications.Sdk.Utils.Html.Extensions;
using Blackbird.Applications.Sdk.Utils.Parsers;
using Newtonsoft.Json;
using RestSharp;

namespace Apps.Wordpress.Actions;
Expand Down Expand Up @@ -75,9 +76,10 @@ public async Task<WordPressItem> GetPageById([ActionParameter] PageRequest input
{
var client = new WordpressRestClient(Creds);
var request = new WordpressRestRequest(Endpoint + $"/{input.Id}", Method.Get, Creds);
var post = await client.ExecuteWithHandling<BaseDto>(request);
var post = await client.ExecuteWithHandling(request);

return new(post);
var dto = JsonConvert.DeserializeObject<BaseDto>(post.Content!)!;
return new(dto);
}

[Action("Get page missing translations (P)", Description = "Gets all the languages that are missing for this page.")]
Expand Down Expand Up @@ -114,14 +116,15 @@ public async Task<WordPressItem> GetTranslationByPage([ActionParameter] PageRequ
[Action("Get page as HTML", Description = "Get page by id as HTML file")]
public async Task<FileResponse> GetPageByIdAsHtml([ActionParameter] PageRequest input)
{
var client = new CustomWordpressClient(Creds);
var page = await client.Pages.GetByIDAsync(input.Id);

var html = (page.Title.Rendered, page.Content.Rendered).AsHtml();
var client = new WordpressRestClient(Creds);
var request = new WordpressRestRequest(Endpoint + $"/{input.Id}", Method.Get, Creds);
var post = await client.ExecuteWithHandling<BaseDto>(request);

var html = (post.Title.Rendered, post.Content.Rendered).AsHtml();

using var stream = new MemoryStream(Encoding.UTF8.GetBytes(html));
var file = await _fileManagementClient.UploadAsync(stream, MediaTypeNames.Text.Html,
$"{page.Title.Rendered}.html");
$"{post.Title.Rendered}.html");
return new(file);
}

Expand Down
2 changes: 1 addition & 1 deletion Apps.Wordpress/Api/RestSharp/WordpressRestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task<List<T>> Paginate<T>(RestRequest request)
});

var response = await ExecuteWithHandling(request);
totalPages ??= int.Parse(response.Headers.First(x => x.Name == "X-Wp-Totalpages").Value.ToString());
totalPages ??= int.Parse(response.Headers.First(x => x.Name!.Equals("X-Wp-Totalpages", StringComparison.OrdinalIgnoreCase)).Value.ToString());
var content = response.Content;

var data = JsonConvert.DeserializeObject<T[]>(response.Content);
Expand Down
4 changes: 2 additions & 2 deletions Apps.Wordpress/Apps.Wordpress.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Product>Wordpress (+ Polylang)</Product>
<Version>1.2.1</Version>
<Version>1.2.2</Version>
<Description>The world’s most popular website builder</Description>
<AssemblyName>Apps.Wordpress</AssemblyName>
</PropertyGroup>
Expand All @@ -13,7 +13,7 @@
<PackageReference Include="Blackbird.Applications.SDK.Extensions.FileManagement" Version="1.0.1" />
<PackageReference Include="Blackbird.Applications.Sdk.Utils" Version="1.0.16" />
<PackageReference Include="Blackbird.Applications.Sdk.Utils.Html" Version="1.0.1" />
<PackageReference Include="WordPressPCL" Version="2.0.1" />
<PackageReference Include="WordPressPCL" Version="2.1.0" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource CopyToOutputDirectory="Always" Include="image\icon.png"></EmbeddedResource>
Expand Down

0 comments on commit 9b872da

Please sign in to comment.