From bbca4f8cf04d8ca3bdde981a53d7d49f3ff5bec0 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 30 Dec 2015 17:57:19 -0800 Subject: 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. --- app/controllers/notes_controller.rb | 7 +++++++ app/services/evernote.rb | 13 +++++++++++++ app/views/notes/index.html.erb | 5 +++-- 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 app/services/evernote.rb 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 @@ -

Notes#index

-

Find me in app/views/notes/index.html.erb

+<% @notebooks.each do |b| %> + <%= b.name %>
+<% end %> -- cgit v1.2.3