Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #11

Merged
merged 8 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 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.0</Version>
<Version>1.2.1</Version>
<Description>The world’s most popular website builder</Description>
<AssemblyName>Apps.Wordpress</AssemblyName>
</PropertyGroup>
Expand Down
37 changes: 23 additions & 14 deletions Apps.Wordpress/Events/Polling/PollingList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
using Apps.Wordpress.Events.Polling.Models.Memory;
using Apps.Wordpress.Models.Dtos;
using Apps.Wordpress.Models.Entities;
using Apps.Wordpress.Models.Requests;
using Blackbird.Applications.Sdk.Common;
using Blackbird.Applications.Sdk.Common.Dynamic;
using Blackbird.Applications.Sdk.Common.Invocation;
using Blackbird.Applications.Sdk.Common.Polling;
using Blackbird.Applications.Sdk.Utils.Extensions.String;
using Blackbird.Applications.Sdk.Utils.Extensions.System;
using RestSharp;

namespace Apps.Wordpress.Events.Polling;
Expand All @@ -21,51 +23,58 @@ public PollingList(InvocationContext invocationContext) : base(invocationContext
{
}

[PollingEvent("On post created", "On a new post created")]
[PollingEvent("On posts created", "On new posts are created")]
public Task<PollingEventResponse<ContentCreatedPollingMemory, ContentPollingResult>> OnPostCreated(
PollingEventRequest<ContentCreatedPollingMemory> request)
PollingEventRequest<ContentCreatedPollingMemory> request,
[PollingEventParameter] LanguageOptionalRequest languageRequest)
=> PollContentCreation(request, new()
{
["after"] = request.Memory?.LastCreationDate.ToString(Formats.ISO8601) ?? string.Empty
["after"] = request.Memory?.LastCreationDate.ToString(Formats.ISO8601) ?? string.Empty,
["lang"] = languageRequest.Language ?? string.Empty
}, "posts", () => new()
{
LastCreationDate = DateTime.UtcNow
});


[PollingEvent("On post updated", "On a specific post updated")]
[PollingEvent("On posts updated", "On specific posts are updated")]
public Task<PollingEventResponse<ContentUpdatedPollingMemory, ContentPollingResult>> OnPostUpdated(
PollingEventRequest<ContentUpdatedPollingMemory> request,
[PollingEventParameter] [Display("Post ID")] [DataSource(typeof(PostDataHandler))]
string? postId)
string? postId, [PollingEventParameter] LanguageOptionalRequest languageRequest)
=> PollContentChanges(request, postId, new()
{
["modified_after"] = request.Memory?.LastModificationTime.ToString(Formats.ISO8601) ?? string.Empty
["modified_after"] = request.Memory?.LastModificationTime.ToString(Formats.ISO8601) ?? string.Empty,
["lang"] = languageRequest.Language ?? string.Empty
}, "posts", () => new()
{
LastModificationTime = DateTime.UtcNow
});

[PollingEvent("On page created", "On a new page created")]
[PollingEvent("On pages created", "On new pages are created")]
public Task<PollingEventResponse<ContentCreatedPollingMemory, ContentPollingResult>> OnPageCreated(
PollingEventRequest<ContentCreatedPollingMemory> request)
PollingEventRequest<ContentCreatedPollingMemory> request,
[PollingEventParameter] LanguageOptionalRequest languageRequest)
=> PollContentCreation(request, new()
{
["after"] = request.Memory?.LastCreationDate.ToString(Formats.ISO8601) ?? string.Empty
["after"] = request.Memory?.LastCreationDate.ToString(Formats.ISO8601) ?? string.Empty,
["lang"] = languageRequest.Language ?? string.Empty
}, "pages", () => new()
{
LastCreationDate = DateTime.UtcNow
});


[PollingEvent("On page updated", "On a specific page updated")]
[PollingEvent("On pages updated", "On specific pages are updated")]
public Task<PollingEventResponse<ContentUpdatedPollingMemory, ContentPollingResult>> OnPageUpdated(
PollingEventRequest<ContentUpdatedPollingMemory> request,
[PollingEventParameter] [Display("Page ID")] [DataSource(typeof(PageDataHandler))]
string? pageId)
string? pageId,
[PollingEventParameter] LanguageOptionalRequest languageRequest)
=> PollContentChanges(request, pageId, new()
{
["modified_after"] = request.Memory?.LastModificationTime.ToString(Formats.ISO8601) ?? string.Empty
["modified_after"] = request.Memory?.LastModificationTime.ToString(Formats.ISO8601) ?? string.Empty,
["lang"] = languageRequest.Language ?? string.Empty
}, "pages", () => new()
{
LastModificationTime = DateTime.UtcNow
Expand All @@ -83,7 +92,7 @@ private async Task<PollingEventResponse<T, ContentPollingResult>> PollContentCre
};
}

var items = await ListContentItems(endpoint.WithQuery(query));
var items = await ListContentItems(endpoint.WithQuery(query.AllIsNotNull()));

if (!items.Any())
{
Expand Down Expand Up @@ -119,7 +128,7 @@ private async Task<PollingEventResponse<T, ContentPollingResult>> PollContentCha
}

var items = string.IsNullOrWhiteSpace(resourceId)
? await ListContentItems(endpoint.WithQuery(query))
? await ListContentItems(endpoint.WithQuery(query.AllIsNotNull()))
: await GetContentItem($"{endpoint}/{resourceId}", request.Memory);

if (!items.Any())
Expand Down
12 changes: 12 additions & 0 deletions Apps.Wordpress/Models/Requests/LanguageRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Apps.Wordpress.DataSourceHandlers;
using Blackbird.Applications.Sdk.Common;
using Blackbird.Applications.Sdk.Common.Dynamic;

namespace Apps.Wordpress.Models.Requests;

public class LanguageOptionalRequest
{
[Display("Language (P)")]
[DataSource(typeof(LanguageDataHandler))]
public string? Language { get; set; }
}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ Let us know if you're interested!

## Events

- **On post created** triggers when a new post is created.
- **On post updated** triggers when any post is updated.
- **On page created** triggers when a new page is created.
- **On page updated** triggers when any page is updated.
- **On posts created** triggers when new posts are created.
- **On posts updated** triggers when any posts are updated.
- **On pages created** triggers when new pages are created.
- **On pages updated** triggers when any pages are updated.

## Feedback

Expand Down