joplin 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +6 -3
- data/Makefile +6 -0
- data/README.md +22 -26
- data/bin/joplin +55 -0
- data/joplin.gemspec +5 -3
- data/lib/joplin.rb +92 -1
- data/lib/joplin/version.rb +1 -1
- metadata +39 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c47aee19cc5f53aea14432231fb49276a97b22a8c9c076fb333adc14ca5c5103
|
4
|
+
data.tar.gz: ade107e1875175fb080eaa33a6b69752eade65e97d51ab21d1fd9f5e496eb779
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03ab75b8e2704463fcdaf5ca91d94bb01ee0a84be655c81b73e139dba299d0368a3c0d878287c00f1f029df2e657fd7cf5b1d4fd36e864a4f493094e6d4b6ed8
|
7
|
+
data.tar.gz: 8175d47bac51209a1e04727daa32b7f43368d8d8c7506c5aadac7811b2046cb5910e391bca72302cd76b76e6d3db727a13a1e06fd75b5bef4ac102a3874517ce
|
data/.gitignore
CHANGED
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/
|
@@ -10,7 +11,7 @@ GEM
|
|
10
11
|
faraday (1.0.1)
|
11
12
|
multipart-post (>= 1.2, < 3)
|
12
13
|
multipart-post (2.1.1)
|
13
|
-
rake (
|
14
|
+
rake (13.0.1)
|
14
15
|
rspec (3.9.0)
|
15
16
|
rspec-core (~> 3.9.0)
|
16
17
|
rspec-expectations (~> 3.9.0)
|
@@ -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
|
@@ -32,8 +34,9 @@ DEPENDENCIES
|
|
32
34
|
bundler (~> 1.17)
|
33
35
|
faraday (~> 1.0)
|
34
36
|
joplin!
|
35
|
-
rake (~>
|
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,55 @@
|
|
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(<svg height="8" width="100%"><g fill="none" stroke="black" stroke-width="4"><path stroke-dasharray="20,10,5,5,5,10" d="M0 4 l415 0" /></g></svg>)
|
48
|
+
|
49
|
+
new_note.body = notes.map { |n| "\# #{n.title}\n\n#{n.body}" }.join("\n#{divider}\n")
|
50
|
+
new_note.save!
|
51
|
+
puts "Saved: #{new_note.title} with id: #{new_note.id}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
MyCLI.start(ARGV)
|
data/joplin.gemspec
CHANGED
@@ -30,11 +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
|
+
spec.add_dependency "faraday", "~> 1.0"
|
37
38
|
spec.add_development_dependency "bundler", "~> 1.17"
|
38
|
-
spec.add_development_dependency "rake", "~>
|
39
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
39
40
|
spec.add_development_dependency "rspec", "~> 3.0"
|
41
|
+
spec.add_development_dependency "thor", "~> 1.0.1"
|
40
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,13 +122,44 @@ 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
|
68
137
|
note = JSON.parse response.body
|
138
|
+
if response.status != 200
|
139
|
+
raise Error.new note["error"]
|
140
|
+
end
|
69
141
|
@body = note['body']
|
70
142
|
@title = note['title']
|
71
143
|
@id = note["id"]
|
72
144
|
end
|
73
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
|
74
165
|
end
|
data/lib/joplin/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: joplin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
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
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -30,14 +44,14 @@ dependencies:
|
|
30
44
|
requirements:
|
31
45
|
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
47
|
+
version: '13.0'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
54
|
+
version: '13.0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rspec
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,10 +66,25 @@ dependencies:
|
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
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
|
55
83
|
description: joplin API
|
56
84
|
email:
|
57
85
|
- daniel@bretoi.com
|
58
|
-
executables:
|
86
|
+
executables:
|
87
|
+
- joplin
|
59
88
|
extensions: []
|
60
89
|
extra_rdoc_files: []
|
61
90
|
files:
|
@@ -69,6 +98,7 @@ files:
|
|
69
98
|
- README.md
|
70
99
|
- Rakefile
|
71
100
|
- bin/console
|
101
|
+
- bin/joplin
|
72
102
|
- bin/setup
|
73
103
|
- joplin.gemspec
|
74
104
|
- lib/joplin.rb
|
@@ -80,7 +110,7 @@ metadata:
|
|
80
110
|
homepage_uri: http://github.com/danielb2/joplin
|
81
111
|
source_code_uri: http://github.com/danielb2/joplin
|
82
112
|
changelog_uri: http://github.com/danielb2/joplin
|
83
|
-
post_install_message:
|
113
|
+
post_install_message:
|
84
114
|
rdoc_options: []
|
85
115
|
require_paths:
|
86
116
|
- lib
|
@@ -96,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
126
|
version: '0'
|
97
127
|
requirements: []
|
98
128
|
rubygems_version: 3.0.3
|
99
|
-
signing_key:
|
129
|
+
signing_key:
|
100
130
|
specification_version: 4
|
101
131
|
summary: joplin API
|
102
132
|
test_files: []
|