joplin 0.2.2 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a548230abdb46652ed58a42e17cf54ae2d6588469c048195885d103da825529
4
- data.tar.gz: b91fa6b4827d935cc1bd0733f77612f00912b9b447b2a920df9a38bb511ba90a
3
+ metadata.gz: 9b1a0e93bcfc54d72099552315b11447f4b5148d47813d2fd71b246e345b8575
4
+ data.tar.gz: d89280141c723a08d54f8719c87cda2f5e7f5df23d92d0ccad081c6e6df26d29
5
5
  SHA512:
6
- metadata.gz: 798618899c8e96cab2d8baaba45bad5c6e67bb72ca502564e5f1b385740fda0df2921a6627c19e4d2ceffa6e6c5c205c41bee8053379472f1929bbe36bca763e
7
- data.tar.gz: ea96a14efefb18c14d468722eee148f1ae75dc62af31a8eabb548e6d8f0fe1ac7e67927f9dff85336cb6650873621120b8cf36169d884200b16b7a7d493d1ed2
6
+ metadata.gz: ed07f8cdc4f7f3b3fff0cd4b038106f8108bce3be2eff24b6742c1e4b92b8a1b2ca689ba8cef5ef8046bdf2b839cadb146b465597ad2de890fa5ed2b79f8afdc
7
+ data.tar.gz: 9b802ca5813ed504d50157827d5f7c89693ce97229c793d479cd425b5d9db03d8fd4dc937d24464b792d45fcd1de2d91aeaba364e81d1887777ec1fe48b12372
data/Gemfile CHANGED
@@ -8,3 +8,5 @@ gemspec
8
8
  gem "faraday", "~> 1.0"
9
9
 
10
10
  gem "thor", "~> 1.0"
11
+
12
+ gem "sqlite3", "~> 1.4"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- joplin (0.1.3)
4
+ joplin (0.5.1)
5
5
  faraday (~> 1.0)
6
6
 
7
7
  GEM
@@ -25,6 +25,7 @@ GEM
25
25
  diff-lcs (>= 1.2.0, < 2.0)
26
26
  rspec-support (~> 3.9.0)
27
27
  rspec-support (3.9.3)
28
+ sqlite3 (1.4.2)
28
29
  thor (1.0.1)
29
30
 
30
31
  PLATFORMS
@@ -36,7 +37,8 @@ DEPENDENCIES
36
37
  joplin!
37
38
  rake (~> 13.0)
38
39
  rspec (~> 3.0)
40
+ sqlite3 (~> 1.4)
39
41
  thor (~> 1.0)
40
42
 
41
43
  BUNDLED WITH
42
- 1.17.2
44
+ 1.17.3
data/Makefile CHANGED
@@ -5,4 +5,10 @@ push: clean all
5
5
  gem push *gem
6
6
 
7
7
  clean:
8
- rm *gem
8
+ rm -f *gem
9
+
10
+ test:
11
+ rake
12
+
13
+ install: clean all
14
+ gem install --local *gem
data/README.md CHANGED
@@ -8,7 +8,7 @@ Creating a note
8
8
  Joplin::token = "your joplintoken here copied from the webclippper settings"
9
9
 
10
10
  begin
11
- note = Joplin::Notes.new
11
+ note = Joplin::Note.new
12
12
  note.title = "a new note"
13
13
  note.body = "markdown content"
14
14
  note.save!
@@ -19,12 +19,22 @@ end
19
19
 
20
20
  updating a note
21
21
  ```ruby
22
- note = Joplin::Notes.new "6e3811c7a73148a" # note id can be found in the information of any note
22
+ note = Joplin::Note.new "6e3811c7a73148a" # note id can be found in the information of any note
23
23
  note.title = "a new note title"
24
24
  note.save!
25
- end
26
25
  ```
27
26
 
27
+ ### A note on the token
28
+
29
+ If you've got joplin installed, you can do:
30
+
31
+ ``` ruby
32
+ require "joplin/token"
33
+ token = Joplin::Token.get
34
+ ```
35
+
36
+ to get the token programatically. It reads from the sqlite database located in `~/.config/joplin-desktop`
37
+
28
38
 
29
39
  ## CLI
30
40
 
@@ -32,4 +42,4 @@ end
32
42
 
33
43
  Will take a notebook and concatenate all notes into one for easy export to PDF
34
44
 
