Class: Evernotable::Command::Base

Inherits:
Object
  • Object
show all
Includes:
Utilities
Defined in:
lib/evernotable/command/base.rb

Direct Known Subclasses

Auth, Help, Task

Instance Method Summary collapse

Methods included from Utilities

#display, #encrypt_key, #error, #format_with_bang, #output_with_bang, #read_from_file, #wrap_enml, #write_to_file

Constructor Details

#initialize(params = [], env = :sandbox) ⇒ Base

Returns a new instance of Base.



10
11
12
13
14
15
# File 'lib/evernotable/command/base.rb', line 10

def initialize(params=[], env=:sandbox)
  @config = YAML.load(File.read('lib/evernotable_config.yml'))
  @env = env.to_s
  @args = params.map {|p| p.strip}
  @highline = HighLine.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



40
41
# File 'lib/evernotable/command/base.rb', line 40

def method_missing(method_name, *args)
end

Instance Method Details

#authenticate_user(user = []) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/evernotable/command/base.rb', line 17

def authenticate_user(user=[])
  user = read_from_file(credentials_file).split('/') if user.empty?
  @user_client = Evernotable::Client::User.new({:user => user.first, :password => user.last, :config => @config, :env => @env})
  begin
    @user_client.authenticate
  rescue Evernotable::Client::ClientException => ex
    raise Evernotable::Command::CommandFailed, "Invalid Evernote credentials."
  end
end

#invoke_clientObject



32
33
34
35
36
37
38
# File 'lib/evernotable/command/base.rb', line 32

def invoke_client
  begin
    yield
  rescue Evernotable::Client::ClientException => ex
    raise Evernotable::Command::CommandFailed, "Oops. That didn't work."
  end
end

#note_clientObject



27
28
29
30
# File 'lib/evernotable/command/base.rb', line 27

def note_client
  authenticate_user
  Evernotable::Client::Note.new({:user_shard => @user_client.current_user.shardId, :client_token => @user_client.client_token, :config => @config, :env => @env})
end