Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log entry functionality #254

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ Contributors
------------

* Chris Pruitt, advice and feedback
* Marcus Rönnbäck
2 changes: 2 additions & 0 deletions PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ Use these subsections to denote what chages are made. Delete any sections that a
### Security

- in case of vulnerabilities.


54 changes: 53 additions & 1 deletion letterboxd/letterboxd.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
from .services.member import Member
from .services.search import Search
from .services.list import Lists
from .services.log_entry import LogEntry
from .services.comment import Comment


# TODO: Write these modules
# from .services.comment import Comment
# from .services.log_entry import LogEntry

# from .services.news import News


Expand Down Expand Up @@ -175,3 +177,53 @@ def create_list(self, list_creation_request):
list_creation_request=list_creation_request
)
return list_create_response

def entries(self, log_entry_request):
"""
:param log_entry_request: dict - LogEntriesRequest
:return: services.log_entry.LogEntry object
"""
log_entry = LogEntry(log_entry_request=log_entry_request, api=self.api)
return log_entry

def entry(self, entry_id):
"""
:param entry_id: string - id

:return: services.log_entry.LogEntry object
"""
log_entry = LogEntry(entry_id=entry_id, api=self.api)
return log_entry

def update_entry(self, entry_id, log_entry_request):
"""
:param entry_id: string - id
:param log_entry_request: dict - request

:return: services.log_entry.LogEntry object
"""
log_entry = LogEntry(
entry_id=entry_id, log_entry_request=log_entry_request, api=self.api
)
return log_entry

def update_comment(self, comment_id, comment_request):
"""
:param comment_id: string - id
:param comment_request: dict - request

:return: services.comment.Comment object
"""
comment = Comment(
comment_id=comment_id, comment_request=comment_request, api=self.api
)
return comment

def delete_comment(self, comment_id):
"""
:param comment_id: string - id

:return: services.comment.Comment object
"""
comment = Comment(comment_id=comment_id, api=self.api)
return comment
88 changes: 88 additions & 0 deletions letterboxd/services/comment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import logging

logging.getLogger(__name__)


class Comment(object):
"""
/comment for the Letterboxd API
"""

def __init__(self, api, comment_id=None, comment_request=None):
self._api = api
self._comment_id = comment_id
self._comment_request = comment_request

def update(self, comment_id=None, comment_update_request=None):
"""
[PATCH]/comment/{id}

Update the message portion of a comment.
Calls to this endpoint must include the access token for an authenticated member.
Comments may only be edited by their owner.

:param comment_id: string - id
:param comment_update_request: dict - CommentUpdateRequest

:return: comment_update_response - dict - CommentUpdateResponse
"""
if comment_id is None:
comment_id = self._comment_id
if comment_update_request is None:
comment_update_request = self._comment_request
response = self._api.api_call(
path=f"comment/{comment_id}", method="PATCH", params=comment_update_request,
)
comment_update_response = response.json()
return comment_update_response

def delete(self, comment_id=None):
"""
[DELETE]/comment/{id}

Delete a comment.
Calls to this endpoint must include the access token for an authenticated member.
Comments may be deleted by their owner, or by the owner of the thread to which they are posted.

:param comment_id: string - id

:return: bool - Success
"""
if comment_id is None:
comment_id = self._comment_id
response = self._api.api_call(
path=f"comment/{comment_id}", method="DELETE", params={}
)
if response.status_code == 204:
# 204: Success
return True
else:
return False

def report(self, comment_id=None, report_comment_request=None):
"""
[PATCH]/comment/{id}

Update the message portion of a comment.
Calls to this endpoint must include the access token for an authenticated member.
Comments may only be edited by their owner.

:param comment_id: string - id
:param report_comment_request: dict - ReportCommentRequest

:return: comment_update_response - dict - CommentUpdateResponse
"""
if comment_id is None:
comment_id = self._comment_id
if report_comment_request is None:
report_comment_request = self._comment_request
response = self._api.api_call(
path=f"comment/{comment_id}/report",
method="PATCH",
params=report_comment_request,
)
if response.status_code == 204:
# 204: Success
return True
else:
return False
Loading