evernote_oauth 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +14 -1
- data/lib/evernote_oauth.rb +1 -0
- data/lib/evernote_oauth/business_note_store.rb +24 -0
- data/lib/evernote_oauth/client.rb +32 -27
- data/lib/evernote_oauth/version.rb +1 -1
- metadata +3 -2
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.4
|
4
4
|
|
5
5
|
Install the gem
|
6
6
|
---------------
|
@@ -90,6 +90,19 @@ shared_notebook = shared_note_store.getSharedNotebookByAuth
|
|
90
90
|
shared_note_store.listTagsByNotebook(shared_notebook.notebookGuid)
|
91
91
|
```
|
92
92
|
|
93
|
+
### NoteStore for Business ###
|
94
|
+
If you want to get the list of notebooks in your business account:
|
95
|
+
```ruby
|
96
|
+
business_note_store = client.business_note_store
|
97
|
+
btoken = business_note_store.token
|
98
|
+
business_note_store.listNotebooks(btoken)
|
99
|
+
```
|
100
|
+
You can also omit authenticationToken in the arguments of NoteStore functions:
|
101
|
+
```ruby
|
102
|
+
business_note_store = client.business_note_store
|
103
|
+
business_note_store.listNotebooks
|
104
|
+
```
|
105
|
+
|
93
106
|
### Method Chaining ###
|
94
107
|
You can chain methods:
|
95
108
|
```ruby
|
data/lib/evernote_oauth.rb
CHANGED
@@ -11,5 +11,6 @@ require 'evernote_oauth/client'
|
|
11
11
|
require 'evernote_oauth/user_store'
|
12
12
|
require 'evernote_oauth/note_store'
|
13
13
|
require 'evernote_oauth/shared_note_store'
|
14
|
+
require 'evernote_oauth/business_note_store'
|
14
15
|
require 'evernote_oauth/store_attachable'
|
15
16
|
require 'evernote_oauth/version'
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module EvernoteOAuth
|
2
|
+
|
3
|
+
class Client
|
4
|
+
def business_note_store(options={})
|
5
|
+
auth = user_store.authenticateToBusiness(options[:token] || @token)
|
6
|
+
EvernoteOAuth::BusinessNoteStore.new(
|
7
|
+
token: auth.authenticationToken,
|
8
|
+
client: thrift_client(::Evernote::EDAM::NoteStore::NoteStore::Client,
|
9
|
+
auth.noteStoreUrl)
|
10
|
+
)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class BusinessNoteStore
|
15
|
+
include ::EvernoteOAuth::ThriftClientDelegation
|
16
|
+
attr_reader :token
|
17
|
+
|
18
|
+
def initialize(options={})
|
19
|
+
@token = options[:token]
|
20
|
+
@client = options[:client]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -4,16 +4,18 @@ module EvernoteOAuth
|
|
4
4
|
def initialize(options={})
|
5
5
|
config_file = "config/evernote.yml"
|
6
6
|
if File.exist?(config_file)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
config = YAML.load(ERB.new(File.read(config_file)).result)[Rails.env]
|
8
|
+
@consumer_key = config['consumer_key']
|
9
|
+
@consumer_secret = config['consumer_secret']
|
10
|
+
@sandbox = config['sandbox'] ? true : false
|
11
11
|
end
|
12
12
|
|
13
13
|
@consumer_key = options[:consumer_key] || @consumer_key
|
14
14
|
@consumer_secret = options[:consumer_secret] || @consumer_secret
|
15
15
|
@sandbox = true if @sandbox == nil
|
16
16
|
@sandbox = (options[:sandbox] == nil ? @sandbox : options[:sandbox])
|
17
|
+
@service_host = options[:service_host] || (@sandbox ? 'sandbox.evernote.com' : 'www.evernote.com')
|
18
|
+
@additional_headers = options[:additional_headers]
|
17
19
|
@token = options[:token]
|
18
20
|
@secret = options[:secret]
|
19
21
|
end
|
@@ -36,32 +38,35 @@ module EvernoteOAuth
|
|
36
38
|
end
|
37
39
|
|
38
40
|
private
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
41
|
+
def consumer
|
42
|
+
@consumer ||= OAuth::Consumer.new(
|
43
|
+
@consumer_key,
|
44
|
+
@consumer_secret,
|
45
|
+
{site: endpoint,
|
46
|
+
request_token_path: "/oauth",
|
47
|
+
access_token_path: "/oauth"}
|
48
|
+
)
|
49
|
+
end
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
def endpoint(path=nil)
|
52
|
+
url = "https://#{@service_host}"
|
53
|
+
url += "/#{path}" if path
|
54
|
+
url
|
55
|
+
end
|
54
56
|
|
55
|
-
|
56
|
-
|
57
|
-
|
57
|
+
def access_token
|
58
|
+
@access_token ||= OAuth::AccessToken.new(consumer, @token, @secret)
|
59
|
+
end
|
58
60
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
61
|
+
def thrift_client(client_class, url)
|
62
|
+
transport = Thrift::HTTPClientTransport.new(url)
|
63
|
+
transport.add_headers(
|
64
|
+
'User-Agent' => "EvernoteOAuth / #{::EvernoteOAuth::VERSION}; Ruby / #{RUBY_VERSION};"
|
65
|
+
)
|
66
|
+
transport.add_headers(@additional_headers) if @additional_headers
|
67
|
+
protocol = Thrift::BinaryProtocol.new(transport)
|
68
|
+
client_class.new(protocol)
|
69
|
+
end
|
65
70
|
|
66
71
|
end
|
67
72
|
end
|
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.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: oauth
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- lib/evernote/edam/type/resource.rb
|
78
78
|
- lib/evernote/edam/type/shared_notebook.rb
|
79
79
|
- lib/evernote/edam/type/tag.rb
|
80
|
+
- lib/evernote_oauth/business_note_store.rb
|
80
81
|
- lib/evernote_oauth/client.rb
|
81
82
|
- lib/evernote_oauth/note_store.rb
|
82
83
|
- lib/evernote_oauth/shared_note_store.rb
|