├── sample ├── ruby_on_rails │ ├── app │ │ ├── mailers │ │ │ └── .gitkeep │ │ ├── models │ │ │ └── .gitkeep │ │ ├── helpers │ │ │ ├── home_helper.rb │ │ │ ├── login_helper.rb │ │ │ ├── note_store_helper.rb │ │ │ ├── user_store_helper.rb │ │ │ └── application_helper.rb │ │ ├── assets │ │ │ ├── stylesheets │ │ │ │ ├── images │ │ │ │ │ ├── ui-icons_222222_256x240.png │ │ │ │ │ ├── ui-icons_2e83ff_256x240.png │ │ │ │ │ ├── ui-icons_454545_256x240.png │ │ │ │ │ ├── ui-icons_888888_256x240.png │ │ │ │ │ ├── ui-icons_cd0a0a_256x240.png │ │ │ │ │ ├── ui-bg_flat_0_aaaaaa_40x100.png │ │ │ │ │ ├── ui-bg_flat_75_ffffff_40x100.png │ │ │ │ │ ├── ui-bg_glass_55_fbf9ee_1x400.png │ │ │ │ │ ├── ui-bg_glass_65_ffffff_1x400.png │ │ │ │ │ ├── ui-bg_glass_75_dadada_1x400.png │ │ │ │ │ ├── ui-bg_glass_75_e6e6e6_1x400.png │ │ │ │ │ ├── ui-bg_glass_95_fef1ec_1x400.png │ │ │ │ │ └── ui-bg_highlight-soft_75_cccccc_1x100.png │ │ │ │ ├── home.css.scss │ │ │ │ ├── login.css.scss │ │ │ │ ├── note_store.css.scss │ │ │ │ ├── user_store.css.scss │ │ │ │ ├── application.css │ │ │ │ ├── coderay.css │ │ │ │ └── jquery-ui-1.9.1.custom.min.css │ │ │ └── javascripts │ │ │ │ ├── home.js.coffee │ │ │ │ ├── login.js.coffee │ │ │ │ ├── note_store.js.coffee │ │ │ │ ├── user_store.js.coffee │ │ │ │ └── application.js │ │ ├── controllers │ │ │ ├── application_controller.rb │ │ │ ├── login_controller.rb │ │ │ ├── home_controller.rb │ │ │ ├── evernote_controller.rb │ │ │ ├── user_store_controller.rb │ │ │ ├── advanced_controller.rb │ │ │ └── note_store_controller.rb │ │ └── views │ │ │ ├── layouts │ │ │ └── application.html.haml │ │ │ ├── advanced │ │ │ └── api_result.html.haml │ │ │ └── home │ │ │ ├── index.html.haml │ │ │ ├── api_result.html.haml │ │ │ └── _api_list.html.haml │ ├── lib │ │ ├── assets │ │ │ └── .gitkeep │ │ └── tasks │ │ │ └── .gitkeep │ ├── public │ │ ├── favicon.ico │ │ ├── rails.png │ │ ├── enlogo.png │ │ ├── evernote_logo_center.png │ │ ├── robots.txt │ │ ├── 500.html │ │ ├── 422.html │ │ └── 404.html │ ├── test │ │ ├── fixtures │ │ │ └── .gitkeep │ │ ├── unit │ │ │ ├── .gitkeep │ │ │ └── helpers │ │ │ │ ├── home_helper_test.rb │ │ │ │ ├── login_helper_test.rb │ │ │ │ ├── note_store_helper_test.rb │ │ │ │ └── user_store_helper_test.rb │ │ ├── functional │ │ │ ├── .gitkeep │ │ │ ├── home_controller_test.rb │ │ │ ├── login_controller_test.rb │ │ │ ├── note_store_controller_test.rb │ │ │ └── user_store_controller_test.rb │ │ ├── integration │ │ │ └── .gitkeep │ │ ├── performance │ │ │ └── browsing_test.rb │ │ └── test_helper.rb │ ├── vendor │ │ ├── plugins │ │ │ └── .gitkeep │ │ └── assets │ │ │ ├── javascripts │ │ │ └── .gitkeep │ │ │ └── stylesheets │ │ │ └── .gitkeep │ ├── .gitignore │ ├── config │ │ ├── evernote.yml │ │ ├── environment.rb │ │ ├── boot.rb │ │ ├── locales │ │ │ └── en.yml │ │ ├── initializers │ │ │ ├── mime_types.rb │ │ │ ├── backtrace_silencers.rb │ │ │ ├── omniauth.rb │ │ │ ├── session_store.rb │ │ │ ├── secret_token.rb │ │ │ ├── wrap_parameters.rb │ │ │ └── inflections.rb │ │ ├── routes.rb │ │ ├── database.yml │ │ ├── environments │ │ │ ├── development.rb │ │ │ ├── test.rb │ │ │ └── production.rb │ │ └── application.rb │ ├── config.ru │ ├── doc │ │ └── README_FOR_APP │ ├── Rakefile │ ├── script │ │ └── rails │ ├── db │ │ └── seeds.rb │ ├── Gemfile │ ├── README.md │ └── Gemfile.lock ├── sinatra │ ├── .gitignore │ ├── config │ │ ├── database.yml │ │ └── evernote.yml │ ├── config.ru │ ├── views │ │ ├── error.slim │ │ ├── authorize.slim │ │ ├── layout.slim │ │ └── notes.slim │ ├── Rakefile │ ├── Gemfile │ ├── db │ │ └── migrate │ │ │ ├── 20130216003455_create_notes.rb │ │ │ └── 20130216003343_create_users.rb │ ├── Gemfile.lock │ ├── README.md │ └── app.rb └── client │ ├── enlogo.png │ └── EDAMTest.rb ├── .gitignore ├── lib ├── evernote_oauth │ ├── version.rb │ ├── note_store.rb │ ├── business_note_store.rb │ ├── user_store.rb │ ├── shared_note_store.rb │ ├── store_attachable.rb │ ├── thrift_client_delegation.rb │ ├── client.rb │ └── business_utils.rb ├── evernote │ └── edam │ │ ├── note_store │ │ ├── note_list.rb │ │ ├── notes_metadata_list.rb │ │ ├── sync_chunk.rb │ │ └── note_metadata.rb │ │ └── type │ │ ├── notebook.rb │ │ ├── shared_notebook.rb │ │ ├── tag.rb │ │ ├── user.rb │ │ ├── resource.rb │ │ └── note.rb ├── evernote_types.rb └── evernote_oauth.rb ├── spec ├── spec_helper.rb └── evernote_oauth │ ├── note_store_spec.rb │ ├── business_note_store_spec.rb │ ├── store_attachable_spec.rb │ ├── user_store_spec.rb │ ├── shared_note_store_spec.rb │ ├── client_spec.rb │ └── business_utils_spec.rb ├── evernote_oauth.gemspec ├── LICENSE └── README.md /sample/ruby_on_rails/app/mailers/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/models/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/lib/assets/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/lib/tasks/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/public/favicon.ico: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/test/fixtures/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/test/unit/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/test/functional/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/test/integration/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/vendor/plugins/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/vendor/assets/javascripts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/vendor/assets/stylesheets/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /sample/sinatra/.gitignore: -------------------------------------------------------------------------------- 1 | .rvmrc 2 | *.sqlite3 3 | Gemfile.lock 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .rvmrc 2 | .irbrc 3 | *.gem 4 | *.swp 5 | .yardoc 6 | doc/ 7 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/.gitignore: -------------------------------------------------------------------------------- 1 | tmp 2 | log 3 | *.sqlite3 4 | Gemfile.lock 5 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/helpers/home_helper.rb: -------------------------------------------------------------------------------- 1 | module HomeHelper 2 | end 3 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/helpers/login_helper.rb: -------------------------------------------------------------------------------- 1 | module LoginHelper 2 | end 3 | -------------------------------------------------------------------------------- /lib/evernote_oauth/version.rb: -------------------------------------------------------------------------------- 1 | module EvernoteOAuth 2 | VERSION = "0.2.3" 3 | end 4 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/helpers/note_store_helper.rb: -------------------------------------------------------------------------------- 1 | module NoteStoreHelper 2 | end 3 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/helpers/user_store_helper.rb: -------------------------------------------------------------------------------- 1 | module UserStoreHelper 2 | end 3 | -------------------------------------------------------------------------------- /sample/sinatra/config/database.yml: -------------------------------------------------------------------------------- 1 | adapter: "sqlite3" 2 | database: "db/evernote.sqlite3" 3 | -------------------------------------------------------------------------------- /sample/client/enlogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Evernote/evernote-oauth-ruby/HEAD/sample/client/enlogo.png -------------------------------------------------------------------------------- /sample/ruby_on_rails/public/rails.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Evernote/evernote-oauth-ruby/HEAD/sample/ruby_on_rails/public/rails.png -------------------------------------------------------------------------------- /sample/sinatra/config.ru: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | require 'bundler' 3 | 4 | Bundler.require 5 | 6 | require './app' 7 | run EnWebhook 8 | -------------------------------------------------------------------------------- /sample/sinatra/views/error.slim: -------------------------------------------------------------------------------- 1 | p 2 | span style='color:red' An error occurred: #{@error} 3 | p 4 | a href='/reset' Start over 5 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/public/enlogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Evernote/evernote-oauth-ruby/HEAD/sample/ruby_on_rails/public/enlogo.png -------------------------------------------------------------------------------- /sample/sinatra/Rakefile: -------------------------------------------------------------------------------- 1 | require "sinatra" 2 | require "sinatra/activerecord" 3 | require "sinatra/activerecord/rake" 4 | require "./app" 5 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/test/unit/helpers/home_helper_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class HomeHelperTest < ActionView::TestCase 4 | end 5 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/test/unit/helpers/login_helper_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class LoginHelperTest < ActionView::TestCase 4 | end 5 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/test/unit/helpers/note_store_helper_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class NoteStoreHelperTest < ActionView::TestCase 4 | end 5 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/test/unit/helpers/user_store_helper_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class UserStoreHelperTest < ActionView::TestCase 4 | end 5 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/public/evernote_logo_center.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Evernote/evernote-oauth-ruby/HEAD/sample/ruby_on_rails/public/evernote_logo_center.png -------------------------------------------------------------------------------- /sample/sinatra/config/evernote.yml: -------------------------------------------------------------------------------- 1 | consumer_key: <%= ENV['EN_CONSUMER_KEY'] || "" %> 2 | consumer_secret: <%= ENV['EN_CONSUMER_SECRET'] || "" %> 3 | sandbox: true 4 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'rspec' 2 | 3 | Dir.glob(File.join(File.join(File.dirname(__FILE__), "..", "lib"), "**.rb")).each do |file| 4 | require file 5 | end 6 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/config/evernote.yml: -------------------------------------------------------------------------------- 1 | development: 2 | consumer_key: <%= ENV['EN_CONSUMER_KEY'] %> 3 | consumer_secret: <%= ENV['EN_CONSUMER_SECRET'] %> 4 | sandbox: true 5 | -------------------------------------------------------------------------------- /sample/sinatra/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem "evernote_oauth" 4 | gem "sinatra" 5 | gem "sinatra-activerecord" 6 | gem "sqlite3" 7 | gem "rake" 8 | gem "slim" 9 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require ::File.expand_path('../config/environment', __FILE__) 4 | run EvernoteSample::Application 5 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/assets/stylesheets/images/ui-icons_222222_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Evernote/evernote-oauth-ruby/HEAD/sample/ruby_on_rails/app/assets/stylesheets/images/ui-icons_222222_256x240.png -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/assets/stylesheets/images/ui-icons_2e83ff_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Evernote/evernote-oauth-ruby/HEAD/sample/ruby_on_rails/app/assets/stylesheets/images/ui-icons_2e83ff_256x240.png -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/assets/stylesheets/images/ui-icons_454545_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Evernote/evernote-oauth-ruby/HEAD/sample/ruby_on_rails/app/assets/stylesheets/images/ui-icons_454545_256x240.png -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/assets/stylesheets/images/ui-icons_888888_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Evernote/evernote-oauth-ruby/HEAD/sample/ruby_on_rails/app/assets/stylesheets/images/ui-icons_888888_256x240.png -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/assets/stylesheets/images/ui-icons_cd0a0a_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Evernote/evernote-oauth-ruby/HEAD/sample/ruby_on_rails/app/assets/stylesheets/images/ui-icons_cd0a0a_256x240.png -------------------------------------------------------------------------------- /sample/ruby_on_rails/config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the rails application 2 | require File.expand_path('../application', __FILE__) 3 | 4 | # Initialize the rails application 5 | EvernoteSample::Application.initialize! 6 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/test/functional/home_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class HomeControllerTest < ActionController::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/test/functional/login_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class LoginControllerTest < ActionController::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/assets/stylesheets/images/ui-bg_flat_0_aaaaaa_40x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Evernote/evernote-oauth-ruby/HEAD/sample/ruby_on_rails/app/assets/stylesheets/images/ui-bg_flat_0_aaaaaa_40x100.png -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/assets/stylesheets/images/ui-bg_flat_75_ffffff_40x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Evernote/evernote-oauth-ruby/HEAD/sample/ruby_on_rails/app/assets/stylesheets/images/ui-bg_flat_75_ffffff_40x100.png -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/assets/stylesheets/images/ui-bg_glass_55_fbf9ee_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Evernote/evernote-oauth-ruby/HEAD/sample/ruby_on_rails/app/assets/stylesheets/images/ui-bg_glass_55_fbf9ee_1x400.png -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/assets/stylesheets/images/ui-bg_glass_65_ffffff_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Evernote/evernote-oauth-ruby/HEAD/sample/ruby_on_rails/app/assets/stylesheets/images/ui-bg_glass_65_ffffff_1x400.png -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/assets/stylesheets/images/ui-bg_glass_75_dadada_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Evernote/evernote-oauth-ruby/HEAD/sample/ruby_on_rails/app/assets/stylesheets/images/ui-bg_glass_75_dadada_1x400.png -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/assets/stylesheets/images/ui-bg_glass_75_e6e6e6_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Evernote/evernote-oauth-ruby/HEAD/sample/ruby_on_rails/app/assets/stylesheets/images/ui-bg_glass_75_e6e6e6_1x400.png -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/assets/stylesheets/images/ui-bg_glass_95_fef1ec_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Evernote/evernote-oauth-ruby/HEAD/sample/ruby_on_rails/app/assets/stylesheets/images/ui-bg_glass_95_fef1ec_1x400.png -------------------------------------------------------------------------------- /sample/ruby_on_rails/test/functional/note_store_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class NoteStoreControllerTest < ActionController::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/test/functional/user_store_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class UserStoreControllerTest < ActionController::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/assets/stylesheets/home.css.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the Home controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ 4 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/assets/stylesheets/images/ui-bg_highlight-soft_75_cccccc_1x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Evernote/evernote-oauth-ruby/HEAD/sample/ruby_on_rails/app/assets/stylesheets/images/ui-bg_highlight-soft_75_cccccc_1x100.png -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/assets/stylesheets/login.css.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the Login controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ 4 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/config/boot.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | 3 | # Set up gems listed in the Gemfile. 4 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 5 | 6 | require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) 7 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/assets/stylesheets/note_store.css.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the NoteStore controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ 4 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/assets/stylesheets/user_store.css.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the UserStore controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ 4 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/doc/README_FOR_APP: -------------------------------------------------------------------------------- 1 | Use this README file to introduce your application and point to useful places in the API for learning more. 2 | Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries. 3 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/public/robots.txt: -------------------------------------------------------------------------------- 1 | # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file 2 | # 3 | # To ban all spiders from the entire site uncomment the next two lines: 4 | # User-Agent: * 5 | # Disallow: / 6 | -------------------------------------------------------------------------------- /lib/evernote/edam/note_store/note_list.rb: -------------------------------------------------------------------------------- 1 | module Evernote 2 | module EDAM 3 | module NoteStore 4 | class NoteList 5 | extend ::EvernoteOAuth::StoreAttachable 6 | attach_note_store :notes 7 | end 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Sample localization file for English. Add more files in this directory for other locales. 2 | # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. 3 | 4 | en: 5 | hello: "Hello world" 6 | -------------------------------------------------------------------------------- /lib/evernote/edam/note_store/notes_metadata_list.rb: -------------------------------------------------------------------------------- 1 | module Evernote 2 | module EDAM 3 | module NoteStore 4 | class NotesMetadataList 5 | extend NoteStoreAttachable 6 | attach_note_store :notes 7 | end 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new mime types for use in respond_to blocks: 4 | # Mime::Type.register "text/richtext", :rtf 5 | # Mime::Type.register_alias "text/html", :iphone 6 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | require 'open-uri' 2 | 3 | class ApplicationController < ActionController::Base 4 | protect_from_forgery 5 | helper_method :authtoken 6 | 7 | def authtoken 8 | session[:authtoken] 9 | end 10 | 11 | end 12 | -------------------------------------------------------------------------------- /sample/sinatra/views/authorize.slim: -------------------------------------------------------------------------------- 1 | p 2 | a href='/authorize' Click here 3 | | to authorize this application to access your Evernote account. 4 | | You will be directed to evernote.com to authorize access, 5 | | then returned to this application after authorization is complete. 6 | 7 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/assets/javascripts/home.js.coffee: -------------------------------------------------------------------------------- 1 | # Place all the behaviors and hooks related to the matching controller here. 2 | # All this logic will automatically be available in application.js. 3 | # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ 4 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/assets/javascripts/login.js.coffee: -------------------------------------------------------------------------------- 1 | # Place all the behaviors and hooks related to the matching controller here. 2 | # All this logic will automatically be available in application.js. 3 | # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ 4 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/assets/javascripts/note_store.js.coffee: -------------------------------------------------------------------------------- 1 | # Place all the behaviors and hooks related to the matching controller here. 2 | # All this logic will automatically be available in application.js. 3 | # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ 4 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/assets/javascripts/user_store.js.coffee: -------------------------------------------------------------------------------- 1 | # Place all the behaviors and hooks related to the matching controller here. 2 | # All this logic will automatically be available in application.js. 3 | # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ 4 | -------------------------------------------------------------------------------- /sample/sinatra/db/migrate/20130216003455_create_notes.rb: -------------------------------------------------------------------------------- 1 | class CreateNotes < ActiveRecord::Migration 2 | def change 3 | create_table :notes do |t| 4 | t.string :guid 5 | t.string :user_id 6 | t.string :title 7 | t.string :content 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /sample/sinatra/db/migrate/20130216003343_create_users.rb: -------------------------------------------------------------------------------- 1 | class CreateUsers < ActiveRecord::Migration 2 | def change 3 | create_table :users do |t| 4 | t.string :user_id 5 | t.string :username 6 | t.string :token 7 | t.boolean :active, default: true 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/evernote/edam/note_store/sync_chunk.rb: -------------------------------------------------------------------------------- 1 | module Evernote 2 | module EDAM 3 | module NoteStore 4 | class SyncChunk 5 | extend ::EvernoteOAuth::StoreAttachable 6 | attach_note_store :notes, :notebooks, :tags, :searches, :resources, :linkedNotebooks 7 | end 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rake 2 | # Add your own tasks in files placed in lib/tasks ending in .rake, 3 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 4 | 5 | require File.expand_path('../config/application', __FILE__) 6 | 7 | EvernoteSample::Application.load_tasks 8 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/script/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. 3 | 4 | APP_PATH = File.expand_path('../../config/application', __FILE__) 5 | require File.expand_path('../../config/boot', __FILE__) 6 | require 'rails/commands' 7 | -------------------------------------------------------------------------------- /lib/evernote/edam/type/notebook.rb: -------------------------------------------------------------------------------- 1 | module Evernote 2 | module EDAM 3 | module Type 4 | class Notebook 5 | 6 | # Determines if the user can create notes in this notebook. 7 | # 8 | # @return [Boolean] 9 | def writable? 10 | !self.restrictions.noCreateNotes 11 | end 12 | 13 | end 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/db/seeds.rb: -------------------------------------------------------------------------------- 1 | # This file should contain all the record creation needed to seed the database with its default values. 2 | # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). 3 | # 4 | # Examples: 5 | # 6 | # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) 7 | # Mayor.create(name: 'Emanuel', city: cities.first) 8 | -------------------------------------------------------------------------------- /lib/evernote/edam/type/shared_notebook.rb: -------------------------------------------------------------------------------- 1 | module Evernote 2 | module EDAM 3 | module Type 4 | class SharedNotebook 5 | 6 | # Returns the associated notebook shared 7 | # 8 | # @return [Evernote::EDAM::Type::Notebook] 9 | def notebook 10 | @notebook ||= note_store.getNotebook(notebookGuid) 11 | end 12 | 13 | end 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /lib/evernote/edam/type/tag.rb: -------------------------------------------------------------------------------- 1 | module Evernote 2 | module EDAM 3 | module Type 4 | class Tag 5 | 6 | # Returns the tag that holds this tag within the tag organizational hierarchy. 7 | # 8 | # @return [Evernote::EDAM::Type::Tag] 9 | def parent 10 | @parent ||= note_store.getTag(parentGuid) if parentGuid 11 | end 12 | 13 | end 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/views/layouts/application.html.haml: -------------------------------------------------------------------------------- 1 | !!! 2 | %html 3 | %head 4 | %title EvernoteSample 5 | = stylesheet_link_tag "application", :media => "all" 6 | = stylesheet_link_tag 'http://dev.evernote.com/documentation/reference/style.css' 7 | = javascript_include_tag "application" 8 | = csrf_meta_tags 9 | %body 10 | %h1 Evernote Sample Usage of API for Ruby 11 | %hr 12 | = yield 13 | -------------------------------------------------------------------------------- /lib/evernote/edam/note_store/note_metadata.rb: -------------------------------------------------------------------------------- 1 | module Evernote 2 | module EDAM 3 | module NoteStore 4 | class NoteMetadata 5 | 6 | # Returns the tags that are applied to this note. 7 | # 8 | # @return [Array] 9 | def tags 10 | @tags ||= (tagGuids || []).map{|guid| note_store.getTag(guid)} 11 | end 12 | 13 | end 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/test/performance/browsing_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | require 'rails/performance_test_help' 3 | 4 | class BrowsingTest < ActionDispatch::PerformanceTest 5 | # Refer to the documentation for all available options 6 | # self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory] 7 | # :output => 'tmp/performance', :formats => [:flat] } 8 | 9 | def test_homepage 10 | get '/' 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /sample/sinatra/views/layout.slim: -------------------------------------------------------------------------------- 1 | html 2 | head 3 | title Evernote Ruby Webhook Demo 4 | body 5 | h1 Evernote Ruby Webhook Demo 6 | p 7 | This application uses the Sinatra framework to demonstrate the use of webhook. 8 | | OAuth support is implemented using the Ruby OAuth RubyGem. 9 | hr 10 | 11 | h2 Evernote Authentication 12 | == yield 13 | 14 | -------------------------------------------------------------------------------- /lib/evernote_types.rb: -------------------------------------------------------------------------------- 1 | require 'evernote_oauth/store_attachable' 2 | 3 | require 'evernote/edam/type/user' 4 | require 'evernote/edam/type/note' 5 | require 'evernote/edam/type/notebook' 6 | require 'evernote/edam/type/resource' 7 | require 'evernote/edam/type/shared_notebook' 8 | require 'evernote/edam/type/tag' 9 | 10 | require 'evernote/edam/note_store/note_list' 11 | require 'evernote/edam/note_store/note_metadata' 12 | require 'evernote/edam/note_store/sync_chunk' 13 | 14 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } 5 | 6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. 7 | # Rails.backtrace_cleaner.remove_silencers! 8 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/config/initializers/omniauth.rb: -------------------------------------------------------------------------------- 1 | config = YAML.load(ERB.new(File.read('config/evernote.yml')).result)[Rails.env] 2 | site = config['sandbox'] ? 'https://sandbox.evernote.com' : 'https://www.evernote.com' 3 | 4 | Rails.application.config.middleware.use OmniAuth::Builder do 5 | provider :evernote, config['consumer_key'], config['consumer_secret'], :client_options => {:site => site} 6 | end 7 | 8 | OmniAuth.config.on_failure = LoginController.action(:oauth_failure) 9 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'rails', '3.2.12' 4 | gem 'sqlite3' 5 | gem 'haml-rails' 6 | gem 'evernote_oauth' 7 | gem 'omniauth-evernote' 8 | gem 'nokogiri' 9 | gem 'coderay' 10 | gem 'rails_autolink' 11 | gem 'execjs' 12 | gem 'therubyracer' 13 | gem 'awesome_print' 14 | 15 | group :assets do 16 | gem 'sass-rails', '~> 3.2.3' 17 | gem 'coffee-rails', '~> 3.2.1' 18 | gem 'uglifier', '>= 1.0.3' 19 | end 20 | 21 | gem 'jquery-rails' 22 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/config/initializers/session_store.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | EvernoteSample::Application.config.session_store :cookie_store, key: '_evernote-sample_session' 4 | 5 | # Use the database for sessions instead of the cookie-based default, 6 | # which shouldn't be used to store highly confidential information 7 | # (create the session table with "rails generate session_migration") 8 | # EvernoteSample::Application.config.session_store :active_record_store 9 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/views/advanced/api_result.html.haml: -------------------------------------------------------------------------------- 1 | = link_to 'Back to the list', root_path 2 | %hr 3 | %h2= params[:method].to_s.titleize 4 | %h2 Code 5 | = CodeRay.scan(@code, :ruby).div(:line_numbers => :table).html_safe 6 | %h2 Result 7 | = CodeRay.scan(@result.inspect, :ruby).div.html_safe 8 | - if @note 9 | %h2 Note 10 | = auto_link @note 11 | - if @docs && @doc_urls 12 | %h2 Document 13 | - @docs.zip(@doc_urls).each do |doc, doc_url| 14 | = link_to 'API Document', doc_url 15 | = doc.html_safe 16 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/controllers/login_controller.rb: -------------------------------------------------------------------------------- 1 | class LoginController < ApplicationController 2 | rescue_from OAuth::Unauthorized, :with => Proc.new{redirect_to root_path} 3 | 4 | def callback 5 | session[:authtoken] = request.env['omniauth.auth']['credentials']['token'] 6 | session[:dry_run] = true 7 | redirect_to root_path 8 | end 9 | 10 | def oauth_failure 11 | redirect_to root_path 12 | end 13 | 14 | def logout 15 | session.clear 16 | redirect_to root_path 17 | end 18 | 19 | end 20 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/test/test_helper.rb: -------------------------------------------------------------------------------- 1 | ENV["RAILS_ENV"] = "test" 2 | require File.expand_path('../../config/environment', __FILE__) 3 | require 'rails/test_help' 4 | 5 | class ActiveSupport::TestCase 6 | # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. 7 | # 8 | # Note: You'll currently still have to declare fixtures explicitly in integration tests 9 | # -- they do not yet inherit this setting 10 | fixtures :all 11 | 12 | # Add more helper methods to be used by all tests here... 13 | end 14 | -------------------------------------------------------------------------------- /lib/evernote_oauth.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | require 'oauth' 3 | require 'yaml' 4 | require 'evernote-thrift' 5 | 6 | require 'evernote_types' 7 | 8 | require 'evernote_oauth/thrift_client_delegation' 9 | require 'evernote_oauth/user_store' 10 | require 'evernote_oauth/note_store' 11 | require 'evernote_oauth/shared_note_store' 12 | require 'evernote_oauth/business_note_store' 13 | require 'evernote_oauth/business_utils' 14 | require 'evernote_oauth/store_attachable' 15 | require 'evernote_oauth/version' 16 | 17 | require 'evernote_oauth/client' 18 | -------------------------------------------------------------------------------- /lib/evernote/edam/type/user.rb: -------------------------------------------------------------------------------- 1 | module Evernote 2 | module EDAM 3 | module Type 4 | class User 5 | 6 | # Determines if this user is a part of a business 7 | # 8 | # @return [Boolean] 9 | def belongs_to_business? 10 | self.accounting.businessId != nil 11 | end 12 | 13 | # Returns the business name 14 | # 15 | # @return [String] 16 | def business_name 17 | self.accounting.businessName 18 | end 19 | 20 | end 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/config/initializers/secret_token.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Your secret key for verifying the integrity of signed cookies. 4 | # If you change this key, all old signed cookies will become invalid! 5 | # Make sure the secret is at least 30 characters and all random, 6 | # no regular words or you'll be exposed to dictionary attacks. 7 | EvernoteSample::Application.config.secret_token = 'c2fdc08ed383d0545c79c2afccaa125fb00dc3400e4b004ba3134cc71d59c4f82e60b9b0fd4926bc4a7ceca13c6d4b6db2bae41e161c28e90b267d17793ddca5' 8 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | # 3 | # This file contains settings for ActionController::ParamsWrapper which 4 | # is enabled by default. 5 | 6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. 7 | ActiveSupport.on_load(:action_controller) do 8 | wrap_parameters format: [:json] 9 | end 10 | 11 | # Disable root element in JSON by default. 12 | ActiveSupport.on_load(:active_record) do 13 | self.include_root_in_json = false 14 | end 15 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/config/routes.rb: -------------------------------------------------------------------------------- 1 | EvernoteSample::Application.routes.draw do 2 | root :to => 'home#index' 3 | 4 | get '/modes/switch' => 'home#switch_mode', :as => 'switch_mode' 5 | 6 | get '/auth/:provider/callback' => 'login#callback' 7 | get '/logout' => 'login#logout', :as => 'logout' 8 | get '/oauth_failure' => 'login#oauth_failure' 9 | 10 | get 'user_store/:method' => 'user_store#call', :as => 'user_store' 11 | get 'note_store/:method' => 'note_store#call', :as => 'note_store' 12 | get 'advanced/:method' => 'advanced#call', :as => 'advanced' 13 | end 14 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/views/home/index.html.haml: -------------------------------------------------------------------------------- 1 | - if ENV['EN_CONSUMER_KEY'].blank? || ENV['EN_CONSUMER_SECRET'].blank? 2 | %h2 You have to set your Evernote Consumer Key and Consumer Secret in you environmental variables first. 3 | %ul 4 | %li= "EN_CONSUMER_KEY: #{ENV['EN_CONSUMER_KEY']}" 5 | %li= "EN_CONSUMER_SECRET: #{ENV['EN_CONSUMER_SECRET']}" 6 | 7 | - elsif authtoken 8 | = link_to (session[:dry_run] ? "Allow actual API call" : "Prohibit actual API call"), switch_mode_path 9 | | 10 | = link_to 'Logout', logout_path 11 | %hr 12 | = render 'api_list' 13 | - else 14 | = link_to 'Login via Evernote', '/auth/evernote' 15 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format 4 | # (all these examples are active by default): 5 | # ActiveSupport::Inflector.inflections do |inflect| 6 | # inflect.plural /^(ox)$/i, '\1en' 7 | # inflect.singular /^(ox)en/i, '\1' 8 | # inflect.irregular 'person', 'people' 9 | # inflect.uncountable %w( fish sheep ) 10 | # end 11 | # 12 | # These inflection rules are supported but not enabled by default: 13 | # ActiveSupport::Inflector.inflections do |inflect| 14 | # inflect.acronym 'RESTful' 15 | # end 16 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/assets/stylesheets/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll be compiled into application.css, which will include all the files 3 | * listed below. 4 | * 5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, 6 | * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. 7 | * 8 | * You're free to add application-wide styles to this file and they'll appear at the top of the 9 | * compiled file, but it's generally better to create a new file per style scope. 10 | * 11 | *= require_self 12 | *= require_tree . 13 | */ 14 | 15 | fieldset { 16 | border: none; 17 | } 18 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/views/home/api_result.html.haml: -------------------------------------------------------------------------------- 1 | = link_to 'Back to the list', root_path 2 | %hr 3 | %h2= "#{controller_name.classify}##{params[:method]}" 4 | %h2 Code 5 | = CodeRay.scan(@code, :ruby).div(line_numbers: :table).html_safe 6 | %h2 Result 7 | - if params[:method] == 'getResourceData' 8 | %img{:src => "data:image/png;base64,#{[@result].pack('m')}"} 9 | = CodeRay.scan(truncate(@result.inspect, length: 100), :ruby).div.html_safe 10 | - else 11 | = CodeRay.scan(@result.awesome_inspect(plain: true), :ruby).div.html_safe 12 | - if @note 13 | %h2 Note 14 | = auto_link @note 15 | - if @doc && @doc_url 16 | %h2 Document 17 | = link_to 'API Document', @doc_url 18 | = @doc.html_safe 19 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/config/database.yml: -------------------------------------------------------------------------------- 1 | # SQLite version 3.x 2 | # gem install sqlite3 3 | # 4 | # Ensure the SQLite 3 gem is defined in your Gemfile 5 | # gem 'sqlite3' 6 | development: 7 | adapter: sqlite3 8 | database: db/development.sqlite3 9 | pool: 5 10 | timeout: 5000 11 | 12 | # Warning: The database defined as "test" will be erased and 13 | # re-generated from your development database when you run "rake". 14 | # Do not set this db to the same as development or production. 15 | test: 16 | adapter: sqlite3 17 | database: db/test.sqlite3 18 | pool: 5 19 | timeout: 5000 20 | 21 | production: 22 | adapter: sqlite3 23 | database: db/production.sqlite3 24 | pool: 5 25 | timeout: 5000 26 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/assets/javascripts/application.js: -------------------------------------------------------------------------------- 1 | // This is a manifest file that'll be compiled into application.js, which will include all the files 2 | // listed below. 3 | // 4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, 5 | // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. 6 | // 7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 8 | // the compiled file. 9 | // 10 | // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD 11 | // GO AFTER THE REQUIRES BELOW. 12 | // 13 | //= require jquery 14 | //= require jquery-ui 15 | //= require jquery_ujs 16 | //= require_tree . 17 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | We're sorry, but something went wrong (500) 5 | 17 | 18 | 19 | 20 | 21 |
22 |

