readwise 0.1.0 → 0.3.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: 60dff970e4d8c8989265de5ff247010545019f0ca9f9f93f027726de8dda5755
4
- data.tar.gz: 5c4ad097f466e5adf35424dc07f51d45865ea325d3fa455f17c8d0d2290fa6e7
3
+ metadata.gz: 3430c0062c1b93b7f57032195dd68953f5747fe221104c3f9d27edac52bc6fa2
4
+ data.tar.gz: 9436565954a21d0b34b8ae7896ded212801daf05512d1fb512207272547792c9
5
5
  SHA512:
6
- metadata.gz: 63f00184411add2fb4403ebf67cf1fcc89a677ec84826524a92be7fce52d46bf53d2a654db17d9f04e1a89eb15ac938e7ff6ebb861e0c2931ca1d65c1803f247
7
- data.tar.gz: 301c9c0f4bf4a810bf62a2f1a2f116f56969535c71c7b4811192be20db1c9bdba71d74962252930f6d2e85b77bcffb1e29610f311fbffd03f07f6913fcb54514
6
+ metadata.gz: e9d2cf349ca75d6b9a21dcf60c2c8ea2af9ddff6e3aace2ecb82c748b9a1845204e1ac7c9d72c23e5a6c4dbcd9bf682c455162d72ac56b62fb5348d32f958b6f
7
+ data.tar.gz: 4fdcdc6cca2bb5a7881ee8beceb1c3096f348776839fed87c330d8bb91abd004d1ab75bff9cd9e9ce5d23b0d57c3f1ed55b34738ae9888c3fd42e72c94447dd2
@@ -0,0 +1,3 @@
1
+ # These are supported funding model platforms
2
+
3
+ github: andjosh
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.3.0] - 2023-02-28
6
+
7
+ - Change `Tag` from hash to struct ([#6](https://github.com/andjosh/readwise-ruby/pull/6) from [@ajistrying](https://github.com/ajistrying))
8
+
9
+ ## [0.2.0] - 2023-02-20
10
+
11
+ - Add support for `Book.note` ([#4](https://github.com/andjosh/readwise-ruby/pull/4))
12
+
5
13
  ## [0.1.0] - 2023-01-16
6
14
 
7
15
  - Initial release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- readwise (0.1.0)
4
+ readwise (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -17,6 +17,8 @@ GEM
17
17
  rspec-expectations (3.12.2)
18
18
  diff-lcs (>= 1.2.0, < 2.0)
19
19
  rspec-support (~> 3.12.0)
20
+ rspec-file_fixtures (0.1.6)
21
+ rspec (~> 3.0)
20
22
  rspec-mocks (3.12.2)
21
23
  diff-lcs (>= 1.2.0, < 2.0)
22
24
  rspec-support (~> 3.12.0)
@@ -26,10 +28,11 @@ PLATFORMS
26
28
  ruby
27
29
 
28
30
  DEPENDENCIES
29
- bundler (~> 1.17)
31
+ bundler (~> 2.4.4)
30
32
  rake (~> 10.0)
31
33
  readwise!
32
34
  rspec (~> 3.0)
35
+ rspec-file_fixtures (~> 0.1.6)
33
36
 
34
37
  BUNDLED WITH
35
- 1.17.2
38
+ 2.4.4
data/README.md CHANGED
@@ -28,7 +28,7 @@ First, obtain an API access token from https://readwise.io/access_token.
28
28
  client = Readwise::Client.new(token: token)
29
29
 
30
30
  books = client.export # export all highlights
31
- books = client.export(updated_after: '2023-01-01') # export recent highlights
31
+ books = client.export(updated_after: '2023-01-17T22:02:48Z') # export recent highlights
32
32
  books = client.export(book_ids: ['123']) # export specific highlights
33
33
 
34
34
  puts books.first.title # books are Readwise::Book structs
@@ -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/book.rb CHANGED
@@ -9,6 +9,7 @@ module Readwise
9
9
  :category,
10
10
  :cover_image_url,
11
11
  :highlights,
12
+ :note,
12
13
  :readable_title,
13
14
  :readwise_url,
14
15
  :source,
@@ -1,7 +1,8 @@
1
1
  require 'json'
2
2
  require 'net/http'
3
- require_relative 'book.rb'
4
- require_relative 'highlight.rb'
3
+ require_relative 'book'
4
+ require_relative 'highlight'
5
+ require_relative 'tag'
5
6
 
6
7
  module Readwise
7
8
  class Client
@@ -35,20 +36,7 @@ module Readwise
35
36
  private
36
37
 
37
38
  def export_page(page_cursor: nil, updated_after: nil, book_ids: [])
38
- params = {}
39
- params['updatedAfter'] = updated_after if updated_after
40
- params['ids'] = book_ids if book_ids.any?
41
- params['pageCursor'] = page_cursor if page_cursor
42
- url = 'https://readwise.io/api/v2/export/?' + URI.encode_www_form(params)
43
- export_uri = URI.parse(url)
44
- export_req = Net::HTTP::Get.new(export_uri)
45
- export_req['Authorization'] = "Token #{@token}"
46
- export_res = Net::HTTP.start(export_uri.hostname, export_uri.port, use_ssl: true) do |http|
47
- http.request(export_req)
48
- end
49
- raise Error, 'Export request failed' unless export_res.is_a?(Net::HTTPSuccess)
50
-
51
- parsed_body = JSON.parse(export_res.body)
39
+ parsed_body = get_export_page(page_cursor: page_cursor, updated_after: updated_after, book_ids: book_ids)
52
40
  results = parsed_body.dig('results').map do |item|
53
41
  Book.new(
54
42
  asin: item['asin'],
@@ -56,11 +44,17 @@ module Readwise
56
44
  book_id: item['user_book_id'].to_s,
57
45
  category: item['category'],
58
46
  cover_image_url: item['cover_image_url'],
47
+ note: item['document_note'],
59
48
  readable_title: item['readable_title'],
60
49
  readwise_url: item['readwise_url'],
61
50
  source: item['source'],
62
51
  source_url: item['source_url'],
63
- tags: item['book_tags'],
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,
64
58
  title: item['title'],
65
59
  unique_url: item['unique_url'],
66
60
  highlights: item['highlights'].map do |highlight|
@@ -78,7 +72,12 @@ module Readwise
78
72
  location_type: highlight['location_type'],
79
73
  note: highlight['note'],
80
74
  readwise_url: highlight['readwise_url'],
81
- tags: highlight['tags'],
75
+ tags: highlight['tags'].map do |tag|
76
+ Tag.new(
77
+ tag_id: tag['id'].to_s,
78
+ name: tag['name']
79
+ )
80
+ end,
82
81
  text: highlight['text'],
83
82
  updated_at: highlight['updated_at'],
84
83
  url: highlight['url'],
@@ -91,5 +90,22 @@ module Readwise
91
90
  next_page_cursor: parsed_body.dig('nextPageCursor')
92
91
  }
93
92
  end
93
+
94
+ def get_export_page(page_cursor: nil, updated_after: nil, book_ids: [])
95
+ params = {}
96
+ params['updatedAfter'] = updated_after if updated_after
97
+ params['ids'] = book_ids if book_ids.any?
98
+ 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)
107
+
108
+ JSON.parse(export_res.body)
109
+ end
94
110
  end
95
111
  end
@@ -0,0 +1,8 @@
1
+ module Readwise
2
+ Tag = Struct.new(
3
+ 'ReadwiseTag',
4
+ :tag_id,
5
+ :name,
6
+ keyword_init: true
7
+ )
8
+ end
@@ -1,3 +1,3 @@
1
1
  module Readwise
2
- VERSION = "0.1.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/readwise.gemspec CHANGED
@@ -36,7 +36,8 @@ 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", "~> 1.17"
39
+ spec.add_development_dependency "bundler", "~> 2.4.4"
40
40
  spec.add_development_dependency "rake", "~> 10.0"
41
41
  spec.add_development_dependency "rspec", "~> 3.0"
42
+ spec.add_development_dependency "rspec-file_fixtures", "~> 0.1.6"
42
43
  end
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.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Beckman
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-01-16 00:00:00.000000000 Z
11
+ date: 2023-02-28 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: '1.17'
19
+ version: 2.4.4
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: '1.17'
26
+ version: 2.4.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-file_fixtures
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.1.6
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.1.6
55
69
  description: Minimal Readwise API client and highlight parsing library
56
70
  email:
57
71
  - josh@joshbeckman.org
@@ -59,6 +73,7 @@ executables: []
59
73
  extensions: []
60
74
  extra_rdoc_files: []
61
75
  files:
76
+ - ".github/FUNDING.yml"
62
77
  - ".gitignore"
63
78
  - CHANGELOG.md
64
79
  - CODE_OF_CONDUCT.md
@@ -73,6 +88,7 @@ files:
73
88
  - lib/readwise/book.rb
74
89
  - lib/readwise/client.rb
75
90
  - lib/readwise/highlight.rb
91
+ - lib/readwise/tag.rb
76
92
  - lib/readwise/version.rb
77
93
  - readwise.gemspec
78
94
  homepage: https://github.com/andjosh/readwise-ruby
@@ -83,7 +99,7 @@ metadata:
83
99
  homepage_uri: https://github.com/andjosh/readwise-ruby
84
100
  source_code_uri: https://github.com/andjosh/readwise-ruby
85
101
  changelog_uri: https://github.com/andjosh/readwise-ruby/blob/main/CHANGELOG.md
86
- post_install_message:
102
+ post_install_message:
87
103
  rdoc_options: []
88
104
  require_paths:
89
105
  - lib
@@ -98,8 +114,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
114
  - !ruby/object:Gem::Version
99
115
  version: '0'
100
116
  requirements: []
101
- rubygems_version: 3.0.3.1
102
- signing_key:
117
+ rubygems_version: 3.4.7
118
+ signing_key:
103
119
  specification_version: 4
104
120
  summary: Readwise API client
105
121
  test_files: []