evernotable 1.0.0 → 1.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.
@@ -7,7 +7,7 @@ class Evernotable::CLI
7
7
  def self.start(*args)
8
8
  command = args.shift.strip rescue "help"
9
9
  Evernotable::Command.load
10
- Evernotable::Command.run(command, args)
10
+ Evernotable::Command.run(command, args, :production)
11
11
  end
12
12
 
13
13
  end
@@ -3,12 +3,12 @@ require 'evernotable/client'
3
3
  require 'yaml'
4
4
 
5
5
  class Evernotable::Client::Base
6
- attr_reader :config
7
6
  attr_reader :current_user
8
7
  attr_reader :client_token
9
8
 
10
9
  def initialize(params={})
11
10
  @config = params[:config] || nil
11
+ @env = params[:env]
12
12
  @current_user = params[:current_user] || nil
13
13
  @client_token = params[:client_token] || nil
14
14
  end
@@ -7,7 +7,7 @@ class Evernotable::Client::Note < Evernotable::Client::Base
7
7
 
8
8
  def initialize(params={})
9
9
  super(params)
10
- @api = @config["note_api"]["sandbox"] #TODO: variablize the api env
10
+ @api = @config["note_api"][@env]
11
11
  @notebook_name = @config["notebook"]["name"]
12
12
  @notebook_guid = nil
13
13
  @instance = Evernote::NoteStore.new("#{@api}#{params[:user_shard]}")
@@ -4,7 +4,7 @@ class Evernotable::Client::User < Evernotable::Client::Base
4
4
 
5
5
  def initialize(params={})
6
6
  super
7
- api = @config["user_api"]["sandbox"] #TODO: variablize the api env
7
+ api = @config["user_api"][@env]
8
8
  @instance = Evernote::UserStore.new(api, {:username => params[:user], :password => params[:password], :consumer_key => @config["api_credentials"]["consumer_key"], :consumer_secret => @config["api_credentials"]["consumer_secret"]})
9
9
  end
10
10
 
@@ -24,7 +24,7 @@ module Evernotable
24
24
  @@commands.include?(cmd)
25
25
  end
26
26
 
27
- def self.run(cmd, arguments=[])
27
+ def self.run(cmd, arguments=[], env=:sandbox)
28
28
  if cmd.nil? || cmd.empty?
29
29
  output_with_bang("Use *evernotable help* for additional information.")
30
30
  exit(1)
@@ -36,7 +36,7 @@ module Evernotable
36
36
  else
37
37
  #instantiate command and invoke method on it
38
38
  method = arguments.shift || :help
39
- obj = eval("Evernotable::Command::#{cmd.capitalize}").new(arguments)
39
+ obj = eval("Evernotable::Command::#{cmd.capitalize}").new(arguments, env)
40
40
  obj.send(method)
41
41
  end
42
42
  rescue CommandFailed => ex
@@ -7,15 +7,16 @@ class Evernotable::Command::Base
7
7
 
8
8
  include Evernotable::Utilities
9
9
 
10
- def initialize(params=[])
10
+ def initialize(params=[], env=:sandbox)
11
11
  @config = YAML.load(File.read('lib/evernotable_config.yml'))
12
+ @env = env.to_s
12
13
  @args = params.map {|p| p.strip}
13
14
  @highline = HighLine.new
14
15
  end
15
16
 
16
17
  def authenticate_user(user=[])
17
18
  user = read_from_file(credentials_file).split('/') if user.empty?
18
- @user_client = Evernotable::Client::User.new({:user => user.first, :password => user.last, :config => @config})
19
+ @user_client = Evernotable::Client::User.new({:user => user.first, :password => user.last, :config => @config, :env => @env})
19
20
  begin
20
21
  @user_client.authenticate
21
22
  rescue Evernotable::Client::ClientException => ex
@@ -25,7 +26,7 @@ class Evernotable::Command::Base
25
26
 
26
27
  def note_client
27
28
  authenticate_user
28
- Evernotable::Client::Note.new({:user_shard => @user_client.current_user.shardId, :client_token => @user_client.client_token, :config => @config})
29
+ Evernotable::Client::Note.new({:user_shard => @user_client.current_user.shardId, :client_token => @user_client.client_token, :config => @config, :env => @env})
29
30
  end
30
31
 
31
32
  def invoke_client
