rnote 0.0.1 → 0.0.2

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 CHANGED
@@ -14,6 +14,15 @@ rescue LoadError
14
14
  RNOTE_SANDBOX_ONLY = false
15
15
  end
16
16
 
17
+ # load optional production consumer key
18
+ begin
19
+ require_relative 'rnote/consumer'
20
+ rescue LoadError
21
+ # ignore
22
+ PRODUCTION_CONSUMER_KEY = nil
23
+ PRODUCTION_CONSUMER_SECRET = nil
24
+ end
25
+
17
26
  require 'rnote/version'
18
27
  require 'rnote/converter'
19
28
  require 'rnote/persister'
data/lib/rnote/auth.rb CHANGED
@@ -36,13 +36,25 @@ module Rnote
36
36
  logout
37
37
  end
38
38
  end
39
+
40
+ ## Consumer Key and Secret provided in published gem.
41
+ #
42
+ # we'll use these if the user doesn't provide their own
43
+ # we do this check here, instead of in Persister,
44
+ # so we can verify this is only used in production, not sandbox.
45
+ #
46
+
47
+ consumer_key = @persister.get_consumer_key || ( ! sandbox && PRODUCTION_CONSUMER_KEY )
48
+ raise 'no consumer key to use, please provide one.' unless consumer_key
49
+ consumer_secret = @persister.get_consumer_secret || ( ! sandbox && PRODUCTION_CONSUMER_SECRET )
50
+ raise 'no consumer secret to use, please provide one.' unless consumer_secret
39
51
 
40
52
  ## Get a user key using these crednetials
41
53
 
42
54
  # this client isn't authorized, and can only request authorization. no api calls.
43
55
  auth_client = EvernoteOAuth::Client.new(
44
- consumer_key: @persister.get_consumer_key,
45
- consumer_secret: @persister.get_consumer_secret,
56
+ consumer_key: consumer_key,
57
+ consumer_secret: consumer_secret,
46
58
  sandbox: sandbox
47
59
  )
48
60
 
@@ -42,18 +42,21 @@ command :login do |c|
42
42
  puts "login successful using developer key"
43
43
  else
44
44
  # then fall back to using a username and password
45
+
46
+ user = options[:user]
47
+ password = options[:password]
45
48
 
46
- if not options[:u]
49
+ if user.nil?
47
50
  answer = ask("Enter your username: ")
48
- options[:u] = answer
51
+ user = answer.chomp
49
52
  end
50
53
 
51
- if not options[:p]
54
+ if password.nil?
52
55
  answer = ask("Enter your password: ") { |q| q.echo = 'x' }
53
- options[:p] = answer
56
+ password = answer.chomp
54
57
  end
55
58
 
56
- $app.auth.login_with_password(options[:user],options[:password], options[:sandbox])
59
+ $app.auth.login_with_password(user,password, options[:sandbox])
57
60
 
58
61
  # test the login with a harmless api call.
59
62
  $app.auth.client.user_store.getUser
@@ -0,0 +1,3 @@
1
+
2
+ PRODUCTION_CONSUMER_KEY = 'dragonfax'
3
+ PRODUCTION_CONSUMER_SECRET = '5b110ac7e792579c'
@@ -121,7 +121,7 @@ EOF
121
121
  end
122
122
 
123
123
  def summarize
124
- self.txt_content[0..30]
124
+ self.txt_content.strip.gsub(/\s+/,' ')[0..100]
125
125
  end
126
126
 
127
127
  end
data/lib/rnote/find.rb CHANGED
@@ -76,7 +76,7 @@ module Rnote
76
76
  def display_results(notes)
77
77
  inc = 1
78
78
  notes.each do |note|
79
- puts "#{inc}: #{note.title} - #{note.tagNames.join(', ')}\n#{note.summarize}\n"
79
+ puts "#{inc}: #{note.title} - #{note.tagNames.join(', ')}\n#{note.summarize}\n\n"
80
80
  inc += 1
81
81
  end
82
82
  end
@@ -6,12 +6,20 @@ SEARCH_FILE = RNOTE_HOME + '/search_cache'
6
6
 
7
7
  =begin
8
8
 
9
- These files are always YAML.
9
+ # settings and cache files
10
10
 
11
- You can create and modify the rc file, at will.
11
+ These files are all YAML.
12
12
 
13
- You shouldn't touch the auth or search_cache.
14
- These are auto-generated
13
+ You shouldn't touch the auth or search_cache. These are auto-generated by the tool.
14
+
15
+ When we add user settings they'll be in an 'rnoterc' file. Which you can create and modify at will.
16
+ But there are no user settings yet.
17
+
18
+ # cached values
19
+
20
+ consumer key and secret
21
+ if a consumer key and secret are provided (as happens in the published gem),
22
+ then it will be used unless one is provided by the user instead.
15
23
 
16
24
  =end
17
25
 
@@ -148,21 +156,13 @@ EOF
148
156
 
149
157
  def get_consumer_key
150
158
  read_config do |config|
151
- if config[:consumer_key].nil?
152
- raise "no consumer key saved"
153
- else
154
- config[:consumer_key]
155
- end
159
+ config[:consumer_key]
156
160
  end
157
161
  end
158
162
 
159
163
  def get_consumer_secret
160
164
  read_config do |config|
161
- if config[:consumer_secret].nil?
162
- raise "noc consumer secret saved"
163
- else
164
- config[:consumer_secret]
165
- end
165
+ config[:consumer_secret]
166
166
  end
167
167
  end
168
168
 
data/lib/rnote/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rnote
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
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.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -192,6 +192,7 @@ files:
192
192
  - lib/rnote/cmd/remove.rb
193
193
  - lib/rnote/cmd/show.rb
194
194
  - lib/rnote/cmd/who.rb
195
+ - lib/rnote/consumer.rb
195
196
  - lib/rnote/converter.rb
196
197
  - lib/rnote/edit.rb
197
198
  - lib/rnote/find.rb