readwise 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +39 -0
- data/.gitignore +1 -1
- data/CHANGELOG.md +4 -0
- data/lib/readwise/client.rb +57 -41
- data/lib/readwise/version.rb +1 -1
- data/readwise.gemspec +1 -1
- metadata +5 -5
- 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,10 @@
|
|
|
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
|
+
|
|
5
9
|
## [0.3.0] - 2023-02-28
|
|
6
10
|
|
|
7
11
|
- Change `Tag` from hash to struct ([#6](https://github.com/andjosh/readwise-ruby/pull/6) from [@ajistrying](https://github.com/ajistrying))
|
data/lib/readwise/client.rb
CHANGED
|
@@ -8,6 +8,8 @@ module Readwise
|
|
|
8
8
|
class Client
|
|
9
9
|
class Error < StandardError; end
|
|
10
10
|
|
|
11
|
+
BASE_URL = "https://readwise.io/api/v2/"
|
|
12
|
+
|
|
11
13
|
def initialize(token: nil)
|
|
12
14
|
raise ArgumentError unless token
|
|
13
15
|
@token = token.to_s
|
|
@@ -21,6 +23,14 @@ module Readwise
|
|
|
21
23
|
raise NotImplementedError
|
|
22
24
|
end
|
|
23
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
|
+
|
|
24
34
|
def export(updated_after: nil, book_ids: [])
|
|
25
35
|
resp = export_page(updated_after: updated_after, book_ids: book_ids)
|
|
26
36
|
next_page_cursor = resp[:next_page_cursor]
|
|
@@ -49,40 +59,10 @@ module Readwise
|
|
|
49
59
|
readwise_url: item['readwise_url'],
|
|
50
60
|
source: item['source'],
|
|
51
61
|
source_url: item['source_url'],
|
|
52
|
-
tags: item['book_tags'].map
|
|
53
|
-
Tag.new(
|
|
54
|
-
tag_id: tag['id'].to_s,
|
|
55
|
-
name: tag['name']
|
|
56
|
-
)
|
|
57
|
-
end,
|
|
62
|
+
tags: item['book_tags'].map { |tag| transform_tag(tag) },
|
|
58
63
|
title: item['title'],
|
|
59
64
|
unique_url: item['unique_url'],
|
|
60
|
-
highlights: item['highlights'].map
|
|
61
|
-
Highlight.new(
|
|
62
|
-
book_id: highlight['book_id'].to_s,
|
|
63
|
-
color: highlight['color'],
|
|
64
|
-
created_at: highlight['created_at'],
|
|
65
|
-
end_location: highlight['end_location'],
|
|
66
|
-
external_id: highlight['external_id'],
|
|
67
|
-
highlight_id: highlight['id'].to_s,
|
|
68
|
-
highlighted_at: highlight['highlighted_at'],
|
|
69
|
-
is_discard: highlight['is_discard'],
|
|
70
|
-
is_favorite: highlight['is_favorite'],
|
|
71
|
-
location: highlight['location'],
|
|
72
|
-
location_type: highlight['location_type'],
|
|
73
|
-
note: highlight['note'],
|
|
74
|
-
readwise_url: highlight['readwise_url'],
|
|
75
|
-
tags: highlight['tags'].map do |tag|
|
|
76
|
-
Tag.new(
|
|
77
|
-
tag_id: tag['id'].to_s,
|
|
78
|
-
name: tag['name']
|
|
79
|
-
)
|
|
80
|
-
end,
|
|
81
|
-
text: highlight['text'],
|
|
82
|
-
updated_at: highlight['updated_at'],
|
|
83
|
-
url: highlight['url'],
|
|
84
|
-
)
|
|
85
|
-
end
|
|
65
|
+
highlights: item['highlights'].map { |highlight| transform_highlight(highlight) },
|
|
86
66
|
)
|
|
87
67
|
end
|
|
88
68
|
{
|
|
@@ -96,16 +76,52 @@ module Readwise
|
|
|
96
76
|
params['updatedAfter'] = updated_after if updated_after
|
|
97
77
|
params['ids'] = book_ids if book_ids.any?
|
|
98
78
|
params['pageCursor'] = page_cursor if page_cursor
|
|
99
|
-
url = '
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
export_req['Authorization'] = "Token #{@token}"
|
|
103
|
-
export_res = Net::HTTP.start(export_uri.hostname, export_uri.port, use_ssl: true) do |http|
|
|
104
|
-
http.request(export_req)
|
|
105
|
-
end
|
|
106
|
-
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)
|
|
107
82
|
|
|
108
|
-
|
|
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)
|
|
109
125
|
end
|
|
110
126
|
end
|
|
111
127
|
end
|
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
|
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
|