summaryrefslogtreecommitdiffstats
path: root/lib/evernote
diff options
context:
space:
mode:
Diffstat (limited to 'lib/evernote')
-rw-r--r--lib/evernote/client.rb6
-rw-r--r--lib/evernote/user_store.rb28
2 files changed, 26 insertions, 8 deletions
diff --git a/lib/evernote/client.rb b/lib/evernote/client.rb
index 1141087..80eb484 100644
--- a/lib/evernote/client.rb
+++ b/lib/evernote/client.rb
@@ -7,7 +7,11 @@ module Evernote
def initialize(klass, url, thrift_client_options = {})
thrift_opts = THRIFT_DEFAULTS.merge(thrift_client_options)
- ThriftClient.new(klass, url, thrift_opts)
+ @client = ThriftClient.new(klass, url, thrift_opts)
+ end
+
+ def method_missing(name, *args, &block)
+ @client.send(name, *args, &block)
end
end
end \ No newline at end of file
diff --git a/lib/evernote/user_store.rb b/lib/evernote/user_store.rb
index 1be8cb6..bbbdfcb 100644
--- a/lib/evernote/user_store.rb
+++ b/lib/evernote/user_store.rb
@@ -1,16 +1,30 @@
module Evernote
class UserStore
- def initialize(uri, opts = {}, thrift_client_options = {})
- @consumer_key = opts[:consumer_key]
- @consumer_secret = opts[:consumer_secret]
- @username = opts[:username]
- @password = opts[:password]
+ AuthenticationFailure = Class.new(StandardError)
+
+ 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"
+ raise ArgumentError, "'consumer_key', 'consumer_secret', 'username' and 'password' are required"
end
- Evernote::Client.new(Evernote::EDAM::UserStore::UserStore::Client, uri, thrift_client_options)
+ @client = Evernote::Client.new(Evernote::EDAM::UserStore::UserStore::Client, uri, thrift_client_options)
+ end
+
+ def authenticate
+ @client.authenticate(@username, @password, @consumer_key, @consumer_secret)
+ rescue Evernote::EDAM::Error::EDAMUserException
+ raise AuthenticationFailure
+ end
+
+ def method_missing(name, *args, &block)
+ @client.send(name, *args, &block)
end
end
end