-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
new(usr): Add first pass at Readwise API V3 (support for Reader) #13
base: main
Are you sure you want to change the base?
Changes from 2 commits
1d24c90
1b24080
c774ec4
cb813c4
e48be2c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
require 'time' | ||
|
||
module Readwise | ||
Document = Struct.new( | ||
'ReadwiseDocument', | ||
:author, | ||
:category, # One of: article, email, rss, highlight, note, pdf, epub, tweet or video. | ||
# Default is guessed based on the URL, usually article. | ||
:created_at, | ||
:html, | ||
:id, | ||
:image_url, | ||
:location, # One of: new, later, archive or feed. Default is new. | ||
:notes, | ||
:published_date, | ||
:reading_progress, | ||
:site_name, | ||
:source, | ||
:source_url, | ||
:summary, | ||
:tags, | ||
:title, | ||
:updated_at, | ||
:url, | ||
:word_count, | ||
:parent_id, # both highlights and notes made in Reader are also considered Documents. | ||
# Highlights and notes will have `parent_id` set, which is the Document id | ||
# of the article/book/etc and highlight that they belong to, respectively. | ||
keyword_init: true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. btw if you can choose to only support Ruby 3.2 or newer then it defaults to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤷🏼 It's not that burdensome to keep around. Ruby 3.0 isn't EOL until next year, I think. |
||
) do | ||
def created_at_time | ||
return unless created_at | ||
|
||
Time.parse(created_at) | ||
end | ||
|
||
def updated_at_time | ||
return unless updated_at | ||
|
||
Time.parse(updated_at) | ||
end | ||
|
||
def published_date_time | ||
return unless published_date | ||
|
||
Time.at(published_date/1000) | ||
end | ||
|
||
def read?(threshold: 0.85) | ||
reading_progress >= threshold | ||
end | ||
|
||
def parent? | ||
parent_id.nil? | ||
end | ||
|
||
def child? | ||
!parent? | ||
end | ||
|
||
def in_new? | ||
location == 'new' | ||
end | ||
|
||
def in_later? | ||
location == 'later' | ||
end | ||
|
||
def in_archive? | ||
location == 'archive' | ||
end | ||
|
||
def pdf? | ||
category == 'pdf' | ||
end | ||
|
||
def epub? | ||
category == 'epub' | ||
end | ||
|
||
def tweet? | ||
category == 'tweet' | ||
end | ||
|
||
def video? | ||
category == 'video' | ||
end | ||
|
||
def article? | ||
category == 'article' | ||
end | ||
|
||
def book? | ||
category == 'book' | ||
end | ||
|
||
def email? | ||
category == 'email' | ||
end | ||
|
||
def rss? | ||
category == 'rss' | ||
end | ||
|
||
def highlight? | ||
category == 'highlight' | ||
end | ||
|
||
def note? | ||
category == 'note' | ||
end | ||
|
||
def serialize | ||
to_h | ||
end | ||
end | ||
|
||
DocumentCreate = Struct.new( | ||
'ReadwiseDocumentCreate', | ||
:author, | ||
:category, # One of: article, email, rss, highlight, note, pdf, epub, tweet or video. | ||
# Default is guessed based on the URL, usually article. | ||
:html, | ||
:image_url, | ||
:location, # One of: new, later, archive or feed. Default is new. | ||
:notes, | ||
:published_date, | ||
:saved_using, | ||
:should_clean_html, | ||
:summary, | ||
:tags, | ||
:title, | ||
:url, | ||
keyword_init: true | ||
) do | ||
def serialize | ||
to_h.compact | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
require 'readwise' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warning TODO: Write tests for the new methods |
||
|
||
RSpec.describe Readwise do | ||
it "has a version number" do | ||
expect(Readwise::VERSION).not_to be nil | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Warning
tODO: update the README with examples of these methods and a disclaimer that they are in beta and liable to change.