We're sorry, but something went wrong.

23 |
24 | 25 | 26 | -------------------------------------------------------------------------------- /sample/sinatra/views/notes.slim: -------------------------------------------------------------------------------- 1 | p style='color:green' 2 | | Congratulations, you have successfully authorized this application to access your Evernote account! 3 | hr 4 | 5 | - if @note 6 | p 7 | | #{@note.title} is updated by webhook. 8 | hr 9 | 10 | p 11 | | Following notes are webhooked from you Evernote account "#{@user.username}": 12 | ul 13 | - @notes.each do |note| 14 | li= note.title 15 | hr 16 | 17 | p 18 | | Let's see what happens if webhook notifications are sent by clicking following links. 19 | | Following links simulate Evernote webhook notifications which would be sent when notes are created. 20 | - @evernote_notes.each do |note| 21 | li 22 | - url = "/webhook?userId=#{@user.user_id}&guid=#{note.guid}&reason=create" 23 | a href="#{url}" #{url} 24 | 25 | -------------------------------------------------------------------------------- /lib/evernote_oauth/note_store.rb: -------------------------------------------------------------------------------- 1 | module EvernoteOAuth 2 | 3 | module NoteStore 4 | include ::EvernoteOAuth::UserStore 5 | 6 | # Returns note_store 7 | # 8 | # @return [EvernoteOAuth::NoteStore::Store] 9 | def note_store(options={}) 10 | @note_store = EvernoteOAuth::NoteStore::Store.new( 11 | token: options[:token] || @token, 12 | client: thrift_client(::Evernote::EDAM::NoteStore::NoteStore::Client, 13 | options[:note_store_url] || user_store.getNoteStoreUrl) 14 | ) 15 | end 16 | 17 | class Store 18 | include ::EvernoteOAuth::ThriftClientDelegation 19 | 20 | def initialize(options={}) 21 | @token = options[:token] 22 | @client = options[:client] 23 | end 24 | 25 | end 26 | 27 | end 28 | 29 | end 30 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The change you wanted was rejected (422) 5 | 17 | 18 | 19 | 20 | 21 |
22 |

The change you wanted was rejected.

23 |

Maybe you tried to change something you didn't have access to.

24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The page you were looking for doesn't exist (404) 5 | 17 | 18 | 19 | 20 | 21 |
22 |

The page you were looking for doesn't exist.

23 |

You may have mistyped the address or the page may have moved.

