rnote 0.0.1

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/find.rb ADDED
@@ -0,0 +1,132 @@
1
+
2
+ require 'highline/import'
3
+ require 'evernote-thrift'
4
+ require 'rnote/converter'
5
+
6
+ module Rnote
7
+
8
+ class Find
9
+
10
+ # Warning
11
+ # Don't take the Notes resulting from these searches and try to update them in Evernote
12
+ # they may not be fully populate, missing tags, or content.
13
+ # instead just use this list to display the note lists, or to get the guid and pull the whole note again.
14
+
15
+ MAX_RESULTS_PER_PAGE = 10
16
+
17
+ def initialize(auth,persister)
18
+ @auth = auth # auth instead of client so I can postpone connecting.
19
+ @persister = persister
20
+ end
21
+
22
+ # runs a search
23
+ # returns the results
24
+ def search(options,args)
25
+
26
+ # process arguments into an evernote search query
27
+ filter = Evernote::EDAM::NoteStore::NoteFilter.new
28
+ filter.order = Evernote::EDAM::Type::NoteSortOrder::UPDATED
29
+ if options[:title]
30
+ args << "intitle:'#{options[:title]}'"
31
+ end
32
+ filter.words = args.join(' ')
33
+
34
+ page = 0
35
+ notes = @auth.client.note_store.findNotes(filter,page * MAX_RESULTS_PER_PAGE,MAX_RESULTS_PER_PAGE).notes
36
+
37
+ # we fully pouplate each note at search time
38
+ # poor choice for performance, though
39
+ notes.each do |note|
40
+ fill_note(note)
41
+ end
42
+
43
+ notes
44
+ end
45
+
46
+ def fill_note(note)
47
+ note.content = @auth.client.note_store.getNoteContent(note.guid)
48
+ note.tagNames = @auth.client.note_store.getNoteTagNames(note.guid)
49
+ end
50
+
51
+ def get_full_note(guid)
52
+ note = @auth.client.note_store.getNote(guid,true,false,false,false)
53
+ note.tagNames = @auth.client.note_store.getNoteTagNames(note.guid)
54
+ note
55
+ end
56
+
57
+ # runs the search
58
+ # displays it
59
+ # saves it.
60
+ # returns nothing
61
+ def find_cmd(options,args)
62
+
63
+ results = search(options,args)
64
+
65
+ if results.empty?
66
+ @persister.save_last_search_guids([])
67
+ puts "no notes found"
68
+ else
69
+ guids = results.map { |note| note.guid }
70
+ @persister.save_last_search_guids(guids)
71
+ display_results(results)
72
+ end
73
+ end
74
+
75
+
76
+ def display_results(notes)
77
+ inc = 1
78
+ notes.each do |note|
79
+ puts "#{inc}: #{note.title} - #{note.tagNames.join(', ')}\n#{note.summarize}\n"
80
+ inc += 1
81
+ end
82
+ end
83
+
84
+ def Find.include_search_options(noun)
85
+ noun.desc "phrase to find in title of note"
86
+ noun.flag :title
87
+ end
88
+
89
+ def Find.has_search_options(options)
90
+ !! options[:title]
91
+ end
92
+
93
+ # get the note to edit. whether from options or last search result or interactively
94
+ # run a searching using the options and/or arguments
95
+ # use last search if it makes sense to do so.
96
+ # returns a note
97
+ def find_note(options,args)
98
+
99
+ results = nil
100
+ if args.length == 1 and not Find.has_search_options(options) and args[0].match(/^\d{1,3}$/)
101
+ # no search options, one argument, and its a small number
102
+ # they are asking to pick from the last search results
103
+ guids = @persister.get_last_search_guids
104
+ guid = guids[args[0].to_i] # the chosen note
105
+ note = get_full_note(guid)
106
+ results = [note] # fake a result set with it.
107
+ else
108
+ results = search(options,args)
109
+ end
110
+
111
+ if results.length == 0
112
+ raise "no matching note found."
113
+ elsif results.length == 1
114
+ return results[0]
115
+ else
116
+ if options[:interactive]
117
+ display_results(results)
118
+ answer = ask 'Which note? ', Integer do |q|
119
+ q.in = 1..results.length
120
+ end
121
+ results[answer - 1]
122
+ else
123
+ raise 'too many results. or try --interactive to select'
124
+ end
125
+ end
126
+
127
+ end
128
+
129
+ end
130
+
131
+
132
+ end
@@ -0,0 +1,249 @@
1
+
2
+ require 'yaml'
3
+
4
+ AUTH_FILE = RNOTE_HOME + '/auth'
5
+ SEARCH_FILE = RNOTE_HOME + '/search_cache'
6
+
7
+ =begin
8
+
9
+ These files are always YAML.
10
+
11
+ You can create and modify the rc file, at will.
12
+
13
+ You shouldn't touch the auth or search_cache.
14
+ These are auto-generated
15
+
16
+ =end
17
+
18
+
19
+ if not File.exists?(RNOTE_HOME)
20
+ Dir.mkdir(RNOTE_HOME)
21
+ end
22
+
23
+ module Rnote
24
+
25
+ module ConfigFile
26
+
27
+ def modify_config
28
+
29
+ raise if self.methods.include?(:readonly) and readonly
30
+
31
+ # TODO lock the file through this process
32
+
33
+ config = {}
34
+ if File.exists?(@config_file)
35
+ config = YAML.load_file(@config_file)
36
+ end
37
+
38
+ result = yield config
39
+
40
+ # TODO unlink is unnecessary, just truncate the file and write the new content.
41
+ # this will keep permissions and lock
42
+ File.unlink(@config_file) if File.exists?(@config_file)
43
+ File.open(@config_file, 'w') do |f|
44
+ f.write header if self.methods.include? :header
45
+ f.write config.to_yaml
46
+ after_vivify if self.methods.include? :after_vivify
47
+ end
48
+
49
+ result
50
+ end
51
+
52
+ def read_config
53
+
54
+ config = {}
55
+ if File.exists?(@config_file)
56
+ config = YAML.load_file(@config_file)
57
+ end
58
+
59
+ yield config
60
+ end
61
+
62
+ end
63
+
64
+ class AuthCache
65
+
66
+ include ConfigFile
67
+
68
+ def initialize
69
+ @config_file = AUTH_FILE
70
+ end
71
+
72
+ def header
73
+ <<EOF
74
+
75
+ #
76
+ # This file is auto-generated and shouldn't be edited by hand
77
+ #
78
+ # deleting this file is akin to logging out.
79
+ #
80
+
81
+ EOF
82
+ end
83
+
84
+ def after_vivify
85
+ FileUtils.chmod 0600, AUTH_FILE
86
+ end
87
+
88
+ def persist_username(username)
89
+ modify_config do |config|
90
+ config[:username] = username
91
+ end
92
+ end
93
+
94
+
95
+ def persist_user_token(user_token)
96
+ modify_config do |config|
97
+ config[:user_token] = user_token
98
+ end
99
+ end
100
+
101
+ def persist_developer_token(developer_token)
102
+ modify_config do |config|
103
+ config[:developer_token] = developer_token
104
+ end
105
+ end
106
+
107
+ def forget_user_token
108
+ modify_config do |config|
109
+ config.delete(:user_token)
110
+ end
111
+ end
112
+
113
+ def forget_username
114
+ modify_config do |config|
115
+ config.delete(:username)
116
+ end
117
+ end
118
+
119
+ def forget_developer_token
120
+ modify_config do |config|
121
+ config.delete(:developer_token)
122
+ end
123
+ end
124
+
125
+ def get_user_token
126
+ read_config do |config|
127
+ config[:user_token]
128
+ end
129
+ end
130
+
131
+ def get_username
132
+ read_config do |config|
133
+ config[:username]
134
+ end
135
+ end
136
+
137
+ def get_developer_token
138
+ read_config do |config|
139
+ config[:developer_token]
140
+ end
141
+ end
142
+
143
+ def get_sandbox
144
+ read_config do |config|
145
+ config[:sandbox]
146
+ end
147
+ end
148
+
149
+ def get_consumer_key
150
+ read_config do |config|
151
+ if config[:consumer_key].nil?
152
+ raise "no consumer key saved"
153
+ else
154
+ config[:consumer_key]
155
+ end
156
+ end
157
+ end
158
+
159
+ def get_consumer_secret
160
+ read_config do |config|
161
+ if config[:consumer_secret].nil?
162
+ raise "noc consumer secret saved"
163
+ else
164
+ config[:consumer_secret]
165
+ end
166
+ end
167
+ end
168
+
169
+ def persist_sandbox(sandbox)
170
+ raise if ! sandbox and RNOTE_SANDBOX_ONLY
171
+ modify_config do |config|
172
+ config[:sandbox] = sandbox
173
+ end
174
+ end
175
+
176
+ def persist_consumer_key(consumer_key)
177
+ modify_config do|config|
178
+ config[:consumer_key] = consumer_key
179
+ end
180
+ end
181
+
182
+ def persist_consumer_secret(consumer_secret)
183
+ modify_config do |config|
184
+ config[:consumer_secret] = consumer_secret
185
+ end
186
+ end
187
+
188
+ def forget_sandbox
189
+ modify_config do |config|
190
+ config.delete(:sandbox)
191
+ end
192
+ end
193
+
194
+ end
195
+
196
+ class SearchCache
197
+
198
+ include ConfigFile
199
+
200
+ def initialize
201
+ @config_file = SEARCH_FILE
202
+ end
203
+
204
+ def header
205
+ <<EOF
206
+
207
+ #
208
+ # This file is auto-generated and shouldn't be edited by hand
209
+ #
210
+ # feel free to delete this file.
211
+ #
212
+
213
+ EOF
214
+ end
215
+
216
+ def save_last_search_guids(guids)
217
+ modify_config do |config|
218
+ config[:last_search] = guids
219
+ end
220
+ end
221
+
222
+ def get_last_search_guids
223
+ read_config do |config|
224
+ config[:last_search] || []
225
+ end
226
+ end
227
+
228
+ end
229
+
230
+ class Persister
231
+
232
+ def initialize()
233
+ @auth_cache = AuthCache.new
234
+ @search_cache = SearchCache.new
235
+ end
236
+
237
+ def method_missing(method,*args)
238
+ if @auth_cache.respond_to?(method)
239
+ @auth_cache.method(method).call(*args)
240
+ elsif @search_cache.respond_to?(method)
241
+ @search_cache.method(method).call(*args)
242
+ else
243
+ super
244
+ end
245
+ end
246
+
247
+ end
248
+
249
+ end
@@ -0,0 +1,3 @@
1
+ module Rnote
2
+ VERSION = '0.0.1'
3
+ end
data/rnote.rdoc ADDED
@@ -0,0 +1,5 @@
1
+ = rnote
2
+
3
+ Generate this with
4
+ rnote rdoc
5
+ After you have described your command line interface
metadata ADDED
@@ -0,0 +1,232 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rnote
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jason Stillwell
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rdoc
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: aruba
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: minitest-reporters
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: gli
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - '='
84
+ - !ruby/object:Gem::Version
85
+ version: 2.5.4
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - '='
92
+ - !ruby/object:Gem::Version
93
+ version: 2.5.4
94
+ - !ruby/object:Gem::Dependency
95
+ name: evernote-thrift
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: evernote_oauth
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 0.1.8
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: 0.1.8
126
+ - !ruby/object:Gem::Dependency
127
+ name: mechanize
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :runtime
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: nokogiri
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :runtime
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ - !ruby/object:Gem::Dependency
159
+ name: highline
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :runtime
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ description: ! " RNote is a command line tool for accessing Evernote.\n You
175
+ can use it to find, create, and edit notes directly on the Evernote Cloud.\n RNote
176
+ will launch your own EDITOR when you ask to edit a note. Much like git does for
177
+ commit messages.\n"
178
+ email: dragonfax@gmail.com
179
+ executables:
180
+ - rnote
181
+ extensions: []
182
+ extra_rdoc_files:
183
+ - rnote.rdoc
184
+ files:
185
+ - bin/rnote
186
+ - lib/rnote/auth.rb
187
+ - lib/rnote/cmd/create.rb
188
+ - lib/rnote/cmd/edit.rb
189
+ - lib/rnote/cmd/find.rb
190
+ - lib/rnote/cmd/login.rb
191
+ - lib/rnote/cmd/logout.rb
192
+ - lib/rnote/cmd/remove.rb
193
+ - lib/rnote/cmd/show.rb
194
+ - lib/rnote/cmd/who.rb
195
+ - lib/rnote/converter.rb
196
+ - lib/rnote/edit.rb
197
+ - lib/rnote/find.rb
198
+ - lib/rnote/persister.rb
199
+ - lib/rnote/version.rb
200
+ - lib/rnote.rb
201
+ - rnote.rdoc
202
+ homepage: http://github.com/dragonfax/evernote
203
+ licenses: []
204
+ post_install_message:
205
+ rdoc_options:
206
+ - --title
207
+ - rnote
208
+ - --main
209
+ - README.rdoc
210
+ - -ri
211
+ require_paths:
212
+ - lib
213
+ - lib
214
+ required_ruby_version: !ruby/object:Gem::Requirement
215
+ none: false
216
+ requirements:
217
+ - - ! '>='
218
+ - !ruby/object:Gem::Version
219
+ version: '0'
220
+ required_rubygems_version: !ruby/object:Gem::Requirement
221
+ none: false
222
+ requirements:
223
+ - - ! '>='
224
+ - !ruby/object:Gem::Version
225
+ version: '0'
226
+ requirements: []
227
+ rubyforge_project:
228
+ rubygems_version: 1.8.24
229
+ signing_key:
230
+ specification_version: 3
231
+ summary: CLI to Evernote
232
+ test_files: []