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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3430c0062c1b93b7f57032195dd68953f5747fe221104c3f9d27edac52bc6fa2
4
- data.tar.gz: 9436565954a21d0b34b8ae7896ded212801daf05512d1fb512207272547792c9
3
+ metadata.gz: 766eb82d68f06591b6e05211877532619182404c3aa29c24720de5cd1788ad0a
4
+ data.tar.gz: 70b4affa8b2e46271fb1d690e00328be10e1fcbb5fd6a3d5ae08135947818671
5
5
  SHA512:
6
- metadata.gz: e9d2cf349ca75d6b9a21dcf60c2c8ea2af9ddff6e3aace2ecb82c748b9a1845204e1ac7c9d72c23e5a6c4dbcd9bf682c455162d72ac56b62fb5348d32f958b6f
7
- data.tar.gz: 4fdcdc6cca2bb5a7881ee8beceb1c3096f348776839fed87c330d8bb91abd004d1ab75bff9cd9e9ce5d23b0d57c3f1ed55b34738ae9888c3fd42e72c94447dd2
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
@@ -46,7 +46,7 @@ build-iPhoneSimulator/
46
46
 
47
47
  # for a library or gem, you might want to ignore these files since the code is
48
48
  # intended to run in multiple environments; otherwise, check them in:
49
- # Gemfile.lock
49
+ Gemfile.lock
50
50
  # .ruby-version
51
51
  # .ruby-gemset
52
52
 
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))
@@ -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 do |tag|
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 do |highlight|
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 = 'https://readwise.io/api/v2/export/?' + URI.encode_www_form(params)
100
- export_uri = URI.parse(url)
101
- export_req = Net::HTTP::Get.new(export_uri)
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
- JSON.parse(export_res.body)
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
@@ -1,3 +1,3 @@
1
1
  module Readwise
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
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.4.4"
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.3.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-02-28 00:00:00.000000000 Z
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.4.4
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.4.4
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