joplin 0.2.0 → 0.4.0

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: c47aee19cc5f53aea14432231fb49276a97b22a8c9c076fb333adc14ca5c5103
4
- data.tar.gz: ade107e1875175fb080eaa33a6b69752eade65e97d51ab21d1fd9f5e496eb779
3
+ metadata.gz: 4b4f629e9d1111d44489677862012bb90708a49838db1c0453765e6c5e02cfb7
4
+ data.tar.gz: 54299abfa751d6fa58c0750e8dcf6e1a452124d2495b5604430ada3348574766
5
5
  SHA512:
6
- metadata.gz: 03ab75b8e2704463fcdaf5ca91d94bb01ee0a84be655c81b73e139dba299d0368a3c0d878287c00f1f029df2e657fd7cf5b1d4fd36e864a4f493094e6d4b6ed8
7
- data.tar.gz: 8175d47bac51209a1e04727daa32b7f43368d8d8c7506c5aadac7811b2046cb5910e391bca72302cd76b76e6d3db727a13a1e06fd75b5bef4ac102a3874517ce
6
+ metadata.gz: e53f9e2c97f333220afe60a2f0972d783c917c5b94973464225daa544f12d0e9813870ec56a259bcb08a5029cabd90952ff7784a5eed26c23452abcae010faee
7
+ data.tar.gz: 1e88e83442899c217e413415af68ebdc7b71450c11086031b36508b8e90819a3e85c313fb9e2eb244465ff48737a38e6091d1b1f32d603f07c3cf37296e619f3
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.4.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.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
@@ -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, :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,12 +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(<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>)
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
- new_note.body = notes.map { |n| "\# #{n.title}\n\n#{n.body}" }.join("\n#{divider}\n")
67
+ desc :build, "build a note from a note containing references"
68
+
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.)
73
+
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)
50
87
  new_note.save!
51
88
  puts "Saved: #{new_note.title} with id: #{new_note.id}"
52
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
53
96
  end
54
97
 
55
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.0"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/joplin.rb CHANGED
@@ -17,6 +17,15 @@ module Joplin
17
17
  return parsed
18
18
  end
19
19
 
20
+ def self.get_token
21
+ begin
22
+ settings = JSON.parse File.read("#{ENV['HOME']}/.config/joplin-desktop/settings.json")
23
+ return settings['api.token']
24
+ rescue
25
+ return nil
26
+ end
27
+ end
28
+
20
29
  def self.token
21
30
  @@token
22
31
  end
@@ -133,7 +142,9 @@ body: #{self.body}"""
133
142
 
134
143
  private
135
144
  def parse response
136
- return if not response.body
145
+ if response.body.empty?
146
+ raise "No note found with id #{@id}"
147
+ end
137
148
  note = JSON.parse response.body
138
149
  if response.status != 200
139
150
  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.0
4
+ version: 0.4.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: 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