Skip to content

Commit

Permalink
fix: update PUT body to match forem's API
Browse files Browse the repository at this point in the history
The PUT API for updating an article expects an `article` property
on the body that that `body_markdown` is a part of. This should be
a pretty simple API change along with the interface update.

As a side note, I was not able to get tests running locally,
but I'll adjust accordingly as I need to from the CI  results.

closes #35
  • Loading branch information
jmcdo29 authored and maxime1992 committed Aug 15, 2021
1 parent a43d936 commit 9746d2e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/article.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ export class Article {

public async publishArticle(): Promise<ArticlePublishedStatus> {
const body: ArticleApi = {
body_markdown: this.readArticleOnDisk(),
article: { body_markdown: this.readArticleOnDisk() },
};

let frontMatter: ArticleFrontMatter;

try {
frontMatter = this.extractDataFromFrontMatter(body.body_markdown);
frontMatter = this.extractDataFromFrontMatter(body.article.body_markdown);
} catch {
return Promise.resolve({
articleId: this.articleConfig.id,
Expand All @@ -113,7 +113,7 @@ export class Article {
};
}

if (remoteArticleBodyMarkdown && remoteArticleBodyMarkdown.trim() === body.body_markdown.trim()) {
if (remoteArticleBodyMarkdown && remoteArticleBodyMarkdown.trim() === body.article.body_markdown.trim()) {
return {
articleId: this.articleConfig.id,
updateStatus: UpdateStatus.ALREADY_UP_TO_DATE as UpdateStatus.ALREADY_UP_TO_DATE,
Expand Down
5 changes: 4 additions & 1 deletion src/dev-to-git.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ export interface ArticleConfig extends ArticleConfigFile {
}

// https://dev.to/api#available-json-parameters
// new Dev.to update parameters https://docs.forem.com/api/#operation/updateArticle
export interface ArticleApi {
body_markdown: string;
article: {
body_markdown: string;
};
}

export interface ArticleApiResponse {
Expand Down

0 comments on commit 9746d2e

Please sign in to comment.