Class: Evernote::UserStore

Inherits:
Object
  • Object
show all
Defined in:
lib/evernote/user_store.rb

Constant Summary collapse

AuthenticationFailure =
Class.new(StandardError)

Instance Method Summary collapse

Constructor Details

#initialize(uri, auth_file, auth_env, thrift_client_options = {}) ⇒ UserStore

Returns a new instance of UserStore.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/evernote/user_store.rb', line 8

def initialize(uri, auth_file, auth_env, thrift_client_options = {})
  credentials = YAML.load_file(auth_file)[auth_env.to_s]
  
  @consumer_key = credentials["consumer_key"]
  @consumer_secret = credentials["consumer_secret"]
  @username = credentials["username"]
  @password = credentials["password"]

  unless @consumer_key && @consumer_secret && @username && @password
    raise ArgumentError, "'consumer_key', 'consumer_secret', 'username' and 'password' are required"
  end

  @client = Evernote::Client.new(Evernote::EDAM::UserStore::UserStore::Client, uri, thrift_client_options)
  
  validate_version
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



31
32
33
# File 'lib/evernote/user_store.rb', line 31

def method_missing(name, *args, &block)
  @client.send(name, *args, &block)
end

Instance Method Details

#authenticateObject



25
26
27
28
29
# File 'lib/evernote/user_store.rb', line 25

def authenticate
  @client.authenticate(@username, @password, @consumer_key, @consumer_secret)
rescue Evernote::EDAM::Error::EDAMUserException
  raise AuthenticationFailure
end

#validate_versionObject

Raises:



35
36
37
# File 'lib/evernote/user_store.rb', line 35

def validate_version
  raise VersionOutOfDate, "The vendored Evernote client code is out of date and needs to be regenerated" unless version_valid?
end

#version_valid?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/evernote/user_store.rb', line 39

def version_valid?
  checkVersion("Ruby EDAMTest", Evernote::EDAM::UserStore::EDAM_VERSION_MAJOR, Evernote::EDAM::UserStore::EDAM_VERSION_MINOR)
end