Skip to content

Commit

Permalink
Develop (#11)
Browse files Browse the repository at this point in the history
* added categories

* Updated csproj

* added polling events

* added docs

* added language input to polling events

---------

Co-authored-by: vitalii-bezuhlyi <[email protected]>
  • Loading branch information
bZverok and vitalii-bezuhlyi authored Jun 12, 2024
1 parent 2e95b34 commit ca0a130
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 19 deletions.
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

0 comments on commit ca0a130

Please sign in to comment.