joplin 0.1.3 → 0.1.4
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/README.md +19 -32
- data/bin/joplin +31 -0
- data/joplin.gemspec +3 -2
- data/lib/joplin.rb +63 -1
- data/lib/joplin/version.rb +1 -1
- metadata +20 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a00bb3fcafc4b1e31a2248b00e5a94bf68385b2b98d3b41d0119b3b451e14916
|
4
|
+
data.tar.gz: e58b2a8e7ce244728258de458da08174c9b36852bcbf58a7d2f11f41946a7a2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13b659f736facbeeea76548a0b83a7060d24f8f7ae8ceb1e7f7c56305d0a62ec0476709ac5d623248f98fc0f8896572d908af5bbff9244145d93f005d2790d28
|
7
|
+
data.tar.gz: 9cd4f0bfd7eace341b36e3909d5a1b5eea48d57e21e1d1c85a50722801447b49bb03f83f894704fba7d1e5aea79d12a41233f01e9c9b1e1c05e5892f42be507a
|
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/README.md
CHANGED
@@ -1,39 +1,26 @@
|
|
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
|
28
|
-
|
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
|
-
|
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).
|
32
|
-
|
33
|
-
## Contributing
|
34
|
-
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/danielb2/joplin.
|
36
|
-
|
37
|
-
## License
|
38
|
-
|
39
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
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
|
+
```
|
data/bin/joplin
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "./lib/joplin.rb"
|
4
|
+
require 'thor'
|
5
|
+
|
6
|
+
|
7
|
+
class MyCLI < Thor
|
8
|
+
class_option :token, :type => :string #, required: true
|
9
|
+
class_option :help, :type => :boolean
|
10
|
+
class_option :version, :type => :boolean
|
11
|
+
map ["-v", "--version"] => :version
|
12
|
+
map ["-h", "--help"] => :help
|
13
|
+
option :token, :required => true
|
14
|
+
option :'dry-run', desc: "dry-run", aliases: '-n'
|
15
|
+
desc :clean, "clean unused resources"
|
16
|
+
def clean
|
17
|
+
Joplin::token = options[:token]
|
18
|
+
Joplin::Resource.orphaned.map { |r|
|
19
|
+
r.delete if not options['dry-run']
|
20
|
+
puts "Deleted #{r.id}"
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
method_options :force => :boolean
|
25
|
+
desc "version", "get version of program"
|
26
|
+
def version
|
27
|
+
puts Joplin::VERSION
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
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
@@ -24,7 +24,50 @@ module Joplin
|
|
24
24
|
|
25
25
|
self.uri = "http://localhost:41184"
|
26
26
|
|
27
|
-
class
|
27
|
+
class Resource
|
28
|
+
attr_reader :id
|
29
|
+
|
30
|
+
def self.all
|
31
|
+
url = "#{Joplin::uri}/resources/?token=#{Joplin::token}&fields=id"
|
32
|
+
res = Faraday.get url
|
33
|
+
parsed = JSON.parse res.body
|
34
|
+
if res.status != 200
|
35
|
+
throw Error.new(parsed['error'])
|
36
|
+
end
|
37
|
+
parsed.map do |resource|
|
38
|
+
Resource.new resource['id']
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def initialize(id=nil)
|
43
|
+
|
44
|
+
raise Error.new("need id") unless id
|
45
|
+
@id = id
|
46
|
+
url = "#{Joplin::uri}/resources/#{id}?token=#{Joplin::token}&fields=mime,filename,id"
|
47
|
+
res = Faraday.get url
|
48
|
+
@parsed = JSON.parse res.body
|
49
|
+
end
|
50
|
+
|
51
|
+
def delete
|
52
|
+
url = "#{Joplin::uri}/resources/#{id}?token=#{Joplin::token}"
|
53
|
+
res = Faraday.delete url
|
54
|
+
res.status == 200
|
55
|
+
end
|
56
|
+
|
57
|
+
def to_s
|
58
|
+
"""id: #{@id},
|
59
|
+
mime: #{@parsed['mime']}
|
60
|
+
filename: #{@parsed['filename']}"""
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.orphaned
|
64
|
+
resources = all.map { |r| r.id }
|
65
|
+
note_resources = Note.all.map { |n| n.resources }.flatten.map { |r| r.id }
|
66
|
+
resources.difference(note_resources).map { |id| Resource.new id }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
class Note
|
28
71
|
attr_accessor :body
|
29
72
|
attr_accessor :title
|
30
73
|
attr_reader :id
|
@@ -38,6 +81,16 @@ module Joplin
|
|
38
81
|
end
|
39
82
|
end
|
40
83
|
|
84
|
+
def resources
|
85
|
+
url = "#{Joplin::uri}/notes/#{id}/resources?token=#{Joplin::token}&fields=id"
|
86
|
+
res = Faraday.get url
|
87
|
+
parsed = JSON.parse res.body
|
88
|
+
parsed.map do |resource_data|
|
89
|
+
id = resource_data['id']
|
90
|
+
Resource.new id
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
41
94
|
def to_json
|
42
95
|
{
|
43
96
|
title: @title,
|
@@ -62,6 +115,15 @@ title: #{self.title}
|
|
62
115
|
body: #{self.body}"""
|
63
116
|
end
|
64
117
|
|
118
|
+
def self.all
|
119
|
+
url = "#{Joplin::uri}/notes/?token=#{Joplin::token}&fields=id"
|
120
|
+
res = Faraday.get url
|
121
|
+
parsed = JSON.parse res.body
|
122
|
+
parsed.map do |note|
|
123
|
+
Note.new note['id']
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
65
127
|
private
|
66
128
|
def parse response
|
67
129
|
return if not response.body
|
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.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Bretoi
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-04 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
|