Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #39 from Sakimori/main
Browse files Browse the repository at this point in the history
Adding share methods to Post and Project objects
  • Loading branch information
valknight authored Aug 14, 2024
2 parents 995d30c + d457b11 commit 4d4c382
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
16 changes: 16 additions & 0 deletions cohost/models/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ def edit(self, headline: str, blocks: list = [], cws: list = [],
adult=adult,
draft=draft
)

def share(self, headline: str, blocks: list = [], cws: list = [],
tags: list = [], adult: bool = False, draft=False):
from cohost.models.project import EditableProject
if not isinstance(self.project, EditableProject):
raise AttributeError("Post isn't attached to an EditableProject -\
do you have Post permissions for this project?")
return self.project.post(
headline=headline,
blocks=blocks,
cws=cws,
tags=tags,
adult=adult,
draft=draft,
shareOfPostId=self.postId
)

@property
def postId(self):
Expand Down
13 changes: 11 additions & 2 deletions cohost/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def projectInfo(self) -> dict[str, Any]:
raise AttributeError("Project not found")

def post(self, headline: str, blocks: list = [], cws: list = [],
tags: list = [], adult: bool = False, draft=False):
tags: list = [], adult: bool = False, draft=False, shareOfPostId: int = None):
# Basic flow: you send a POST to project/{handle}/posts
# This gives us back a post ID, as well as a API link
# For example:
Expand Down Expand Up @@ -209,8 +209,12 @@ def post(self, headline: str, blocks: list = [], cws: list = [],
'adultContent': adult,
'blocks': blockL,
'cws': cws,
'tags': tags
'tags': tags,
}
if shareOfPostId is not None:
postData.update({
'shareOfPostId': shareOfPostId
})
req = fetch(
'postJSON',
'/project/{}/posts'.format(self.handle),
Expand All @@ -237,6 +241,10 @@ def post(self, headline: str, blocks: list = [], cws: list = [],
'cws': cws,
'tags': tags
}
if shareOfPostId is not None:
postData.update({
'shareOfPostId': shareOfPostId
})
req = fetch(
'put',
'/project/{}/posts/{}'.format(self.handle, req['postId']),
Expand Down Expand Up @@ -272,6 +280,7 @@ def editPost(self, postId: int,
'cws': cws,
'tags': tags
}

req = fetch(
'put',
'/project/{}/posts/{}'.format(self.handle, postId),
Expand Down

0 comments on commit 4d4c382

Please sign in to comment.