evernote_oauth 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +42 -3
- data/lib/evernote_oauth.rb +2 -0
- data/lib/evernote_oauth/note_store.rb +5 -5
- data/lib/evernote_oauth/shared_note_store.rb +26 -0
- data/lib/evernote_oauth/thrift_client_delegation.rb +22 -0
- data/lib/evernote_oauth/user_store.rb +4 -4
- data/lib/evernote_oauth/version.rb +1 -1
- data/spec/evernote_oauth/note_store_spec.rb +4 -1
- data/spec/evernote_oauth/shared_note_store_spec.rb +30 -0
- data/spec/evernote_oauth/user_store_spec.rb +3 -0
- metadata +4 -1
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Evernote OAuth / Thrift API client library for Ruby
|
2
2
|
===================================================
|
3
|
-
- Evernote OAuth version 0.1.
|
3
|
+
- Evernote OAuth version 0.1.1
|
4
4
|
|
5
5
|
Install the gem
|
6
6
|
---------------
|
@@ -34,6 +34,7 @@ client = EvernoteOAuth::Client.new(
|
|
34
34
|
|
35
35
|
Usage
|
36
36
|
-----
|
37
|
+
### OAuth ###
|
37
38
|
```ruby
|
38
39
|
client = EvernoteOAuth::Client.new
|
39
40
|
request_token = client.request_token(:oauth_callback => 'YOUR CALLBACK URL')
|
@@ -46,9 +47,47 @@ access_token = request_token.get_access_token(oauth_verifier: params[:oauth_veri
|
|
46
47
|
```
|
47
48
|
Now you can make other API calls
|
48
49
|
```ruby
|
49
|
-
|
50
|
+
token = access_token.token
|
51
|
+
client = EvernoteOAuth::Client.new(token: token)
|
50
52
|
note_store = client.note_store
|
51
|
-
notebooks = note_store.listNotebooks(
|
53
|
+
notebooks = note_store.listNotebooks(token)
|
54
|
+
```
|
55
|
+
|
56
|
+
### UserStore ###
|
57
|
+
Once you acquire token, you can use UserStore. For example, if you want to call UserStore.getUser:
|
58
|
+
```ruby
|
59
|
+
user_store = EvernoteOAuth::Client.new(token: token).user_store
|
60
|
+
user_store.getUser(token)
|
61
|
+
```
|
62
|
+
You can also omit authenticationToken in the arguments of UserStore functions:
|
63
|
+
```ruby
|
64
|
+
user_store.getUser
|
65
|
+
```
|
66
|
+
|
67
|
+
### NoteStore ###
|
68
|
+
If you want to call NoteStore.listNotebooks:
|
69
|
+
```ruby
|
70
|
+
note_store = EvernoteOAuth::Client.new(token: token).note_store
|
71
|
+
note_store.listNotebooks(token)
|
72
|
+
```
|
73
|
+
You can also omit authenticationToken in the arguments of NoteStore functions:
|
74
|
+
```ruby
|
75
|
+
note_store.listNotebooks
|
76
|
+
```
|
77
|
+
|
78
|
+
### NoteStore for linked notebooks ###
|
79
|
+
If you want to get tags for linked notebooks:
|
80
|
+
```ruby
|
81
|
+
linked_notebook = note_store.listLinkedNotebooks.first # any notebook
|
82
|
+
shared_note_store = client.shared_note_store(linked_notebook)
|
83
|
+
stoken = shared_note_store.token
|
84
|
+
shared_notebook = shared_note_store.getSharedNotebookByAuth(stoken)
|
85
|
+
shared_note_store.listTagsByNotebook(stoken, shared_notebook.notebookGuid)
|
86
|
+
```
|
87
|
+
You can also omit authenticationToken in the arguments of NoteStore functions:
|
88
|
+
```ruby
|
89
|
+
shared_notebook = shared_note_store.getSharedNotebookByAuth
|
90
|
+
shared_note_store.listTagsByNotebook(shared_notebook.notebookGuid)
|
52
91
|
```
|
53
92
|
|
54
93
|
References
|
data/lib/evernote_oauth.rb
CHANGED
@@ -4,7 +4,9 @@ require 'yaml'
|
|
4
4
|
|
5
5
|
require 'evernote-thrift'
|
6
6
|
|
7
|
+
require 'evernote_oauth/thrift_client_delegation'
|
7
8
|
require 'evernote_oauth/client'
|
8
9
|
require 'evernote_oauth/user_store'
|
9
10
|
require 'evernote_oauth/note_store'
|
11
|
+
require 'evernote_oauth/shared_note_store'
|
10
12
|
require 'evernote_oauth/version'
|
@@ -3,20 +3,20 @@ module EvernoteOAuth
|
|
3
3
|
class Client
|
4
4
|
def note_store(options={})
|
5
5
|
@note_store = EvernoteOAuth::NoteStore.new(
|
6
|
+
token: options[:token] || @token,
|
6
7
|
client: thrift_client(::Evernote::EDAM::NoteStore::NoteStore::Client,
|
7
|
-
options[:note_store_url] || user_store.getNoteStoreUrl
|
8
|
+
options[:note_store_url] || user_store.getNoteStoreUrl)
|
8
9
|
)
|
9
10
|
end
|
10
11
|
end
|
11
12
|
|
12
13
|
class NoteStore
|
14
|
+
include ::EvernoteOAuth::ThriftClientDelegation
|
15
|
+
|
13
16
|
def initialize(options={})
|
17
|
+
@token = options[:token]
|
14
18
|
@client = options[:client]
|
15
19
|
end
|
16
|
-
|
17
|
-
def method_missing(name, *args, &block)
|
18
|
-
@client.send(name, *args, &block)
|
19
|
-
end
|
20
20
|
end
|
21
21
|
|
22
22
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module EvernoteOAuth
|
2
|
+
|
3
|
+
class Client
|
4
|
+
def shared_note_store(shared_notebook, options={})
|
5
|
+
EvernoteOAuth::SharedNoteStore.new(
|
6
|
+
shared_notebook: shared_notebook,
|
7
|
+
token: options[:token] || @token,
|
8
|
+
client: thrift_client(::Evernote::EDAM::NoteStore::NoteStore::Client,
|
9
|
+
shared_notebook.noteStoreUrl)
|
10
|
+
)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class SharedNoteStore
|
15
|
+
include ::EvernoteOAuth::ThriftClientDelegation
|
16
|
+
attr_reader :token
|
17
|
+
|
18
|
+
def initialize(options={})
|
19
|
+
@shared_notebook = options[:shared_notebook]
|
20
|
+
@client = options[:client]
|
21
|
+
@token = authenticateToSharedNotebook(@shared_notebook.shareKey,
|
22
|
+
options[:token]).authenticationToken
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module EvernoteOAuth
|
2
|
+
|
3
|
+
module ThriftClientDelegation
|
4
|
+
def method_missing(name, *args, &block)
|
5
|
+
method = @client.class.instance_method(name)
|
6
|
+
parameters = method.parameters
|
7
|
+
if parameters.size != args.size &&
|
8
|
+
idx_token = parameters.index{|e| e.last == :authenticationToken}
|
9
|
+
new_args = args.dup.insert(idx_token, @token)
|
10
|
+
begin
|
11
|
+
@client.send(name, *new_args, &block)
|
12
|
+
rescue ArgumentError => e
|
13
|
+
puts e.inspect
|
14
|
+
@client.send(name, *args, &block)
|
15
|
+
end
|
16
|
+
else
|
17
|
+
@client.send(name, *args, &block)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -3,6 +3,7 @@ module EvernoteOAuth
|
|
3
3
|
class Client
|
4
4
|
def user_store
|
5
5
|
@user_store = EvernoteOAuth::UserStore.new(
|
6
|
+
token: @token,
|
6
7
|
client: thrift_client(::Evernote::EDAM::UserStore::UserStore::Client,
|
7
8
|
endpoint('edam/user'))
|
8
9
|
)
|
@@ -10,15 +11,14 @@ module EvernoteOAuth
|
|
10
11
|
end
|
11
12
|
|
12
13
|
class UserStore
|
14
|
+
include ::EvernoteOAuth::ThriftClientDelegation
|
15
|
+
|
13
16
|
def initialize(options={})
|
17
|
+
@token = options[:token]
|
14
18
|
@client = options[:client]
|
15
19
|
raise 'API version is not up to date' unless version_valid?
|
16
20
|
end
|
17
21
|
|
18
|
-
def method_missing(name, *args, &block)
|
19
|
-
@client.send(name, *args, &block)
|
20
|
-
end
|
21
|
-
|
22
22
|
def version_valid?
|
23
23
|
checkVersion("EDAMTest",
|
24
24
|
::Evernote::EDAM::UserStore::EDAM_VERSION_MAJOR,
|
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), "/../spec_helper")
|
|
2
2
|
|
3
3
|
describe "EvernoteOAuth::NoteStore" do
|
4
4
|
context "#initialize" do
|
5
|
-
it "assigns instance variables
|
5
|
+
it "assigns instance variables" do
|
6
6
|
note_store = EvernoteOAuth::NoteStore.new(client: 'client')
|
7
7
|
note_store.instance_variable_get(:@client).should == 'client'
|
8
8
|
end
|
@@ -11,6 +11,9 @@ describe "EvernoteOAuth::NoteStore" do
|
|
11
11
|
it "dispatches method" do
|
12
12
|
mock_client = mock(Object)
|
13
13
|
mock_client.should_receive(:send).with(:call_method, 'args')
|
14
|
+
mock_client.class.should_receive(:instance_method).with(:call_method).and_return{
|
15
|
+
Proc.new {|a| a}
|
16
|
+
}
|
14
17
|
note_store = EvernoteOAuth::NoteStore.new(client: mock_client)
|
15
18
|
note_store.call_method('args')
|
16
19
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "/../spec_helper")
|
2
|
+
|
3
|
+
describe "EvernoteOAuth::SharedNoteStore" do
|
4
|
+
context "#initialize" do
|
5
|
+
it "assigns instance variables" do
|
6
|
+
sn = Struct.new(:shareKey).new('shareKey')
|
7
|
+
auth_token = Struct.new(:authenticationToken).new('token')
|
8
|
+
EvernoteOAuth::SharedNoteStore.any_instance.should_receive(
|
9
|
+
:authenticateToSharedNotebook).and_return(auth_token)
|
10
|
+
note_store = EvernoteOAuth::SharedNoteStore.new(client: 'client', shared_notebook: sn)
|
11
|
+
note_store.instance_variable_get(:@client).should == 'client'
|
12
|
+
note_store.token.should == 'token'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
context "#method_missing" do
|
16
|
+
it "dispatches method" do
|
17
|
+
mock_client = mock(Object)
|
18
|
+
mock_client.should_receive(:send).with(:call_method, 'args')
|
19
|
+
mock_client.class.should_receive(:instance_method).with(:call_method).and_return{
|
20
|
+
Proc.new {|a| a}
|
21
|
+
}
|
22
|
+
sn = Struct.new(:shareKey).new('shareKey')
|
23
|
+
auth_token = Struct.new(:authenticationToken).new('token')
|
24
|
+
EvernoteOAuth::SharedNoteStore.any_instance.should_receive(
|
25
|
+
:authenticateToSharedNotebook).and_return(auth_token)
|
26
|
+
note_store = EvernoteOAuth::SharedNoteStore.new(client: mock_client, shared_notebook: sn)
|
27
|
+
note_store.call_method('args')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -16,6 +16,9 @@ describe "EvernoteOAuth::UserStore" do
|
|
16
16
|
it "dispatches method" do
|
17
17
|
mock_client = mock(Object)
|
18
18
|
mock_client.should_receive(:send).with(:call_method, 'args')
|
19
|
+
mock_client.class.should_receive(:instance_method).with(:call_method).and_return{
|
20
|
+
Proc.new {|a| a}
|
21
|
+
}
|
19
22
|
EvernoteOAuth::UserStore.any_instance.stub(:version_valid?){true}
|
20
23
|
user_store = EvernoteOAuth::UserStore.new(client: mock_client)
|
21
24
|
user_store.call_method('args')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: evernote_oauth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -71,11 +71,14 @@ files:
|
|
71
71
|
- evernote_oauth.gemspec
|
72
72
|
- lib/evernote_oauth/client.rb
|
73
73
|
- lib/evernote_oauth/note_store.rb
|
74
|
+
- lib/evernote_oauth/shared_note_store.rb
|
75
|
+
- lib/evernote_oauth/thrift_client_delegation.rb
|
74
76
|
- lib/evernote_oauth/user_store.rb
|
75
77
|
- lib/evernote_oauth/version.rb
|
76
78
|
- lib/evernote_oauth.rb
|
77
79
|
- spec/evernote_oauth/client_spec.rb
|
78
80
|
- spec/evernote_oauth/note_store_spec.rb
|
81
|
+
- spec/evernote_oauth/shared_note_store_spec.rb
|
79
82
|
- spec/evernote_oauth/user_store_spec.rb
|
80
83
|
- spec/spec_helper.rb
|
81
84
|
homepage: http://github.com/rekotan/evernote_oauth
|