@@ -4,22 +4,34 @@ class Evernotable::Command::Task < Evernotable::Command::Base
4
4
 
5
5
  def add
6
6
  invoke_client do
7
- note_client.add_note(@args.first)
8
- display 'Done.'
7
+ unless @args.empty?
8
+ note_client.add_note(@args.first)
9
+ display 'Done.'
10
+ else
11
+ display 'Nothing to add!'
12
+ end
9
13
  end
10
14
  end
11
15
 
12
16
  def list
13
17
  invoke_client do
14
18
  notes = note_client.list_notes
15
- notes.collect{|n| n.title}.each_with_index{|n, i| display "#{i+1}. #{n}"}
19
+ if notes.empty?
20
+ display 'No tasks!'
21
+ else
22
+ notes.collect{|n| n.title}.each_with_index{|n, i| display "#{i+1}. #{n}"}
23
+ end
16
24
  end
17
25
  end
18
26
 
19
27
  def remove
20
28
  invoke_client do
21
- note_client.remove_note(@args.first)
22
- display 'Done.'
29
+ unless @args.empty?
30
+ note_client.remove_note(@args.first)
31
+ display 'Done.'
32
+ else
33
+ display 'Nothing to remove!'
34
+ end
23
35
  end
24
36
  end
25
37
 
@@ -1,3 +1,3 @@
1
1
  module Evernotable
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -6,7 +6,7 @@ user_api:
6
6
  production: https://www.evernote.com/edam/user
7
7
  note_api:
8
8
  sandbox: http://sandbox.evernote.com/edam/note/
9
- production: http://www.evernote.com/edam/note/
9
+ production: https://www.evernote.com/edam/note/
10
10
  notebook:
11
11
  name: evernotable
12
12
  credentials_file:
@@ -10,8 +10,6 @@ describe Evernotable::Client::Base do
10
10
  base_client = Evernotable::Client::Base.new({:config => @config})
11
11
  base_client.should_not be_nil
12
12
  base_client.current_user.should be_nil
13
- base_client.config.should_not be_nil
14
- base_client.config["api_credentials"]["consumer_key"].should == 'kswamin'
15
- base_client.config["api_credentials"]["consumer_secret"].should == 'dbd87f40e8507b16'
13
+ base_client.client_token.should be_nil
16
14
  end
17
15
  end
@@ -5,15 +5,14 @@ describe Evernotable::Client::Note do
5
5
 
6
6
  before(:all) do
7
7
  @config = YAML.load(File.read('lib/evernotable_config.yml'))
8
- @user_client = Evernotable::Client::User.new({:user => 'kswamin', :password => 'dumbass', :config => @config})
8
+ @user_client = Evernotable::Client::User.new({:user => 'kswamin', :password => 'dumbass', :config => @config, :env => 'sandbox'})
9
9
  @user_client.authenticate
10
- @note_client = Evernotable::Client::Note.new({:user_shard => @user_client.current_user.shardId, :client_token => @user_client.client_token, :config => @config})
10
+ @note_client = Evernotable::Client::Note.new({:user_shard => @user_client.current_user.shardId, :client_token => @user_client.client_token, :config => @config, :env => 'sandbox'})
11
11
  #@note_client.expunge_notebook #TODO: doesn't work for some weird reason, investigate
12
12
  end
13
13
 
14
14
  it 'should appropriately be initialized' do
15
15
  @note_client.should_not be_nil
16
- @note_client.config.should_not be_nil
17
16
  @note_client.notebook_guid.should be_nil
18
17
  end
19
18
 
@@ -8,21 +8,20 @@ describe Evernotable::Client::User do
8
8
  end
9
9
 
10
10
  it 'should appropriately be initialized' do
11
- user_client = Evernotable::Client::User.new({:user => 'kswamin', :password => 'dumbass', :config => @config})
11
+ user_client = Evernotable::Client::User.new({:user => 'kswamin', :password => 'dumbass', :config => @config, :env => 'sandbox'})
12
12
  user_client.should_not be_nil
13
- user_client.config.should_not be_nil
14
13
  end
15
14
 
16
15
  describe '#authenticate' do
17
16
  it 'should authenticate the user successfully' do
18
- user_client = Evernotable::Client::User.new({:user => 'kswamin', :password => 'dumbass', :config => @config})
17
+ user_client = Evernotable::Client::User.new({:user => 'kswamin', :password => 'dumbass', :config => @config, :env => 'sandbox'})
19
18
  user_client.should_not be_nil
