rnote 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/rnote.rb +0 -1
- data/lib/rnote/auth.rb +11 -0
- data/lib/rnote/cmd/create.rb +33 -1
- data/lib/rnote/cmd/edit.rb +2 -2
- data/lib/rnote/cmd/find.rb +1 -1
- data/lib/rnote/cmd/list.rb +19 -0
- data/lib/rnote/cmd/remove.rb +19 -1
- data/lib/rnote/cmd/rename.rb +45 -0
- data/lib/rnote/cmd/show.rb +1 -1
- data/lib/rnote/{converter.rb → noun/note/converter.rb} +36 -9
- data/lib/rnote/{edit.rb → noun/note/edit.rb} +1 -0
- data/lib/rnote/{find.rb → noun/note/find.rb} +1 -1
- data/lib/rnote/noun/tag/find.rb +17 -0
- data/lib/rnote/version.rb +1 -1
- metadata +8 -5
data/lib/rnote.rb
CHANGED
data/lib/rnote/auth.rb
CHANGED
@@ -118,6 +118,17 @@ module Rnote
|
|
118
118
|
def is_logged_in
|
119
119
|
@persister.get_user_token or @persister.get_developer_token
|
120
120
|
end
|
121
|
+
|
122
|
+
# how did we log in? Some features are only available with some login types.
|
123
|
+
def login_type
|
124
|
+
if @persister.get_user_token
|
125
|
+
:user_token
|
126
|
+
elsif @persister.get_developer_token
|
127
|
+
:developer_token
|
128
|
+
else
|
129
|
+
nil
|
130
|
+
end
|
131
|
+
end
|
121
132
|
|
122
133
|
def who
|
123
134
|
if is_logged_in
|
data/lib/rnote/cmd/create.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
|
2
2
|
require 'gli'
|
3
3
|
|
4
|
-
require 'rnote/edit'
|
4
|
+
require 'rnote/noun/note/edit'
|
5
|
+
require 'rnote/noun/tag/find'
|
5
6
|
|
6
7
|
include GLI::App
|
7
8
|
|
@@ -14,6 +15,37 @@ Unlike most commands, the command line arguments aren't used in a search.
|
|
14
15
|
Instead any command line arguments provided are used for the title of the new note.
|
15
16
|
EOF
|
16
17
|
command :create do |verb|
|
18
|
+
|
19
|
+
d 'create a new tag'
|
20
|
+
verb.command :tag do |noun|
|
21
|
+
|
22
|
+
# TODO check that the tag doesn't already exist
|
23
|
+
|
24
|
+
noun.action do |global_options, options, args|
|
25
|
+
|
26
|
+
if args.length < 1
|
27
|
+
raise "You must provide the tag name."
|
28
|
+
end
|
29
|
+
if args.length > 1
|
30
|
+
raise "You can only provide one tag name to create."
|
31
|
+
end
|
32
|
+
|
33
|
+
tag_name = args[0]
|
34
|
+
|
35
|
+
# verify tag doesn't exist
|
36
|
+
if Rnote::Tag.get_tag_by_name(tag_name)
|
37
|
+
raise "tag #{tag_name} already exists"
|
38
|
+
end
|
39
|
+
|
40
|
+
# create the tag
|
41
|
+
tag = Evernote::EDAM::Type::Tag.new()
|
42
|
+
tag.name = tag_name
|
43
|
+
$app.auth.client.note_store.createTag(tag)
|
44
|
+
puts "tag created"
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
17
49
|
|
18
50
|
d 'create a new note'
|
19
51
|
verb.command :note do |noun|
|
data/lib/rnote/cmd/edit.rb
CHANGED
data/lib/rnote/cmd/find.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
|
2
|
+
require 'gli'
|
3
|
+
|
4
|
+
include GLI::App
|
5
|
+
|
6
|
+
d 'list items in evernote'
|
7
|
+
long_desc 'list items such as notes, tags, notebooks, without displaying their content.'
|
8
|
+
|
9
|
+
command :list do |verb|
|
10
|
+
|
11
|
+
d 'list all tags in the account'
|
12
|
+
verb.command :tags do |noun|
|
13
|
+
|
14
|
+
noun.action do |global_options, options, args|
|
15
|
+
$app.auth.client.note_store.listTags.each { |tag| puts tag.name }
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
data/lib/rnote/cmd/remove.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
|
2
|
-
require 'rnote/find'
|
3
2
|
require 'highline/import'
|
3
|
+
require 'rnote/noun/note/find'
|
4
|
+
require 'rnote/noun/tag/find'
|
4
5
|
|
5
6
|
include GLI::App
|
6
7
|
|
@@ -9,6 +10,23 @@ include GLI::App
|
|
9
10
|
d 'remove a note'
|
10
11
|
long_desc "Remove a note, but don't expunge it. The note stays in the users Trash"
|
11
12
|
command :remove do |verb|
|
13
|
+
|
14
|
+
verb.desc 'remove a tag (expunge, but not truly delete)'
|
15
|
+
verb.command :tag do |noun|
|
16
|
+
|
17
|
+
noun.action do |global_options, options, args|
|
18
|
+
|
19
|
+
if $app.auth.login_type != :developer_token
|
20
|
+
raise "Only a developer token has the expunge permisisons necessary to delete a tag. A user/password cannot delete tags."
|
21
|
+
end
|
22
|
+
|
23
|
+
tag_name = args[0]
|
24
|
+
tag = Rnote::Tag.get_tag_by_name(tag_name)
|
25
|
+
$app.auth.client.note_store.expungeTag(tag.guid)
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
12
30
|
|
13
31
|
verb.desc 'remove a note'
|
14
32
|
verb.command :note do |noun|
|
@@ -0,0 +1,45 @@
|
|
1
|
+
|
2
|
+
require 'gli'
|
3
|
+
|
4
|
+
require 'rnote/noun/tag/find'
|
5
|
+
|
6
|
+
include GLI::App
|
7
|
+
|
8
|
+
d 'rename an item in evernote'
|
9
|
+
long_desc <<EOF
|
10
|
+
Rename a tag, notebook or a note without change the content or other details of the note
|
11
|
+
|
12
|
+
Note that for notes this can also be acheived simply by editing the note. Or running:
|
13
|
+
|
14
|
+
$ rnote edit note --title "old note title" --set-title "new note title" --no-editor
|
15
|
+
EOF
|
16
|
+
|
17
|
+
command :rename do |verb|
|
18
|
+
|
19
|
+
verb.desc 'rename a tag'
|
20
|
+
verb.command :tag do |noun|
|
21
|
+
|
22
|
+
noun.action do |global_options,options,args|
|
23
|
+
|
24
|
+
old_tag_name = args[0]
|
25
|
+
new_tag_name = nil
|
26
|
+
if args.length < 2
|
27
|
+
raise "not enough arguments, must specify both old and new tag name"
|
28
|
+
elsif args.length == 2
|
29
|
+
new_tag_name = args[1]
|
30
|
+
elsif args.length == 3 and args[1] == 'to'
|
31
|
+
new_tag_name = args[2]
|
32
|
+
else
|
33
|
+
raise "too many arguments"
|
34
|
+
end
|
35
|
+
|
36
|
+
tag = Rnote::Tag.get_tag_by_name(old_tag_name)
|
37
|
+
|
38
|
+
tag.name = new_tag_name
|
39
|
+
$app.auth.client.note_store.updateTag(tag)
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
data/lib/rnote/cmd/show.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
|
2
2
|
require 'nokogiri'
|
3
3
|
require 'yaml'
|
4
|
-
|
5
4
|
require 'evernote-thrift'
|
6
5
|
|
7
6
|
|
@@ -28,14 +27,21 @@ class Evernote::EDAM::Type::Note
|
|
28
27
|
# the kind its own editors create. Which doesn't involve much nesting.
|
29
28
|
class EnmlDocument < Nokogiri::XML::SAX::Document # Nokogiri SAX parser
|
30
29
|
|
31
|
-
attr_accessor :_txt, :
|
30
|
+
attr_accessor :_txt, :nested_div_count, :in_pre, :in_ul, :in_ol, :next_number
|
32
31
|
|
33
32
|
def initialize
|
34
33
|
@_txt = ''
|
35
|
-
@in_div = false
|
36
34
|
@in_pre = false
|
35
|
+
@next_number = 1
|
36
|
+
@in_ul = false
|
37
|
+
@in_ol = false
|
38
|
+
@nested_div_count = 0
|
37
39
|
super
|
38
40
|
end
|
41
|
+
|
42
|
+
def in_div
|
43
|
+
nested_div_count > 0
|
44
|
+
end
|
39
45
|
|
40
46
|
def characters string
|
41
47
|
|
@@ -50,14 +56,27 @@ class Evernote::EDAM::Type::Note
|
|
50
56
|
case name
|
51
57
|
when 'en-todo'
|
52
58
|
if Hash[attrs]['checked'] == 'true'
|
53
|
-
self._txt << '[X]'
|
59
|
+
self._txt << '[X] '
|
54
60
|
else
|
55
|
-
self._txt << '[ ]'
|
61
|
+
self._txt << '[ ] '
|
56
62
|
end
|
57
63
|
when 'div'
|
58
|
-
self.
|
64
|
+
self.nested_div_count += 1
|
59
65
|
when 'pre'
|
60
66
|
self.in_pre = true
|
67
|
+
when 'ol'
|
68
|
+
self.next_number = 1
|
69
|
+
self.in_ol = true
|
70
|
+
when 'ul'
|
71
|
+
self.next_number = 1
|
72
|
+
self.in_ul = true
|
73
|
+
when 'li'
|
74
|
+
if in_ol
|
75
|
+
self._txt << next_number.to_s + '. '
|
76
|
+
self.next_number += 1
|
77
|
+
elsif in_ul
|
78
|
+
self._txt << '* '
|
79
|
+
end
|
61
80
|
else
|
62
81
|
# nothing
|
63
82
|
end
|
@@ -66,13 +85,21 @@ class Evernote::EDAM::Type::Note
|
|
66
85
|
def end_element name
|
67
86
|
case name
|
68
87
|
when 'div'
|
69
|
-
self.
|
88
|
+
raise "unmatched <div> tags" if self.nested_div_count <= 0
|
89
|
+
self.nested_div_count -= 1
|
70
90
|
# a newline for every div (whether its got a <br> in it or not)
|
71
91
|
self._txt << "\n"
|
72
92
|
when 'pre'
|
73
93
|
self.in_pre = false
|
74
94
|
when 'br'
|
75
95
|
# ignore it, as its always in a div, and every div will be a newline anyways
|
96
|
+
when 'ul'
|
97
|
+
self.in_ul = false
|
98
|
+
when 'ol'
|
99
|
+
self.in_ol = false
|
100
|
+
when 'li'
|
101
|
+
# unnecessary, as we're in a div, so the other \n is kept
|
102
|
+
# self._txt << "\n"
|
76
103
|
else
|
77
104
|
# nothing
|
78
105
|
end
|
@@ -108,8 +135,8 @@ class Evernote::EDAM::Type::Note
|
|
108
135
|
txt.gsub!('>','>')
|
109
136
|
|
110
137
|
# replace todo items
|
111
|
-
txt.gsub!('[ ]','<en-todo
|
112
|
-
txt.gsub!('[X]','<en-todo checked="true"/>')
|
138
|
+
txt.gsub!('[ ] ','<en-todo/>')
|
139
|
+
txt.gsub!('[X] ','<en-todo checked="true"/>')
|
113
140
|
|
114
141
|
# every newline becomes a <div></div>
|
115
142
|
# an empty line becomes a <div><br/></div>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
module Rnote
|
3
|
+
|
4
|
+
module Tag
|
5
|
+
|
6
|
+
def self.get_tag_by_name(tag_name)
|
7
|
+
# TODO Do I really have to search through all tags manually?
|
8
|
+
tags = $app.auth.client.note_store.listTags.select { |tag| tag.name.downcase == tag_name.downcase }
|
9
|
+
if tags.empty?
|
10
|
+
nil
|
11
|
+
else
|
12
|
+
tags.first
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/lib/rnote/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rnote
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -187,15 +187,18 @@ files:
|
|
187
187
|
- lib/rnote/cmd/create.rb
|
188
188
|
- lib/rnote/cmd/edit.rb
|
189
189
|
- lib/rnote/cmd/find.rb
|
190
|
+
- lib/rnote/cmd/list.rb
|
190
191
|
- lib/rnote/cmd/login.rb
|
191
192
|
- lib/rnote/cmd/logout.rb
|
192
193
|
- lib/rnote/cmd/remove.rb
|
194
|
+
- lib/rnote/cmd/rename.rb
|
193
195
|
- lib/rnote/cmd/show.rb
|
194
196
|
- lib/rnote/cmd/who.rb
|
195
197
|
- lib/rnote/consumer.rb
|
196
|
-
- lib/rnote/converter.rb
|
197
|
-
- lib/rnote/edit.rb
|
198
|
-
- lib/rnote/find.rb
|
198
|
+
- lib/rnote/noun/note/converter.rb
|
199
|
+
- lib/rnote/noun/note/edit.rb
|
200
|
+
- lib/rnote/noun/note/find.rb
|
201
|
+
- lib/rnote/noun/tag/find.rb
|
199
202
|
- lib/rnote/persister.rb
|
200
203
|
- lib/rnote/version.rb
|
201
204
|
- lib/rnote.rb
|