24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /spec/evernote_oauth/note_store_spec.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "/../spec_helper") 2 | 3 | describe "EvernoteOAuth::NoteStore" do 4 | include EvernoteOAuth::NoteStore 5 | 6 | context "#initialize" do 7 | it "assigns instance variables" do 8 | note_store = EvernoteOAuth::NoteStore::Store.new(client: 'client') 9 | note_store.instance_variable_get(:@client).should == 'client' 10 | end 11 | end 12 | context "#method_missing" do 13 | it "dispatches method" do 14 | mock_client = double(Object) 15 | mock_client.should_receive(:send).with(:call_method, 'args') 16 | mock_client.class.should_receive(:instance_method).with(:call_method).and_return{ 17 | Proc.new {|a| a} 18 | } 19 | note_store = EvernoteOAuth::NoteStore::Store.new(client: mock_client) 20 | note_store.call_method('args') 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /spec/evernote_oauth/business_note_store_spec.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "/../spec_helper") 2 | 3 | describe "EvernoteOAuth::BusinessNoteStore" do 4 | include EvernoteOAuth::BusinessNoteStore 5 | 6 | context "#initialize" do 7 | it "assigns instance variables" do 8 | business_note_store = EvernoteOAuth::BusinessNoteStore::Store.new(client: 'client') 9 | business_note_store.instance_variable_get(:@client).should == 'client' 10 | end 11 | end 12 | context "#method_missing" do 13 | it "dispatches method" do 14 | mock_client = double(Object) 15 | mock_client.should_receive(:send).with(:call_method, 'args') 16 | mock_client.class.should_receive(:instance_method).with(:call_method).and_return{ 17 | Proc.new {|a| a} 18 | } 19 | note_store = EvernoteOAuth::BusinessNoteStore::Store.new(client: mock_client) 20 | note_store.call_method('args') 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /lib/evernote_oauth/business_note_store.rb: -------------------------------------------------------------------------------- 1 | module EvernoteOAuth 2 | 3 | module BusinessNoteStore 4 | include UserStore 5 | 6 | # Returns note_store for a business account 7 | # 8 | # @return [EvernoteOAuth::BusinessNoteStore::Store] 9 | def business_note_store(options={}) 10 | auth = user_store.authenticateToBusiness(options[:token] || @token) 11 | EvernoteOAuth::BusinessNoteStore::Store.new( 12 | token: auth.authenticationToken, 13 | client: thrift_client(::Evernote::EDAM::NoteStore::NoteStore::Client, 14 | auth.noteStoreUrl), 15 | user: auth.user 16 | ) 17 | end 18 | 19 | class Store 20 | include ::EvernoteOAuth::ThriftClientDelegation 21 | attr_reader :token, :user 22 | 23 | def initialize(options={}) 24 | @token = options[:token] 25 | @client = options[:client] 26 | @user = options[:user] 27 | end 28 | end 29 | 30 | end 31 | 32 | end 33 | -------------------------------------------------------------------------------- /lib/evernote_oauth/user_store.rb: -------------------------------------------------------------------------------- 1 | module EvernoteOAuth 2 | 3 | module UserStore 4 | 5 | # Returns user_store 6 | # 7 | # @return [EvernoteOAuth::UserStore::Store] 8 | def user_store 9 | @user_store = EvernoteOAuth::UserStore::Store.new( 10 | token: @token, 11 | client: thrift_client(::Evernote::EDAM::UserStore::UserStore::Client, 12 | endpoint('edam/user')) 13 | ) 14 | end 15 | 16 | class Store 17 | include ::EvernoteOAuth::ThriftClientDelegation 18 | 19 | def initialize(options={}) 20 | @token = options[:token] 21 | @client = options[:client] 22 | raise 'API version is not up to date' unless version_valid? 23 | end 24 | 25 | def version_valid? 26 | checkVersion("EDAMTest", 27 | ::Evernote::EDAM::UserStore::EDAM_VERSION_MAJOR, 28 | ::Evernote::EDAM::UserStore::EDAM_VERSION_MINOR) 29 | end 30 | end 31 | 32 | end 33 | 34 | end 35 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/controllers/home_controller.rb: -------------------------------------------------------------------------------- 1 | class HomeController < ApplicationController 2 | def index 3 | @available_us_methods = UserStoreController.private_instance_methods(false).select{|m| 4 | !m.to_s.start_with?('_') 5 | } 6 | @unavailable_us_methods = 7 | Evernote::EDAM::UserStore::UserStore::Client.instance_methods(false).select{|m| 8 | !m.to_s.match(/send_|recv_/) 9 | }.sort - @available_us_methods 10 | 11 | @available_ns_methods = NoteStoreController.private_instance_methods(false).select{|m| 12 | !m.to_s.start_with?('_') 13 | } 14 | @unavailable_ns_methods = 15 | Evernote::EDAM::NoteStore::NoteStore::Client.instance_methods(false).select{|m| 16 | !m.to_s.match(/send_|recv_/) 17 | }.sort - @available_ns_methods 18 | @available_advanced_methods = AdvancedController.private_instance_methods(false).select{|m| 19 | !m.to_s.start_with?('_') 20 | } 21 | end 22 | 23 | def switch_mode 24 | session[:dry_run] = !session[:dry_run] 25 | redirect_to :root 26 | end 27 | 28 | end 29 | -------------------------------------------------------------------------------- /lib/evernote_oauth/shared_note_store.rb: -------------------------------------------------------------------------------- 1 | module EvernoteOAuth 2 | 3 | module SharedNoteStore 4 | 5 | # Returns note_store for a shared notebook 6 | # 7 | # @param linked_notebook [Evernote::EDAM::Type::LinkedNotebook] 8 | # @return [EvernoteOAuth::SharedNoteStore::Store] 9 | def shared_note_store(linked_notebook, options={}) 10 | EvernoteOAuth::SharedNoteStore::Store.new( 11 | linked_notebook: linked_notebook, 12 | token: options[:token] || @token, 13 | client: thrift_client(::Evernote::EDAM::NoteStore::NoteStore::Client, 14 | linked_notebook.noteStoreUrl) 15 | ) 16 | end 17 | 18 | class Store 19 | include ::EvernoteOAuth::ThriftClientDelegation 20 | attr_reader :token 21 | 22 | def initialize(options={}) 23 | @linked_notebook = options[:linked_notebook] 24 | @client = options[:client] 25 | @token = authenticateToSharedNotebook(@linked_notebook.shareKey, 26 | options[:token]).authenticationToken 27 | end 28 | end 29 | 30 | end 31 | 32 | end 33 | -------------------------------------------------------------------------------- /lib/evernote_oauth/store_attachable.rb: -------------------------------------------------------------------------------- 1 | module EvernoteOAuth 2 | module StoreAttachable 3 | def attach_user_store(*field_symbols) 4 | attach_store('user', *field_symbols) 5 | end 6 | 7 | def attach_note_store(*field_symbols) 8 | attach_store('note', *field_symbols) 9 | end 10 | 11 | def attach_store(type, *field_symbols) 12 | field_symbols.each do |fs| 13 | define_method(fs) do 14 | original = "@#{fs}".to_sym 15 | target = "@#{fs}_with_#{type}_stores".to_sym 16 | with_stores = ( 17 | instance_variable_get(target) || 18 | begin 19 | store_name = "#{type}_store" 20 | if respond_to?(store_name.to_sym) 21 | store = eval(store_name) 22 | [instance_variable_get(original)].flatten.each{|n| 23 | n.define_singleton_method(store_name.to_sym){store} 24 | } 25 | end 26 | instance_variable_get(original) 27 | end 28 | ) 29 | instance_variable_set(target, with_stores) 30 | end 31 | end 32 | end 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | 3 | # These methods are not available to third party applications 4 | UNAVAILABLE_METHODS = [:authenticate, :authenticateLongSession, :refreshAuthentication, :emailNote, :expungeInactiveNotes, 5 | :expungeLinkedNotebook, :expungeNote, :expungeNotebook, :expungeNotes, :expungeSearch, 6 | :expungeSharedNotebooks, :expungeTag, :getAccountSize, :getAds, :getRandomAd] 7 | 8 | def link_to_user_store(method_name) 9 | link_to link_body(method_name), user_store_path(method: method_name), 10 | :id => "user_store_#{method_name}" 11 | end 12 | 13 | def link_to_note_store(method_name) 14 | link_to link_body(method_name), note_store_path(method: method_name), 15 | :id => "note_store_#{method_name}" 16 | end 17 | 18 | def link_to_advanced(method_name) 19 | link_to method_name.to_s.titleize, advanced_path(method: method_name), 20 | :id => "advanced_#{method_name}" 21 | end 22 | 23 | private 24 | # Show the 'unavailable' label 25 | def link_body(method_name) 26 | "#{('[UNAVAILABLE] ' if UNAVAILABLE_METHODS.include?(method_name))}#{method_name}" 27 | end 28 | 29 | end 30 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/controllers/evernote_controller.rb: -------------------------------------------------------------------------------- 1 | class EvernoteController < ApplicationController 2 | 3 | DOC_URL_BASE = 'http://dev.evernote.com/documentation/reference' 4 | 5 | def call 6 | begin 7 | send(params[:method]) 8 | rescue NoMethodError => e 9 | redirect_to root_path and return 10 | end 11 | 12 | @result = (run_code? && @code ? eval(@code) : 'N/A') rescue $! 13 | @code ||= 'N/A' 14 | @doc = doc 15 | 16 | render 'home/api_result' 17 | end 18 | 19 | private 20 | # Scrape Evernote API reference 21 | def doc(clazz=controller_name.classify, method=params[:method]) 22 | doc_id = "Fn_#{clazz}_#{method}" 23 | doc_page = "#{DOC_URL_BASE}/#{clazz}.html" 24 | @doc_url = "#{doc_page}##{doc_id}" 25 | 26 | doc = Nokogiri::HTML(open(@doc_url)).css('div.definition').select{|n| 27 | n.child.attributes['id'].value == doc_id 28 | }.first 29 | doc.xpath('.//a').each do |el| 30 | href = el.attributes['href'].value 31 | el.attributes['href'].value = "#{DOC_URL_BASE}/#{href}" unless href.start_with?('http') 32 | end 33 | doc.to_s.html_safe 34 | end 35 | 36 | def run_code? 37 | !session[:dry_run] 38 | end 39 | 40 | end 41 | -------------------------------------------------------------------------------- /spec/evernote_oauth/store_attachable_spec.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "/../spec_helper") 2 | 3 | describe "EvernoteOAuth::StoreAttachable" do 4 | 5 | context "#attach_user_store" do 6 | it "assigns user_store to a field" do 7 | class MyObject 8 | extend EvernoteOAuth::StoreAttachable 9 | attr_accessor :dummy_field 10 | attach_user_store :dummy_field 11 | end 12 | object = MyObject.new 13 | object.define_singleton_method(:user_store) do 14 | :dummy_user_store 15 | end 16 | object.dummy_field = Object.new 17 | 18 | object.dummy_field.user_store.should == object.user_store 19 | end 20 | end 21 | 22 | context "#attach_note_store" do 23 | it "assigns note_store to a field" do 24 | class MyObject 25 | extend EvernoteOAuth::StoreAttachable 26 | attr_accessor :dummy_field 27 | attach_note_store :dummy_field 28 | end 29 | object = MyObject.new 30 | object.define_singleton_method(:note_store) do 31 | :dummy_note_store 32 | end 33 | object.dummy_field = Object.new 34 | 35 | object.dummy_field.note_store.should == object.note_store 36 | end 37 | end 38 | 39 | end 40 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/README.md: -------------------------------------------------------------------------------- 1 | Evernote Sample Usage of API for Ruby on Rails 2 | ============================================== 3 | This is a sample application of Ruby on Rails with evernote_oauth gem and evernote-omniauth gem. 4 | 5 | Setup 6 | ----- 7 | - Set environmental variables below: 8 | - EN_CONSUMER_KEY: Your API Consumer Key 9 | - EN_CONSUMER_SECRET: Your API Consumer Secret 10 | - You need a sandbox account. If you haven't had a Sandbox account yet, you can create one [here](https://sandbox.evernote.com/Registration.action) 11 | - `bundle install` 12 | - If you don't have bundler gem, you can install it with `gem install bundler`. 13 | 14 | How to use? 15 | ----------- 16 | You can start rails server with `rails start`. Once the rails server starts, you can access `http://localhost:3000` and see the application. 17 | 18 | This sample application gives you sample code on how to use each API. When you log in first, it runs as a reference mode which just shows how to write code and API document. If you want to run the API call and see actual return value, you can click the "Allow actual API call" link on the top of root page. 19 | 20 | Methods with "[UNAVAILABLE]" are only available to Evernote's internal applications or deprecated. 21 | -------------------------------------------------------------------------------- /sample/sinatra/Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | activemodel (3.2.13) 5 | activesupport (= 3.2.13) 6 | builder (~> 3.0.0) 7 | activerecord (3.2.13) 8 | activemodel (= 3.2.13) 9 | activesupport (= 3.2.13) 10 | arel (~> 3.0.2) 11 | tzinfo (~> 0.3.29) 12 | activesupport (3.2.13) 13 | i18n (= 0.6.1) 14 | multi_json (~> 1.0) 15 | arel (3.0.2) 16 | builder (3.0.4) 17 | evernote-thrift (1.25.1) 18 | evernote_oauth (0.2.3) 19 | evernote-thrift 20 | oauth (>= 0.4.1) 21 | i18n (0.6.1) 22 | multi_json (1.7.2) 23 | oauth (0.4.7) 24 | rack (1.5.2) 25 | rack-protection (1.5.0) 26 | rack 27 | rake (10.0.4) 28 | sinatra (1.4.2) 29 | rack (~> 1.5, >= 1.5.2) 30 | rack-protection (~> 1.4) 31 | tilt (~> 1.3, >= 1.3.4) 32 | sinatra-activerecord (1.2.2) 33 | activerecord (~> 3.0) 34 | sinatra (~> 1.0) 35 | slim (1.3.6) 36 | temple (~> 0.5.5) 37 | tilt (~> 1.3.3) 38 | sqlite3 (1.3.7) 39 | temple (0.5.5) 40 | tilt (1.3.6) 41 | tzinfo (0.3.37) 42 | 43 | PLATFORMS 44 | ruby 45 | 46 | DEPENDENCIES 47 | evernote_oauth 48 | rake 49 | sinatra 50 | sinatra-activerecord 51 | slim 52 | sqlite3 53 | -------------------------------------------------------------------------------- /spec/evernote_oauth/user_store_spec.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "/../spec_helper") 2 | 3 | describe "EvernoteOAuth::UserStore" do 4 | include EvernoteOAuth::UserStore 5 | 6 | context "#initialize" do 7 | it "assigns instance variables and checks version" do 8 | EvernoteOAuth::UserStore::Store.any_instance.stub(:version_valid?){true} 9 | user_store = EvernoteOAuth::UserStore::Store.new(client: 'client') 10 | user_store.instance_variable_get(:@client).should == 'client' 11 | end 12 | it "raises error when version is not valid" do 13 | EvernoteOAuth::UserStore::Store.any_instance.stub(:version_valid?){false} 14 | lambda{EvernoteOAuth::UserStore::Store.new(client: 'client')}.should raise_error 15 | end 16 | end 17 | context "#method_missing" do 18 | it "dispatches method" do 19 | mock_client = double(Object) 20 | mock_client.should_receive(:send).with(:call_method, 'args') 21 | mock_client.class.should_receive(:instance_method).with(:call_method).and_return{ 22 | Proc.new {|a| a} 23 | } 24 | EvernoteOAuth::UserStore::Store.any_instance.stub(:version_valid?){true} 25 | user_store = EvernoteOAuth::UserStore::Store.new(client: mock_client) 26 | user_store.call_method('args') 27 | end 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /lib/evernote/edam/type/resource.rb: -------------------------------------------------------------------------------- 1 | module Evernote 2 | module EDAM 3 | module Type 4 | class Resource 5 | @note_by_options = {} 6 | 7 | # Returns the note that holds this resource. 8 | # 9 | # @param options [Hash] options for {http://dev.evernote.com/documentation/reference/NoteStore.html#Fn_NoteStore_getNote}. 10 | # @option options [String] :with_content 11 | # @option options [String] :with_resources_data 12 | # @option options [String] :with_resources_recognition 13 | # @option options [String] :with_resources_alternate_data 14 | # @return [Evernote::EDAM::Type::Note] 15 | def note(options={}) 16 | options = { 17 | with_content: false, 18 | with_resources_data: false, 19 | with_resources_recognition: false, 20 | with_resources_alternate_data: false 21 | }.merge(options) 22 | 23 | @note_by_opions[options] || 24 | (@note_by_options[options] = note_store.getNote( 25 | noteGuid, 26 | options[:with_content], 27 | options[:with_resources_data], 28 | options[:with_resources_recognition], 29 | options[:with_resources_alternate_data]) 30 | ) 31 | end 32 | 33 | end 34 | end 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /evernote_oauth.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | lib = File.expand_path('../lib/', __FILE__) 3 | $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib) 4 | 5 | require 'evernote_oauth/version' 6 | 7 | Gem::Specification.new do |s| 8 | s.name = %q{evernote_oauth} 9 | s.version = EvernoteOAuth::VERSION 10 | 11 | s.authors = ["Evernote"] 12 | s.date = Time.now.strftime('%Y-%m-%d') 13 | s.licenses = ['BSD 2-Clause'] 14 | s.description = %q{evernote_oauth is a Ruby client for the Evernote API using OAuth and Thrift.} 15 | s.email = %q{api@evernote.com} 16 | s.files = ["LICENSE", "README.md", "evernote_oauth.gemspec"] + Dir.glob('{lib,spec}/**/*') 17 | s.has_rdoc = false 18 | s.homepage = %q{http://github.com/evernote/evernote-oauth-ruby} 19 | s.rdoc_options = ["--inline-source", "--charset=UTF-8"] 20 | s.require_paths = ["lib"] 21 | s.rubyforge_project = %q{evernote_oauth} 22 | s.rubygems_version = EvernoteOAuth::VERSION 23 | s.summary = %q{Ruby client for the Evernote API using OAuth and Thrift.} 24 | 25 | if s.respond_to? :specification_version then 26 | current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION 27 | s.specification_version = 2 28 | 29 | s.add_dependency 'oauth', '>= 0.4.1' 30 | s.add_dependency 'evernote-thrift' 31 | s.add_development_dependency 'rspec' 32 | s.add_development_dependency 'yard' 33 | s.add_development_dependency 'redcarpet' 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2014 by Evernote Corporation, All rights reserved. 3 | * 4 | * Use of the source code and binary libraries included in this package 5 | * is permitted under the following terms: 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | -------------------------------------------------------------------------------- /spec/evernote_oauth/shared_note_store_spec.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "/../spec_helper") 2 | 3 | describe "EvernoteOAuth::SharedNoteStore" do 4 | include EvernoteOAuth::SharedNoteStore 5 | 6 | context "#initialize" do 7 | it "assigns instance variables" do 8 | sn = Struct.new(:shareKey).new('shareKey') 9 | auth_token = Struct.new(:authenticationToken).new('token') 10 | EvernoteOAuth::SharedNoteStore::Store.any_instance.should_receive( 11 | :authenticateToSharedNotebook).and_return(auth_token) 12 | note_store = EvernoteOAuth::SharedNoteStore::Store.new(client: 'client', linked_notebook: sn) 13 | note_store.instance_variable_get(:@client).should == 'client' 14 | note_store.token.should == 'token' 15 | end 16 | end 17 | context "#method_missing" do 18 | it "dispatches method" do 19 | mock_client = double(Object) 20 | mock_client.should_receive(:send).with(:call_method, 'args') 21 | mock_client.class.should_receive(:instance_method).with(:call_method).and_return{ 22 | Proc.new {|a| a} 23 | } 24 | sn = Struct.new(:shareKey).new('shareKey') 25 | auth_token = Struct.new(:authenticationToken).new('token') 26 | EvernoteOAuth::SharedNoteStore::Store.any_instance.should_receive( 27 | :authenticateToSharedNotebook).and_return(auth_token) 28 | note_store = EvernoteOAuth::SharedNoteStore::Store.new(client: mock_client, linked_notebook: sn) 29 | note_store.call_method('args') 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/config/environments/development.rb: -------------------------------------------------------------------------------- 1 | EvernoteSample::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb 3 | 4 | # In the development environment your application's code is reloaded on 5 | # every request. This slows down response time but is perfect for development 6 | # since you don't have to restart the web server when you make code changes. 7 | config.cache_classes = false 8 | 9 | # Log error messages when you accidentally call methods on nil. 10 | config.whiny_nils = true 11 | 12 | # Show full error reports and disable caching 13 | config.consider_all_requests_local = true 14 | config.action_controller.perform_caching = false 15 | 16 | # Don't care if the mailer can't send 17 | config.action_mailer.raise_delivery_errors = false 18 | 19 | # Print deprecation notices to the Rails logger 20 | config.active_support.deprecation = :log 21 | 22 | # Only use best-standards-support built into browsers 23 | config.action_dispatch.best_standards_support = :builtin 24 | 25 | # Raise exception on mass assignment protection for Active Record models 26 | config.active_record.mass_assignment_sanitizer = :strict 27 | 28 | # Log the query plan for queries taking more than this (works 29 | # with SQLite, MySQL, and PostgreSQL) 30 | config.active_record.auto_explain_threshold_in_seconds = 0.5 31 | 32 | # Do not compress assets 33 | config.assets.compress = false 34 | 35 | # Expands the lines which load the assets 36 | config.assets.debug = true 37 | end 38 | -------------------------------------------------------------------------------- /lib/evernote_oauth/thrift_client_delegation.rb: -------------------------------------------------------------------------------- 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 | result = @client.send(name, *new_args, &block) 12 | rescue ArgumentError => e 13 | result = @client.send(name, *args, &block) 14 | end 15 | else 16 | result = @client.send(name, *args, &block) 17 | end 18 | 19 | attr_value = self 20 | [result].flatten.each{|r| 21 | begin 22 | r.define_singleton_method(attr_name){attr_value} 23 | rescue TypeError # Fixnum/TrueClass/FalseClass/NilClass 24 | next 25 | end 26 | } 27 | result 28 | end 29 | 30 | private 31 | def attr_name 32 | name = underscore(self.class.name.gsub(/::Store$/, '').split('::').last) 33 | if name.end_with?('user_store') 34 | :user_store 35 | elsif name.end_with?('note_store') 36 | :note_store 37 | else 38 | raise "Unsupported type: #{self.class.name}" 39 | end 40 | end 41 | 42 | def underscore(word) 43 | word.to_s.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). 44 | gsub(/([a-z\d])([A-Z])/,'\1_\2'). 45 | tr("-", "_"). 46 | downcase 47 | end 48 | end 49 | 50 | end 51 | -------------------------------------------------------------------------------- /lib/evernote/edam/type/note.rb: -------------------------------------------------------------------------------- 1 | module Evernote 2 | module EDAM 3 | module Type 4 | class Note 5 | 6 | # Returns the notebook that contains this note. 7 | # 8 | # @return [Evernote::EDAM::Type::Notebook] 9 | def notebook 10 | @notebook ||= note_store.getNotebook(notebookGuid) 11 | end 12 | 13 | # Returns the tags that are applied to this note. 14 | # 15 | # @return [Array] 16 | def tags 17 | @tags ||= (tagGuids || []).map{|guid| note_store.getTag(guid)} 18 | end 19 | 20 | # Add resource to this note. 21 | # 22 | # @param filename [String] the name of the resource 23 | # @param file [File] 24 | # @param mime [String] MIME type of the resource 25 | # 26 | # @return [String] Hexdigest of the given file 27 | def add_resource(filename, file, mime) 28 | hash_func = Digest::MD5.new 29 | 30 | data = Evernote::EDAM::Type::Data.new 31 | data.size = file.size 32 | data.bodyHash = hash_func.digest(file) 33 | data.body = file 34 | 35 | resource = Evernote::EDAM::Type::Resource.new 36 | resource.mime = mime 37 | resource.data = data 38 | resource.attributes = Evernote::EDAM::Type::ResourceAttributes.new 39 | resource.attributes.fileName = filename 40 | 41 | self.resources = [] unless self.resources 42 | self.resources << resource 43 | 44 | hash_func.hexdigest(file) 45 | end 46 | end 47 | end 48 | end 49 | end 50 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/config/environments/test.rb: -------------------------------------------------------------------------------- 1 | EvernoteSample::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb 3 | 4 | # The test environment is used exclusively to run your application's 5 | # test suite. You never need to work with it otherwise. Remember that 6 | # your test database is "scratch space" for the test suite and is wiped 7 | # and recreated between test runs. Don't rely on the data there! 8 | config.cache_classes = true 9 | 10 | # Configure static asset server for tests with Cache-Control for performance 11 | config.serve_static_assets = true 12 | config.static_cache_control = "public, max-age=3600" 13 | 14 | # Log error messages when you accidentally call methods on nil 15 | config.whiny_nils = true 16 | 17 | # Show full error reports and disable caching 18 | config.consider_all_requests_local = true 19 | config.action_controller.perform_caching = false 20 | 21 | # Raise exceptions instead of rendering exception templates 22 | config.action_dispatch.show_exceptions = false 23 | 24 | # Disable request forgery protection in test environment 25 | config.action_controller.allow_forgery_protection = false 26 | 27 | # Tell Action Mailer not to deliver emails to the real world. 28 | # The :test delivery method accumulates sent emails in the 29 | # ActionMailer::Base.deliveries array. 30 | config.action_mailer.delivery_method = :test 31 | 32 | # Raise exception on mass assignment protection for Active Record models 33 | config.active_record.mass_assignment_sanitizer = :strict 34 | 35 | # Print deprecation notices to the stderr 36 | config.active_support.deprecation = :stderr 37 | end 38 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/controllers/user_store_controller.rb: -------------------------------------------------------------------------------- 1 | class UserStoreController < EvernoteController 2 | 3 | private 4 | def authenticate; end 5 | def authenticateLongSession; end 6 | 7 | def authenticateToBusiness 8 | @code = <<-CODE 9 | client = EvernoteOAuth::Client.new 10 | user_store = client.user_store 11 | user_store.authenticateToBusiness(authtoken) 12 | CODE 13 | end 14 | 15 | def checkVersion 16 | @code = <<-CODE 17 | client = EvernoteOAuth::Client.new 18 | user_store = client.user_store 19 | user_store.checkVersion('Evernote EDAMTest (Ruby)', Evernote::EDAM::UserStore::EDAM_VERSION_MAJOR, Evernote::EDAM::UserStore::EDAM_VERSION_MINOR) 20 | CODE 21 | end 22 | 23 | def getBootstrapInfo 24 | @code = <<-CODE 25 | client = EvernoteOAuth::Client.new 26 | user_store = client.user_store 27 | user_store.getBootstrapInfo('en_US') 28 | CODE 29 | end 30 | 31 | def getNoteStoreUrl 32 | @code = <<-CODE 33 | client = EvernoteOAuth::Client.new(token: authtoken) 34 | user_store = client.user_store 35 | user_store.getNoteStoreUrl 36 | CODE 37 | end 38 | 39 | def getPremiumInfo 40 | @code = <<-CODE 41 | client = EvernoteOAuth::Client.new(token: authtoken) 42 | user_store = client.user_store 43 | user_store.getPremiumInfo 44 | CODE 45 | end 46 | 47 | def getPublicUserInfo 48 | @code = <<-CODE 49 | client = EvernoteOAuth::Client.new(token: authtoken) 50 | user_store = client.user_store 51 | user_store.getPublicUserInfo('evernote') 52 | CODE 53 | end 54 | 55 | def getUser 56 | @code = <<-CODE 57 | client = EvernoteOAuth::Client.new(token: authtoken) 58 | user_store = client.user_store 59 | user_store.getUser 60 | CODE 61 | end 62 | 63 | def refreshAuthentication; end 64 | 65 | end 66 | -------------------------------------------------------------------------------- /sample/sinatra/README.md: -------------------------------------------------------------------------------- 1 | Evernote Sample Sinatra Application for OAuth and Webhook 2 | ========================================================= 3 | 4 | What is this? 5 | ------------- 6 | This is a sample app for OAuth and webhook with a basic usage of Evernote API. You can't test actual webhook in your local environment though, you would see how it works. 7 | 8 | What is Webhook? 9 | ---------------- 10 | If you are building web service and want to track changes of users notes on Evernote, you don't have to poll for them. 11 | You can register to receive notifications every time a user creates or updates a note. [Learn more about Webhook](http://dev.evernote.com/documentation/cloud/chapters/polling_notification.php). 12 | 13 | Setup 14 | ----- 15 | - You need a sandbox account. If you haven't had a Sandbox account yet, you can create one [here](https://sandbox.evernote.com/Registration.action) 16 | - It might be better that you create one or more notes in your Sandbox account before playing around this sample app. 17 | - Set environmental variables below: 18 | - EN_CONSUMER_KEY: Your API Consumer Key 19 | - EN_CONSUMER_SECRET: Your API Consumer Secret 20 | 21 | Or you can edit config/evernote.yml 22 | ```ruby 23 | consumer_key: YOUR CONSUMER KEY 24 | consumer_secret: YOUR CONSUMER SECRET 25 | sandbox: [true or false] 26 | ``` 27 | - Install dependent gems and create database with following commands: 28 | ```sh 29 | bundle install 30 | rake db:migrate 31 | ``` 32 | 33 | Run 34 | --- 35 | ```sh 36 | bundle exec rackup config.ru 37 | ``` 38 | Then you can access this app: [http://localhost:9292](http://localhost:9292). 39 | 40 | References 41 | ---------- 42 | - Evernote Developers: [http://dev.evernote.com/](http://dev.evernote.com/) 43 | - API Document: [http://dev.evernote.com/documentation/reference/](http://dev.evernote.com/documentation/reference/) 44 | -------------------------------------------------------------------------------- /spec/evernote_oauth/client_spec.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "/../spec_helper") 2 | 3 | describe "EvernoteOAuth::Client" do 4 | before :each do 5 | @client = EvernoteOAuth::Client.new( 6 | consumer_key: 'consumer_key', 7 | consumer_secret: 'consumer_secret', 8 | sandbox: false, 9 | token: 'token', 10 | secret: 'secret' 11 | ) 12 | end 13 | context "#initialize" do 14 | it "assigns instance variables" do 15 | @client.instance_variable_get(:@consumer_key).should == 'consumer_key' 16 | @client.instance_variable_get(:@consumer_secret).should == 'consumer_secret' 17 | @client.instance_variable_get(:@sandbox).should == false 18 | @client.instance_variable_get(:@token).should == 'token' 19 | @client.instance_variable_get(:@secret).should == 'secret' 20 | end 21 | end 22 | context "#authorize" do 23 | it "assigns returns access token" do 24 | mock_access_token = double(OAuth::AccessToken) 25 | mock_access_token.should_receive(:token).and_return('token') 26 | mock_access_token.should_receive(:secret).and_return('secret') 27 | mock_request_token = double(OAuth::RequestToken) 28 | mock_request_token.should_receive(:get_access_token).and_return(mock_access_token) 29 | OAuth::RequestToken.stub(:new){mock_request_token} 30 | 31 | @client.authorize('token', 'secret').should == mock_access_token 32 | end 33 | end 34 | context "#request_token" do 35 | it "calls OAuth::Consumer#get_request_token" do 36 | mock_request_token = double(OAuth::RequestToken) 37 | mock_consumer = double(OAuth::Consumer) 38 | mock_consumer.should_receive(:options).and_return({}) 39 | mock_consumer.should_receive(:get_request_token).with({}).and_return(mock_request_token) 40 | @client.stub(:consumer){mock_consumer} 41 | @client.request_token.should == mock_request_token 42 | end 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/views/home/_api_list.html.haml: -------------------------------------------------------------------------------- 1 | %h2 Sample Use Cases 2 | %ul 3 | - @available_advanced_methods.each do |m| 4 | %li= link_to_advanced m 5 | 6 | %h2 Basic Usage of UserStore 7 | %ul 8 | - @available_us_methods.each do |m| 9 | %li= link_to_user_store m 10 | - unless @unavailable_us_methods.blank? 11 | %h4 Not implemented 12 | %ul 13 | - @unavailable_us_methods.each do |m| 14 | %li= m 15 | 16 | %h2 Basic Usage of NoteStore 17 | %ul 18 | - @available_ns_methods.each do |m| 19 | %li= link_to_note_store m 20 | - unless @unavailable_ns_methods.blank? 21 | %h4 Not implemented 22 | %ul 23 | - @unavailable_ns_methods.each do |m| 24 | %li= m 25 | 26 | -# For NoteStore#createLinkedNotebook, NoteStore#createSharedNotebook 27 | - ['createLinkedNotebook', 'createSharedNotebook'].each do |m| 28 | %div{id: "#{m}-form", title: "Type your email address"} 29 | = form_tag do 30 | %fieldset 31 | = label_tag "email" 32 | = text_field_tag "email", '', 33 | :class => "text ui-widget-content ui-corner-all", :id => "email-#{m}", :size => 30 34 | 35 | :javascript 36 | $("##{m}-form").dialog({ 37 | autoOpen: false, 38 | height: 220, 39 | width: 400, 40 | modal: true, 41 | buttons: { 42 | Proceed: function() { 43 | window.location = 44 | $('#note_store_#{m}').attr('href') + '?email=' + $("#email-#{m}").val(); 45 | }, 46 | Cancel: function() { 47 | $( this ).dialog( "close" ); 48 | } 49 | } 50 | }); 51 | $("##{m}-form").keypress(function(e) { 52 | if (e.keyCode == $.ui.keyCode.ENTER) { 53 | window.location = 54 | $('#note_store_#{m}').attr('href') + '?email=' + $("#email-#{m}").val(); 55 | return false; 56 | } 57 | }); 58 | $("#note_store_#{m}").bind('click', function() { 59 | $("##{m}-form").dialog("open"); 60 | return false; 61 | }); 62 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/controllers/advanced_controller.rb: -------------------------------------------------------------------------------- 1 | class AdvancedController < EvernoteController 2 | 3 | def call 4 | begin 5 | send(params[:method]) 6 | rescue NoMethodError => e 7 | redirect_to root_path and return 8 | end 9 | 10 | @result = run_code? ? eval(@code) : "N/A" rescue $! 11 | 12 | @docs, @doc_urls = [], [] 13 | (@class_and_methods || []).each do |cm| 14 | @docs << doc(cm[:clazz], cm[:method]) 15 | @doc_urls << @doc_url 16 | end 17 | 18 | render 'advanced/api_result' 19 | end 20 | 21 | private 22 | def count_notes_by_notebook_name 23 | @class_and_methods = [ 24 | {clazz: 'NoteStore', method: 'listNotebooks'}, 25 | {clazz: 'NoteStore', method: 'findNoteCounts'} 26 | ] 27 | @code = <<-CODE 28 | client = EvernoteOAuth::Client.new(token: authtoken) 29 | note_store = client.note_store 30 | 31 | notebooks = note_store.listNotebooks 32 | notebook_names_by_guid = Hash[notebooks.map{|n| [n.guid, n.name]}] 33 | 34 | note_counts = note_store.findNoteCounts(Evernote::EDAM::NoteStore::NoteFilter.new, false) 35 | 36 | Hash[note_counts.notebookCounts.map{|guid, count| 37 | [notebook_names_by_guid[guid], count] 38 | }] 39 | CODE 40 | end 41 | 42 | def create_note_with_image 43 | @class_and_methods = [ 44 | {clazz: 'NoteStore', method: 'createNote'} 45 | ] 46 | @code = <<-CODE 47 | client = EvernoteOAuth::Client.new(token: authtoken) 48 | note_store = client.note_store 49 | 50 | note = Evernote::EDAM::Type::Note.new( 51 | title: 'Note', 52 | tagNames: ['Evernote API Sample'] 53 | ) 54 | 55 | filename = "enlogo.png" 56 | image = File.open(File.join(Rails.root, 'public', filename), "rb") { |io| io.read } 57 | hexdigest = note.add_resource(filename, image, 'image/png') 58 | 59 | note.content = < 61 | 62 | Content
63 | 64 |
65 | EOF 66 | 67 | note_store.createNote(note) 68 | CODE 69 | end 70 | 71 | end 72 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/config/environments/production.rb: -------------------------------------------------------------------------------- 1 | EvernoteSample::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb 3 | 4 | # Code is not reloaded between requests 5 | config.cache_classes = true 6 | 7 | # Full error reports are disabled and caching is turned on 8 | config.consider_all_requests_local = false 9 | config.action_controller.perform_caching = true 10 | 11 | # Disable Rails's static asset server (Apache or nginx will already do this) 12 | config.serve_static_assets = false 13 | 14 | # Compress JavaScripts and CSS 15 | config.assets.compress = true 16 | 17 | # Don't fallback to assets pipeline if a precompiled asset is missed 18 | config.assets.compile = false 19 | 20 | # Generate digests for assets URLs 21 | config.assets.digest = true 22 | 23 | # Defaults to nil and saved in location specified by config.assets.prefix 24 | # config.assets.manifest = YOUR_PATH 25 | 26 | # Specifies the header that your server uses for sending files 27 | # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache 28 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx 29 | 30 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 31 | # config.force_ssl = true 32 | 33 | # See everything in the log (default is :info) 34 | # config.log_level = :debug 35 | 36 | # Prepend all log lines with the following tags 37 | # config.log_tags = [ :subdomain, :uuid ] 38 | 39 | # Use a different logger for distributed setups 40 | # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) 41 | 42 | # Use a different cache store in production 43 | # config.cache_store = :mem_cache_store 44 | 45 | # Enable serving of images, stylesheets, and JavaScripts from an asset server 46 | # config.action_controller.asset_host = "http://assets.example.com" 47 | 48 | # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) 49 | # config.assets.precompile += %w( search.js ) 50 | 51 | # Disable delivery errors, bad email addresses will be ignored 52 | # config.action_mailer.raise_delivery_errors = false 53 | 54 | # Enable threaded mode 55 | # config.threadsafe! 56 | 57 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 58 | # the I18n.default_locale when a translation can not be found) 59 | config.i18n.fallbacks = true 60 | 61 | # Send deprecation notices to registered listeners 62 | config.active_support.deprecation = :notify 63 | 64 | # Log the query plan for queries taking more than this (works 65 | # with SQLite, MySQL, and PostgreSQL) 66 | # config.active_record.auto_explain_threshold_in_seconds = 0.5 67 | end 68 | -------------------------------------------------------------------------------- /lib/evernote_oauth/client.rb: -------------------------------------------------------------------------------- 1 | module EvernoteOAuth 2 | class Client 3 | include ::EvernoteOAuth::UserStore 4 | include ::EvernoteOAuth::NoteStore 5 | include ::EvernoteOAuth::SharedNoteStore 6 | include ::EvernoteOAuth::BusinessNoteStore 7 | include ::EvernoteOAuth::BusinessUtils 8 | 9 | def initialize(options={}) 10 | config_file = "config/evernote.yml" 11 | if File.exist?(config_file) 12 | require 'erb' 13 | if defined?(Rails) 14 | config = YAML.load(ERB.new(File.read(config_file)).result)[Rails.env] 15 | else 16 | config = YAML.load(ERB.new(File.read(config_file)).result) 17 | end 18 | @consumer_key = config['consumer_key'] 19 | @consumer_secret = config['consumer_secret'] 20 | @sandbox = config['sandbox'] ? true : false 21 | end 22 | 23 | @consumer_key = options[:consumer_key] || @consumer_key 24 | @consumer_secret = options[:consumer_secret] || @consumer_secret 25 | @sandbox = true if @sandbox == nil 26 | @sandbox = (options[:sandbox] == nil ? @sandbox : options[:sandbox]) 27 | @service_host = options[:service_host] || (@sandbox ? 'sandbox.evernote.com' : 'www.evernote.com') 28 | @additional_headers = options[:additional_headers] 29 | @token = options[:token] 30 | @secret = options[:secret] 31 | end 32 | 33 | def authorize(token, secret, options={}) 34 | request_token = OAuth::RequestToken.new(consumer, token, secret) 35 | @access_token = request_token.get_access_token(options) 36 | @token = @access_token.token 37 | @secret = @access_token.secret 38 | @access_token 39 | end 40 | 41 | def request_token(options={}) 42 | consumer.options[:authorize_path] = '/OAuth.action' 43 | consumer.get_request_token(options) 44 | end 45 | 46 | private 47 | def consumer 48 | @consumer ||= OAuth::Consumer.new( 49 | @consumer_key, 50 | @consumer_secret, 51 | {site: endpoint, 52 | request_token_path: "/oauth", 53 | access_token_path: "/oauth"} 54 | ) 55 | end 56 | 57 | def endpoint(path=nil) 58 | url = "https://#{@service_host}" 59 | url += "/#{path}" if path 60 | url 61 | end 62 | 63 | def access_token 64 | @access_token ||= OAuth::AccessToken.new(consumer, @token, @secret) 65 | end 66 | 67 | def thrift_client(client_class, url) 68 | if m = /:A=([^:]+):/.match(@token) 69 | key_id = m[1] 70 | else 71 | key_id = @consumer_key || 'nil' 72 | end 73 | 74 | transport = Thrift::HTTPClientTransport.new(url) 75 | transport.add_headers( 76 | 'User-Agent' => "#{key_id} / #{::EvernoteOAuth::VERSION}; Ruby / #{RUBY_VERSION};" 77 | ) 78 | transport.add_headers(@additional_headers) if @additional_headers 79 | protocol = Thrift::BinaryProtocol.new(transport) 80 | client_class.new(protocol) 81 | end 82 | 83 | end 84 | end 85 | 86 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/config/application.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../boot', __FILE__) 2 | 3 | require 'rails/all' 4 | 5 | if defined?(Bundler) 6 | # If you precompile assets before deploying to production, use this line 7 | Bundler.require(*Rails.groups(:assets => %w(development test))) 8 | # If you want your assets lazily compiled in production, use this line 9 | # Bundler.require(:default, :assets, Rails.env) 10 | end 11 | 12 | module EvernoteSample 13 | class Application < Rails::Application 14 | # Settings in config/environments/* take precedence over those specified here. 15 | # Application configuration should go into files in config/initializers 16 | # -- all .rb files in that directory are automatically loaded. 17 | 18 | # Custom directories with classes and modules you want to be autoloadable. 19 | # config.autoload_paths += %W(#{config.root}/extras) 20 | 21 | # Only load the plugins named here, in the order given (default is alphabetical). 22 | # :all can be used as a placeholder for all plugins not explicitly named. 23 | # config.plugins = [ :exception_notification, :ssl_requirement, :all ] 24 | 25 | # Activate observers that should always be running. 26 | # config.active_record.observers = :cacher, :garbage_collector, :forum_observer 27 | 28 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. 29 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. 30 | # config.time_zone = 'Central Time (US & Canada)' 31 | 32 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. 33 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] 34 | # config.i18n.default_locale = :de 35 | 36 | # Configure the default encoding used in templates for Ruby 1.9. 37 | config.encoding = "utf-8" 38 | 39 | # Configure sensitive parameters which will be filtered from the log file. 40 | config.filter_parameters += [:password] 41 | 42 | # Enable escaping HTML in JSON. 43 | config.active_support.escape_html_entities_in_json = true 44 | 45 | # Use SQL instead of Active Record's schema dumper when creating the database. 46 | # This is necessary if your schema can't be completely dumped by the schema dumper, 47 | # like if you have constraints or database-specific column types 48 | # config.active_record.schema_format = :sql 49 | 50 | # Enforce whitelist mode for mass assignment. 51 | # This will create an empty whitelist of attributes available for mass-assignment for all models 52 | # in your app. As such, your models will need to explicitly whitelist or blacklist accessible 53 | # parameters by using an attr_accessible or attr_protected declaration. 54 | config.active_record.whitelist_attributes = true 55 | 56 | # Enable the asset pipeline 57 | config.assets.enabled = true 58 | 59 | # Version of your assets, change this if you want to expire all your assets 60 | config.assets.version = '1.0' 61 | end 62 | end 63 | -------------------------------------------------------------------------------- /lib/evernote_oauth/business_utils.rb: -------------------------------------------------------------------------------- 1 | module EvernoteOAuth 2 | 3 | module BusinessUtils 4 | include ::EvernoteOAuth::UserStore 5 | include ::EvernoteOAuth::NoteStore 6 | include ::EvernoteOAuth::SharedNoteStore 7 | include ::EvernoteOAuth::BusinessNoteStore 8 | 9 | # Creates a note in the given business notebook. 10 | # 11 | # @param note [Evernote::EDAM::Type::Note] See {http://dev.evernote.com/documentation/reference/Types.html#Struct_Note}. 12 | # @param business_notebook [Evernote::EDAM::Type::LinkedNotebook] A LinkedNotebook object corresponding to the business notebook. See {http://dev.evernote.com/documentation/reference/Types.html#Struct_LinkedNotebook}. 13 | # @return [Evernote::EDAM::Type::Note] The newly created Note from the service. The server-side GUIDs for the Note and any Resources will be saved in this object. 14 | def create_note_in_business_notebook(note, business_notebook) 15 | shared_notebook = shared_note_store(business_notebook).getSharedNotebookByAuth 16 | note.notebookGuid = shared_notebook.notebookGuid 17 | shared_note_store(business_notebook).createNote(note) 18 | end 19 | 20 | # Lists all business notebooks the user can access. 21 | # 22 | # @return [Array] The list of LinkedNotebook. See {http://dev.evernote.com/documentation/reference/Types.html#Struct_LinkedNotebook}. 23 | def list_business_notebooks 24 | note_store.listLinkedNotebooks.select(&:businessId) 25 | end 26 | 27 | # Creates a business notebook in the business account and LinkedNotebook for the user. 28 | # 29 | # @param notebook [Evernote::EDAM::Type::Notebook] See {http://dev.evernote.com/documentation/reference/Types.html#Struct_Notebook}. 30 | # @return [Evernote::EDAM::Type::LinkedNotebook] The LinkedNotebook corresponding to the notebook in the business account. See {http://dev.evernote.com/documentation/reference/Types.html#Struct_LinkedNotebook}. 31 | def create_business_notebook(notebook) 32 | business_notebook = business_note_store.createNotebook(notebook) 33 | shared_notebook = business_notebook.sharedNotebooks.first 34 | business_user = business_note_store.user 35 | linked_notebook = Evernote::EDAM::Type::LinkedNotebook.new( 36 | shareKey: shared_notebook.shareKey, 37 | shareName: business_notebook.name, 38 | username: business_user.username, 39 | shardId: business_user.shardId 40 | ) 41 | note_store.createLinkedNotebook(linked_notebook) 42 | end 43 | 44 | # Get a notebook object corresponding to the given business notebook. 45 | # 46 | # @param business_notebook [Evernote::EDAM::Type::LinkedNotebook] A LinkedNotebook object. See {http://dev.evernote.com/documentation/reference/Types.html#Struct_LinkedNotebook}. 47 | # @return [Evernote::EDAM::Type::Notebook] A Notebook object corresponding to the given LinkedNotebook. 48 | def get_corresponding_notebook(business_notebook) 49 | shared_notebook = shared_note_store(business_notebook).getSharedNotebookByAuth 50 | business_note_store.getNotebook(shared_notebook.notebookGuid) 51 | end 52 | 53 | end 54 | 55 | end 56 | -------------------------------------------------------------------------------- /spec/evernote_oauth/business_utils_spec.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "/../spec_helper") 2 | 3 | describe "EvernoteOAuth::BusinessUtils" do 4 | include EvernoteOAuth::BusinessUtils 5 | 6 | context "#create_note_in_business_notebook" do 7 | it "calls createNote with shared_note_store" do 8 | note = Evernote::EDAM::Type::Note.new 9 | business_notebook = Evernote::EDAM::Type::LinkedNotebook.new 10 | shared_notebook = Evernote::EDAM::Type::SharedNotebook.new(notebookGuid: 'notebook_guid') 11 | shared_note_store = double(Object) 12 | shared_note_store.stub(:getSharedNotebookByAuth).and_return(shared_notebook) 13 | shared_note_store.stub(:createNote).and_return(note) 14 | should_receive(:shared_note_store).with(business_notebook).twice.and_return(shared_note_store) 15 | create_note_in_business_notebook(note, business_notebook).should == note 16 | end 17 | end 18 | 19 | context "#list_business_notebooks" do 20 | it "calls listLinkedNotebooks with note_store" do 21 | ln1 = Evernote::EDAM::Type::LinkedNotebook.new(businessId: 'Evernote') 22 | ln2 = Evernote::EDAM::Type::LinkedNotebook.new 23 | ln3 = Evernote::EDAM::Type::LinkedNotebook.new(businessId: 'Evernote') 24 | note_store = double(Object) 25 | note_store.stub(:listLinkedNotebooks).and_return([ln1, ln2, ln3]) 26 | should_receive(:note_store).and_return(note_store) 27 | list_business_notebooks.should == [ln1, ln3] 28 | end 29 | end 30 | 31 | context "#create_business_notebook" do 32 | it "calls createNote with shared_note_store" do 33 | notebook = Evernote::EDAM::Type::Notebook.new 34 | shared_notebook = Evernote::EDAM::Type::SharedNotebook.new( 35 | shareKey: 'shareKey' 36 | ) 37 | business_notebook = Evernote::EDAM::Type::Notebook.new( 38 | name: 'name', 39 | sharedNotebooks: [shared_notebook] 40 | ) 41 | business_note_store = double(Object) 42 | business_note_store.stub(:createNotebook).with(notebook).and_return(business_notebook) 43 | should_receive(:business_note_store).twice.and_return(business_note_store) 44 | 45 | business_user = Evernote::EDAM::Type::User.new( 46 | username: 'username', 47 | shardId: 'shardId' 48 | ) 49 | business_note_store.stub(:user).and_return(business_user) 50 | 51 | note_store = double(Object) 52 | note_store.should_receive(:createLinkedNotebook).with( 53 | Evernote::EDAM::Type::LinkedNotebook.new( 54 | shareKey: 'shareKey', 55 | shareName: 'name', 56 | username: 'username', 57 | shardId: 'shardId' 58 | ) 59 | ) 60 | should_receive(:note_store).and_return(note_store) 61 | 62 | create_business_notebook(notebook) 63 | end 64 | end 65 | 66 | context "#get_corresponding_notebook" do 67 | it "calls getNotebookWithGuid with business_note_store" do 68 | business_notebook = Evernote::EDAM::Type::LinkedNotebook.new 69 | shared_notebook = Evernote::EDAM::Type::SharedNotebook.new(notebookGuid: 'notebook_guid') 70 | shared_note_store = double(Object) 71 | shared_note_store.stub(:getSharedNotebookByAuth).and_return(shared_notebook) 72 | should_receive(:shared_note_store).with(business_notebook).and_return(shared_note_store) 73 | 74 | business_note_store = double(Object) 75 | business_note_store.should_receive(:getNotebook).with('notebook_guid') 76 | should_receive(:business_note_store).and_return(business_note_store) 77 | 78 | get_corresponding_notebook(business_notebook) 79 | end 80 | end 81 | 82 | end 83 | -------------------------------------------------------------------------------- /sample/client/EDAMTest.rb: -------------------------------------------------------------------------------- 1 | # 2 | # A simple Evernote API demo script that lists all notebooks in the user's 3 | # account and creates a simple test note in the default notebook. 4 | # 5 | # Before running this sample, you must: 6 | # - fill in your Evernote developer token. 7 | # - install evernote-thrift gem. 8 | # 9 | # To run (Unix): 10 | # ruby EDAMTest.rb 11 | # 12 | 13 | require "digest/md5" 14 | require 'evernote_oauth' 15 | 16 | # Real applications authenticate with Evernote using OAuth, but for the 17 | # purpose of exploring the API, you can get a developer token that allows 18 | # you to access your own Evernote account. To get a developer token, visit 19 | # https://sandbox.evernote.com/api/DeveloperToken.action 20 | authToken = "your developer token" 21 | 22 | if authToken == "your developer token" 23 | puts "Please fill in your developer token" 24 | puts "To get a developer token, visit https://sandbox.evernote.com/api/DeveloperToken.action" 25 | exit(1) 26 | end 27 | 28 | # Initial development is performed on our sandbox server. To use the production 29 | # service, add "sandbox: false" option and replace your 30 | # developer token above with a token from 31 | # https://www.evernote.com/api/DeveloperToken.action 32 | client = EvernoteOAuth::Client.new(token: authToken) 33 | 34 | # List all of the notebooks in the user's account 35 | note_store = client.note_store 36 | notebooks = note_store.listNotebooks(authToken) 37 | puts "Found #{notebooks.size} notebooks:" 38 | defaultNotebook = notebooks.first 39 | notebooks.each do |notebook| 40 | puts " * #{notebook.name}" 41 | end 42 | 43 | puts 44 | puts "Creating a new note in the default notebook: #{defaultNotebook.name}" 45 | puts 46 | 47 | # To create a new note, simply create a new Note object and fill in 48 | # attributes such as the note's title. 49 | note = Evernote::EDAM::Type::Note.new 50 | note.title = "Test note from EDAMTest.rb" 51 | 52 | # To include an attachment such as an image in a note, first create a Resource 53 | # for the attachment. At a minimum, the Resource contains the binary attachment 54 | # data, an MD5 hash of the binary data, and the attachment MIME type. It can also 55 | #/ include attributes such as filename and location. 56 | filename = "enlogo.png" 57 | image = File.open(filename, "rb") { |io| io.read } 58 | hashFunc = Digest::MD5.new 59 | 60 | data = Evernote::EDAM::Type::Data.new 61 | data.size = image.size 62 | data.bodyHash = hashFunc.digest(image) 63 | data.body = image 64 | 65 | resource = Evernote::EDAM::Type::Resource.new 66 | resource.mime = "image/png" 67 | resource.data = data 68 | resource.attributes = Evernote::EDAM::Type::ResourceAttributes.new 69 | resource.attributes.fileName = filename 70 | 71 | # Now, add the new Resource to the note's list of resources 72 | note.resources = [ resource ] 73 | 74 | # To display the Resource as part of the note's content, include an 75 | # tag in the note's ENML content. The en-media tag identifies the corresponding 76 | # Resource using the MD5 hash. 77 | hashHex = hashFunc.hexdigest(image) 78 | 79 | # The content of an Evernote note is represented using Evernote Markup Language 80 | # (ENML). The full ENML specification can be found in the Evernote API Overview 81 | # at http://dev.evernote.com/documentation/cloud/chapters/ENML.php 82 | note.content = < 84 | 85 | Here is the Evernote logo:
86 | 87 |
88 | EOF 89 | 90 | # Finally, send the new note to Evernote using the createNote method 91 | # The new Note object that is returned will contain server-generated 92 | # attributes such as the new note's unique GUID. 93 | createdNote = note_store.createNote(authToken, note) 94 | 95 | puts "Successfully created a new note with GUID: #{createdNote.guid}" 96 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | actionmailer (3.2.12) 5 | actionpack (= 3.2.12) 6 | mail (~> 2.4.4) 7 | actionpack (3.2.12) 8 | activemodel (= 3.2.12) 9 | activesupport (= 3.2.12) 10 | builder (~> 3.0.0) 11 | erubis (~> 2.7.0) 12 | journey (~> 1.0.4) 13 | rack (~> 1.4.5) 14 | rack-cache (~> 1.2) 15 | rack-test (~> 0.6.1) 16 | sprockets (~> 2.2.1) 17 | activemodel (3.2.12) 18 | activesupport (= 3.2.12) 19 | builder (~> 3.0.0) 20 | activerecord (3.2.12) 21 | activemodel (= 3.2.12) 22 | activesupport (= 3.2.12) 23 | arel (~> 3.0.2) 24 | tzinfo (~> 0.3.29) 25 | activeresource (3.2.12) 26 | activemodel (= 3.2.12) 27 | activesupport (= 3.2.12) 28 | activesupport (3.2.12) 29 | i18n (~> 0.6) 30 | multi_json (~> 1.0) 31 | arel (3.0.2) 32 | awesome_print (1.2.0) 33 | builder (3.0.4) 34 | coderay (1.0.9) 35 | coffee-rails (3.2.2) 36 | coffee-script (>= 2.2.0) 37 | railties (~> 3.2.0) 38 | coffee-script (2.2.0) 39 | coffee-script-source 40 | execjs 41 | coffee-script-source (1.6.2) 42 | erubis (2.7.0) 43 | evernote-thrift (1.25.1) 44 | evernote_oauth (0.2.3) 45 | evernote-thrift 46 | oauth (>= 0.4.1) 47 | execjs (1.4.0) 48 | multi_json (~> 1.0) 49 | haml (4.0.1) 50 | tilt 51 | haml-rails (0.4) 52 | actionpack (>= 3.1, < 4.1) 53 | activesupport (>= 3.1, < 4.1) 54 | haml (>= 3.1, < 4.1) 55 | railties (>= 3.1, < 4.1) 56 | hashie (1.2.0) 57 | hike (1.2.1) 58 | i18n (0.6.4) 59 | journey (1.0.4) 60 | jquery-rails (2.2.1) 61 | railties (>= 3.0, < 5.0) 62 | thor (>= 0.14, < 2.0) 63 | json (1.7.7) 64 | libv8 (3.11.8.17) 65 | mail (2.4.4) 66 | i18n (>= 0.4.0) 67 | mime-types (~> 1.16) 68 | treetop (~> 1.4.8) 69 | mime-types (1.21) 70 | multi_json (1.7.2) 71 | nokogiri (1.5.9) 72 | oauth (0.4.7) 73 | omniauth (1.1.3) 74 | hashie (~> 1.2) 75 | rack 76 | omniauth-evernote (1.2.0) 77 | evernote-thrift 78 | multi_json (~> 1.0) 79 | omniauth-oauth (~> 1.0) 80 | omniauth-oauth (1.0.1) 81 | oauth 82 | omniauth (~> 1.0) 83 | polyglot (0.3.3) 84 | rack (1.4.5) 85 | rack-cache (1.2) 86 | rack (>= 0.4) 87 | rack-ssl (1.3.3) 88 | rack 89 | rack-test (0.6.2) 90 | rack (>= 1.0) 91 | rails (3.2.12) 92 | actionmailer (= 3.2.12) 93 | actionpack (= 3.2.12) 94 | activerecord (= 3.2.12) 95 | activeresource (= 3.2.12) 96 | activesupport (= 3.2.12) 97 | bundler (~> 1.0) 98 | railties (= 3.2.12) 99 | rails_autolink (1.0.9) 100 | rails (~> 3.1) 101 | railties (3.2.12) 102 | actionpack (= 3.2.12) 103 | activesupport (= 3.2.12) 104 | rack-ssl (~> 1.3.2) 105 | rake (>= 0.8.7) 106 | rdoc (~> 3.4) 107 | thor (>= 0.14.6, < 2.0) 108 | rake (10.0.4) 109 | rdoc (3.12.2) 110 | json (~> 1.4) 111 | ref (1.0.4) 112 | sass (3.2.7) 113 | sass-rails (3.2.6) 114 | railties (~> 3.2.0) 115 | sass (>= 3.1.10) 116 | tilt (~> 1.3) 117 | sprockets (2.2.2) 118 | hike (~> 1.2) 119 | multi_json (~> 1.0) 120 | rack (~> 1.0) 121 | tilt (~> 1.1, != 1.3.0) 122 | sqlite3 (1.3.7) 123 | therubyracer (0.11.4) 124 | libv8 (~> 3.11.8.12) 125 | ref 126 | thor (0.17.0) 127 | tilt (1.3.6) 128 | treetop (1.4.12) 129 | polyglot 130 | polyglot (>= 0.3.1) 131 | tzinfo (0.3.37) 132 | uglifier (1.3.0) 133 | execjs (>= 0.3.0) 134 | multi_json (~> 1.0, >= 1.0.2) 135 | 136 | PLATFORMS 137 | ruby 138 | 139 | DEPENDENCIES 140 | awesome_print 141 | coderay 142 | coffee-rails (~> 3.2.1) 143 | evernote_oauth 144 | execjs 145 | haml-rails 146 | jquery-rails 147 | nokogiri 148 | omniauth-evernote 149 | rails (= 3.2.12) 150 | rails_autolink 151 | sass-rails (~> 3.2.3) 152 | sqlite3 153 | therubyracer 154 | uglifier (>= 1.0.3) 155 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/assets/stylesheets/coderay.css: -------------------------------------------------------------------------------- 1 | .CodeRay { 2 | background-color: hsl(0,0%,95%); 3 | border: 1px solid silver; 4 | color: black; 5 | } 6 | .CodeRay pre { 7 | margin: 0px; 8 | 9 | padding: 5px; 10 | white-space: pre; 11 | white-space: pre-wrap; 12 | white-space: pre-line; 13 | word-wrap: break-word; 14 | background: none; 15 | } 16 | 17 | span.CodeRay { white-space: pre; border: 0px; padding: 2px; } 18 | 19 | table.CodeRay { border-collapse: collapse; width: 100%; padding: 2px; } 20 | table.CodeRay td { padding: 2px 4px; vertical-align: top; } 21 | 22 | .CodeRay .line-numbers { 23 | background-color: hsl(180,65%,90%); 24 | color: gray; 25 | text-align: right; 26 | -webkit-user-select: none; 27 | -moz-user-select: none; 28 | user-select: none; 29 | } 30 | .CodeRay .line-numbers a { 31 | background-color: hsl(180,65%,90%) !important; 32 | color: gray !important; 33 | text-decoration: none !important; 34 | } 35 | .CodeRay .line-numbers a:target { color: blue !important; } 36 | .CodeRay .line-numbers .highlighted { color: red !important; } 37 | .CodeRay .line-numbers .highlighted a { color: red !important; } 38 | .CodeRay span.line-numbers { padding: 0px 4px; } 39 | .CodeRay .line { display: block; float: left; width: 100%; } 40 | .CodeRay .code { width: 100%; } 41 | 42 | .CodeRay .debug { color: white !important; background: blue !important; } 43 | 44 | .CodeRay .annotation { color:#007 } 45 | .CodeRay .attribute-name { color:#b48 } 46 | .CodeRay .attribute-value { color:#700 } 47 | .CodeRay .binary { color:#509 } 48 | .CodeRay .char .content { color:#D20 } 49 | .CodeRay .char .delimiter { color:#710 } 50 | .CodeRay .char { color:#D20 } 51 | .CodeRay .class { color:#B06; font-weight:bold } 52 | .CodeRay .class-variable { color:#369 } 53 | .CodeRay .color { color:#0A0 } 54 | .CodeRay .comment { color:#777 } 55 | .CodeRay .comment .char { color:#444 } 56 | .CodeRay .comment .delimiter { color:#444 } 57 | .CodeRay .complex { color:#A08 } 58 | .CodeRay .constant { color:#036; font-weight:bold } 59 | .CodeRay .decorator { color:#B0B } 60 | .CodeRay .definition { color:#099; font-weight:bold } 61 | .CodeRay .delimiter { color:black } 62 | .CodeRay .directive { color:#088; font-weight:bold } 63 | .CodeRay .doc { color:#970 } 64 | .CodeRay .doc-string { color:#D42; font-weight:bold } 65 | .CodeRay .doctype { color:#34b } 66 | .CodeRay .entity { color:#800; font-weight:bold } 67 | .CodeRay .error { color:#F00; background-color:#FAA } 68 | .CodeRay .escape { color:#666 } 69 | .CodeRay .exception { color:#C00; font-weight:bold } 70 | .CodeRay .float { color:#60E } 71 | .CodeRay .function { color:#06B; font-weight:bold } 72 | .CodeRay .global-variable { color:#d70 } 73 | .CodeRay .hex { color:#02b } 74 | .CodeRay .imaginary { color:#f00 } 75 | .CodeRay .include { color:#B44; font-weight:bold } 76 | .CodeRay .inline { background-color: hsla(0,0%,0%,0.07); color: black } 77 | .CodeRay .inline-delimiter { font-weight: bold; color: #666 } 78 | .CodeRay .instance-variable { color:#33B } 79 | .CodeRay .integer { color:#00D } 80 | .CodeRay .key .char { color: #60f } 81 | .CodeRay .key .delimiter { color: #404 } 82 | .CodeRay .key { color: #606 } 83 | .CodeRay .keyword { color:#080; font-weight:bold } 84 | .CodeRay .label { color:#970; font-weight:bold } 85 | .CodeRay .local-variable { color:#963 } 86 | .CodeRay .namespace { color:#707; font-weight:bold } 87 | .CodeRay .octal { color:#40E } 88 | .CodeRay .operator { } 89 | .CodeRay .predefined { color:#369; font-weight:bold } 90 | .CodeRay .predefined-constant { color:#069 } 91 | .CodeRay .predefined-type { color:#0a5; font-weight:bold } 92 | .CodeRay .preprocessor { color:#579 } 93 | .CodeRay .pseudo-class { color:#00C; font-weight:bold } 94 | .CodeRay .regexp .content { color:#808 } 95 | .CodeRay .regexp .delimiter { color:#404 } 96 | .CodeRay .regexp .modifier { color:#C2C } 97 | .CodeRay .regexp { background-color:hsla(300,100%,50%,0.06); } 98 | .CodeRay .reserved { color:#080; font-weight:bold } 99 | .CodeRay .shell .content { color:#2B2 } 100 | .CodeRay .shell .delimiter { color:#161 } 101 | .CodeRay .shell { background-color:hsla(120,100%,50%,0.06); } 102 | .CodeRay .string .char { color: #b0b } 103 | .CodeRay .string .content { color: #D20 } 104 | .CodeRay .string .delimiter { color: #710 } 105 | .CodeRay .string .modifier { color: #E40 } 106 | .CodeRay .string { background-color:hsla(0,100%,50%,0.05); } 107 | .CodeRay .symbol .content { color:#A60 } 108 | .CodeRay .symbol .delimiter { color:#630 } 109 | .CodeRay .symbol { color:#A60 } 110 | .CodeRay .tag { color:#070 } 111 | .CodeRay .type { color:#339; font-weight:bold } 112 | .CodeRay .value { color: #088; } 113 | .CodeRay .variable { color:#037 } 114 | 115 | .CodeRay .insert { background: hsla(120,100%,50%,0.12) } 116 | .CodeRay .delete { background: hsla(0,100%,50%,0.12) } 117 | .CodeRay .change { color: #bbf; background: #007; } 118 | .CodeRay .head { color: #f8f; background: #505 } 119 | .CodeRay .head .filename { color: white; } 120 | 121 | .CodeRay .delete .eyecatcher { background-color: hsla(0,100%,50%,0.2); border: 1px solid hsla(0,100%,45%,0.5); margin: -1px; border-bottom: none; border-top-left-radius: 5px; border-top-right-radius: 5px; } 122 | .CodeRay .insert .eyecatcher { background-color: hsla(120,100%,50%,0.2); border: 1px solid hsla(120,100%,25%,0.5); margin: -1px; border-top: none; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; } 123 | 124 | .CodeRay .insert .insert { color: #0c0; background:transparent; font-weight:bold } 125 | .CodeRay .delete .delete { color: #c00; background:transparent; font-weight:bold } 126 | .CodeRay .change .change { color: #88f } 127 | .CodeRay .head .head { color: #f4f } 128 | -------------------------------------------------------------------------------- /sample/sinatra/app.rb: -------------------------------------------------------------------------------- 1 | ## 2 | # en_webhook.rb 3 | # Copyright 2013 Evernote Corporation. All rights reserved. 4 | # 5 | # This sample web application demonstrates the process of using Webhook. 6 | # More information can be found in http://dev.evernote.com/documentation/cloud/chapters/polling_notification.php#webhooks. 7 | # 8 | # Note that we're not attempting to demonstrate Ruby/Sinatra best practices or 9 | # build a scalable multi-user web application, we're simply giving you an idea 10 | # of how to use Webhook. 11 | # 12 | # Note that you can't use webhook on your localhost. 13 | # You have to deploy your applicatin on a public server and request a webhook. 14 | # http://dev.evernote.com/support/ 15 | # 16 | # Requires the Sinatra framework, ActiveRecord and the OAuth RubyGem. You can install these 17 | # components as follows: 18 | # 19 | # gem install evernote_oauth 20 | # gem install sinatra 21 | # gem install active_record 22 | # 23 | # To run this application: 24 | # 25 | # ruby -rubygems en_webhook.rb 26 | # 27 | # Sinatra will start on port 4567. You can view the sample application by visiting 28 | # http://localhost:4567 in a browser. 29 | ## 30 | 31 | class User < ActiveRecord::Base 32 | validates :user_id, :username, :token, :active, presence: true 33 | after_initialize :set_default 34 | def set_default 35 | self.active ||= true 36 | end 37 | end 38 | 39 | class Note < ActiveRecord::Base 40 | validates :guid, :user_id, :title, :content, presence: true 41 | end 42 | 43 | class EnWebhook < Sinatra::Base 44 | register Sinatra::ActiveRecordExtension 45 | enable :sessions 46 | 47 | ## 48 | # Index page 49 | ## 50 | get '/' do 51 | if session[:user_id] 52 | redirect '/notes' 53 | else 54 | slim :authorize 55 | end 56 | end 57 | 58 | ## 59 | # Reset the session 60 | ## 61 | get '/reset' do 62 | session.clear 63 | slim :authorize 64 | end 65 | 66 | ## 67 | # Get temporary credentials and redirect the user to Evernote for authoriation 68 | ## 69 | get '/authorize' do 70 | callback_url = request.url.chomp("authorize").concat("callback") 71 | 72 | begin 73 | client = EvernoteOAuth::Client.new 74 | session[:request_token] = client.request_token(:oauth_callback => callback_url) 75 | redirect session[:request_token].authorize_url 76 | rescue => e 77 | @error = "Error obtaining temporary credentials: #{e.message}" 78 | slim :error 79 | end 80 | end 81 | 82 | ## 83 | # Receive callback from the Evernote authorization page and exchange the 84 | # temporary credentials for an token credentials. 85 | ## 86 | get '/callback' do 87 | if params['oauth_verifier'] 88 | oauth_verifier = params['oauth_verifier'] 89 | 90 | begin 91 | access_token = session[:request_token].get_access_token(:oauth_verifier => oauth_verifier).token 92 | 93 | # Create User record with username and token 94 | user_store = EvernoteOAuth::Client.new(token: access_token).user_store 95 | evernote_user = user_store.getUser 96 | 97 | @user = User.find_or_initialize_by_user_id(user_id: evernote_user.id) 98 | @user.username = evernote_user.username 99 | @user.token = access_token 100 | @user.save! 101 | 102 | session[:user_id] = @user.user_id 103 | redirect '/notes' 104 | rescue => e 105 | @error = e.message 106 | slim :error 107 | end 108 | else 109 | @error = "Content owner did not authorize the temporary credentials" 110 | slim :error 111 | end 112 | end 113 | 114 | get '/notes' do 115 | @user = User.find_by_user_id(session[:user_id]) 116 | redirect '/reset' unless @user 117 | 118 | @notes = Note.where(user_id: @user.user_id) 119 | 120 | note_store = EvernoteOAuth::Client.new(token: @user.token).note_store 121 | @evernote_notes = note_store.findNotesMetadata( 122 | ::Evernote::EDAM::NoteStore::NoteFilter.new, 0, 10, 123 | ::Evernote::EDAM::NoteStore::NotesMetadataResultSpec.new).notes 124 | slim :notes 125 | end 126 | 127 | ## 128 | # Handle webhook notification from the Evernote. 129 | # 130 | # In this sample, it simply saves and updates title and content of a note according to the parameter. 131 | # 132 | # It is important that when your web service receives a polling notification from Evernote, 133 | # it returns HTTP status code 200 (the standard response for successful HTTP requests). 134 | # 135 | # Specifically, your service should not return a failure code (e.g.: HTTP 500) when called by Evernote. 136 | # Even when the notification may not be relevant to your application, you should return 200. 137 | # A status other than 200 indicates to us that the message was not delivered successfully, 138 | # which could cause your integration with Evernote to malfunction. 139 | # 140 | # http://dev.evernote.com/documentation/cloud/chapters/polling_notification.php 141 | ## 142 | get '/webhook' do 143 | # Evernote webhook should include userId, guid and reason in its parameter 144 | halt 400 unless params.include?('userId') && params.include?('guid') && params.include?('reason') 145 | # Reason should be either craete or update 146 | halt 400 unless ['create', 'update'].include?(params[:reason]) 147 | 148 | begin 149 | evernote_user_id = params[:userId] 150 | note_guid = params[:guid] 151 | 152 | @user = User.find_by_user_id(evernote_user_id) 153 | return if @user.nil? || !@user.active? 154 | 155 | note_store = EvernoteOAuth::Client.new(token: @user.token).note_store 156 | evernote_note = note_store.getNote(note_guid, true, false, false, false) 157 | @note = Note.find_or_initialize_by_user_id_and_guid(@user.user_id, note_guid) 158 | @note.title = evernote_note.title 159 | @note.content = evernote_note.content 160 | @note.save! 161 | rescue 162 | puts $! 163 | @user.update_attribute(:active, false) 164 | redirect '/' 165 | return 166 | end 167 | 168 | # Just returning 200 is fine. This is only for showing webhook result on the browser. 169 | @notes = Note.where(user_id: @user.user_id) 170 | note_store = EvernoteOAuth::Client.new(token: @user.token).note_store 171 | @evernote_notes = note_store.findNotesMetadata( 172 | ::Evernote::EDAM::NoteStore::NoteFilter.new, 0, 10, 173 | ::Evernote::EDAM::NoteStore::NotesMetadataResultSpec.new).notes 174 | slim :notes 175 | end 176 | 177 | end 178 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Gem Version](https://badge.fury.io/rb/evernote_oauth.png)](http://badge.fury.io/rb/evernote_oauth) 2 | 3 | Evernote OAuth / Thrift API client library for Ruby 4 | =================================================== 5 | 6 | Install the gem 7 | --------------- 8 | gem install evernote_oauth 9 | 10 | Prerequisites 11 | ------------- 12 | In order to use the code in this SDK, you need to obtain an API key from http://dev.evernote.com/documentation/cloud. You'll also find full API documentation on that page. 13 | 14 | In order to run the sample code, you need a user account on the sandbox service where you will do your development. Sign up for an account at https://sandbox.evernote.com/Registration.action 15 | 16 | In order to run the client client sample code, you need a developer token. Get one at https://sandbox.evernote.com/api/DeveloperToken.action 17 | 18 | Setup 19 | ----- 20 | Put your API keys in the config/evernote.yml 21 | ```ruby 22 | development: 23 | consumer_key: YOUR CONSUMER KEY 24 | consumer_secret: YOUR CONSUMER SECRET 25 | sandbox: [true or false] 26 | ``` 27 | Or you can just pass those information when you create an instance of the client 28 | ```ruby 29 | client = EvernoteOAuth::Client.new( 30 | consumer_key: YOUR CONSUMER KEY, 31 | consumer_secret: YOUR CONSUMER SECRET, 32 | sandbox: [true or false] 33 | ) 34 | ``` 35 | 36 | Usage 37 | ----- 38 | ### OAuth ### 39 | ```ruby 40 | client = EvernoteOAuth::Client.new 41 | request_token = client.request_token(:oauth_callback => 'YOUR CALLBACK URL') 42 | request_token.authorize_url 43 | => https://sandbox.evernote.com/OAuth.action?oauth_token=OAUTH_TOKEN 44 | ``` 45 | To obtain the access token 46 | ```ruby 47 | access_token = request_token.get_access_token(oauth_verifier: params[:oauth_verifier]) 48 | ``` 49 | Now you can make other API calls 50 | ```ruby 51 | token = access_token.token 52 | client = EvernoteOAuth::Client.new(token: token) 53 | note_store = client.note_store 54 | notebooks = note_store.listNotebooks(token) 55 | ``` 56 | 57 | ### UserStore ### 58 | Once you acquire token, you can use UserStore. For example, if you want to call UserStore.getUser: 59 | ```ruby 60 | user_store = EvernoteOAuth::Client.new(token: token).user_store 61 | user_store.getUser 62 | ``` 63 | You can omit authenticationToken in the arguments of UserStore/NoteStore functions: 64 | 65 | ### NoteStore ### 66 | If you want to call NoteStore.listNotebooks: 67 | ```ruby 68 | note_store = EvernoteOAuth::Client.new(token: token).note_store 69 | note_store.listNotebooks 70 | ``` 71 | 72 | ### NoteStore for linked notebooks ### 73 | If you want to get tags for linked notebooks: 74 | ```ruby 75 | linked_notebook = note_store.listLinkedNotebooks.first # any notebook 76 | shared_note_store = client.shared_note_store(linked_notebook) 77 | shared_notebook = shared_note_store.getSharedNotebookByAuth 78 | shared_note_store.listTagsByNotebook(shared_notebook.notebookGuid) 79 | ``` 80 | 81 | ### NoteStore for Business ### 82 | If you want to get the list of notebooks in your business account: 83 | ```ruby 84 | user_store = client.user_store 85 | user = user_store.getUser 86 | business_note_store = client.business_note_store 87 | if user.belongs_to_business? 88 | business_note_store.listNotebooks 89 | end 90 | ``` 91 | 92 | ### Method Chaining ### 93 | You can chain methods: 94 | ```ruby 95 | note_store.findNotes(Evernote::EDAM::NoteStore::NoteFilter.new, 0, 10).first.tags.first.parent 96 | => [] 97 | ``` 98 | Here are the additional methods for each types: 99 | 100 | - Evernote::EDAM::NoteStore::NoteList 101 | - notes 102 | - Evernote::EDAM::NoteStore::NoteMetadata 103 | - tags 104 | - Evernote::EDAM::NoteStore::NotesMetadataList 105 | - notes 106 | - Evernote::EDAM::NoteStore::SyncChunk 107 | - notes, notebooks, tags, searches, resources, linkedNotebooks 108 | - Evernote::EDAM::Type::Note 109 | - notebook, tags 110 | - Evernote::EDAM::Type::Resource 111 | - note: needs hash argument 112 | - with_constant: boolean 113 | - with_resources_data: boolean 114 | - with_resources_recognition: boolean 115 | - with_resources_alternate_data: boolean 116 | - Evernote::EDAM::Type::SharedNotebook 117 | - notebook 118 | - Evernote::EDAM::Type::Tag 119 | - parent 120 | 121 | Notes: Those methods call thrift API internally. The result will be cached in the object so that the second method call wouldn't thrift API again. 122 | 123 | ### Image Adding ### 124 | Additional method is defined in Note to be easily added an image: 125 | ```ruby 126 | note = Evernote::EDAM::Type::Note.new( 127 | title: 'Note', 128 | tagNames: ['Evernote API Sample'] 129 | ) 130 | 131 | filename = "enlogo.png" 132 | image = File.open(filename, "rb") { |io| io.read } 133 | hexdigest = note.add_resource(filename, image, 'image/png') 134 | ``` 135 | You can use hexdigest within ENXML: 136 | ```xml 137 | 138 | ``` 139 | 140 | Utility methods for Business 141 | ---------------------------- 142 | This gem provides some utility methods to deal with Evernote Business. 143 | 144 | ### List business notebooks ### 145 | To list all business notebooks the user can access 146 | ```ruby 147 | client = EvernoteOAuth::Client.new(token: token) 148 | client.list_business_notebooks 149 | ``` 150 | 151 | ### Create a business note ### 152 | To create a business note in a business notebook 153 | ```ruby 154 | note = Evernote::EDAM::Type::Note.new 155 | business_notebook = client.list_business_notebooks.first 156 | client.create_note_in_business_notebook(note, business_notebook) 157 | ``` 158 | 159 | ### Create a business notebook ### 160 | To create a business notebook 161 | ```ruby 162 | notebook = Evernote::EDAM::Type::Notebook.new 163 | client.create_business_notebook(notebook) 164 | ``` 165 | 166 | ### Get a notebook corresponding to the given business notebook ### 167 | ```ruby 168 | business_notebook = client.list_business_notebooks.first 169 | client.get_corresponding_notebook(business_notebook) 170 | ``` 171 | 172 | ### Determine if the user can edit the notebook ### 173 | ```ruby 174 | notebook.writable? 175 | ``` 176 | 177 | ### Determine if the user is a part of a business ### 178 | ```ruby 179 | user.belongs_to_business? 180 | ``` 181 | 182 | ### Get a business name of the user ### 183 | ```ruby 184 | user.business_name 185 | ``` 186 | 187 | References 188 | ---------- 189 | - Evernote Developers: http://dev.evernote.com/ 190 | - API Document: http://dev.evernote.com/documentation/reference/ 191 | -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/assets/stylesheets/jquery-ui-1.9.1.custom.min.css: -------------------------------------------------------------------------------- 1 | /*! jQuery UI - v1.9.1 - 2012-10-30 2 | * http://jqueryui.com 3 | * Includes: jquery.ui.core.css, jquery.ui.resizable.css, jquery.ui.button.css, jquery.ui.dialog.css 4 | * To view and modify this theme, visit http://jqueryui.com/themeroller/?ffDefault=Verdana%2CArial%2Csans-serif&fwDefault=normal&fsDefault=1.1em&cornerRadius=4px&bgColorHeader=cccccc&bgTextureHeader=03_highlight_soft.png&bgImgOpacityHeader=75&borderColorHeader=aaaaaa&fcHeader=222222&iconColorHeader=222222&bgColorContent=ffffff&bgTextureContent=01_flat.png&bgImgOpacityContent=75&borderColorContent=aaaaaa&fcContent=222222&iconColorContent=222222&bgColorDefault=e6e6e6&bgTextureDefault=02_glass.png&bgImgOpacityDefault=75&borderColorDefault=d3d3d3&fcDefault=555555&iconColorDefault=888888&bgColorHover=dadada&bgTextureHover=02_glass.png&bgImgOpacityHover=75&borderColorHover=999999&fcHover=212121&iconColorHover=454545&bgColorActive=ffffff&bgTextureActive=02_glass.png&bgImgOpacityActive=65&borderColorActive=aaaaaa&fcActive=212121&iconColorActive=454545&bgColorHighlight=fbf9ee&bgTextureHighlight=02_glass.png&bgImgOpacityHighlight=55&borderColorHighlight=fcefa1&fcHighlight=363636&iconColorHighlight=2e83ff&bgColorError=fef1ec&bgTextureError=02_glass.png&bgImgOpacityError=95&borderColorError=cd0a0a&fcError=cd0a0a&iconColorError=cd0a0a&bgColorOverlay=aaaaaa&bgTextureOverlay=01_flat.png&bgImgOpacityOverlay=0&opacityOverlay=30&bgColorShadow=aaaaaa&bgTextureShadow=01_flat.png&bgImgOpacityShadow=0&opacityShadow=30&thicknessShadow=8px&offsetTopShadow=-8px&offsetLeftShadow=-8px&cornerRadiusShadow=8px 5 | * Copyright (c) 2012 jQuery Foundation and other contributors Licensed MIT */.ui-helper-hidden{display:none}.ui-helper-hidden-accessible{position:absolute!important;clip:rect(1px);clip:rect(1px,1px,1px,1px)}.ui-helper-reset{margin:0;padding:0;border:0;outline:0;line-height:1.3;text-decoration:none;font-size:100%;list-style:none}.ui-helper-clearfix:before,.ui-helper-clearfix:after{content:"";display:table}.ui-helper-clearfix:after{clear:both}.ui-helper-clearfix{zoom:1}.ui-helper-zfix{width:100%;height:100%;top:0;left:0;position:absolute;opacity:0;filter:Alpha(Opacity=0)}.ui-state-disabled{cursor:default!important}.ui-icon{display:block;text-indent:-99999px;overflow:hidden;background-repeat:no-repeat}.ui-widget-overlay{position:absolute;top:0;left:0;width:100%;height:100%}.ui-resizable{position:relative}.ui-resizable-handle{position:absolute;font-size:0.1px;display:block}.ui-resizable-disabled .ui-resizable-handle,.ui-resizable-autohide .ui-resizable-handle{display:none}.ui-resizable-n{cursor:n-resize;height:7px;width:100%;top:-5px;left:0}.ui-resizable-s{cursor:s-resize;height:7px;width:100%;bottom:-5px;left:0}.ui-resizable-e{cursor:e-resize;width:7px;right:-5px;top:0;height:100%}.ui-resizable-w{cursor:w-resize;width:7px;left:-5px;top:0;height:100%}.ui-resizable-se{cursor:se-resize;width:12px;height:12px;right:1px;bottom:1px}.ui-resizable-sw{cursor:sw-resize;width:9px;height:9px;left:-5px;bottom:-5px}.ui-resizable-nw{cursor:nw-resize;width:9px;height:9px;left:-5px;top:-5px}.ui-resizable-ne{cursor:ne-resize;width:9px;height:9px;right:-5px;top:-5px}.ui-button{display:inline-block;position:relative;padding:0;margin-right:.1em;cursor:pointer;text-align:center;zoom:1;overflow:visible}.ui-button,.ui-button:link,.ui-button:visited,.ui-button:hover,.ui-button:active{text-decoration:none}.ui-button-icon-only{width:2.2em}button.ui-button-icon-only{width:2.4em}.ui-button-icons-only{width:3.4em}button.ui-button-icons-only{width:3.7em}.ui-button .ui-button-text{display:block;line-height:1.4}.ui-button-text-only .ui-button-text{padding:.4em 1em}.ui-button-icon-only .ui-button-text,.ui-button-icons-only .ui-button-text{padding:.4em;text-indent:-9999999px}.ui-button-text-icon-primary .ui-button-text,.ui-button-text-icons .ui-button-text{padding:.4em 1em .4em 2.1em}.ui-button-text-icon-secondary .ui-button-text,.ui-button-text-icons .ui-button-text{padding:.4em 2.1em .4em 1em}.ui-button-text-icons .ui-button-text{padding-left:2.1em;padding-right:2.1em}input.ui-button{padding:.4em 1em}.ui-button-icon-only .ui-icon,.ui-button-text-icon-primary .ui-icon,.ui-button-text-icon-secondary .ui-icon,.ui-button-text-icons .ui-icon,.ui-button-icons-only .ui-icon{position:absolute;top:50%;margin-top:-8px}.ui-button-icon-only .ui-icon{left:50%;margin-left:-8px}.ui-button-text-icon-primary .ui-button-icon-primary,.ui-button-text-icons .ui-button-icon-primary,.ui-button-icons-only .ui-button-icon-primary{left:.5em}.ui-button-text-icon-secondary .ui-button-icon-secondary,.ui-button-text-icons .ui-button-icon-secondary,.ui-button-icons-only .ui-button-icon-secondary{right:.5em}.ui-button-text-icons .ui-button-icon-secondary,.ui-button-icons-only .ui-button-icon-secondary{right:.5em}.ui-buttonset{margin-right:7px}.ui-buttonset .ui-button{margin-left:0;margin-right:-.3em}button.ui-button::-moz-focus-inner{border:0;padding:0}.ui-dialog{position:absolute;padding:.2em;width:300px;overflow:hidden}.ui-dialog .ui-dialog-titlebar{padding:.4em 1em;position:relative}.ui-dialog .ui-dialog-title{float:left;margin:.1em 16px .1em 0}.ui-dialog .ui-dialog-titlebar-close{position:absolute;right:.3em;top:50%;width:19px;margin:-10px 0 0 0;padding:1px;height:18px}.ui-dialog .ui-dialog-titlebar-close span{display:block;margin:1px}.ui-dialog .ui-dialog-titlebar-close:hover,.ui-dialog .ui-dialog-titlebar-close:focus{padding:0}.ui-dialog .ui-dialog-content{position:relative;border:0;padding:.5em 1em;background:none;overflow:auto;zoom:1}.ui-dialog .ui-dialog-buttonpane{text-align:left;border-width:1px 0 0 0;background-image:none;margin:.5em 0 0 0;padding:.3em 1em .5em .4em}.ui-dialog .ui-dialog-buttonpane .ui-dialog-buttonset{float:right}.ui-dialog .ui-dialog-buttonpane button{margin:.5em .4em .5em 0;cursor:pointer}.ui-dialog .ui-resizable-se{width:14px;height:14px;right:3px;bottom:3px}.ui-draggable .ui-dialog-titlebar{cursor:move}.ui-widget{font-family:Verdana,Arial,sans-serif;font-size:1.1em}.ui-widget .ui-widget{font-size:1em}.ui-widget input,.ui-widget select,.ui-widget textarea,.ui-widget button{font-family:Verdana,Arial,sans-serif;font-size:1em}.ui-widget-content{border:1px solid #aaa;background:#fff url(images/ui-bg_flat_75_ffffff_40x100.png) 50% 50% repeat-x;color:#222}.ui-widget-content a{color:#222}.ui-widget-header{border:1px solid #aaa;background:#ccc url(images/ui-bg_highlight-soft_75_cccccc_1x100.png) 50% 50% repeat-x;color:#222;font-weight:bold}.ui-widget-header a{color:#222}.ui-state-default,.ui-widget-content .ui-state-default,.ui-widget-header .ui-state-default{border:1px solid #d3d3d3;background:#e6e6e6 url(images/ui-bg_glass_75_e6e6e6_1x400.png) 50% 50% repeat-x;font-weight:normal;color:#555}.ui-state-default a,.ui-state-default a:link,.ui-state-default a:visited{color:#555;text-decoration:none}.ui-state-hover,.ui-widget-content .ui-state-hover,.ui-widget-header .ui-state-hover,.ui-state-focus,.ui-widget-content .ui-state-focus,.ui-widget-header .ui-state-focus{border:1px solid #999;background:#dadada url(images/ui-bg_glass_75_dadada_1x400.png) 50% 50% repeat-x;font-weight:normal;color:#212121}.ui-state-hover a,.ui-state-hover a:hover,.ui-state-hover a:link,.ui-state-hover a:visited{color:#212121;text-decoration:none}.ui-state-active,.ui-widget-content .ui-state-active,.ui-widget-header .ui-state-active{border:1px solid #aaa;background:#fff url(images/ui-bg_glass_65_ffffff_1x400.png) 50% 50% repeat-x;font-weight:normal;color:#212121}.ui-state-active a,.ui-state-active a:link,.ui-state-active a:visited{color:#212121;text-decoration:none}.ui-state-highlight,.ui-widget-content .ui-state-highlight,.ui-widget-header .ui-state-highlight{border:1px solid #fcefa1;background:#fbf9ee url(images/ui-bg_glass_55_fbf9ee_1x400.png) 50% 50% repeat-x;color:#363636}.ui-state-highlight a,.ui-widget-content .ui-state-highlight a,.ui-widget-header .ui-state-highlight a{color:#363636}.ui-state-error,.ui-widget-content .ui-state-error,.ui-widget-header .ui-state-error{border:1px solid #cd0a0a;background:#fef1ec url(images/ui-bg_glass_95_fef1ec_1x400.png) 50% 50% repeat-x;color:#cd0a0a}.ui-state-error a,.ui-widget-content .ui-state-error a,.ui-widget-header .ui-state-error a{color:#cd0a0a}.ui-state-error-text,.ui-widget-content .ui-state-error-text,.ui-widget-header .ui-state-error-text{color:#cd0a0a}.ui-priority-primary,.ui-widget-content .ui-priority-primary,.ui-widget-header .ui-priority-primary{font-weight:bold}.ui-priority-secondary,.ui-widget-content .ui-priority-secondary,.ui-widget-header .ui-priority-secondary{opacity:.7;filter:Alpha(Opacity=70);font-weight:normal}.ui-state-disabled,.ui-widget-content .ui-state-disabled,.ui-widget-header .ui-state-disabled{opacity:.35;filter:Alpha(Opacity=35);background-image:none}.ui-state-disabled .ui-icon{filter:Alpha(Opacity=35)}.ui-icon{width:16px;height:16px;background-image:url(images/ui-icons_222222_256x240.png)}.ui-widget-content .ui-icon{background-image:url(images/ui-icons_222222_256x240.png)}.ui-widget-header .ui-icon{background-image:url(images/ui-icons_222222_256x240.png)}.ui-state-default .ui-icon{background-image:url(images/ui-icons_888888_256x240.png)}.ui-state-hover .ui-icon,.ui-state-focus .ui-icon{background-image:url(images/ui-icons_454545_256x240.png)}.ui-state-active .ui-icon{background-image:url(images/ui-icons_454545_256x240.png)}.ui-state-highlight .ui-icon{background-image:url(images/ui-icons_2e83ff_256x240.png)}.ui-state-error .ui-icon,.ui-state-error-text .ui-icon{background-image:url(images/ui-icons_cd0a0a_256x240.png)}.ui-icon-carat-1-n{background-position:0 0}.ui-icon-carat-1-ne{background-position:-16px 0}.ui-icon-carat-1-e{background-position:-32px 0}.ui-icon-carat-1-se{background-position:-48px 0}.ui-icon-carat-1-s{background-position:-64px 0}.ui-icon-carat-1-sw{background-position:-80px 0}.ui-icon-carat-1-w{background-position:-96px 0}.ui-icon-carat-1-nw{background-position:-112px 0}.ui-icon-carat-2-n-s{background-position:-128px 0}.ui-icon-carat-2-e-w{background-position:-144px 0}.ui-icon-triangle-1-n{background-position:0 -16px}.ui-icon-triangle-1-ne{background-position:-16px -16px}.ui-icon-triangle-1-e{background-position:-32px -16px}.ui-icon-triangle-1-se{background-position:-48px -16px}.ui-icon-triangle-1-s{background-position:-64px -16px}.ui-icon-triangle-1-sw{background-position:-80px -16px}.ui-icon-triangle-1-w{background-position:-96px -16px}.ui-icon-triangle-1-nw{background-position:-112px -16px}.ui-icon-triangle-2-n-s{background-position:-128px -16px}.ui-icon-triangle-2-e-w{background-position:-144px -16px}.ui-icon-arrow-1-n{background-position:0 -32px}.ui-icon-arrow-1-ne{background-position:-16px -32px}.ui-icon-arrow-1-e{background-position:-32px -32px}.ui-icon-arrow-1-se{background-position:-48px -32px}.ui-icon-arrow-1-s{background-position:-64px -32px}.ui-icon-arrow-1-sw{background-position:-80px -32px}.ui-icon-arrow-1-w{background-position:-96px -32px}.ui-icon-arrow-1-nw{background-position:-112px -32px}.ui-icon-arrow-2-n-s{background-position:-128px -32px}.ui-icon-arrow-2-ne-sw{background-position:-144px -32px}.ui-icon-arrow-2-e-w{background-position:-160px -32px}.ui-icon-arrow-2-se-nw{background-position:-176px -32px}.ui-icon-arrowstop-1-n{background-position:-192px -32px}.ui-icon-arrowstop-1-e{background-position:-208px -32px}.ui-icon-arrowstop-1-s{background-position:-224px -32px}.ui-icon-arrowstop-1-w{background-position:-240px -32px}.ui-icon-arrowthick-1-n{background-position:0 -48px}.ui-icon-arrowthick-1-ne{background-position:-16px -48px}.ui-icon-arrowthick-1-e{background-position:-32px -48px}.ui-icon-arrowthick-1-se{background-position:-48px -48px}.ui-icon-arrowthick-1-s{background-position:-64px -48px}.ui-icon-arrowthick-1-sw{background-position:-80px -48px}.ui-icon-arrowthick-1-w{background-position:-96px -48px}.ui-icon-arrowthick-1-nw{background-position:-112px -48px}.ui-icon-arrowthick-2-n-s{background-position:-128px -48px}.ui-icon-arrowthick-2-ne-sw{background-position:-144px -48px}.ui-icon-arrowthick-2-e-w{background-position:-160px -48px}.ui-icon-arrowthick-2-se-nw{background-position:-176px -48px}.ui-icon-arrowthickstop-1-n{background-position:-192px -48px}.ui-icon-arrowthickstop-1-e{background-position:-208px -48px}.ui-icon-arrowthickstop-1-s{background-position:-224px -48px}.ui-icon-arrowthickstop-1-w{background-position:-240px -48px}.ui-icon-arrowreturnthick-1-w{background-position:0 -64px}.ui-icon-arrowreturnthick-1-n{background-position:-16px -64px}.ui-icon-arrowreturnthick-1-e{background-position:-32px -64px}.ui-icon-arrowreturnthick-1-s{background-position:-48px -64px}.ui-icon-arrowreturn-1-w{background-position:-64px -64px}.ui-icon-arrowreturn-1-n{background-position:-80px -64px}.ui-icon-arrowreturn-1-e{background-position:-96px -64px}.ui-icon-arrowreturn-1-s{background-position:-112px -64px}.ui-icon-arrowrefresh-1-w{background-position:-128px -64px}.ui-icon-arrowrefresh-1-n{background-position:-144px -64px}.ui-icon-arrowrefresh-1-e{background-position:-160px -64px}.ui-icon-arrowrefresh-1-s{background-position:-176px -64px}.ui-icon-arrow-4{background-position:0 -80px}.ui-icon-arrow-4-diag{background-position:-16px -80px}.ui-icon-extlink{background-position:-32px -80px}.ui-icon-newwin{background-position:-48px -80px}.ui-icon-refresh{background-position:-64px -80px}.ui-icon-shuffle{background-position:-80px -80px}.ui-icon-transfer-e-w{background-position:-96px -80px}.ui-icon-transferthick-e-w{background-position:-112px -80px}.ui-icon-folder-collapsed{background-position:0 -96px}.ui-icon-folder-open{background-position:-16px -96px}.ui-icon-document{background-position:-32px -96px}.ui-icon-document-b{background-position:-48px -96px}.ui-icon-note{background-position:-64px -96px}.ui-icon-mail-closed{background-position:-80px -96px}.ui-icon-mail-open{background-position:-96px -96px}.ui-icon-suitcase{background-position:-112px -96px}.ui-icon-comment{background-position:-128px -96px}.ui-icon-person{background-position:-144px -96px}.ui-icon-print{background-position:-160px -96px}.ui-icon-trash{background-position:-176px -96px}.ui-icon-locked{background-position:-192px -96px}.ui-icon-unlocked{background-position:-208px -96px}.ui-icon-bookmark{background-position:-224px -96px}.ui-icon-tag{background-position:-240px -96px}.ui-icon-home{background-position:0 -112px}.ui-icon-flag{background-position:-16px -112px}.ui-icon-calendar{background-position:-32px -112px}.ui-icon-cart{background-position:-48px -112px}.ui-icon-pencil{background-position:-64px -112px}.ui-icon-clock{background-position:-80px -112px}.ui-icon-disk{background-position:-96px -112px}.ui-icon-calculator{background-position:-112px -112px}.ui-icon-zoomin{background-position:-128px -112px}.ui-icon-zoomout{background-position:-144px -112px}.ui-icon-search{background-position:-160px -112px}.ui-icon-wrench{background-position:-176px -112px}.ui-icon-gear{background-position:-192px -112px}.ui-icon-heart{background-position:-208px -112px}.ui-icon-star{background-position:-224px -112px}.ui-icon-link{background-position:-240px -112px}.ui-icon-cancel{background-position:0 -128px}.ui-icon-plus{background-position:-16px -128px}.ui-icon-plusthick{background-position:-32px -128px}.ui-icon-minus{background-position:-48px -128px}.ui-icon-minusthick{background-position:-64px -128px}.ui-icon-close{background-position:-80px -128px}.ui-icon-closethick{background-position:-96px -128px}.ui-icon-key{background-position:-112px -128px}.ui-icon-lightbulb{background-position:-128px -128px}.ui-icon-scissors{background-position:-144px -128px}.ui-icon-clipboard{background-position:-160px -128px}.ui-icon-copy{background-position:-176px -128px}.ui-icon-contact{background-position:-192px -128px}.ui-icon-image{background-position:-208px -128px}.ui-icon-video{background-position:-224px -128px}.ui-icon-script{background-position:-240px -128px}.ui-icon-alert{background-position:0 -144px}.ui-icon-info{background-position:-16px -144px}.ui-icon-notice{background-position:-32px -144px}.ui-icon-help{background-position:-48px -144px}.ui-icon-check{background-position:-64px -144px}.ui-icon-bullet{background-position:-80px -144px}.ui-icon-radio-on{background-position:-96px -144px}.ui-icon-radio-off{background-position:-112px -144px}.ui-icon-pin-w{background-position:-128px -144px}.ui-icon-pin-s{background-position:-144px -144px}.ui-icon-play{background-position:0 -160px}.ui-icon-pause{background-position:-16px -160px}.ui-icon-seek-next{background-position:-32px -160px}.ui-icon-seek-prev{background-position:-48px -160px}.ui-icon-seek-end{background-position:-64px -160px}.ui-icon-seek-start{background-position:-80px -160px}.ui-icon-seek-first{background-position:-80px -160px}.ui-icon-stop{background-position:-96px -160px}.ui-icon-eject{background-position:-112px -160px}.ui-icon-volume-off{background-position:-128px -160px}.ui-icon-volume-on{background-position:-144px -160px}.ui-icon-power{background-position:0 -176px}.ui-icon-signal-diag{background-position:-16px -176px}.ui-icon-signal{background-position:-32px -176px}.ui-icon-battery-0{background-position:-48px -176px}.ui-icon-battery-1{background-position:-64px -176px}.ui-icon-battery-2{background-position:-80px -176px}.ui-icon-battery-3{background-position:-96px -176px}.ui-icon-circle-plus{background-position:0 -192px}.ui-icon-circle-minus{background-position:-16px -192px}.ui-icon-circle-close{background-position:-32px -192px}.ui-icon-circle-triangle-e{background-position:-48px -192px}.ui-icon-circle-triangle-s{background-position:-64px -192px}.ui-icon-circle-triangle-w{background-position:-80px -192px}.ui-icon-circle-triangle-n{background-position:-96px -192px}.ui-icon-circle-arrow-e{background-position:-112px -192px}.ui-icon-circle-arrow-s{background-position:-128px -192px}.ui-icon-circle-arrow-w{background-position:-144px -192px}.ui-icon-circle-arrow-n{background-position:-160px -192px}.ui-icon-circle-zoomin{background-position:-176px -192px}.ui-icon-circle-zoomout{background-position:-192px -192px}.ui-icon-circle-check{background-position:-208px -192px}.ui-icon-circlesmall-plus{background-position:0 -208px}.ui-icon-circlesmall-minus{background-position:-16px -208px}.ui-icon-circlesmall-close{background-position:-32px -208px}.ui-icon-squaresmall-plus{background-position:-48px -208px}.ui-icon-squaresmall-minus{background-position:-64px -208px}.ui-icon-squaresmall-close{background-position:-80px -208px}.ui-icon-grip-dotted-vertical{background-position:0 -224px}.ui-icon-grip-dotted-horizontal{background-position:-16px -224px}.ui-icon-grip-solid-vertical{background-position:-32px -224px}.ui-icon-grip-solid-horizontal{background-position:-48px -224px}.ui-icon-gripsmall-diagonal-se{background-position:-64px -224px}.ui-icon-grip-diagonal-se{background-position:-80px -224px}.ui-corner-all,.ui-corner-top,.ui-corner-left,.ui-corner-tl{-moz-border-radius-topleft:4px;-webkit-border-top-left-radius:4px;-khtml-border-top-left-radius:4px;border-top-left-radius:4px}.ui-corner-all,.ui-corner-top,.ui-corner-right,.ui-corner-tr{-moz-border-radius-topright:4px;-webkit-border-top-right-radius:4px;-khtml-border-top-right-radius:4px;border-top-right-radius:4px}.ui-corner-all,.ui-corner-bottom,.ui-corner-left,.ui-corner-bl{-moz-border-radius-bottomleft:4px;-webkit-border-bottom-left-radius:4px;-khtml-border-bottom-left-radius:4px;border-bottom-left-radius:4px}.ui-corner-all,.ui-corner-bottom,.ui-corner-right,.ui-corner-br{-moz-border-radius-bottomright:4px;-webkit-border-bottom-right-radius:4px;-khtml-border-bottom-right-radius:4px;border-bottom-right-radius:4px}.ui-widget-overlay{background:#aaa url(images/ui-bg_flat_0_aaaaaa_40x100.png) 50% 50% repeat-x;opacity:.3;filter:Alpha(Opacity=30)}.ui-widget-shadow{margin:-8px 0 0 -8px;padding:8px;background:#aaa url(images/ui-bg_flat_0_aaaaaa_40x100.png) 50% 50% repeat-x;opacity:.3;filter:Alpha(Opacity=30);-moz-border-radius:8px;-khtml-border-radius:8px;-webkit-border-radius:8px;border-radius:8px} -------------------------------------------------------------------------------- /sample/ruby_on_rails/app/controllers/note_store_controller.rb: -------------------------------------------------------------------------------- 1 | class NoteStoreController < EvernoteController 2 | 3 | private 4 | def authenticateToSharedNote 5 | @code = <<-CODE 6 | client = EvernoteOAuth::Client.new(token: authtoken) 7 | note_store = client.note_store 8 | 9 | note = Evernote::EDAM::Type::Note.new 10 | note.title = "Note" 11 | note.content = < 13 | 14 | Content 15 | EOF 16 | note.tagNames = ["Evernote API Sample"] 17 | 18 | created_note = note_store.createNote(note) 19 | share_key = note_store.shareNote(created_note.guid) 20 | 21 | note_store.authenticateToSharedNote(created_note.guid, share_key) 22 | CODE 23 | end 24 | 25 | def authenticateToSharedNotebook 26 | @code = <<-CODE 27 | client = EvernoteOAuth::Client.new(token: authtoken) 28 | note_store = client.note_store 29 | linked_notebooks = note_store.listLinkedNotebooks 30 | 31 | linked_notebook = linked_notebooks.first 32 | share_key = linked_notebook.shareKey 33 | note_store.authenticateToSharedNotebook(share_key) 34 | CODE 35 | end 36 | 37 | def createLinkedNotebook 38 | @code = <<-CODE 39 | client = EvernoteOAuth::Client.new(token: authtoken) 40 | note_store = client.note_store 41 | user_store = client.user_store 42 | 43 | notebook = Evernote::EDAM::Type::Notebook.new 44 | notebook.name = "Notebook #{Time.now.to_i}" 45 | created_notebook = note_store.createNotebook(notebook) 46 | 47 | shared_notebook = Evernote::EDAM::Type::SharedNotebook.new 48 | shared_notebook.email = '#{params[:email]}' 49 | shared_notebook.notebookGuid = created_notebook.guid 50 | created_shared_notebook = note_store.createSharedNotebook(shared_notebook) 51 | 52 | user = user_store.getUser 53 | 54 | linked_notebook = Evernote::EDAM::Type::LinkedNotebook.new 55 | linked_notebook.shareName = "Linked Notebook" 56 | linked_notebook.username = user.username 57 | linked_notebook.shareKey = created_shared_notebook.shareKey 58 | linked_notebook.shardId = user.shardId 59 | 60 | note_store.createLinkedNotebook(linked_notebook) 61 | CODE 62 | end 63 | 64 | def createSharedNotebook 65 | @code = <<-CODE 66 | client = EvernoteOAuth::Client.new(token: authtoken) 67 | note_store = client.note_store 68 | user_store = client.user_store 69 | 70 | notebook = Evernote::EDAM::Type::Notebook.new 71 | notebook.name = "Notebook #{Time.now.to_i}" 72 | 73 | created_notebook = note_store.createNotebook(notebook) 74 | 75 | shared_notebook = Evernote::EDAM::Type::SharedNotebook.new 76 | shared_notebook.email = '#{params[:email]}' 77 | shared_notebook.allowPreview = false 78 | shared_notebook.notebookGuid = created_notebook.guid 79 | 80 | note_store.createSharedNotebook(shared_notebook) 81 | CODE 82 | end 83 | 84 | def updateSharedNotebook 85 | @code = <<-CODE 86 | client = EvernoteOAuth::Client.new(token: authtoken) 87 | note_store = client.note_store 88 | linked_notebooks = note_store.listLinkedNotebooks 89 | 90 | linked_notebook = linked_notebooks.first 91 | shared_note_store = client.shared_note_store(linked_notebook) 92 | shared_notebook = shared_note_store.getSharedNotebookByAuth 93 | 94 | note_store.updateSharedNotebook(shared_notebook) 95 | CODE 96 | end 97 | 98 | def copyNote 99 | @code = <<-CODE 100 | client = EvernoteOAuth::Client.new(token: authtoken) 101 | note_store = client.note_store 102 | 103 | note = Evernote::EDAM::Type::Note.new 104 | note.title = "Note" 105 | note.content = < 107 | 108 | Content 109 | EOF 110 | note.tagNames = ["Evernote API Sample"] 111 | 112 | created_note = note_store.createNote(note) 113 | 114 | note_store.copyNote(created_note.guid, created_note.notebookGuid) 115 | CODE 116 | end 117 | 118 | def createNote 119 | @code = <<-CODE 120 | client = EvernoteOAuth::Client.new(token: authtoken) 121 | note_store = client.note_store 122 | 123 | note = Evernote::EDAM::Type::Note.new 124 | note.title = "Note" 125 | note.content = < 127 | 128 | Content 129 | EOF 130 | note.tagNames = ["Evernote API Sample"] 131 | 132 | note_store.createNote(note) 133 | CODE 134 | end 135 | 136 | def createNotebook 137 | @code = <<-CODE 138 | client = EvernoteOAuth::Client.new(token: authtoken) 139 | note_store = client.note_store 140 | 141 | notebook = Evernote::EDAM::Type::Notebook.new 142 | notebook.name = "Notebook #{Time.now.to_i}" 143 | 144 | note_store.createNotebook(notebook) 145 | CODE 146 | end 147 | 148 | def createSearch 149 | @code = <<-CODE 150 | client = EvernoteOAuth::Client.new(token: authtoken) 151 | note_store = client.note_store 152 | 153 | saved_search = Evernote::EDAM::Type::SavedSearch.new 154 | saved_search.name = "SavedSearch #{Time.now.to_i}" 155 | saved_search.query = "created:20070704" 156 | saved_search.format = Evernote::EDAM::Type::QueryFormat::USER 157 | 158 | note_store.createSearch(saved_search) 159 | CODE 160 | end 161 | 162 | def createTag 163 | @code = <<-CODE 164 | client = EvernoteOAuth::Client.new(token: authtoken) 165 | note_store = client.note_store 166 | 167 | tag = Evernote::EDAM::Type::Tag.new 168 | tag.name = "Evernote API Sample #{Time.now.to_i}" 169 | 170 | note_store.createTag(tag) 171 | CODE 172 | end 173 | 174 | def deleteNote 175 | @code = <<-CODE 176 | client = EvernoteOAuth::Client.new(token: authtoken) 177 | note_store = client.note_store 178 | 179 | note = Evernote::EDAM::Type::Note.new 180 | note.title = "Note" 181 | note.content = < 183 | 184 | Content 185 | EOF 186 | note.tagNames = ["Evernote API Sample"] 187 | 188 | created_note = note_store.createNote(note) 189 | 190 | note_store.deleteNote(created_note.guid) 191 | CODE 192 | end 193 | 194 | def emailNote 195 | @note = 'This function is not available to third party applications. Calls will result in an EDAMUserException with the error code PERMISSION_DENIED.' 196 | end 197 | 198 | def expungeInactiveNotes; end 199 | def expungeLinkedNotebook; end 200 | def expungeNote; end 201 | def expungeNotebook; end 202 | def expungeNotes; end 203 | def expungeSearch; end 204 | def expungeSharedNotebooks; end 205 | def expungeTag; end 206 | 207 | def findNoteCounts 208 | @code = <<-CODE 209 | client = EvernoteOAuth::Client.new(token: authtoken) 210 | note_store = client.note_store 211 | 212 | note_filter = Evernote::EDAM::NoteStore::NoteFilter.new 213 | note_store.findNoteCounts(note_filter, false) 214 | CODE 215 | end 216 | 217 | def findNoteOffset 218 | @code = <<-CODE 219 | client = EvernoteOAuth::Client.new(token: authtoken) 220 | note_store = client.note_store 221 | 222 | note = Evernote::EDAM::Type::Note.new 223 | note.title = "Note" 224 | note.content = < 226 | 227 | Content 228 | EOF 229 | note.tagNames = ["Evernote API Sample"] 230 | 231 | created_note = note_store.createNote(note) 232 | 233 | note_filter = Evernote::EDAM::NoteStore::NoteFilter.new 234 | note_store.findNoteOffset(note_filter, created_note.guid) 235 | CODE 236 | end 237 | 238 | def findNotesMetadata 239 | @code = <<-CODE 240 | client = EvernoteOAuth::Client.new(token: authtoken) 241 | note_store = client.note_store 242 | 243 | note_filter = Evernote::EDAM::NoteStore::NoteFilter.new 244 | notes_metadata_result_spec = Evernote::EDAM::NoteStore::NotesMetadataResultSpec.new 245 | note_store.findNotesMetadata(note_filter, 0, 100, notes_metadata_result_spec) 246 | CODE 247 | end 248 | 249 | def findNotes 250 | @code = <<-CODE 251 | client = EvernoteOAuth::Client.new(token: authtoken) 252 | note_store = client.note_store 253 | 254 | note_filter = Evernote::EDAM::NoteStore::NoteFilter.new 255 | note_store.findNotes(note_filter, 0, 10) 256 | CODE 257 | end 258 | 259 | def findRelated 260 | @code = <<-CODE 261 | client = EvernoteOAuth::Client.new(token: authtoken) 262 | note_store = client.note_store 263 | 264 | related_query = Evernote::EDAM::NoteStore::RelatedQuery.new 265 | related_query.plainText = 'content' 266 | related_result_spec = Evernote::EDAM::NoteStore::RelatedResultSpec.new 267 | related_result_spec.maxNotes = 10 268 | related_result_spec.maxNotebooks = 10 269 | related_result_spec.maxTags = 10 270 | note_store.findRelated(related_query, related_result_spec) 271 | CODE 272 | end 273 | 274 | def getDefaultNotebook 275 | @code = <<-CODE 276 | client = EvernoteOAuth::Client.new(token: authtoken) 277 | note_store = client.note_store 278 | 279 | note_store.getDefaultNotebook 280 | CODE 281 | end 282 | 283 | def getFilteredSyncChunk 284 | @code = <<-CODE 285 | client = EvernoteOAuth::Client.new(token: authtoken) 286 | note_store = client.note_store 287 | 288 | sync_chunk_filter = Evernote::EDAM::NoteStore::SyncChunkFilter.new 289 | sync_chunk_filter.includeNotes = true 290 | note_store.getFilteredSyncChunk(0, 1, sync_chunk_filter) 291 | CODE 292 | end 293 | 294 | def getLinkedNotebookSyncChunk 295 | @code = <<-CODE 296 | client = EvernoteOAuth::Client.new(token: authtoken) 297 | note_store = client.note_store 298 | linked_notebooks = note_store.listLinkedNotebooks 299 | 300 | linked_notebook = linked_notebooks.first 301 | shared_note_store = client.shared_note_store(linked_notebook) 302 | 303 | shared_note_store.getLinkedNotebookSyncChunk(authtoken, linked_notebook, 0, 1, true) 304 | CODE 305 | end 306 | 307 | def getLinkedNotebookSyncState 308 | @code = <<-CODE 309 | client = EvernoteOAuth::Client.new(token: authtoken) 310 | note_store = client.note_store 311 | linked_notebooks = note_store.listLinkedNotebooks 312 | 313 | linked_notebook = linked_notebooks.first 314 | shared_note_store = client.shared_note_store(linked_notebook) 315 | 316 | shared_note_store.getLinkedNotebookSyncState(authtoken, linked_notebook) 317 | CODE 318 | end 319 | 320 | def getNote 321 | @code = <<-CODE 322 | client = EvernoteOAuth::Client.new(token: authtoken) 323 | note_store = client.note_store 324 | 325 | note = Evernote::EDAM::Type::Note.new 326 | note.title = "Note" 327 | note.content = < 329 | 330 | Content 331 | EOF 332 | note.tagNames = ["Evernote API Sample"] 333 | 334 | created_note = note_store.createNote(note) 335 | 336 | note_store.getNote(created_note.guid, true, false, false, false) 337 | CODE 338 | end 339 | 340 | def getNoteApplicationData 341 | @code = <<-CODE 342 | client = EvernoteOAuth::Client.new(token: authtoken) 343 | note_store = client.note_store 344 | 345 | note = Evernote::EDAM::Type::Note.new 346 | note.title = "Note" 347 | note.content = < 349 | 350 | Content 351 | EOF 352 | note.tagNames = ["Evernote API Sample"] 353 | application_data = Evernote::EDAM::Type::LazyMap.new 354 | application_data.fullMap = {'key' => 'value'} 355 | note_attributes = Evernote::EDAM::Type::NoteAttributes.new 356 | note_attributes.applicationData = application_data 357 | note.attributes = note_attributes 358 | 359 | created_note = note_store.createNote(note) 360 | 361 | note_store.getNoteApplicationData(created_note.guid) 362 | CODE 363 | end 364 | 365 | def getNoteApplicationDataEntry 366 | @code = <<-CODE 367 | client = EvernoteOAuth::Client.new(token: authtoken) 368 | note_store = client.note_store 369 | 370 | note = Evernote::EDAM::Type::Note.new 371 | note.title = "Note" 372 | note.content = < 374 | 375 | Content 376 | EOF 377 | note.tagNames = ["Evernote API Sample"] 378 | application_data = Evernote::EDAM::Type::LazyMap.new 379 | application_data.fullMap = {'key' => 'value'} 380 | note_attributes = Evernote::EDAM::Type::NoteAttributes.new 381 | note_attributes.applicationData = application_data 382 | note.attributes = note_attributes 383 | 384 | created_note = note_store.createNote(note) 385 | 386 | note_store.getNoteApplicationDataEntry(created_note.guid, 'key') 387 | CODE 388 | end 389 | 390 | def getNoteContent 391 | @code = <<-CODE 392 | client = EvernoteOAuth::Client.new(token: authtoken) 393 | note_store = client.note_store 394 | 395 | note = Evernote::EDAM::Type::Note.new 396 | note.title = "Note" 397 | note.content = < 399 | 400 | Content 401 | EOF 402 | note.tagNames = ["Evernote API Sample"] 403 | 404 | created_note = note_store.createNote(note) 405 | 406 | note_store.getNoteContent(created_note.guid) 407 | CODE 408 | end 409 | 410 | def getNoteSearchText 411 | @code = <<-CODE 412 | client = EvernoteOAuth::Client.new(token: authtoken) 413 | note_store = client.note_store 414 | 415 | note = Evernote::EDAM::Type::Note.new 416 | note.title = "Note" 417 | note.content = < 419 | 420 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 421 | EOF 422 | note.tagNames = ["Evernote API Sample"] 423 | 424 | created_note = note_store.createNote(note) 425 | 426 | note_store.getNoteSearchText(created_note.guid, false, true) 427 | CODE 428 | end 429 | 430 | def getNoteTagNames 431 | @code = <<-CODE 432 | client = EvernoteOAuth::Client.new(token: authtoken) 433 | note_store = client.note_store 434 | 435 | note = Evernote::EDAM::Type::Note.new 436 | note.title = "Note" 437 | note.content = < 439 | 440 | Content 441 | EOF 442 | note.tagNames = ["Evernote API Sample"] 443 | 444 | created_note = note_store.createNote(note) 445 | 446 | note_store.getNoteTagNames(created_note.guid) 447 | CODE 448 | end 449 | 450 | def getNoteVersion 451 | @code = <<-CODE 452 | client = EvernoteOAuth::Client.new(token: authtoken) 453 | note_store = client.note_store 454 | 455 | note = Evernote::EDAM::Type::Note.new 456 | note.title = "Note Version 1" 457 | note.content = < 459 | 460 | Version 1 461 | EOF 462 | note.tagNames = ["Evernote API Sample"] 463 | 464 | created_note = note_store.createNote(note) 465 | 466 | created_note.title = "Note Version 2" 467 | created_note.content = < 469 | 470 | Version 2 471 | EOF 472 | 473 | updated_note = note_store.updateNote(created_note) 474 | 475 | note_store.getNoteVersion(updated_note.guid, created_note.updateSequenceNum, false, false, false) 476 | CODE 477 | end 478 | 479 | def getNotebook 480 | @code = <<-CODE 481 | client = EvernoteOAuth::Client.new(token: authtoken) 482 | note_store = client.note_store 483 | 484 | notebook = Evernote::EDAM::Type::Notebook.new 485 | notebook.name = "Notebook #{Time.now.to_i}" 486 | 487 | created_notebook = note_store.createNotebook(notebook) 488 | 489 | note_store.getNotebook(created_notebook.guid) 490 | CODE 491 | end 492 | 493 | def getPublicNotebook 494 | @code = <<-CODE 495 | client = EvernoteOAuth::Client.new(token: authtoken) 496 | user_store = client.user_store 497 | note_store = client.note_store 498 | 499 | public_user_info = user_store.getPublicUserInfo('evernotedev') 500 | 501 | note_store.getPublicNotebook(public_user_info.userId, 'cooking_notes') 502 | CODE 503 | end 504 | 505 | def getResource 506 | @code = <<-CODE 507 | client = EvernoteOAuth::Client.new(token: authtoken) 508 | note_store = client.note_store 509 | 510 | note = Evernote::EDAM::Type::Note.new 511 | note.title = "Note" 512 | 513 | filename = "enlogo.png" 514 | image = File.open(File.join(Rails.root, 'public', filename), "rb") { |io| io.read } 515 | hash_func = Digest::MD5.new 516 | 517 | data = Evernote::EDAM::Type::Data.new 518 | data.size = image.size 519 | data.bodyHash = hash_func.digest(image) 520 | data.body = image 521 | 522 | resource = Evernote::EDAM::Type::Resource.new 523 | resource.mime = "image/png" 524 | resource.data = data 525 | resource.attributes = Evernote::EDAM::Type::ResourceAttributes.new 526 | resource.attributes.fileName = filename 527 | 528 | note.resources = [resource] 529 | 530 | note.content = < 532 | 533 | Content
534 | 535 |
536 | EOF 537 | note.tagNames = ["Evernote API Sample"] 538 | 539 | created_note = note_store.createNote(note) 540 | resource_guid = created_note.resources.first.guid 541 | 542 | note_store.getResource(resource_guid, false, false, false, false) 543 | CODE 544 | end 545 | 546 | def getResourceAlternateData 547 | @code = <<-CODE 548 | client = EvernoteOAuth::Client.new(token: authtoken) 549 | note_store = client.note_store 550 | 551 | note = Evernote::EDAM::Type::Note.new 552 | note.title = "Note" 553 | 554 | filename = "enlogo.png" 555 | image = File.open(File.join(Rails.root, 'public', filename), "rb") { |io| io.read } 556 | hash_func = Digest::MD5.new 557 | 558 | data = Evernote::EDAM::Type::Data.new 559 | data.size = image.size 560 | data.bodyHash = hash_func.digest(image) 561 | data.body = image 562 | 563 | alternate_filename = "rails.png" 564 | alternate_image = File.open(File.join(Rails.root, 'public', filename), "rb") { |io| io.read } 565 | 566 | alternate_data = Evernote::EDAM::Type::Data.new 567 | alternate_data.size = alternate_image.size 568 | alternate_data.bodyHash = hash_func.digest(alternate_image) 569 | alternate_data.body = alternate_image 570 | 571 | resource = Evernote::EDAM::Type::Resource.new 572 | resource.mime = "image/png" 573 | resource.data = data 574 | resource.alternateData = alternate_data 575 | resource.attributes = Evernote::EDAM::Type::ResourceAttributes.new 576 | resource.attributes.fileName = filename 577 | 578 | note.resources = [resource] 579 | 580 | note.content = < 582 | 583 | Content
584 | 585 |
586 | EOF 587 | note.tagNames = ["Evernote API Sample"] 588 | 589 | created_note = note_store.createNote(note) 590 | resource_guid = created_note.resources.first.guid 591 | 592 | note_store.getResourceAlternateData(resource_guid) 593 | CODE 594 | end 595 | 596 | def getResourceApplicationData 597 | @code = <<-CODE 598 | client = EvernoteOAuth::Client.new(token: authtoken) 599 | note_store = client.note_store 600 | 601 | note = Evernote::EDAM::Type::Note.new 602 | note.title = "Note" 603 | 604 | filename = "enlogo.png" 605 | image = File.open(File.join(Rails.root, 'public', filename), "rb") { |io| io.read } 606 | hash_func = Digest::MD5.new 607 | 608 | data = Evernote::EDAM::Type::Data.new 609 | data.size = image.size 610 | data.bodyHash = hash_func.digest(image) 611 | data.body = image 612 | 613 | resource = Evernote::EDAM::Type::Resource.new 614 | resource.mime = "image/png" 615 | resource.data = data 616 | resource.attributes = Evernote::EDAM::Type::ResourceAttributes.new 617 | resource.attributes.fileName = filename 618 | 619 | application_data = Evernote::EDAM::Type::LazyMap.new 620 | application_data.fullMap = {'key' => 'value'} 621 | resource_attributes = Evernote::EDAM::Type::ResourceAttributes.new 622 | resource_attributes.applicationData = application_data 623 | resource.attributes = resource_attributes 624 | 625 | note.resources = [resource] 626 | 627 | note.content = < 629 | 630 | Content
631 | 632 |
633 | EOF 634 | note.tagNames = ["Evernote API Sample"] 635 | 636 | created_note = note_store.createNote(note) 637 | resource_guid = created_note.resources.first.guid 638 | 639 | note_store.getResourceApplicationData(resource_guid) 640 | CODE 641 | end 642 | 643 | def getResourceApplicationDataEntry 644 | @code = <<-CODE 645 | client = EvernoteOAuth::Client.new(token: authtoken) 646 | note_store = client.note_store 647 | 648 | note = Evernote::EDAM::Type::Note.new 649 | note.title = "Note" 650 | 651 | filename = "enlogo.png" 652 | image = File.open(File.join(Rails.root, 'public', filename), "rb") { |io| io.read } 653 | hash_func = Digest::MD5.new 654 | 655 | data = Evernote::EDAM::Type::Data.new 656 | data.size = image.size 657 | data.bodyHash = hash_func.digest(image) 658 | data.body = image 659 | 660 | resource = Evernote::EDAM::Type::Resource.new 661 | resource.mime = "image/png" 662 | resource.data = data 663 | resource_attributes = Evernote::EDAM::Type::ResourceAttributes.new 664 | resource_attributes.fileName = filename 665 | 666 | application_data = Evernote::EDAM::Type::LazyMap.new 667 | application_data.fullMap = {'key' => 'value'} 668 | resource_attributes.applicationData = application_data 669 | resource.attributes = resource_attributes 670 | 671 | note.resources = [resource] 672 | 673 | note.content = < 675 | 676 | Content
677 | 678 |
679 | EOF 680 | note.tagNames = ["Evernote API Sample"] 681 | 682 | created_note = note_store.createNote(note) 683 | resource_guid = created_note.resources.first.guid 684 | 685 | note_store.getResourceApplicationDataEntry(resource_guid, 'key') 686 | CODE 687 | end 688 | 689 | def getResourceAttributes 690 | @code = <<-CODE 691 | client = EvernoteOAuth::Client.new(token: authtoken) 692 | note_store = client.note_store 693 | 694 | note = Evernote::EDAM::Type::Note.new 695 | note.title = "Note" 696 | 697 | filename = "enlogo.png" 698 | image = File.open(File.join(Rails.root, 'public', filename), "rb") { |io| io.read } 699 | hash_func = Digest::MD5.new 700 | 701 | data = Evernote::EDAM::Type::Data.new 702 | data.size = image.size 703 | data.bodyHash = hash_func.digest(image) 704 | data.body = image 705 | 706 | resource = Evernote::EDAM::Type::Resource.new 707 | resource.mime = "image/png" 708 | resource.data = data 709 | resource_attributes = Evernote::EDAM::Type::ResourceAttributes.new 710 | resource_attributes.fileName = filename 711 | resource.attributes = resource_attributes 712 | 713 | note.resources = [resource] 714 | 715 | note.content = < 717 | 718 | Content
719 | 720 |
721 | EOF 722 | note.tagNames = ["Evernote API Sample"] 723 | 724 | created_note = note_store.createNote(note) 725 | resource_guid = created_note.resources.first.guid 726 | 727 | note_store.getResourceAttributes(resource_guid) 728 | CODE 729 | end 730 | 731 | def getResourceByHash 732 | @code = <<-CODE 733 | client = EvernoteOAuth::Client.new(token: authtoken) 734 | note_store = client.note_store 735 | 736 | note = Evernote::EDAM::Type::Note.new 737 | note.title = "Note" 738 | filename = "enlogo.png" 739 | image = File.open(File.join(Rails.root, 'public', filename), "rb") { |io| io.read } 740 | hash_func = Digest::MD5.new 741 | 742 | data = Evernote::EDAM::Type::Data.new 743 | data.size = image.size 744 | body_hash = hash_func.digest(image) 745 | data.bodyHash = body_hash 746 | data.body = image 747 | 748 | resource = Evernote::EDAM::Type::Resource.new 749 | resource.mime = "image/png" 750 | resource.data = data 751 | resource_attributes = Evernote::EDAM::Type::ResourceAttributes.new 752 | resource_attributes.fileName = filename 753 | resource.attributes = resource_attributes 754 | 755 | note.resources = [resource] 756 | 757 | note.content = < 759 | 760 | Content
761 | 762 |
763 | EOF 764 | note.tagNames = ["Evernote API Sample"] 765 | 766 | created_note = note_store.createNote(note) 767 | resource_guid = created_note.resources.first.guid 768 | 769 | note_store.getResourceByHash(created_note.guid, body_hash, false, false, false) 770 | CODE 771 | end 772 | 773 | def getResourceData 774 | @code = <<-CODE 775 | client = EvernoteOAuth::Client.new(token: authtoken) 776 | note_store = client.note_store 777 | 778 | note = Evernote::EDAM::Type::Note.new 779 | note.title = "Note" 780 | 781 | filename = "enlogo.png" 782 | image = File.open(File.join(Rails.root, 'public', filename), "rb") { |io| io.read } 783 | hash_func = Digest::MD5.new 784 | 785 | data = Evernote::EDAM::Type::Data.new 786 | data.size = image.size 787 | data.bodyHash = hash_func.digest(image) 788 | data.body = image 789 | 790 | resource = Evernote::EDAM::Type::Resource.new 791 | resource.mime = "image/png" 792 | resource.data = data 793 | resource_attributes = Evernote::EDAM::Type::ResourceAttributes.new 794 | resource_attributes.fileName = filename 795 | resource.attributes = resource_attributes 796 | 797 | note.resources = [resource] 798 | 799 | note.content = < 801 | 802 | Content
803 | 804 |
805 | EOF 806 | note.tagNames = ["Evernote API Sample"] 807 | 808 | created_note = note_store.createNote(note) 809 | resource_guid = created_note.resources.first.guid 810 | 811 | note_store.getResourceData(resource_guid) 812 | CODE 813 | end 814 | 815 | def getResourceRecognition 816 | @code = <<-CODE 817 | client = EvernoteOAuth::Client.new(token: authtoken) 818 | note_store = client.note_store 819 | 820 | note = Evernote::EDAM::Type::Note.new 821 | note.title = "Note" 822 | 823 | filename = "enlogo.png" 824 | image = File.open(File.join(Rails.root, 'public', filename), "rb") { |io| io.read } 825 | hash_func = Digest::MD5.new 826 | 827 | data = Evernote::EDAM::Type::Data.new 828 | data.size = image.size 829 | data.bodyHash = hash_func.digest(image) 830 | data.body = image 831 | 832 | resource = Evernote::EDAM::Type::Resource.new 833 | resource.mime = "image/png" 834 | resource.data = data 835 | resource_attributes = Evernote::EDAM::Type::ResourceAttributes.new 836 | resource_attributes.fileName = filename 837 | resource.attributes = resource_attributes 838 | 839 | note.resources = [resource] 840 | 841 | note.content = < 843 | 844 | Content
845 | 846 |
847 | EOF 848 | note.tagNames = ["Evernote API Sample"] 849 | 850 | created_note = note_store.createNote(note) 851 | resource_guid = created_note.resources.first.guid 852 | 853 | note_store.getResourceRecognition(resource_guid) 854 | CODE 855 | end 856 | 857 | def getResourceSearchText 858 | @code = <<-CODE 859 | client = EvernoteOAuth::Client.new(token: authtoken) 860 | note_store = client.note_store 861 | 862 | note = Evernote::EDAM::Type::Note.new 863 | note.title = "Note" 864 | 865 | filename = "evernote_logo_center.png" 866 | image = File.open(File.join(Rails.root, 'public', filename), "rb") { |io| io.read } 867 | hash_func = Digest::MD5.new 868 | 869 | data = Evernote::EDAM::Type::Data.new 870 | data.size = image.size 871 | data.bodyHash = hash_func.digest(image) 872 | data.body = image 873 | 874 | resource = Evernote::EDAM::Type::Resource.new 875 | resource.mime = "image/png" 876 | resource.data = data 877 | resource_attributes = Evernote::EDAM::Type::ResourceAttributes.new 878 | resource_attributes.fileName = filename 879 | resource.attributes = resource_attributes 880 | 881 | note.resources = [resource] 882 | 883 | note.content = < 885 | 886 | Content
887 | 888 |
889 | EOF 890 | note.tagNames = ["Evernote API Sample"] 891 | 892 | created_note = note_store.createNote(note) 893 | resource_guid = created_note.resources.first.guid 894 | 895 | note_store.getResourceSearchText(resource_guid) 896 | CODE 897 | end 898 | 899 | def getSearch 900 | @code = <<-CODE 901 | client = EvernoteOAuth::Client.new(token: authtoken) 902 | note_store = client.note_store 903 | 904 | saved_search = Evernote::EDAM::Type::SavedSearch.new 905 | saved_search.name = "SavedSearch #{Time.now.to_i}" 906 | saved_search.query = "created:20070704" 907 | saved_search.format = Evernote::EDAM::Type::QueryFormat::USER 908 | 909 | created_search = note_store.createSearch(saved_search) 910 | 911 | note_store.getSearch(created_search.guid) 912 | CODE 913 | end 914 | 915 | def getSharedNotebookByAuth 916 | @code = <<-CODE 917 | client = EvernoteOAuth::Client.new(token: authtoken) 918 | note_store = client.note_store 919 | linked_notebooks = note_store.listLinkedNotebooks 920 | 921 | linked_notebook = linked_notebooks.first 922 | shared_note_store = client.shared_note_store(linked_notebook) 923 | 924 | shared_note_store.getSharedNotebookByAuth 925 | CODE 926 | end 927 | 928 | def getSyncChunk 929 | @code = <<-CODE 930 | client = EvernoteOAuth::Client.new(token: authtoken) 931 | note_store = client.note_store 932 | 933 | note_store.getSyncChunk(0, 1, true) 934 | CODE 935 | end 936 | 937 | def getSyncState 938 | @code = <<-CODE 939 | client = EvernoteOAuth::Client.new(token: authtoken) 940 | note_store = client.note_store 941 | 942 | note_store.getSyncState 943 | CODE 944 | end 945 | 946 | def getSyncStateWithMetrics 947 | @code = <<-CODE 948 | client = EvernoteOAuth::Client.new(token: authtoken) 949 | note_store = client.note_store 950 | 951 | client_usage_metrics = Evernote::EDAM::NoteStore::ClientUsageMetrics.new 952 | client_usage_metrics.sessions = 0 953 | 954 | note_store.getSyncStateWithMetrics(client_usage_metrics) 955 | CODE 956 | end 957 | 958 | def getTag 959 | @code = <<-CODE 960 | client = EvernoteOAuth::Client.new(token: authtoken) 961 | note_store = client.note_store 962 | 963 | tag = Evernote::EDAM::Type::Tag.new 964 | tag.name = "Evernote API Sample #{Time.now.to_i}" 965 | 966 | created_tag = note_store.createTag(tag) 967 | 968 | note_store.getTag(created_tag.guid) 969 | CODE 970 | end 971 | 972 | def listLinkedNotebooks 973 | @code = <<-CODE 974 | client = EvernoteOAuth::Client.new(token: authtoken) 975 | note_store = client.note_store 976 | 977 | note_store.listLinkedNotebooks 978 | CODE 979 | end 980 | 981 | def listNotebooks 982 | @code = <<-CODE 983 | client = EvernoteOAuth::Client.new(token: authtoken) 984 | note_store = client.note_store 985 | 986 | note_store.listNotebooks 987 | CODE 988 | end 989 | 990 | def listNoteVersions 991 | @code = <<-CODE 992 | client = EvernoteOAuth::Client.new(token: authtoken) 993 | note_store = client.note_store 994 | 995 | note = Evernote::EDAM::Type::Note.new 996 | note.title = "Note Version 1" 997 | note.content = < 999 | 1000 | Version 1 1001 | EOF 1002 | note.tagNames = ["Evernote API Sample"] 1003 | 1004 | created_note = note_store.createNote(note) 1005 | 1006 | created_note.title = "Note Version 2" 1007 | created_note.content = < 1009 | 1010 | Version 2 1011 | EOF 1012 | 1013 | updated_note = note_store.updateNote(created_note) 1014 | 1015 | note_store.listNoteVersions(updated_note.guid) 1016 | CODE 1017 | end 1018 | 1019 | def listSearches 1020 | @code = <<-CODE 1021 | client = EvernoteOAuth::Client.new(token: authtoken) 1022 | note_store = client.note_store 1023 | 1024 | note_store.listSearches 1025 | CODE 1026 | end 1027 | 1028 | def listTags 1029 | @code = <<-CODE 1030 | client = EvernoteOAuth::Client.new(token: authtoken) 1031 | note_store = client.note_store 1032 | 1033 | note_store.listTags 1034 | CODE 1035 | end 1036 | 1037 | def listSharedNotebooks 1038 | @code = <<-CODE 1039 | client = EvernoteOAuth::Client.new(token: authtoken) 1040 | note_store = client.note_store 1041 | 1042 | note_store.listSharedNotebooks 1043 | CODE 1044 | end 1045 | 1046 | def listTagsByNotebook 1047 | @code = <<-CODE 1048 | client = EvernoteOAuth::Client.new(token: authtoken) 1049 | note_store = client.note_store 1050 | 1051 | default_notebook = note_store.getDefaultNotebook 1052 | 1053 | note_store.listTagsByNotebook(default_notebook.guid) 1054 | CODE 1055 | end 1056 | 1057 | def sendMessageToSharedNotebookMembers 1058 | @code = <<-CODE 1059 | client = EvernoteOAuth::Client.new(token: authtoken) 1060 | note_store = client.note_store 1061 | 1062 | shared_notebook = note_store.listSharedNotebooks.first 1063 | 1064 | note_store.sendMessageToSharedNotebookMembers(shared_notebook.notebookGuid, "This is a test.", []) 1065 | CODE 1066 | end 1067 | 1068 | def setNoteApplicationDataEntry 1069 | @code = <<-CODE 1070 | client = EvernoteOAuth::Client.new(token: authtoken) 1071 | note_store = client.note_store 1072 | 1073 | note = Evernote::EDAM::Type::Note.new 1074 | note.title = "Note" 1075 | note.content = < 1077 | 1078 | Content 1079 | EOF 1080 | note.tagNames = ["Evernote API Sample"] 1081 | 1082 | created_note = note_store.createNote(note) 1083 | 1084 | note_store.setNoteApplicationDataEntry(created_note.guid, 'key', 'value') 1085 | CODE 1086 | end 1087 | 1088 | def setResourceApplicationDataEntry 1089 | @code = <<-CODE 1090 | client = EvernoteOAuth::Client.new(token: authtoken) 1091 | note_store = client.note_store 1092 | 1093 | note = Evernote::EDAM::Type::Note.new 1094 | note.title = "Note" 1095 | 1096 | filename = "enlogo.png" 1097 | image = File.open(File.join(Rails.root, 'public', filename), "rb") { |io| io.read } 1098 | hash_func = Digest::MD5.new 1099 | 1100 | data = Evernote::EDAM::Type::Data.new 1101 | data.size = image.size 1102 | data.bodyHash = hash_func.digest(image) 1103 | data.body = image 1104 | 1105 | resource = Evernote::EDAM::Type::Resource.new 1106 | resource.mime = "image/png" 1107 | resource.data = data 1108 | resource.attributes = Evernote::EDAM::Type::ResourceAttributes.new 1109 | resource.attributes.fileName = filename 1110 | 1111 | note.resources = [resource] 1112 | 1113 | note.content = < 1115 | 1116 | Content
1117 | 1118 |
1119 | EOF 1120 | note.tagNames = ["Evernote API Sample"] 1121 | 1122 | created_note = note_store.createNote(note) 1123 | resource_guid = created_note.resources.first.guid 1124 | 1125 | note_store.setResourceApplicationDataEntry(resource_guid, 'key', 'value') 1126 | CODE 1127 | end 1128 | 1129 | def shareNote 1130 | @code = <<-CODE 1131 | client = EvernoteOAuth::Client.new(token: authtoken) 1132 | note_store = client.note_store 1133 | 1134 | note = Evernote::EDAM::Type::Note.new 1135 | note.title = "Note" 1136 | note.content = < 1138 | 1139 | Content 1140 | EOF 1141 | note.tagNames = ["Evernote API Sample"] 1142 | 1143 | created_note = note_store.createNote(note) 1144 | 1145 | note_store.shareNote(created_note.guid) 1146 | CODE 1147 | end 1148 | 1149 | def stopSharingNote 1150 | @code = <<-CODE 1151 | client = EvernoteOAuth::Client.new(token: authtoken) 1152 | note_store = client.note_store 1153 | 1154 | note = Evernote::EDAM::Type::Note.new 1155 | note.title = "Note" 1156 | note.content = < 1158 | 1159 | Content 1160 | EOF 1161 | note.tagNames = ["Evernote API Sample"] 1162 | 1163 | created_note = note_store.createNote(note) 1164 | 1165 | note_store.shareNote(created_note.guid) 1166 | 1167 | note_store.stopSharingNote(created_note.guid) 1168 | CODE 1169 | end 1170 | 1171 | def unsetNoteApplicationDataEntry 1172 | @code = <<-CODE 1173 | client = EvernoteOAuth::Client.new(token: authtoken) 1174 | note_store = client.note_store 1175 | 1176 | note = Evernote::EDAM::Type::Note.new 1177 | note.title = "Note" 1178 | note.content = < 1180 | 1181 | Content 1182 | EOF 1183 | note.tagNames = ["Evernote API Sample"] 1184 | 1185 | created_note = note_store.createNote(note) 1186 | 1187 | note_store.setNoteApplicationDataEntry(created_note.guid, 'key', 'value') 1188 | 1189 | note_store.unsetNoteApplicationDataEntry(created_note.guid, 'key') 1190 | CODE 1191 | end 1192 | 1193 | def unsetResourceApplicationDataEntry 1194 | @code = <<-CODE 1195 | client = EvernoteOAuth::Client.new(token: authtoken) 1196 | note_store = client.note_store 1197 | 1198 | note = Evernote::EDAM::Type::Note.new 1199 | note.title = "Note" 1200 | 1201 | filename = "enlogo.png" 1202 | image = File.open(File.join(Rails.root, 'public', filename), "rb") { |io| io.read } 1203 | hash_func = Digest::MD5.new 1204 | 1205 | data = Evernote::EDAM::Type::Data.new 1206 | data.size = image.size 1207 | data.bodyHash = hash_func.digest(image) 1208 | data.body = image 1209 | 1210 | resource = Evernote::EDAM::Type::Resource.new 1211 | resource.mime = "image/png" 1212 | resource.data = data 1213 | resource.attributes = Evernote::EDAM::Type::ResourceAttributes.new 1214 | resource.attributes.fileName = filename 1215 | 1216 | note.resources = [resource] 1217 | 1218 | note.content = < 1220 | 1221 | Content
1222 | 1223 |
1224 | EOF 1225 | note.tagNames = ["Evernote API Sample"] 1226 | 1227 | created_note = note_store.createNote(note) 1228 | resource_guid = created_note.resources.first.guid 1229 | 1230 | note_store.setResourceApplicationDataEntry(resource_guid, 'key', 'value') 1231 | 1232 | note_store.unsetResourceApplicationDataEntry(resource_guid, 'key') 1233 | CODE 1234 | end 1235 | 1236 | def untagAll 1237 | @code = <<-CODE 1238 | client = EvernoteOAuth::Client.new(token: authtoken) 1239 | note_store = client.note_store 1240 | 1241 | note = Evernote::EDAM::Type::Note.new 1242 | note.title = "Note" 1243 | note.content = < 1245 | 1246 | Content 1247 | EOF 1248 | note.tagNames = ["Evernote API Sample #{Time.now.to_i}"] 1249 | 1250 | created_note = note_store.createNote(note) 1251 | created_tag_guid = created_note.tagGuids.first 1252 | 1253 | note_store.untagAll(created_tag_guid) 1254 | CODE 1255 | end 1256 | 1257 | def updateLinkedNotebook 1258 | @code = <<-CODE 1259 | client = EvernoteOAuth::Client.new(token: authtoken) 1260 | note_store = client.note_store 1261 | 1262 | linked_notebook = note_store.listLinkedNotebooks.first 1263 | if linked_notebook.shareName.index('[Updated] ') 1264 | linked_notebook.shareName = linked_notebook.shareName.gsub('[Updated] ', '') 1265 | else 1266 | linked_notebook.shareName = "[Updated] " + linked_notebook.shareName 1267 | end 1268 | 1269 | note_store.updateLinkedNotebook(linked_notebook) 1270 | CODE 1271 | end 1272 | 1273 | def updateNote 1274 | @code = <<-CODE 1275 | client = EvernoteOAuth::Client.new(token: authtoken) 1276 | note_store = client.note_store 1277 | 1278 | note = Evernote::EDAM::Type::Note.new 1279 | note.title = "Note" 1280 | note.content = < 1282 | 1283 | Content 1284 | EOF 1285 | note.tagNames = ["Evernote API Sample"] 1286 | 1287 | created_note = note_store.createNote(note) 1288 | created_note.title = "[Updated] " + created_note.title 1289 | 1290 | note_store.updateNote(created_note) 1291 | CODE 1292 | end 1293 | 1294 | def updateNotebook 1295 | @code = <<-CODE 1296 | client = EvernoteOAuth::Client.new(token: authtoken) 1297 | note_store = client.note_store 1298 | 1299 | notebook = Evernote::EDAM::Type::Notebook.new 1300 | notebook.name = "Notebook #{Time.now.to_i}" 1301 | 1302 | created_notebook = note_store.createNotebook(notebook) 1303 | created_notebook.name = "[Updated] " + created_notebook.name 1304 | 1305 | note_store.updateNotebook(created_notebook) 1306 | CODE 1307 | end 1308 | 1309 | def updateResource 1310 | @code = <<-CODE 1311 | client = EvernoteOAuth::Client.new(token: authtoken) 1312 | note_store = client.note_store 1313 | 1314 | note = Evernote::EDAM::Type::Note.new 1315 | note.title = "Note" 1316 | 1317 | filename = "enlogo.png" 1318 | image = File.open(File.join(Rails.root, 'public', filename), "rb") { |io| io.read } 1319 | hash_func = Digest::MD5.new 1320 | 1321 | data = Evernote::EDAM::Type::Data.new 1322 | data.size = image.size 1323 | data.bodyHash = hash_func.digest(image) 1324 | data.body = image 1325 | 1326 | resource = Evernote::EDAM::Type::Resource.new 1327 | resource.mime = "image/png" 1328 | resource.data = data 1329 | resource.attributes = Evernote::EDAM::Type::ResourceAttributes.new 1330 | resource.attributes.fileName = filename 1331 | 1332 | note.resources = [resource] 1333 | 1334 | note.content = < 1336 | 1337 | Content
1338 | 1339 |
1340 | EOF 1341 | note.tagNames = ["Evernote API Sample"] 1342 | 1343 | created_note = note_store.createNote(note) 1344 | resource_guid = created_note.resources.first.guid 1345 | 1346 | created_resource = note_store.getResource(resource_guid, false, false, false, false) 1347 | created_resource.width = 300 1348 | created_resource.height = 300 1349 | 1350 | note_store.updateResource(created_resource) 1351 | CODE 1352 | end 1353 | 1354 | def updateSearch 1355 | @code = <<-CODE 1356 | client = EvernoteOAuth::Client.new(token: authtoken) 1357 | note_store = client.note_store 1358 | 1359 | saved_search = Evernote::EDAM::Type::SavedSearch.new 1360 | saved_search.name = "SavedSearch #{Time.now.to_i}" 1361 | saved_search.query = "created:20070704" 1362 | saved_search.format = Evernote::EDAM::Type::QueryFormat::USER 1363 | 1364 | created_saved_search = note_store.createSearch(saved_search) 1365 | created_saved_search.name = "[Updated] " + created_saved_search.name 1366 | created_saved_search.query = "created:20201231" 1367 | 1368 | note_store.updateSearch(created_saved_search) 1369 | CODE 1370 | end 1371 | 1372 | def updateTag 1373 | @code = <<-CODE 1374 | client = EvernoteOAuth::Client.new(token: authtoken) 1375 | note_store = client.note_store 1376 | 1377 | tag = Evernote::EDAM::Type::Tag.new 1378 | tag.name = "Evernote API Sample #{Time.now.to_i}" 1379 | 1380 | created_tag = note_store.createTag(tag) 1381 | created_tag.name = "[Updated] " + created_tag.name 1382 | 1383 | note_store.updateTag(created_tag) 1384 | CODE 1385 | end 1386 | 1387 | end 1388 | --------------------------------------------------------------------------------