joplin 0.1.3 → 0.2.2
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 -1
- data/Makefile +6 -0
- data/README.md +22 -26
- data/bin/joplin +64 -0
- data/joplin.gemspec +3 -2
- data/lib/joplin.rb +89 -1
- data/lib/joplin/version.rb +1 -1
- metadata +23 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a548230abdb46652ed58a42e17cf54ae2d6588469c048195885d103da825529
|
4
|
+
data.tar.gz: b91fa6b4827d935cc1bd0733f77612f00912b9b447b2a920df9a38bb511ba90a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 798618899c8e96cab2d8baaba45bad5c6e67bb72ca502564e5f1b385740fda0df2921a6627c19e4d2ceffa6e6c5c205c41bee8053379472f1929bbe36bca763e
|
7
|
+
data.tar.gz: ea96a14efefb18c14d468722eee148f1ae75dc62af31a8eabb548e6d8f0fe1ac7e67927f9dff85336cb6650873621120b8cf36169d884200b16b7a7d493d1ed2
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
joplin (0.1.
|
4
|
+
joplin (0.1.3)
|
5
|
+
faraday (~> 1.0)
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: https://rubygems.org/
|
@@ -24,6 +25,7 @@ GEM
|
|
24
25
|
diff-lcs (>= 1.2.0, < 2.0)
|
25
26
|
rspec-support (~> 3.9.0)
|
26
27
|
rspec-support (3.9.3)
|
28
|
+
thor (1.0.1)
|
27
29
|
|
28
30
|
PLATFORMS
|
29
31
|
ruby
|
@@ -34,6 +36,7 @@ DEPENDENCIES
|
|
34
36
|
joplin!
|
35
37
|
rake (~> 13.0)
|
36
38
|
rspec (~> 3.0)
|
39
|
+
thor (~> 1.0)
|
37
40
|
|
38
41
|
BUNDLED WITH
|
39
42
|
1.17.2
|
data/Makefile
CHANGED
data/README.md
CHANGED
@@ -1,39 +1,35 @@
|
|
1
1
|
# Joplin
|
2
2
|
|
3
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/joplin`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
## Installation
|
8
|
-
|
9
|
-
Add this line to your application's Gemfile:
|
4
|
+
## usage
|
10
5
|
|
6
|
+
Creating a note
|
11
7
|
```ruby
|
12
|
-
|
8
|
+
Joplin::token = "your joplintoken here copied from the webclippper settings"
|
9
|
+
|
10
|
+
begin
|
11
|
+
note = Joplin::Notes.new
|
12
|
+
note.title = "a new note"
|
13
|
+
note.body = "markdown content"
|
14
|
+
note.save!
|
15
|
+
rescue
|
16
|
+
puts "Joplin not running?"
|
17
|
+
end
|
13
18
|
```
|
14
19
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
## Usage
|
24
|
-
|
25
|
-
TODO: Write usage instructions here
|
26
|
-
|
27
|
-
## Development
|
20
|
+
updating a note
|
21
|
+
```ruby
|
22
|
+
note = Joplin::Notes.new "6e3811c7a73148a" # note id can be found in the information of any note
|
23
|
+
note.title = "a new note title"
|
24
|
+
note.save!
|
25
|
+
end
|
26
|
+
```
|
28
27
|
|
29
|
-
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.
|
30
28
|
|
31
|
-
|
29
|
+
## CLI
|
32
30
|
|
33
|
-
|
31
|
+
### joplin nb2n --token <yourtoken> 'notebook name'
|
34
32
|
|
35
|
-
|
33
|
+
Will take a notebook and concatenate all notes into one for easy export to PDF
|
36
34
|
|
37
|
-
## License
|
38
35
|
|
39
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/bin/joplin
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.expand_path("../../lib", __FILE__)
|
4
|
+
|
5
|
+
require "joplin"
|
6
|
+
require 'thor'
|
7
|
+
|
8
|
+
|
9
|
+
class MyCLI < Thor
|
10
|
+
class_option :token, :type => :string #, required: true
|
11
|
+
class_option :help, :type => :boolean
|
12
|
+
class_option :version, :type => :boolean
|
13
|
+
map ["-v", "--version"] => :version
|
14
|
+
map ["-h", "--help"] => :help
|
15
|
+
option :token, :required => true
|
16
|
+
option :'dry-run', desc: "dry-run", aliases: '-n'
|
17
|
+
desc :clean, "clean unused resources"
|
18
|
+
def clean
|
19
|
+
Joplin::token = options[:token]
|
20
|
+
Joplin::Resource.orphaned.map { |r|
|
21
|
+
r.delete if not options['dry-run']
|
22
|
+
puts "Deleted #{r.id}"
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
method_options :force => :boolean
|
27
|
+
desc "version", "get version of program"
|
28
|
+
def version
|
29
|
+
puts Joplin::VERSION
|
30
|
+
end
|
31
|
+
|
32
|
+
desc :nb2n, "concate all notes in a notebook to one note. Possible PDF export"
|
33
|
+
option :token, :required => true
|
34
|
+
option :type, :type => :string
|
35
|
+
def nb2n(query)
|
36
|
+
Joplin::token = options[:token]
|
37
|
+
results = Joplin.search(query, { type: 'folder' })
|
38
|
+
nb = results[0];
|
39
|
+
if not (nb and nb['title'] == query)
|
40
|
+
abort "notebook #{query} not found"
|
41
|
+
end
|
42
|
+
|
43
|
+
notebook = Joplin::Notebook.new nb['id']
|
44
|
+
notes = notebook.notes
|
45
|
+
new_note = Joplin::Note.new
|
46
|
+
new_note.title = query
|
47
|
+
divider = %Q(
|
48
|
+
|
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>
|
55
|
+
|
56
|
+
)
|
57
|
+
|
58
|
+
new_note.body = notes.map { |n| "\# #{n.title}\n\n#{n.body}" }.join(divider)
|
59
|
+
new_note.save!
|
60
|
+
puts "Saved: #{new_note.title} with id: #{new_note.id}"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
MyCLI.start(ARGV)
|
data/joplin.gemspec
CHANGED
@@ -30,12 +30,13 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
31
31
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
32
32
|
end
|
33
|
-
spec.bindir = "
|
34
|
-
spec.executables = spec.files.grep(%r{^
|
33
|
+
spec.bindir = "bin"
|
34
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }.reject { |f| f =~ /(console|setup)/ }
|
35
35
|
spec.require_paths = ["lib"]
|
36
36
|
|
37
37
|
spec.add_dependency "faraday", "~> 1.0"
|
38
38
|
spec.add_development_dependency "bundler", "~> 1.17"
|
39
39
|
spec.add_development_dependency "rake", "~> 13.0"
|
40
40
|
spec.add_development_dependency "rspec", "~> 3.0"
|
41
|
+
spec.add_development_dependency "thor", "~> 1.0.1"
|
41
42
|
end
|
data/lib/joplin.rb
CHANGED
@@ -10,6 +10,13 @@ module Joplin
|
|
10
10
|
@@token = token
|
11
11
|
end
|
12
12
|
|
13
|
+
def self.search(query, opts = {})
|
14
|
+
url = "#{Joplin::uri}/search/?query=#{query}&token=#{Joplin::token}&type=#{opts[:type]}"
|
15
|
+
res = Faraday.get url
|
16
|
+
parsed = JSON.parse res.body
|
17
|
+
return parsed
|
18
|
+
end
|
19
|
+
|
13
20
|
def self.token
|
14
21
|
@@token
|
15
22
|
end
|
@@ -24,7 +31,50 @@ module Joplin
|
|
24
31
|
|
25
32
|
self.uri = "http://localhost:41184"
|
26
33
|
|
27
|
-
class
|
34
|
+
class Resource
|
35
|
+
attr_reader :id
|
36
|
+
|
37
|
+
def self.all
|
38
|
+
url = "#{Joplin::uri}/resources/?token=#{Joplin::token}&fields=id"
|
39
|
+
res = Faraday.get url
|
40
|
+
parsed = JSON.parse res.body
|
41
|
+
if res.status != 200
|
42
|
+
throw Error.new(parsed['error'])
|
43
|
+
end
|
44
|
+
parsed.map do |resource|
|
45
|
+
Resource.new resource['id']
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def initialize(id=nil)
|
50
|
+
|
51
|
+
raise Error.new("need id") unless id
|
52
|
+
@id = id
|
53
|
+
url = "#{Joplin::uri}/resources/#{id}?token=#{Joplin::token}&fields=mime,filename,id"
|
54
|
+
res = Faraday.get url
|
55
|
+
@parsed = JSON.parse res.body
|
56
|
+
end
|
57
|
+
|
58
|
+
def delete
|
59
|
+
url = "#{Joplin::uri}/resources/#{id}?token=#{Joplin::token}"
|
60
|
+
res = Faraday.delete url
|
61
|
+
res.status == 200
|
62
|
+
end
|
63
|
+
|
64
|
+
def to_s
|
65
|
+
"""id: #{@id},
|
66
|
+
mime: #{@parsed['mime']}
|
67
|
+
filename: #{@parsed['filename']}"""
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.orphaned
|
71
|
+
resources = all.map { |r| r.id }
|
72
|
+
note_resources = Note.all.map { |n| n.resources }.flatten.map { |r| r.id }
|
73
|
+
resources.difference(note_resources).map { |id| Resource.new id }
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
class Note
|
28
78
|
attr_accessor :body
|
29
79
|
attr_accessor :title
|
30
80
|
attr_reader :id
|
@@ -38,6 +88,16 @@ module Joplin
|
|
38
88
|
end
|
39
89
|
end
|
40
90
|
|
91
|
+
def resources
|
92
|
+
url = "#{Joplin::uri}/notes/#{id}/resources?token=#{Joplin::token}&fields=id"
|
93
|
+
res = Faraday.get url
|
94
|
+
parsed = JSON.parse res.body
|
95
|
+
parsed.map do |resource_data|
|
96
|
+
id = resource_data['id']
|
97
|
+
Resource.new id
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
41
101
|
def to_json
|
42
102
|
{
|
43
103
|
title: @title,
|
@@ -62,6 +122,15 @@ title: #{self.title}
|
|
62
122
|
body: #{self.body}"""
|
63
123
|
end
|
64
124
|
|
125
|
+
def self.all
|
126
|
+
url = "#{Joplin::uri}/notes/?token=#{Joplin::token}&fields=id"
|
127
|
+
res = Faraday.get url
|
128
|
+
parsed = JSON.parse res.body
|
129
|
+
parsed.map do |note|
|
130
|
+
Note.new note['id']
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
65
134
|
private
|
66
135
|
def parse response
|
67
136
|
return if not response.body
|
@@ -74,4 +143,23 @@ body: #{self.body}"""
|
|
74
143
|
@id = note["id"]
|
75
144
|
end
|
76
145
|
end
|
146
|
+
|
147
|
+
class Notebook
|
148
|
+
def initialize(id=nil)
|
149
|
+
|
150
|
+
@id = id
|
151
|
+
if id
|
152
|
+
url = "#{Joplin::uri}/folders/#{id}?token=#{Joplin::token}"
|
153
|
+
res = Faraday.get url
|
154
|
+
parsed = JSON.parse res.body
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def notes
|
159
|
+
url = "#{Joplin::uri}/folders/#{@id}/notes?token=#{Joplin::token}"
|
160
|
+
res = Faraday.get url
|
161
|
+
notes = JSON.parse res.body
|
162
|
+
notes.map! { |n| Joplin::Note.new n['id'] }
|
163
|
+
end
|
164
|
+
end
|
77
165
|
end
|
data/lib/joplin/version.rb
CHANGED
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.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Bretoi
|
8
|
-
autorequire:
|
9
|
-
bindir:
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -66,10 +66,25 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: thor
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.0.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.0.1
|
69
83
|
description: joplin API
|
70
84
|
email:
|
71
85
|
- daniel@bretoi.com
|
72
|
-
executables:
|
86
|
+
executables:
|
87
|
+
- joplin
|
73
88
|
extensions: []
|
74
89
|
extra_rdoc_files: []
|
75
90
|
files:
|
@@ -83,6 +98,7 @@ files:
|
|
83
98
|
- README.md
|
84
99
|
- Rakefile
|
85
100
|
- bin/console
|
101
|
+
- bin/joplin
|
86
102
|
- bin/setup
|
87
103
|
- joplin.gemspec
|
88
104
|
- lib/joplin.rb
|
@@ -94,7 +110,7 @@ metadata:
|
|
94
110
|
homepage_uri: http://github.com/danielb2/joplin
|
95
111
|
source_code_uri: http://github.com/danielb2/joplin
|
96
112
|
changelog_uri: http://github.com/danielb2/joplin
|
97
|
-
post_install_message:
|
113
|
+
post_install_message:
|
98
114
|
rdoc_options: []
|
99
115
|
require_paths:
|
100
116
|
- lib
|
@@ -110,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
126
|
version: '0'
|
111
127
|
requirements: []
|
112
128
|
rubygems_version: 3.0.3
|
113
|
-
signing_key:
|
129
|
+
signing_key:
|
114
130
|
specification_version: 4
|
115
131
|
summary: joplin API
|
116
132
|
test_files: []
|