summaryrefslogtreecommitdiffstats
path: root/lib/evernote
diff options
context:
space:
mode:
Diffstat (limited to 'lib/evernote')
-rw-r--r--lib/evernote/client.rb5
-rw-r--r--lib/evernote/user_store.rb34
2 files changed, 25 insertions, 14 deletions
diff --git a/lib/evernote/client.rb b/lib/evernote/client.rb
index 1522d59..6293f17 100644
--- a/lib/evernote/client.rb
+++ b/lib/evernote/client.rb
@@ -1,6 +1,5 @@
module Evernote
class Client
- attr_reader :client
THRIFT_DEFAULTS = {
:transport => Thrift::HTTPClientTransport
@@ -10,5 +9,9 @@ module Evernote
thrift_opts = THRIFT_DEFAULTS.merge(thrift_client_options)
@client = ThriftClient.new(klass, url, thrift_opts)
end
+
+ def method_missing(name, *args, &block)
+ @client.send(name, *args, &block)
+ end
end
end
diff --git a/lib/evernote/user_store.rb b/lib/evernote/user_store.rb
index b9ccc17..b8b6102 100644
--- a/lib/evernote/user_store.rb
+++ b/lib/evernote/user_store.rb
@@ -3,22 +3,34 @@ module Evernote
VersionOutOfDate = Class.new(StandardError)
class UserStore
- attr_reader :client
-
- 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
@client = Evernote::Client.new(Evernote::EDAM::UserStore::UserStore::Client, uri, thrift_client_options)
-
+
validate_version
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
def validate_version
raise VersionOutOfDate, "The vendored Evernote client code is out of date and needs to be regenerated" unless version_valid?
@@ -27,9 +39,5 @@ module Evernote
def version_valid?
checkVersion("Ruby EDAMTest", Evernote::EDAM::UserStore::EDAM_VERSION_MAJOR, Evernote::EDAM::UserStore::EDAM_VERSION_MINOR)
end
-
- def method_missing(name, *args, &block)
- @client.client.send(name, *args, &block)
- end
end
end