aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2015-12-30 17:57:19 -0800
committerTeddy Wing2015-12-30 17:57:19 -0800
commitbbca4f8cf04d8ca3bdde981a53d7d49f3ff5bec0 (patch)
tree88682dd19c31f077202f70f11b08320d52e8fa3c
parent21e6572e9dd2ec3df6a0b9de877c09dd376ee282 (diff)
downloadEvernote-Rails-Example-bbca4f8cf04d8ca3bdde981a53d7d49f3ff5bec0.tar.bz2
NotesController#index: List Evernote notebook names
List the names of all Evernote notebooks. We create a new service to make it easier to query the Evernote Ruby SDK and get all notebooks from it. This code to list notebooks was copied from the Evernote Ruby SDK's sample EDAMTest.rb file (https://github.com/evernote/evernote-sdk-ruby/blob/master/sample/client/EDAMTest.rb#L52-L62). In our controller, we call this service to get our notebooks and pass those to the view where we display each notebook's name. Hard-coded the my Evernote Sandbox access token and NoteStore URL because I didn't save them in the OmniAuth OAuth process. Using these to query the Evernote API using the SDK. Note to self: I'll want to deactivate that Evernote Sandbox account before releasing this.
-rw-r--r--app/controllers/notes_controller.rb7
-rw-r--r--app/services/evernote.rb13
-rw-r--r--app/views/notes/index.html.erb5
3 files changed, 23 insertions, 2 deletions
diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb
index 71be366..a4391f6 100644
--- a/app/controllers/notes_controller.rb
+++ b/app/controllers/notes_controller.rb
@@ -1,4 +1,11 @@
+require_relative '../services/evernote'
+
class NotesController < ApplicationController
def index
+ auth_token = 'S=s1:U=91e2f:E=151f92661a2:C=151f4000220:P=185:A=evernotesandbox199:V=2:H=5777502290baf1ae1b36ad6254592258'
+ notestore_url = 'https://sandbox.evernote.com/shard/s1/notestore'
+
+ e = EvernoteService.new(auth_token, notestore_url)
+ @notebooks = e.notebooks
end
end
diff --git a/app/services/evernote.rb b/app/services/evernote.rb
new file mode 100644
index 0000000..edca3b8
--- /dev/null
+++ b/app/services/evernote.rb
@@ -0,0 +1,13 @@
+class EvernoteService
+ def initialize(auth_token, notestore_url)
+ @auth_token = auth_token
+ @notestore_url = notestore_url
+ end
+
+ def notebooks
+ noteStoreTransport = Thrift::HTTPClientTransport.new(@notestore_url)
+ noteStoreProtocol = Thrift::BinaryProtocol.new(noteStoreTransport)
+ noteStore = Evernote::EDAM::NoteStore::NoteStore::Client.new(noteStoreProtocol)
+ noteStore.listNotebooks(@auth_token)
+ end
+end
diff --git a/app/views/notes/index.html.erb b/app/views/notes/index.html.erb
index 00a278e..28d2850 100644
--- a/app/views/notes/index.html.erb
+++ b/app/views/notes/index.html.erb
@@ -1,2 +1,3 @@
-<h1>Notes#index</h1>
-<p>Find me in app/views/notes/index.html.erb</p>
+<% @notebooks.each do |b| %>
+ <%= b.name %><br />
+<% end %>