Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
Evernote OAuth / Thrift API client library for Ruby
===================================================
- Evernote OAuth version 0.03
- Evernote API version 1.21
- Evernote OAuth version 0.1.0

Install the gem
---------------
Expand Down
8 changes: 4 additions & 4 deletions evernote_oauth.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ Gem::Specification.new do |s|
s.name = %q{evernote_oauth}
s.version = EvernoteOAuth::VERSION

s.authors = ["Kentaro Suzuki"]
s.authors = ["Evernote"]
s.date = %q{2012-08-14}
s.description = %q{evernote_oauth is a Ruby client for the Evernote API using OAuth and Thrift.}
s.email = %q{ksuzuki@gmail.com}
s.files = ["LICENSE", "README.md", "evernote_oauth.gemspec"] + Dir.glob('{lib,spec,vendor}/**/*')
s.email = %q{api@evernote.com}
s.files = ["LICENSE", "README.md", "evernote_oauth.gemspec"] + Dir.glob('{lib,spec}/**/*')
s.has_rdoc = false
s.homepage = %q{http://github.com/rekotan/evernote_oauth}
s.rdoc_options = ["--inline-source", "--charset=UTF-8"]
Expand All @@ -26,7 +26,7 @@ Gem::Specification.new do |s|
s.specification_version = 2

s.add_dependency 'oauth', '>= 0.4.1'
s.add_dependency 'thrift_client', '>= 0.8.1'
s.add_dependency 'evernote-thrift'
s.add_development_dependency 'rspec'
end
end
26 changes: 1 addition & 25 deletions lib/evernote_oauth.rb
Original file line number Diff line number Diff line change
@@ -1,34 +1,10 @@
require 'rubygems'
require 'thrift_client'
require 'oauth'
require 'yaml'

vendor_path = File.expand_path(File.dirname(__FILE__) + "/../vendor")
$LOAD_PATH.unshift "#{vendor_path}/evernote/edam"

require "#{vendor_path}/evernote"
require 'evernote-thrift'

require 'evernote_oauth/client'
require 'evernote_oauth/user_store'
require 'evernote_oauth/note_store'
require 'evernote_oauth/version'

# Path Thrift 0.8.0 Gem for Ruby 1.9.3 compatibility
# See: http://discussion.evernote.com/topic/15321-evernote-ruby-thrift-client-error/
#
if Gem::Version.new(RUBY_VERSION.dup) == Gem::Version.new('1.9.3') &&
Gem.loaded_specs['thrift'].version == Gem::Version.new('0.8.0')
module Thrift
class HTTPClientTransport < BaseTransport

def flush
http = Net::HTTP.new @url.host, @url.port
http.use_ssl = @url.scheme == "https"
resp, data = http.post(@url.request_uri, @outbuf, @headers)
# Was: @inbuf = StringIO.new data
@inbuf = StringIO.new resp.body
@outbuf = ""
end
end
end
end
7 changes: 4 additions & 3 deletions lib/evernote_oauth/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ def access_token
@access_token ||= OAuth::AccessToken.new(consumer, @token, @secret)
end

def thrift_client(client_class, url, options={})
@thrift_client = ThriftClient.new(client_class, url, options.merge(
transport: Thrift::HTTPClientTransport))
def thrift_client(client_class, url)
transport = Thrift::HTTPClientTransport.new(url)
protocol = Thrift::BinaryProtocol.new(transport)
client_class.new(protocol)
end

end
Expand Down
3 changes: 1 addition & 2 deletions lib/evernote_oauth/note_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ class Client
def note_store(options={})
@note_store = EvernoteOAuth::NoteStore.new(
client: thrift_client(::Evernote::EDAM::NoteStore::NoteStore::Client,
user_store(options).getNoteStoreUrl(@token),
options)
options[:note_store_url] || user_store.getNoteStoreUrl(@token))
)
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/evernote_oauth/user_store.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module EvernoteOAuth

