joplin 0.1.2 → 0.2.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: 6bb7600ec9847e6eb0692dd479670b8ed3f7b5a457e00254c2bb292207935da7
4
- data.tar.gz: 4402bbbdf497a6722e07a6b7a6090652a10cabf4abd789d6885a3dd33c7bf6ee
3
+ metadata.gz: c2c49e745ffa9c4f3956e5b5eb8a58f8bcba5aaa253229d571a3fcee4ea282e9
4
+ data.tar.gz: 79987f1e955121ceb1cc6c28c48d72dd7af0b8ab81024079ff5f4a6420e37ad2
5
5
  SHA512:
6
- metadata.gz: 5abcad7280d66a12392f6b7095618488d9c1a4bae113c629352ce7850a55d97f4e2eb719ec7dfe94fa1a87d051067ce8218abce9a52c67fd46479d6e877db56e
7
- data.tar.gz: 8d8de2b6b7d6b4176c18df60081e6a02ac783d7be5485bf0fd8330483426a55dbd94646f6b09ea80f96e9a2fc6924f5c0e12cf8eb6f24f5b774517e4a5fd475e
6
+ metadata.gz: 74cf728f619e860296483243a61253aa968790c2a55f18114842635e9bb6341f83bdc8548324d7b03ecde6c72069bd35a887143236a0ad6361eb9ad0cb0e642e
7
+ data.tar.gz: 9d7d02c45a3c3ff606546425057eb1f5b5d1bfa9fe605f9f45492ddeb06f1e598601b09d76fc198f05a9dd4744d41ec7d3f23db2b787f40ea09e7536d94b50a4
data/Gemfile CHANGED
@@ -6,3 +6,5 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
6
6
  gemspec
7
7
 
8
8
  gem "faraday", "~> 1.0"
9
+
10
+ gem "thor", "~> 1.0"
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- joplin (0.1.0)
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
@@ -1,2 +1,8 @@
1
1
  all:
2
2
  gem build joplin.gemspec
3
+
4
+ push: clean all
5
+ gem push *gem
6
+
7
+ clean:
8
+ rm *gem
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
- TODO: Delete this and the text above, and describe your gem
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
- gem 'joplin'
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
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install joplin
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
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
29
+ ## CLI
32
30
 
33
- ## Contributing
31
+ ### joplin nb2n --token <yourtoken> 'notebook name'
34
32
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/danielb2/joplin.
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).
@@ -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 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>
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)
@@ -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 = "exe"
34
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
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
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
@@ -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 Notes
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
@@ -1,3 +1,3 @@
1
1
  module Joplin
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.1"
3
3
  end
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.1.2
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Bretoi
8
- autorequire:
9
- bindir: exe
8
+ autorequire:
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-25 00:00:00.000000000 Z
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
@@ -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: []