35
-
45
+ The token argument is optional and if you have it installed locally it will find the token
data/bin/joplin CHANGED
@@ -4,6 +4,18 @@ $:.unshift File.expand_path("../../lib", __FILE__)
4
4
 
5
5
  require "joplin"
6
6
  require 'thor'
7
+ require "joplin/token"
8
+
9
+ DIVIDER = %Q(
10
+
11
+ <svg height="50" width="460">
12
+ <style> .line { stroke-width: 1px; fill: black; stroke: black; } </style>
13
+ <g id="triangle"><path d="M0 30 L200 30 Q 220 25 200 35 Z" class="line" /></g>
14
+ <use xlink:href="#triangle" transform="scale(-1 1) translate(-450 0)"/>
15
+ <circle cx="225" cy="32" r="7" class="line"/>
16
+ </svg>
17
+
18
+ )
7
19
 
8
20
 
9
21
  class MyCLI < Thor
@@ -12,14 +24,16 @@ class MyCLI < Thor
12
24
  class_option :version, :type => :boolean
13
25
  map ["-v", "--version"] => :version
14
26
  map ["-h", "--help"] => :help
15
- option :token, :required => true
27
+ option :token
16
28
  option :'dry-run', desc: "dry-run", aliases: '-n'
17
29
  desc :clean, "clean unused resources"
18
30
  def clean
19
- Joplin::token = options[:token]
31
+ Joplin::token = options[:token] || Joplin::Token.get
32
+ puts "Please wait, this can take while."
20
33
  Joplin::Resource.orphaned.map { |r|
21
34
  r.delete if not options['dry-run']
22
- puts "Deleted #{r.id}"
35
+ would = "would have " if options['dry-run']
36
+ puts "#{would}deleted #{r.id}"
23
37
  }
24
38
  end
25
39
 
@@ -30,10 +44,11 @@ class MyCLI < Thor
30
44
  end
31
45
 
32
46
  desc :nb2n, "concate all notes in a notebook to one note. Possible PDF export"
33
- option :token, :required => true
47
+ long_desc "The idea is to make a big note from all the notes in a notebook. PDF export or whatever export can happen from that. The notes are concatenated with a separator."
48
+ option :token
34
49
  option :type, :type => :string
35
50
  def nb2n(query)
36
- Joplin::token = options[:token]
51
+ Joplin::token = options[:token] || Joplin::Token.get
37
52
  results = Joplin.search(query, { type: 'folder' })
38
53
  nb = results[0];
39
54
  if not (nb and nb['title'] == query)
@@ -44,21 +59,40 @@ class MyCLI < Thor
44
59
  notes = notebook.notes
45
60
  new_note = Joplin::Note.new
46
61
  new_note.title = query
47
- divider = %Q(
62
+ new_note.body = notes.map { |n| "\# #{n.title}\n\n#{n.body}" }.join(DIVIDER)
63
+ new_note.save!
64
+ puts "Saved: #{new_note.title} with id: #{new_note.id}"
65
+ end
48
66
 
49
- <svg height="50" width="460">
50
- <style> .line { stroke-width: 1px; fill: black; stroke: black; } </style>
51
- <g id="triangle"><path d="M0 30 L200 30 Q 220 25 200 35 Z" class="line" /></g>
52
- <use xlink:href="#triangle" transform="scale(-1 1) translate(-450 0)"/>
53
- <circle cx="225" cy="32" r="7" class="line"/>
54
- </svg>
67
+ desc :build, "build a note from a note containing references"
55
68
 
56
- )
69
+ long_desc %Q(Takes a note and looks up all the referenced notes and makes a new
70
+ note from those. The notes are concatenated with a separator.\n\nIf you have a
71
+ line with 'title: a title' then it will be used for the title of the built
72
+ email.)
57
73
 
58
- new_note.body = notes.map { |n| "\# #{n.title}\n\n#{n.body}" }.join(divider)
74
+ def build(id)
75
+ token
76
+ note = Joplin::Note.new id
77
+ notes = []
78
+ title = nil
79
+ note.body.each_line { |line|
80
+ title = $1 if line =~ /title: (.*)$/
81
+ line =~ /\(:\/([^)]+)\)/
82
+ notes.push Joplin::Note.new $1 if $1
83
+ }
84
+ new_note = Joplin::Note.new
85
+ new_note.title = title || "built: #{note.title}"
86
+ new_note.body = notes.map { |n| "\# #{n.title}\n\n#{n.body}" }.join(DIVIDER)
59
87
  new_note.save!
60
88
  puts "Saved: #{new_note.title} with id: #{new_note.id}"
61
89
  end
90
+
91
+ private
92
+ def token()
93
+ Joplin::token = options[:token] || Joplin::Token.get
94
+ raise "Couldn't find token in local database and it wasn't passed as an option. You better check yourself!" if not Joplin::token
95
+ end
62
96
  end
63
97
 
64
98
  MyCLI.start(ARGV)
data/joplin.gemspec CHANGED
@@ -11,15 +11,15 @@ Gem::Specification.new do |spec|
11
11
 
12
12
  spec.summary = %q{joplin API}
13
13
  spec.description = %q{joplin API}
14
- spec.homepage = "http://github.com/danielb2/joplin"
14
+ spec.homepage = "http://github.com/danielb2/joplin-ruby"
15
15
  spec.license = "MIT"
16
16
 
17
17
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
18
  # to allow pushing to a single host or delete this section to allow pushing to any host.
19
19
  if spec.respond_to?(:metadata)
20
20
  spec.metadata["homepage_uri"] = spec.homepage
21
- spec.metadata["source_code_uri"] = "http://github.com/danielb2/joplin"
22
- spec.metadata["changelog_uri"] = "http://github.com/danielb2/joplin"
21
+ spec.metadata["source_code_uri"] = "http://github.com/danielb2/joplin-ruby"
22
+ spec.metadata["changelog_uri"] = "http://github.com/danielb2/joplin-ruby"
23
23
  else
24
24
  raise "RubyGems 2.0 or newer is required to protect against " \
25
25
  "public gem pushes."
@@ -1,3 +1,3 @@
1
1
  module Joplin
2
- VERSION = "0.2.2"
2
+ VERSION = "0.5.1"
3
3
  end
data/lib/joplin.rb CHANGED
@@ -5,6 +5,7 @@ require "json"
5
5
  module Joplin
6
6
  class Error < StandardError; end
7
7
  attr_accessor :token
8
+ @@token = nil
8
9
 
9
10
  def self.token= token
10
11
  @@token = token
@@ -17,8 +18,17 @@ module Joplin
17
18
  return parsed
18
19
  end
19
20
 
21
+ def self.get_token
22
+ begin
23
+ settings = JSON.parse File.read("#{ENV['HOME']}/.config/joplin-desktop/settings.json")
24
+ return settings['api.token']
25
+ rescue
26
+ return nil
27
+ end
28
+ end
29
+
20
30
  def self.token
21
- @@token
31
+ @@token || get_token
22
32
  end
23
33
 
24
34
  def self.uri= uri
@@ -133,7 +143,9 @@ body: #{self.body}"""
133
143
 
134
144
  private
135
145
  def parse response
136
- return if not response.body
146
+ if response.body.empty?
147
+ raise "No note found with id #{@id}"
148
+ end
137
149
  note = JSON.parse response.body
138
150
  if response.status != 200
139
151
  raise Error.new note["error"]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: joplin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Bretoi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-08 00:00:00.000000000 Z
11
+ date: 2022-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -103,13 +103,13 @@ files:
103
103
  - joplin.gemspec
104
104
  - lib/joplin.rb
105
105
  - lib/joplin/version.rb
106
- homepage: http://github.com/danielb2/joplin
106
+ homepage: http://github.com/danielb2/joplin-ruby
107
107
  licenses:
108
108
  - MIT
109
109
  metadata:
110
- homepage_uri: http://github.com/danielb2/joplin
111
- source_code_uri: http://github.com/danielb2/joplin
112
- changelog_uri: http://github.com/danielb2/joplin
110
+ homepage_uri: http://github.com/danielb2/joplin-ruby
111
+ source_code_uri: http://github.com/danielb2/joplin-ruby
112
+ changelog_uri: http://github.com/danielb2/joplin-ruby
113
113
  post_install_message:
114
114
  rdoc_options: []
115
115
  require_paths:
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  - !ruby/object:Gem::Version
126
126
  version: '0'
127
127
  requirements: []
128
- rubygems_version: 3.0.3
128
+ rubygems_version: 3.0.9
129
129
  signing_key:
130
130
  specification_version: 4
131
131
  summary: joplin API