diff options
| -rw-r--r-- | lib/evernote/client.rb | 4 | ||||
| -rw-r--r-- | lib/evernote/user_store.rb | 13 | ||||
| -rw-r--r-- | spec/evernote/user_store_spec.rb | 20 |
3 files changed, 31 insertions, 6 deletions
diff --git a/lib/evernote/client.rb b/lib/evernote/client.rb index 80eb484..6293f17 100644 --- a/lib/evernote/client.rb +++ b/lib/evernote/client.rb @@ -1,6 +1,6 @@ module Evernote class Client - + THRIFT_DEFAULTS = { :transport => Thrift::HTTPClientTransport }.freeze @@ -14,4 +14,4 @@ module Evernote @client.send(name, *args, &block) end end -end
\ No newline at end of file +end diff --git a/lib/evernote/user_store.rb b/lib/evernote/user_store.rb index bbbdfcb..b8b6102 100644 --- a/lib/evernote/user_store.rb +++ b/lib/evernote/user_store.rb @@ -1,4 +1,7 @@ module Evernote + + VersionOutOfDate = Class.new(StandardError) + class UserStore AuthenticationFailure = Class.new(StandardError) @@ -15,6 +18,8 @@ module Evernote end @client = Evernote::Client.new(Evernote::EDAM::UserStore::UserStore::Client, uri, thrift_client_options) + + validate_version end def authenticate @@ -26,5 +31,13 @@ module Evernote 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? + end + + def version_valid? + checkVersion("Ruby EDAMTest", Evernote::EDAM::UserStore::EDAM_VERSION_MAJOR, Evernote::EDAM::UserStore::EDAM_VERSION_MINOR) + end end end diff --git a/spec/evernote/user_store_spec.rb b/spec/evernote/user_store_spec.rb index 04ec737..dcc33cd 100644 --- a/spec/evernote/user_store_spec.rb +++ b/spec/evernote/user_store_spec.rb @@ -6,14 +6,23 @@ describe "Evernote::UserStore" do @env = :sandbox end - it "initializes an Evernote::Client" do - Evernote::Client.should_receive(:new).with(Evernote::EDAM::UserStore::UserStore::Client, "https://sandbox.evernote.com/edam/user", {}) - + it "initializes an Evernote::Client and validate the client code version" do + client = mock("Evernote::Client", :checkVersion => true) + Evernote::Client.should_receive(:new).with(Evernote::EDAM::UserStore::UserStore::Client, "https://sandbox.evernote.com/edam/user", {}).and_return(client) + Evernote::UserStore.new("https://sandbox.evernote.com/edam/user", @auth_file, @env) end + + it "should raise an error on init if the version is not up to date" do + Evernote::Client.stub!(:new => mock("Evernote::Client", :checkVersion => false)) + + lambda { + Evernote::UserStore.new("https://sandbox.evernote.com/edam/user", @auth_file, @env) + }.should raise_error(Evernote::VersionOutOfDate, "The vendored Evernote client code is out of date and needs to be regenerated") + end %w(consumer_key consumer_secret username password).each do |credential| - it "raises an exception if no #{credential} is set" do + it "raises an exception if no #{credential} is set" do lambda { Evernote::UserStore.new("https://sandbox.evernote.com/edam/user", @auth_file, :invalid) }.should raise_error(ArgumentError, "'consumer_key', 'consumer_secret', 'username' and 'password' are required") @@ -21,6 +30,7 @@ describe "Evernote::UserStore" do end it "should authenticate" do + Evernote::Client.stub!(:new => mock("Evernote::Client", :checkVersion => true)) user_store = Evernote::UserStore.new("https://sandbox.evernote.com/edam/user", @auth_file, @env) user_store.instance_variable_get(:@client).should_receive(:authenticate).with("cgs", "password", "12345", "ABCDE").and_return(nil) @@ -28,6 +38,7 @@ describe "Evernote::UserStore" do end it "should wrap authentication failure" do + Evernote::Client.stub!(:new => mock("Evernote::Client", :checkVersion => true)) user_store = Evernote::UserStore.new("https://sandbox.evernote.com/edam/user", @auth_file, @env) user_store.instance_variable_get(:@client).should_receive(:authenticate).and_raise(Evernote::EDAM::Error::EDAMUserException) @@ -37,6 +48,7 @@ describe "Evernote::UserStore" do end it "should proxy methods" do + Evernote::Client.stub!(:new => mock("Evernote::Client", :checkVersion => true)) user_store = Evernote::UserStore.new("https://sandbox.evernote.com/edam/user", @auth_file, @env) user_store.instance_variable_get(:@client).should_receive(:foobar).and_return(nil) |
