joplin 0.2.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/Gemfile.lock +4 -2
- data/Makefile +7 -1
- data/README.md +12 -2
- data/bin/joplin +48 -14
- data/joplin.gemspec +3 -3
- data/lib/joplin/version.rb +1 -1
- data/lib/joplin.rb +14 -2
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7dfac990f629dd9162bf5847a84987b5a41d08ca60d6cd2c4f262d1e47437bfe
|
4
|
+
data.tar.gz: c41235cfdeb50f936ce00b366cb46a471c5f17fe226c3220af0b3106ab529e72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6df0a09a49f852756a0d43da46f128b81c3e985c046076dac2bebbdb1fb96c7e4f6ab0b5b9e9a1a88917656619ed28b90f0b45b67366902df2b06555a48d4c2d
|
7
|
+
data.tar.gz: 6fddaddffd9017529b7230c2e1d96760cbedb02d8cccb0a9079ba5f2e5795c89b745d8bb5e55de07b2dd621f278d4d2cad8efab72475416ab869061ac1d3b4cf
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
joplin (0.
|
4
|
+
joplin (0.5.0)
|
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.
|
44
|
+
1.17.3
|
data/Makefile
CHANGED
data/README.md
CHANGED
@@ -22,9 +22,19 @@ updating a note
|
|
22
22
|
note = Joplin::Notes.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
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
50
|
-
<style> .line { stroke-width: 1px; fill: black; stroke: black; } </style>
|
51
|
-
<g id="triangle"><path d="M0 30 L200 25 Q 220 25 200 40 Z" class="line" /></g>
|
52
|
-
<use xlink:href="#triangle" transform="scale(-1 1) translate(-450 0)"/>
|
53
|
-
<circle cx="225" cy="32" r="8" 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
|
-
|
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."
|
data/lib/joplin/version.rb
CHANGED
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
|
-
|
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.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Bretoi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
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.
|
128
|
+
rubygems_version: 3.0.9
|
129
129
|
signing_key:
|
130
130
|
specification_version: 4
|
131
131
|
summary: joplin API
|