class Client
def user_store(options={})
def user_store
@user_store = EvernoteOAuth::UserStore.new(
client: thrift_client(::Evernote::EDAM::UserStore::UserStore::Client,
endpoint('edam/user'), options)
endpoint('edam/user'))
)
end
end
Expand All @@ -21,8 +21,8 @@ def method_missing(name, *args, &block)

def version_valid?
checkVersion("EDAMTest",
::Evernote::EDAM::UserStore::EDAM_VERSION_MAJOR,
::Evernote::EDAM::UserStore::EDAM_VERSION_MINOR)
::Evernote::EDAM::UserStore::EDAM_VERSION_MAJOR,
::Evernote::EDAM::UserStore::EDAM_VERSION_MINOR)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/evernote_oauth/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module EvernoteOAuth
VERSION = "0.0.4"
VERSION = "0.1.0"
end
95 changes: 95 additions & 0 deletions sample/client/EDAMTest.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#
# A simple Evernote API demo script that lists all notebooks in the user's
# account and creates a simple test note in the default notebook.
#
# Before running this sample, you must:
# - fill in your Evernote developer token.
# - install evernote-thrift gem.
#
# To run (Unix):
# ruby EDAMTest.rb
#

require "digest/md5"
require 'evernote_oauth'

# Real applications authenticate with Evernote using OAuth, but for the
# purpose of exploring the API, you can get a developer token that allows
# you to access your own Evernote account. To get a developer token, visit
# https://sandbox.evernote.com/api/DeveloperToken.action
authToken = "your developer token"

if authToken == "your developer token"
puts "Please fill in your developer token"
puts "To get a developer token, visit https://sandbox.evernote.com/api/DeveloperToken.action"
exit(1)
end

# Initial development is performed on our sandbox server. To use the production
# service, add "sandbox: false" option and replace your
# developer token above with a token from
# https://www.evernote.com/api/DeveloperToken.action
client = EvernoteOAuth::Client.new(token: authToken)

# List all of the notebooks in the user's account
note_store = client.note_store
notebooks = note_store.listNotebooks(authToken)
puts "Found #{notebooks.size} notebooks:"
defaultNotebook = notebooks.first
notebooks.each do |notebook|
puts " * #{notebook.name}"
end

puts
puts "Creating a new note in the default notebook: #{defaultNotebook.name}"
puts

# To create a new note, simply create a new Note object and fill in
# attributes such as the note's title.
note = Evernote::EDAM::Type::Note.new
note.title = "Test note from EDAMTest.rb"

# To include an attachment such as an image in a note, first create a Resource
# for the attachment. At a minimum, the Resource contains the binary attachment
# data, an MD5 hash of the binary data, and the attachment MIME type. It can also
#/ include attributes such as filename and location.
filename = "enlogo.png"
image = File.open(filename, "rb") { |io| io.read }
hashFunc = Digest::MD5.new

data = Evernote::EDAM::Type::Data.new
data.size = image.size
data.bodyHash = hashFunc.digest(image)
data.body = image

resource = Evernote::EDAM::Type::Resource.new
resource.mime = "image/png"
resource.data = data
resource.attributes = Evernote::EDAM::Type::ResourceAttributes.new
resource.attributes.fileName = filename

# Now, add the new Resource to the note's list of resources
note.resources = [ resource ]

# To display the Resource as part of the note's content, include an <en-media>
# tag in the note's ENML content. The en-media tag identifies the corresponding
# Resource using the MD5 hash.
hashHex = hashFunc.hexdigest(image)

# The content of an Evernote note is represented using Evernote Markup Language
# (ENML). The full ENML specification can be found in the Evernote API Overview
# at http://dev.evernote.com/documentation/cloud/chapters/ENML.php
note.content = <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">
<en-note>Here is the Evernote logo:<br/>
<en-media type="image/png" hash="#{hashHex}"/>
</en-note>
EOF

# Finally, send the new note to Evernote using the createNote method
# The new Note object that is returned will contain server-generated
# attributes such as the new note's unique GUID.
createdNote = note_store.createNote(authToken, note)

puts "Successfully created a new note with GUID: #{createdNote.guid}"
Binary file added sample/client/enlogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading