Browse Source

Publication id for squidex.

pull/334/head
Sebastian Stehle 8 years ago
parent
commit
294a588384
  1. 3
      extensions/Squidex.Extensions/Actions/Medium/MediumAction.cs
  2. 52
      extensions/Squidex.Extensions/Actions/Medium/MediumActionHandler.cs
  3. 16
      src/Squidex/app/features/rules/pages/rules/actions/medium-action.component.html
  4. 3
      src/Squidex/app/features/rules/pages/rules/actions/medium-action.component.ts

3
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.")] [Display(Name = "Canonical Url", Description = "The original home of this content, if it was originally published elsewhere.")]
public string CanonicalUrl { get; set; } 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.")] [Display(Name = "Tags", Description = "The optional comma separated list of tags.")]
public string Tags { get; set; } public string Tags { get; set; }

52
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("canonicalUrl", Format(action.CanonicalUrl, @event)),
new JProperty("tags", ParseTags(@event, action))); 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); return (Description, ruleJob);
} }
@ -75,34 +80,43 @@ namespace Squidex.Extensions.Actions.Medium
httpClient.DefaultRequestHeaders.Add("Accept-Charset", "utf-8"); httpClient.DefaultRequestHeaders.Add("Accept-Charset", "utf-8");
httpClient.DefaultRequestHeaders.Add("User-Agent", "Squidex Headless CMS"); httpClient.DefaultRequestHeaders.Add("User-Agent", "Squidex Headless CMS");
string id; string path;
HttpResponseMessage response = null;
var meRequest = BuildMeRequest(job); if (!string.IsNullOrWhiteSpace(job.PublicationId))
try
{ {
response = await httpClient.SendAsync(meRequest); path = $"v1/publications/{job.PublicationId}/posts";
var responseString = await response.Content.ReadAsStringAsync();
var responseJson = JToken.Parse(responseString);
id = responseJson["data"]["id"].ToString();
} }
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") 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 RequestBody { get; set; }
public string PublicationId { get; set; }
public string AccessToken { get; set; } public string AccessToken { get; set; }
} }
} }

16
src/Squidex/app/features/rules/pages/rules/actions/medium-action.component.html

@ -75,7 +75,21 @@
<input type="text" class="form-control" id="tags" formControlName="tags" /> <input type="text" class="form-control" id="tags" formControlName="tags" />
<small class="form-text text-muted"> <small class="form-text text-muted">
Comma-separated list of tags. Optional comma-separated list of tags.
</small>
</div>
</div>
<div class="form-group row">
<label class="col col-3 col-form-label" for="publicationId">Publication</label>
<div class="col col-9">
<sqx-control-errors for="publicationId" [submitted]="actionFormSubmitted"></sqx-control-errors>
<input type="text" class="form-control" id="publicationId" formControlName="publicationId" />
<small class="form-text text-muted">
Optional publication id. Go to <a href="https://medium.com/[PUBLICATION]>?format=json" target="_blank" rel="noopener">https://medium.com/[PUBLICATION]?format=json</a> to fetch the id.
</small> </small>
</div> </div>
</div> </div>

3
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', this.actionForm.setControl('tags',
new FormControl(this.action.tags || '')); new FormControl(this.action.tags || ''));
this.actionForm.setControl('publicationId',
new FormControl(this.action.publicationId || ''));
this.actionForm.setControl('isHtml', this.actionForm.setControl('isHtml',
new FormControl(this.action.isHtml || false)); new FormControl(this.action.isHtml || false));
} }

Loading…
Cancel
Save