20
19
  user_client.authenticate
21
20
  user_client.current_user.should_not be_nil
22
21
  user_client.client_token.should_not be_nil
23
22
  end
24
23
  it 'should not authenticate the user successfully' do
25
- user_client = Evernotable::Client::User.new({:user => 'kswamin', :password => 'thewrongpassword', :config => @config})
24
+ user_client = Evernotable::Client::User.new({:user => 'kswamin', :password => 'thewrongpassword', :config => @config, :env => 'sandbox'})
26
25
  user_client.should_not be_nil
27
26
  lambda { user_client.authenticate }.should raise_error(Evernotable::Client::ClientException)
28
27
  user_client.current_user.should be_nil
@@ -32,7 +31,7 @@ describe Evernotable::Client::User do
32
31
 
33
32
  describe '#refresh authentication' do
34
33
  before(:all) do
35
- @user_client = Evernotable::Client::User.new({:user => 'kswamin', :password => 'dumbass', :config => @config})
34
+ @user_client = Evernotable::Client::User.new({:user => 'kswamin', :password => 'dumbass', :config => @config, :env => 'sandbox'})
36
35
  @user_client.authenticate
37
36
  end
38
37
  it 'should refresh the authentication for the user successfully' do
@@ -46,7 +45,7 @@ describe Evernotable::Client::User do
46
45
 
47
46
  describe '#check valid version' do
48
47
  before(:all) do
49
- @user_client = Evernotable::Client::User.new({:user => 'kswamin', :password => 'dumbass', :config => @config})
48
+ @user_client = Evernotable::Client::User.new({:user => 'kswamin', :password => 'dumbass', :config => @config, :env => 'sandbox'})
50
49
  end
51
50
  it 'should check if the version is valid' do
52
51
  @user_client.valid_version?.should be_true
@@ -2,6 +2,7 @@ require 'spec_helper'
2
2
  require 'evernotable/command/task'
3
3
 
4
4
  describe Evernotable::Command::Task do
5
+
5
6
  before(:all) do
6
7
  @task_command = Evernotable::Command::Task.new(['dude!'])
7
8
  end
@@ -12,26 +13,53 @@ describe Evernotable::Command::Task do
12
13
  lambda {@task_command.send(:help)}.should_not raise_error(Evernotable::Command::CommandFailed)
13
14
  end
14
15
 
15
- it 'should add note successfully' do
16
- mock_note_client = mock('Evernotable::Client::Note')
17
- mock_note_client.stub!(:add_note).and_return(true)
18
- @task_command.stub!(:note_client).and_return(mock_note_client)
19
- STDOUT.should_receive(:puts).exactly(1).times.with('Done.')
20
- lambda {@task_command.add}.should_not raise_error(Evernotable::Command::CommandFailed)
16
+ describe '#add note' do
17
+ it 'should add note successfully' do
18
+ mock_note_client = mock('Evernotable::Client::Note')
19
+ mock_note_client.stub!(:add_note).and_return(true)
20
+ @task_command.stub!(:note_client).and_return(mock_note_client)
21
+ STDOUT.should_receive(:puts).exactly(1).times.with('Done.')
22
+ lambda {@task_command.add}.should_not raise_error(Evernotable::Command::CommandFailed)
23
+ end
24
+
25
+ it 'should not add when nothing is supplied' do
26
+ @task_command = Evernotable::Command::Task.new([])
27
+ STDOUT.should_receive(:puts).exactly(1).times.with('Nothing to add!')
28
+ lambda {@task_command.add}.should_not raise_error(Evernotable::Command::CommandFailed)
29
+ end
21
30
  end
22
-
23
- it 'should list notes successfully' do
24
- mock_note_client = mock('Evernotable::Client::Note')
25
- mock_note_client.stub!(:list_notes).and_return(['note1', 'note2'])
26
- @task_command.stub!(:note_client).and_return(mock_note_client)
27
- lambda {@task_command.list}.should_not raise_error(Evernotable::Command::CommandFailed)
31
+
32
+ describe '#remove note' do
33
+ it 'should remove note successfully' do
34
+ mock_note_client = mock('Evernotable::Client::Note')
35
+ mock_note_client.stub!(:remove_note).and_return(true)
36
+ @task_command.stub!(:note_client).and_return(mock_note_client)
37
+ STDOUT.should_receive(:puts).exactly(1).times.with('Done.')
38
+ lambda {@task_command.remove}.should_not raise_error(Evernotable::Command::CommandFailed)
39
+ end
40
+
41
+ it 'should not remove when nothing is supplied' do
42
+ @task_command = Evernotable::Command::Task.new([])
43
+ STDOUT.should_receive(:puts).exactly(1).times.with('Nothing to remove!')
44
+ lambda {@task_command.remove}.should_not raise_error(Evernotable::Command::CommandFailed)
45
+ end
28
46
  end
