diff --git a/extensions/Squidex.Extensions/Actions/Medium/MediumAction.cs b/extensions/Squidex.Extensions/Actions/Medium/MediumAction.cs index 6ee4048bb..1363aa430 100644 --- a/extensions/Squidex.Extensions/Actions/Medium/MediumAction.cs +++ b/extensions/Squidex.Extensions/Actions/Medium/MediumAction.cs @@ -34,6 +34,9 @@ namespace Squidex.Extensions.Actions.Medium [Display(Name = "Canonical Url", Description = "The original home of this content, if it was originally published elsewhere.")] public string CanonicalUrl { get; set; } + [Display(Name = "PublicationId", Description = "Optional publication id.")] + public string PublicationId { get; set; } + [Display(Name = "Tags", Description = "The optional comma separated list of tags.")] public string Tags { get; set; } diff --git a/extensions/Squidex.Extensions/Actions/Medium/MediumActionHandler.cs b/extensions/Squidex.Extensions/Actions/Medium/MediumActionHandler.cs index 9e594c7ec..e3fe88fae 100644 --- a/extensions/Squidex.Extensions/Actions/Medium/MediumActionHandler.cs +++ b/extensions/Squidex.Extensions/Actions/Medium/MediumActionHandler.cs @@ -39,7 +39,12 @@ namespace Squidex.Extensions.Actions.Medium new JProperty("canonicalUrl", Format(action.CanonicalUrl, @event)), new JProperty("tags", ParseTags(@event, action))); - var ruleJob = new MediumJob { AccessToken = action.AccessToken, RequestBody = requestBody.ToString(Formatting.Indented) }; + var ruleJob = new MediumJob + { + AccessToken = action.AccessToken, + PublicationId = action.PublicationId, + RequestBody = requestBody.ToString(Formatting.Indented) + }; return (Description, ruleJob); } @@ -75,34 +80,43 @@ namespace Squidex.Extensions.Actions.Medium httpClient.DefaultRequestHeaders.Add("Accept-Charset", "utf-8"); httpClient.DefaultRequestHeaders.Add("User-Agent", "Squidex Headless CMS"); - string id; - - HttpResponseMessage response = null; + string path; - var meRequest = BuildMeRequest(job); - try + if (!string.IsNullOrWhiteSpace(job.PublicationId)) { - response = await httpClient.SendAsync(meRequest); - - var responseString = await response.Content.ReadAsStringAsync(); - var responseJson = JToken.Parse(responseString); - - id = responseJson["data"]["id"].ToString(); + path = $"v1/publications/{job.PublicationId}/posts"; } - catch (Exception ex) + else { - var requestDump = DumpFormatter.BuildDump(meRequest, response, ex.ToString()); + HttpResponseMessage response = null; - return (requestDump, ex); + var meRequest = BuildMeRequest(job); + try + { + response = await httpClient.SendAsync(meRequest); + + var responseString = await response.Content.ReadAsStringAsync(); + var responseJson = JToken.Parse(responseString); + + var id = responseJson["data"]["id"].ToString(); + + path = $"v1/users/{id}/posts"; + } + catch (Exception ex) + { + var requestDump = DumpFormatter.BuildDump(meRequest, response, ex.ToString()); + + return (requestDump, ex); + } } - return await httpClient.OneWayRequestAsync(BuildPostRequest(job, id), job.RequestBody); + return await httpClient.OneWayRequestAsync(BuildPostRequest(job, path), job.RequestBody); } } - private static HttpRequestMessage BuildPostRequest(MediumJob job, string id) + private static HttpRequestMessage BuildPostRequest(MediumJob job, string path) { - var request = new HttpRequestMessage(HttpMethod.Post, $"https://api.medium.com/v1/users/{id}/posts") + var request = new HttpRequestMessage(HttpMethod.Post, $"https://api.medium.com/{path}") { Content = new StringContent(job.RequestBody, Encoding.UTF8, "application/json") }; @@ -126,6 +140,8 @@ namespace Squidex.Extensions.Actions.Medium { public string RequestBody { get; set; } + public string PublicationId { get; set; } + public string AccessToken { get; set; } } } diff --git a/src/Squidex/app/features/rules/pages/rules/actions/medium-action.component.html b/src/Squidex/app/features/rules/pages/rules/actions/medium-action.component.html index a8424bd7c..4f5bc655f 100644 --- a/src/Squidex/app/features/rules/pages/rules/actions/medium-action.component.html +++ b/src/Squidex/app/features/rules/pages/rules/actions/medium-action.component.html @@ -75,7 +75,21 @@ - Comma-separated list of tags. + Optional comma-separated list of tags. + + + + +
+ + +
+ + + + + + Optional publication id. Go to https://medium.com/[PUBLICATION]?format=json to fetch the id.
diff --git a/src/Squidex/app/features/rules/pages/rules/actions/medium-action.component.ts b/src/Squidex/app/features/rules/pages/rules/actions/medium-action.component.ts index a29f274df..a14f0841c 100644 --- a/src/Squidex/app/features/rules/pages/rules/actions/medium-action.component.ts +++ b/src/Squidex/app/features/rules/pages/rules/actions/medium-action.component.ts @@ -45,6 +45,9 @@ export class MediumActionComponent implements OnInit { this.actionForm.setControl('tags', new FormControl(this.action.tags || '')); + this.actionForm.setControl('publicationId', + new FormControl(this.action.publicationId || '')); + this.actionForm.setControl('isHtml', new FormControl(this.action.isHtml || false)); }