Skip to content

Commit

Permalink
Add review command
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurenceWarne committed Feb 18, 2024
1 parent 7da6fd1 commit 47ab84e
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
emacs_version:
- 27.2
- 28.2
- 29.1
- 29.2

steps:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ You can install it from melpa:
:demand t
;; The main entry point for finito commands
:bind ("C-c b" . finito)
;; Optional, but can improve the aesthetics of book descriptions
:hook (finito-view-mode . visual-line-mode)
:config
;; Downloads the server asynchronously, you can also download the server
;; jar manually from the releases page:
Expand Down
23 changes: 23 additions & 0 deletions finito-graphql.el
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,29 @@
}
}")

(defconst finito--review-book-mutation
(graphql-mutation
(:arguments
(($review . String!)
($book . BookInput!))
(addBookReview
:arguments ((review . ($ review))
(book . ($ book)))
title authors description isbn thumbnailUri
review startedReading lastRead))))

(defconst finito--review-book-mutation-variables
"{
\"review\": \"%s\",
\"book\": {
\"title\": \"%s\",
\"authors\": %s,
\"description\": \"%s\",
\"isbn\": \"%s\",
\"thumbnailUri\": \"%s\"
}
}")

(defconst finito--start-reading-mutation
(graphql-mutation
(:arguments
Expand Down
17 changes: 17 additions & 0 deletions finito-request.el
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,23 @@ BOOK should be the book (as an alist) to rate and RATING the rating."
(s-replace "\"" "'" .isbn)
(s-replace "\"" "'" .img-uri))))))

(defun finito--review-book-request-plist (book review)
"Return a plist with headers and body for an add review request.
BOOK should be the book (as an alist) to review and REVIEW the rating strin."
`(:headers ,finito--headers
:data ,(format "{\"query\":\"%s\", \"variables\": %s}"
finito--review-book-mutation
(let-alist book
(format
finito--review-book-mutation-variables
review
(s-replace "\"" "'" .title)
(finito--seq-to-json-list .authors)
(s-replace "\"" "'" .description)
(s-replace "\"" "'" .isbn)
(s-replace "\"" "'" .img-uri))))))

(defun finito--start-reading-request-plist (book &optional start-date)
"Return a plist with headers and body for a start reading request.
Expand Down
12 changes: 12 additions & 0 deletions finito.el
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,18 @@ maximum of MAX-RESULTS results."
(alist-get 'title book)
rating)))))

(defun finito-review-book-at-point ()
"Add a review for the book at point.
Note this overwrites any existing review."
(interactive)
(finito--wait-for-server-then
(let ((book (finito--book-at-point))
(review (read-string "Review: ")))
(finito--replace-book-at-point-from-request
(finito--review-book-request-plist book review)
(format "Added review for '%s'" (alist-get 'title book))))))

(defun finito-start-book-at-point (&optional date)
"Mark the book at point as currently reading.
Expand Down

0 comments on commit 47ab84e

Please sign in to comment.