readwise 0.2.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +39 -0
- data/.gitignore +1 -1
- data/CHANGELOG.md +8 -0
- data/README.md +1 -1
- data/lib/readwise/client.rb +60 -33
- data/lib/readwise/tag.rb +8 -0
- data/lib/readwise/version.rb +1 -1
- data/readwise.gemspec +1 -1
- metadata +7 -6
- data/Gemfile.lock +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 766eb82d68f06591b6e05211877532619182404c3aa29c24720de5cd1788ad0a
|
4
|
+
data.tar.gz: 70b4affa8b2e46271fb1d690e00328be10e1fcbb5fd6a3d5ae08135947818671
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6b8cda492331d61352a83bc01732fee2d30191419b226327334daf4c00338afe6876bfb5b806318506bc42a5706f826225a2c917dcaf17a0172d9c12cc3cd08
|
7
|
+
data.tar.gz: 7b2e849cc2bff772ebe84c7b93cb0b7bdf9c506c9bce80a79754554590a537717c39882f6b04faa8e43105b5eac20598fd89f1a39002746d8212557a4bdaf42d
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ "main" ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ "main" ]
|
15
|
+
|
16
|
+
permissions:
|
17
|
+
contents: read
|
18
|
+
|
19
|
+
jobs:
|
20
|
+
test:
|
21
|
+
|
22
|
+
runs-on: ubuntu-latest
|
23
|
+
strategy:
|
24
|
+
matrix:
|
25
|
+
ruby-version: ['2.6', '2.7', '3.0', '3.1', '3.2']
|
26
|
+
|
27
|
+
steps:
|
28
|
+
- uses: actions/checkout@v3
|
29
|
+
- name: Set up Ruby
|
30
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
31
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
32
|
+
uses: ruby/setup-ruby@v1
|
33
|
+
with:
|
34
|
+
ruby-version: ${{ matrix.ruby-version }}
|
35
|
+
# bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
36
|
+
- name: Install deps
|
37
|
+
run: bundle install
|
38
|
+
- name: Run tests
|
39
|
+
run: bundle exec rspec
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,14 @@
|
|
2
2
|
|
3
3
|
## [Unreleased]
|
4
4
|
|
5
|
+
## [0.4.0] - 2023-03-19
|
6
|
+
|
7
|
+
- Add `get_highlight` client method ([#10](https://github.com/andjosh/readwise-ruby/pull/10) from [@ajistrying](https://github.com/ajistrying))
|
8
|
+
|
9
|
+
## [0.3.0] - 2023-02-28
|
10
|
+
|
11
|
+
- Change `Tag` from hash to struct ([#6](https://github.com/andjosh/readwise-ruby/pull/6) from [@ajistrying](https://github.com/ajistrying))
|
12
|
+
|
5
13
|
## [0.2.0] - 2023-02-20
|
6
14
|
|
7
15
|
- Add support for `Book.note` ([#4](https://github.com/andjosh/readwise-ruby/pull/4))
|
data/README.md
CHANGED
@@ -37,7 +37,7 @@ puts books.first.highlights.map(&:text) # highlights are Readwise::Highlight str
|
|
37
37
|
|
38
38
|
## Development
|
39
39
|
|
40
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
40
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
41
41
|
|
42
42
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
43
43
|
|
data/lib/readwise/client.rb
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'net/http'
|
3
|
-
require_relative 'book
|
4
|
-
require_relative 'highlight
|
3
|
+
require_relative 'book'
|
4
|
+
require_relative 'highlight'
|
5
|
+
require_relative 'tag'
|
5
6
|
|
6
7
|
module Readwise
|
7
8
|
class Client
|
8
9
|
class Error < StandardError; end
|
9
10
|
|
11
|
+
BASE_URL = "https://readwise.io/api/v2/"
|
12
|
+
|
10
13
|
def initialize(token: nil)
|
11
14
|
raise ArgumentError unless token
|
12
15
|
@token = token.to_s
|
@@ -20,6 +23,14 @@ module Readwise
|
|
20
23
|
raise NotImplementedError
|
21
24
|
end
|
22
25
|
|
26
|
+
def get_highlight(highlight_id:)
|
27
|
+
url = BASE_URL + 'highlights/' + highlight_id
|
28
|
+
|
29
|
+
res = get_readwise_request(url)
|
30
|
+
|
31
|
+
transform_highlight(res)
|
32
|
+
end
|
33
|
+
|
23
34
|
def export(updated_after: nil, book_ids: [])
|
24
35
|
resp = export_page(updated_after: updated_after, book_ids: book_ids)
|
25
36
|
next_page_cursor = resp[:next_page_cursor]
|
@@ -48,30 +59,10 @@ module Readwise
|
|
48
59
|
readwise_url: item['readwise_url'],
|
49
60
|
source: item['source'],
|
50
61
|
source_url: item['source_url'],
|
51
|
-
tags: item['book_tags'],
|
62
|
+
tags: item['book_tags'].map { |tag| transform_tag(tag) },
|
52
63
|
title: item['title'],
|
53
64
|
unique_url: item['unique_url'],
|
54
|
-
highlights: item['highlights'].map
|
55
|
-
Highlight.new(
|
56
|
-
book_id: highlight['book_id'].to_s,
|
57
|
-
color: highlight['color'],
|
58
|
-
created_at: highlight['created_at'],
|
59
|
-
end_location: highlight['end_location'],
|
60
|
-
external_id: highlight['external_id'],
|
61
|
-
highlight_id: highlight['id'].to_s,
|
62
|
-
highlighted_at: highlight['highlighted_at'],
|
63
|
-
is_discard: highlight['is_discard'],
|
64
|
-
is_favorite: highlight['is_favorite'],
|
65
|
-
location: highlight['location'],
|
66
|
-
location_type: highlight['location_type'],
|
67
|
-
note: highlight['note'],
|
68
|
-
readwise_url: highlight['readwise_url'],
|
69
|
-
tags: highlight['tags'],
|
70
|
-
text: highlight['text'],
|
71
|
-
updated_at: highlight['updated_at'],
|
72
|
-
url: highlight['url'],
|
73
|
-
)
|
74
|
-
end
|
65
|
+
highlights: item['highlights'].map { |highlight| transform_highlight(highlight) },
|
75
66
|
)
|
76
67
|
end
|
77
68
|
{
|
@@ -85,16 +76,52 @@ module Readwise
|
|
85
76
|
params['updatedAfter'] = updated_after if updated_after
|
86
77
|
params['ids'] = book_ids if book_ids.any?
|
87
78
|
params['pageCursor'] = page_cursor if page_cursor
|
88
|
-
url = '
|
89
|
-
|
90
|
-
|
91
|
-
export_req['Authorization'] = "Token #{@token}"
|
92
|
-
export_res = Net::HTTP.start(export_uri.hostname, export_uri.port, use_ssl: true) do |http|
|
93
|
-
http.request(export_req)
|
94
|
-
end
|
95
|
-
raise Error, 'Export request failed' unless export_res.is_a?(Net::HTTPSuccess)
|
79
|
+
url = BASE_URL + 'export/?' + URI.encode_www_form(params)
|
80
|
+
|
81
|
+
get_readwise_request(url)
|
96
82
|
|
97
|
-
|
83
|
+
end
|
84
|
+
|
85
|
+
def transform_highlight(res)
|
86
|
+
Highlight.new(
|
87
|
+
book_id: res['book_id'].to_s,
|
88
|
+
color: res['color'],
|
89
|
+
created_at: res['created_at'],
|
90
|
+
end_location: res['end_location'],
|
91
|
+
external_id: res['external_id'],
|
92
|
+
highlight_id: res['id'].to_s,
|
93
|
+
highlighted_at: res['highlighted_at'],
|
94
|
+
is_discard: res['is_discard'],
|
95
|
+
is_favorite: res['is_favorite'],
|
96
|
+
location: res['location'],
|
97
|
+
location_type: res['location_type'],
|
98
|
+
note: res['note'],
|
99
|
+
readwise_url: res['readwise_url'],
|
100
|
+
tags: res['tags'].map { |tag| transform_tag(tag) },
|
101
|
+
text: res['text'],
|
102
|
+
updated_at: res['updated_at'],
|
103
|
+
url: res['url'],
|
104
|
+
)
|
105
|
+
end
|
106
|
+
|
107
|
+
def transform_tag(res)
|
108
|
+
Tag.new(
|
109
|
+
tag_id: res['id'].to_s,
|
110
|
+
name: res['name'],
|
111
|
+
)
|
112
|
+
end
|
113
|
+
|
114
|
+
def get_readwise_request(url)
|
115
|
+
uri = URI.parse(url)
|
116
|
+
req = Net::HTTP::Get.new(uri)
|
117
|
+
req['Authorization'] = "Token #{@token}"
|
118
|
+
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
119
|
+
http.request(req)
|
120
|
+
end
|
121
|
+
|
122
|
+
raise Error, 'Export request failed' unless res.is_a?(Net::HTTPSuccess)
|
123
|
+
|
124
|
+
JSON.parse(res.body)
|
98
125
|
end
|
99
126
|
end
|
100
127
|
end
|
data/lib/readwise/tag.rb
ADDED
data/lib/readwise/version.rb
CHANGED
data/readwise.gemspec
CHANGED
@@ -36,7 +36,7 @@ Gem::Specification.new do |spec|
|
|
36
36
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
37
37
|
spec.require_paths = ["lib"]
|
38
38
|
|
39
|
-
spec.add_development_dependency "bundler", "~> 2.
|
39
|
+
spec.add_development_dependency "bundler", "~> 2.2"
|
40
40
|
spec.add_development_dependency "rake", "~> 10.0"
|
41
41
|
spec.add_development_dependency "rspec", "~> 3.0"
|
42
42
|
spec.add_development_dependency "rspec-file_fixtures", "~> 0.1.6"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: readwise
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Beckman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.
|
19
|
+
version: '2.2'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.
|
26
|
+
version: '2.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -74,11 +74,11 @@ extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
76
|
- ".github/FUNDING.yml"
|
77
|
+
- ".github/workflows/ruby.yml"
|
77
78
|
- ".gitignore"
|
78
79
|
- CHANGELOG.md
|
79
80
|
- CODE_OF_CONDUCT.md
|
80
81
|
- Gemfile
|
81
|
-
- Gemfile.lock
|
82
82
|
- LICENSE.txt
|
83
83
|
- README.md
|
84
84
|
- Rakefile
|
@@ -88,6 +88,7 @@ files:
|
|
88
88
|
- lib/readwise/book.rb
|
89
89
|
- lib/readwise/client.rb
|
90
90
|
- lib/readwise/highlight.rb
|
91
|
+
- lib/readwise/tag.rb
|
91
92
|
- lib/readwise/version.rb
|
92
93
|
- readwise.gemspec
|
93
94
|
homepage: https://github.com/andjosh/readwise-ruby
|
@@ -113,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
114
|
- !ruby/object:Gem::Version
|
114
115
|
version: '0'
|
115
116
|
requirements: []
|
116
|
-
rubygems_version: 3.4.
|
117
|
+
rubygems_version: 3.4.7
|
117
118
|
signing_key:
|
118
119
|
specification_version: 4
|
119
120
|
summary: Readwise API client
|
data/Gemfile.lock
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
readwise (0.2.0)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
diff-lcs (1.5.0)
|
10
|
-
rake (10.5.0)
|
11
|
-
rspec (3.12.0)
|
12
|
-
rspec-core (~> 3.12.0)
|
13
|
-
rspec-expectations (~> 3.12.0)
|
14
|
-
rspec-mocks (~> 3.12.0)
|
15
|
-
rspec-core (3.12.0)
|
16
|
-
rspec-support (~> 3.12.0)
|
17
|
-
rspec-expectations (3.12.2)
|
18
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
-
rspec-support (~> 3.12.0)
|
20
|
-
rspec-file_fixtures (0.1.6)
|
21
|
-
rspec (~> 3.0)
|
22
|
-
rspec-mocks (3.12.2)
|
23
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
-
rspec-support (~> 3.12.0)
|
25
|
-
rspec-support (3.12.0)
|
26
|
-
|
27
|
-
PLATFORMS
|
28
|
-
ruby
|
29
|
-
|
30
|
-
DEPENDENCIES
|
31
|
-
bundler (~> 2.4.4)
|
32
|
-
rake (~> 10.0)
|
33
|
-
readwise!
|
34
|
-
rspec (~> 3.0)
|
35
|
-
rspec-file_fixtures (~> 0.1.6)
|
36
|
-
|
37
|
-
BUNDLED WITH
|
38
|
-
2.4.4
|