29
47
 
30
- it 'should remove note successfully' do
31
- mock_note_client = mock('Evernotable::Client::Note')
32
- mock_note_client.stub!(:remove_note).and_return(true)
33
- @task_command.stub!(:note_client).and_return(mock_note_client)
34
- STDOUT.should_receive(:puts).exactly(1).times.with('Done.')
35
- lambda {@task_command.remove}.should_not raise_error(Evernotable::Command::CommandFailed)
48
+ describe '#list notes' do
49
+ it 'should not list notes when there is nothing ' do
50
+ mock_note_client = mock('Evernotable::Client::Note')
51
+ mock_note_client.stub!(:list_notes).and_return([])
52
+ @task_command.stub!(:note_client).and_return(mock_note_client)
53
+ STDOUT.should_receive(:puts).exactly(1).times.with('No tasks!')
54
+ lambda {@task_command.list}.should_not raise_error(Evernotable::Command::CommandFailed)
55
+ end
56
+
57
+ it 'should list notes successfully' do
58
+ mock_note_client = mock('Evernotable::Client::Note')
59
+ mock_note_client.stub!(:list_notes).and_return([StubNote.new('note1'), StubNote.new('note2')])
60
+ @task_command.stub!(:note_client).and_return(mock_note_client)
61
+ STDOUT.should_receive(:puts).exactly(2).times.with(any_args())
62
+ lambda {@task_command.list}.should_not raise_error(Evernotable::Command::CommandFailed)
63
+ end
36
64
  end
37
65
  end
@@ -13,4 +13,11 @@ end
13
13
  RSpec.configure do |config|
14
14
  config.color_enabled = true
15
15
  config.include DisplayMatcher
16
+ end
17
+
18
+ class StubNote
19
+ attr_reader :title
20
+ def initialize(title)
21
+ @title = title
22
+ end
16
23
  end
@@ -3,6 +3,6 @@ require "evernotable/version"
3
3
 
4
4
  describe Evernotable do
5
5
  it 'returns the correct version of the gem' do
6
- Evernotable::VERSION.should == '1.0.0'
6
+ Evernotable::VERSION.should == '1.0.1'
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evernotable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-29 00:00:00.000000000Z
12
+ date: 2012-03-01 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thrift
16
- requirement: &70349991702640 !ruby/object:Gem::Requirement
16
+ requirement: &70142078492420 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70349991702640
24
+ version_requirements: *70142078492420
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: thrift_client
27
- requirement: &70349991702220 !ruby/object:Gem::Requirement
27
+ requirement: &70142078492000 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70349991702220
35
+ version_requirements: *70142078492000
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: evernote
38
- requirement: &70349991701800 !ruby/object:Gem::Requirement
38
+ requirement: &70142078491580 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70349991701800
46
+ version_requirements: *70142078491580
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: highline
49
- requirement: &70349991701380 !ruby/object:Gem::Requirement
49
+ requirement: &70142078491160 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70349991701380
57
+ version_requirements: *70142078491160
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: encrypted_strings
60
- requirement: &70349991700960 !ruby/object:Gem::Requirement
60
+ requirement: &70142078490740 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70349991700960
68
+ version_requirements: *70142078490740
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
- requirement: &70349991700540 !ruby/object:Gem::Requirement
71
+ requirement: &70142078490320 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70349991700540
79
+ version_requirements: *70142078490320
80
80
  description: A simple commandline task manager that uses Evernote note store. This
81
81
  automatically creates a new distinct Evernote notebook for persistance of these
82
82
  task notes.
@@ -156,3 +156,4 @@ test_files:
156
156
  - spec/spec_helper.rb
157
157
  - spec/utilities_spec.rb
158
158
  - spec/version_spec.rb
159
+ has_rdoc: