evernote 0.1.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.mkd +42 -4
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/evernote.gemspec +15 -18
- data/lib/evernote.rb +3 -0
- data/lib/evernote/client.rb +17 -0
- data/lib/evernote/note_store.rb +11 -0
- data/lib/evernote/user_store.rb +43 -0
- data/spec/evernote/auth.yaml +11 -0
- data/spec/evernote/client_spec.rb +20 -0
- data/spec/evernote/note_store_spec.rb +10 -0
- data/spec/evernote/user_store_spec.rb +57 -0
- metadata +12 -4
- data/spec/evernote_spec.rb +0 -7
data/README.mkd
CHANGED
@@ -1,10 +1,48 @@
|
|
1
1
|
# evernote #
|
2
|
-
This gem is a high level wrapper around Evernote's Thrift-generated ruby code. It
|
2
|
+
This gem is a high level wrapper around Evernote's Thrift-generated ruby code. It bundles up Evernote's thrift-generated code and creates some simple wrapper classes.
|
3
3
|
|
4
|
-
|
4
|
+
# usage #
|
5
|
+
Create a config yml:
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
sandbox:
|
8
|
+
username: user
|
9
|
+
password: password
|
10
|
+
consumer_key: key
|
11
|
+
consumer_secret: secret
|
12
|
+
|
13
|
+
production:
|
14
|
+
username: user
|
15
|
+
password: password
|
16
|
+
consumer_key: key
|
17
|
+
consumer_secret: secret
|
18
|
+
|
19
|
+
Here's an example using the sandbox key:
|
20
|
+
|
21
|
+
require 'evernote'
|
22
|
+
|
23
|
+
user_store_url = "https://sandbox.evernote.com/edam/user"
|
24
|
+
config = File.dirname(__FILE__) + "/config.yml"
|
25
|
+
user_store = Evernote::UserStore.new(user_store_url, config, "sandbox")
|
26
|
+
|
27
|
+
auth_result = user_store.authenticate
|
28
|
+
user = auth_result.user
|
29
|
+
auth_token = auth_result.authenticationToken
|
30
|
+
puts "Authentication was successful for #{user.username}"
|
31
|
+
puts "Authentication token = #{auth_token}"
|
32
|
+
|
33
|
+
Once you've authenticated, you could do something like list all of your notebooks:
|
34
|
+
|
35
|
+
note_store_url = "http://sandbox.evernote.com/edam/note/#{user.shardId}"
|
36
|
+
note_store = Evernote::NoteStore.new(note_store_url)
|
37
|
+
|
38
|
+
notebooks = note_store.listNotebooks(auth_token)
|
39
|
+
puts "Found #{notebooks.size} notebooks:"
|
40
|
+
default_notebook = notebooks[0]
|
41
|
+
notebooks.each { |notebook| puts " * #{notebook.name}"}
|
42
|
+
|
43
|
+
The evernote API can be viewed at http://www.evernote.com/about/developer/api/ref/
|
44
|
+
|
45
|
+
If the vendored code is out of date and you get an error indicating so, feel free to create an issue at http://github.com/cgs/evernote/issues
|
8
46
|
|
9
47
|
## Copyright ##
|
10
48
|
Copyright (c) 2010 Chris Sepic. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -9,7 +9,7 @@ begin
|
|
9
9
|
gem.email = "chris.sepic@gmail.com"
|
10
10
|
gem.homepage = "http://github.com/cgs/evernote"
|
11
11
|
gem.authors = ["Chris Sepic"]
|
12
|
-
gem.files.include %w{vendor/**/*}
|
12
|
+
gem.files.include %w{vendor/**/* spec/evernote/auth.yaml}
|
13
13
|
gem.add_dependency("thrift_client")
|
14
14
|
gem.add_development_dependency "rspec"
|
15
15
|
gem.add_development_dependency "yard"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.8.0
|
data/evernote.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE
|
3
|
-
# Instead, edit Jeweler::Tasks in
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in rakefile, and run the gemspec command
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{evernote}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.8.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Chris Sepic"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-03-19}
|
13
13
|
s.email = %q{chris.sepic@gmail.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE",
|
@@ -24,32 +24,26 @@ Gem::Specification.new do |s|
|
|
24
24
|
"VERSION",
|
25
25
|
"evernote.gemspec",
|
26
26
|
"lib/evernote.rb",
|
27
|
-
"
|
27
|
+
"lib/evernote/client.rb",
|
28
|
+
"lib/evernote/note_store.rb",
|
29
|
+
"lib/evernote/user_store.rb",
|
30
|
+
"spec/evernote/auth.yaml",
|
31
|
+
"spec/evernote/client_spec.rb",
|
32
|
+
"spec/evernote/note_store_spec.rb",
|
33
|
+
"spec/evernote/user_store_spec.rb",
|
28
34
|
"spec/spec.opts",
|
29
35
|
"spec/spec_helper.rb",
|
30
36
|
"vendor/gen-rb/evernote.rb",
|
31
|
-
"vendor/gen-rb/evernote.rb",
|
32
|
-
"vendor/gen-rb/evernote/edam/errors_types.rb",
|
33
37
|
"vendor/gen-rb/evernote/edam/errors_types.rb",
|
34
38
|
"vendor/gen-rb/evernote/edam/limits_constants.rb",
|
35
|
-
"vendor/gen-rb/evernote/edam/limits_constants.rb",
|
36
39
|
"vendor/gen-rb/evernote/edam/limits_types.rb",
|
37
|
-
"vendor/gen-rb/evernote/edam/limits_types.rb",
|
38
|
-
"vendor/gen-rb/evernote/edam/note_store.rb",
|
39
40
|
"vendor/gen-rb/evernote/edam/note_store.rb",
|
40
41
|
"vendor/gen-rb/evernote/edam/note_store_constants.rb",
|
41
|
-
"vendor/gen-rb/evernote/edam/note_store_constants.rb",
|
42
42
|
"vendor/gen-rb/evernote/edam/note_store_types.rb",
|
43
|
-
"vendor/gen-rb/evernote/edam/note_store_types.rb",
|
44
|
-
"vendor/gen-rb/evernote/edam/types_constants.rb",
|
45
43
|
"vendor/gen-rb/evernote/edam/types_constants.rb",
|
46
44
|
"vendor/gen-rb/evernote/edam/types_types.rb",
|
47
|
-
"vendor/gen-rb/evernote/edam/types_types.rb",
|
48
45
|
"vendor/gen-rb/evernote/edam/user_store.rb",
|
49
|
-
"vendor/gen-rb/evernote/edam/user_store.rb",
|
50
|
-
"vendor/gen-rb/evernote/edam/user_store_constants.rb",
|
51
46
|
"vendor/gen-rb/evernote/edam/user_store_constants.rb",
|
52
|
-
"vendor/gen-rb/evernote/edam/user_store_types.rb",
|
53
47
|
"vendor/gen-rb/evernote/edam/user_store_types.rb"
|
54
48
|
]
|
55
49
|
s.homepage = %q{http://github.com/cgs/evernote}
|
@@ -58,7 +52,9 @@ Gem::Specification.new do |s|
|
|
58
52
|
s.rubygems_version = %q{1.3.5}
|
59
53
|
s.summary = %q{High level wrapper for the Evernote API}
|
60
54
|
s.test_files = [
|
61
|
-
"spec/
|
55
|
+
"spec/evernote/client_spec.rb",
|
56
|
+
"spec/evernote/note_store_spec.rb",
|
57
|
+
"spec/evernote/user_store_spec.rb",
|
62
58
|
"spec/spec_helper.rb"
|
63
59
|
]
|
64
60
|
|
@@ -81,3 +77,4 @@ Gem::Specification.new do |s|
|
|
81
77
|
s.add_dependency(%q<yard>, [">= 0"])
|
82
78
|
end
|
83
79
|
end
|
80
|
+
|
data/lib/evernote.rb
CHANGED
@@ -5,3 +5,6 @@ gen_rb_path = File.expand_path(File.dirname(__FILE__) + "/../vendor/gen-rb")
|
|
5
5
|
$LOAD_PATH.unshift gen_rb_path
|
6
6
|
$LOAD_PATH.unshift "#{gen_rb_path}/evernote/edam"
|
7
7
|
require "#{gen_rb_path}/evernote"
|
8
|
+
require "evernote/client"
|
9
|
+
require "evernote/user_store"
|
10
|
+
require "evernote/note_store"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Evernote
|
2
|
+
class Client
|
3
|
+
|
4
|
+
THRIFT_DEFAULTS = {
|
5
|
+
:transport => Thrift::HTTPClientTransport
|
6
|
+
}.freeze
|
7
|
+
|
8
|
+
def initialize(klass, url, thrift_client_options = {})
|
9
|
+
thrift_opts = THRIFT_DEFAULTS.merge(thrift_client_options)
|
10
|
+
@client = ThriftClient.new(klass, url, thrift_opts)
|
11
|
+
end
|
12
|
+
|
13
|
+
def method_missing(name, *args, &block)
|
14
|
+
@client.send(name, *args, &block)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Evernote
|
2
|
+
class NoteStore
|
3
|
+
def initialize(uri, thrift_client_options = {})
|
4
|
+
@client = Evernote::Client.new(Evernote::EDAM::NoteStore::NoteStore::Client, uri, thrift_client_options)
|
5
|
+
end
|
6
|
+
|
7
|
+
def method_missing(name, *args, &block)
|
8
|
+
@client.send(name, *args, &block)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Evernote
|
2
|
+
|
3
|
+
VersionOutOfDate = Class.new(StandardError)
|
4
|
+
|
5
|
+
class UserStore
|
6
|
+
AuthenticationFailure = Class.new(StandardError)
|
7
|
+
|
8
|
+
def initialize(uri, auth_file, auth_env, thrift_client_options = {})
|
9
|
+
credentials = YAML.load_file(auth_file)[auth_env.to_s]
|
10
|
+
|
11
|
+
@consumer_key = credentials["consumer_key"]
|
12
|
+
@consumer_secret = credentials["consumer_secret"]
|
13
|
+
@username = credentials["username"]
|
14
|
+
@password = credentials["password"]
|
15
|
+
|
16
|
+
unless @consumer_key && @consumer_secret && @username && @password
|
17
|
+
raise ArgumentError, "'consumer_key', 'consumer_secret', 'username' and 'password' are required"
|
18
|
+
end
|
19
|
+
|
20
|
+
@client = Evernote::Client.new(Evernote::EDAM::UserStore::UserStore::Client, uri, thrift_client_options)
|
21
|
+
|
22
|
+
validate_version
|
23
|
+
end
|
24
|
+
|
25
|
+
def authenticate
|
26
|
+
@client.authenticate(@username, @password, @consumer_key, @consumer_secret)
|
27
|
+
rescue Evernote::EDAM::Error::EDAMUserException
|
28
|
+
raise AuthenticationFailure
|
29
|
+
end
|
30
|
+
|
31
|
+
def method_missing(name, *args, &block)
|
32
|
+
@client.send(name, *args, &block)
|
33
|
+
end
|
34
|
+
|
35
|
+
def validate_version
|
36
|
+
raise VersionOutOfDate, "The vendored Evernote client code is out of date and needs to be regenerated" unless version_valid?
|
37
|
+
end
|
38
|
+
|
39
|
+
def version_valid?
|
40
|
+
checkVersion("Ruby EDAMTest", Evernote::EDAM::UserStore::EDAM_VERSION_MAJOR, Evernote::EDAM::UserStore::EDAM_VERSION_MINOR)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe "Evernote::Client" do
|
4
|
+
it "initializes a ThriftClient instance that uses HTTP transport" do
|
5
|
+
klass = mock("SomeInternalEvernoteClass")
|
6
|
+
opts = { :transport => Thrift::HTTPClientTransport }
|
7
|
+
ThriftClient.should_receive(:new).with(klass, "https://www.example.com", opts)
|
8
|
+
|
9
|
+
Evernote::Client.new(klass, "https://www.example.com")
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should proxy methods" do
|
13
|
+
thrift_client = mock("ThriftClient")
|
14
|
+
ThriftClient.stub!(:new => thrift_client)
|
15
|
+
thrift_client.should_receive(:foobar)
|
16
|
+
|
17
|
+
client = Evernote::Client.new(mock("SomeInternalEvernoteClass"), "https://www.example.com")
|
18
|
+
client.foobar
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe "Evernote::NoteStore" do
|
4
|
+
it "should proxy methods" do
|
5
|
+
note_store = Evernote::NoteStore.new("http://sandbox.evernote.com/edam/note/")
|
6
|
+
note_store.instance_variable_get(:@client).should_receive(:foobar).and_return(nil)
|
7
|
+
|
8
|
+
note_store.foobar
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe "Evernote::UserStore" do
|
4
|
+
before(:each) do
|
5
|
+
@auth_file = File.dirname(__FILE__) + "/auth.yaml"
|
6
|
+
@env = :sandbox
|
7
|
+
end
|
8
|
+
|
9
|
+
it "initializes an Evernote::Client and validate the client code version" do
|
10
|
+
client = mock("Evernote::Client", :checkVersion => true)
|
11
|
+
Evernote::Client.should_receive(:new).with(Evernote::EDAM::UserStore::UserStore::Client, "https://sandbox.evernote.com/edam/user", {}).and_return(client)
|
12
|
+
|
13
|
+
Evernote::UserStore.new("https://sandbox.evernote.com/edam/user", @auth_file, @env)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should raise an error on init if the version is not up to date" do
|
17
|
+
Evernote::Client.stub!(:new => mock("Evernote::Client", :checkVersion => false))
|
18
|
+
|
19
|
+
lambda {
|
20
|
+
Evernote::UserStore.new("https://sandbox.evernote.com/edam/user", @auth_file, @env)
|
21
|
+
}.should raise_error(Evernote::VersionOutOfDate, "The vendored Evernote client code is out of date and needs to be regenerated")
|
22
|
+
end
|
23
|
+
|
24
|
+
%w(consumer_key consumer_secret username password).each do |credential|
|
25
|
+
it "raises an exception if no #{credential} is set" do
|
26
|
+
lambda {
|
27
|
+
Evernote::UserStore.new("https://sandbox.evernote.com/edam/user", @auth_file, :invalid)
|
28
|
+
}.should raise_error(ArgumentError, "'consumer_key', 'consumer_secret', 'username' and 'password' are required")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should authenticate" do
|
33
|
+
Evernote::Client.stub!(:new => mock("Evernote::Client", :checkVersion => true))
|
34
|
+
user_store = Evernote::UserStore.new("https://sandbox.evernote.com/edam/user", @auth_file, @env)
|
35
|
+
user_store.instance_variable_get(:@client).should_receive(:authenticate).with("cgs", "password", "12345", "ABCDE").and_return(nil)
|
36
|
+
|
37
|
+
user_store.authenticate
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should wrap authentication failure" do
|
41
|
+
Evernote::Client.stub!(:new => mock("Evernote::Client", :checkVersion => true))
|
42
|
+
user_store = Evernote::UserStore.new("https://sandbox.evernote.com/edam/user", @auth_file, @env)
|
43
|
+
user_store.instance_variable_get(:@client).should_receive(:authenticate).and_raise(Evernote::EDAM::Error::EDAMUserException)
|
44
|
+
|
45
|
+
lambda {
|
46
|
+
user_store.authenticate
|
47
|
+
}.should raise_error(Evernote::UserStore::AuthenticationFailure)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should proxy methods" do
|
51
|
+
Evernote::Client.stub!(:new => mock("Evernote::Client", :checkVersion => true))
|
52
|
+
user_store = Evernote::UserStore.new("https://sandbox.evernote.com/edam/user", @auth_file, @env)
|
53
|
+
user_store.instance_variable_get(:@client).should_receive(:foobar).and_return(nil)
|
54
|
+
|
55
|
+
user_store.foobar
|
56
|
+
end
|
57
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: evernote
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Sepic
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-03-19 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -60,7 +60,13 @@ files:
|
|
60
60
|
- VERSION
|
61
61
|
- evernote.gemspec
|
62
62
|
- lib/evernote.rb
|
63
|
-
-
|
63
|
+
- lib/evernote/client.rb
|
64
|
+
- lib/evernote/note_store.rb
|
65
|
+
- lib/evernote/user_store.rb
|
66
|
+
- spec/evernote/auth.yaml
|
67
|
+
- spec/evernote/client_spec.rb
|
68
|
+
- spec/evernote/note_store_spec.rb
|
69
|
+
- spec/evernote/user_store_spec.rb
|
64
70
|
- spec/spec.opts
|
65
71
|
- spec/spec_helper.rb
|
66
72
|
- vendor/gen-rb/evernote.rb
|
@@ -104,5 +110,7 @@ signing_key:
|
|
104
110
|
specification_version: 3
|
105
111
|
summary: High level wrapper for the Evernote API
|
106
112
|
test_files:
|
107
|
-
- spec/
|
113
|
+
- spec/evernote/client_spec.rb
|
114
|
+
- spec/evernote/note_store_spec.rb
|
115
|
+
- spec/evernote/user_store_spec.rb
|
108
116
|
- spec/spec_helper.rb
|