Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* initial release

  • Loading branch information...
commit 03e3659e10e82bd382a9127c4b4aed8dde91050e 1 parent 0accfca
@rubiojr authored
View
4 Gemfile
@@ -6,8 +6,6 @@ source "http://rubygems.org"
# Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc.
group :development do
- gem "shoulda", ">= 0"
- gem "bundler", "~> 1.0.0"
+ gem "bundler", "~> 1.0.0"
gem "jeweler", "~> 1.5.2"
- gem "rcov", ">= 0"
end
View
4 README.rdoc
@@ -1,8 +1,8 @@
-= evertone
+= everton
Description goes here.
-== Contributing to evertone
+== Contributing to everton
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
View
27 Rakefile
@@ -1,5 +1,6 @@
require 'rubygems'
require 'bundler'
+require 'lib/everton'
begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
@@ -12,16 +13,19 @@ require 'rake'
require 'jeweler'
Jeweler::Tasks.new do |gem|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
- gem.name = "evertone"
- gem.homepage = "http://github.com/rubiojr/evertone"
+ gem.version = Everton::VERSION
+ gem.name = "everton"
+ gem.homepage = "http://github.com/rubiojr/everton"
gem.license = "MIT"
- gem.summary = %Q{TODO: one-line summary of your gem}
- gem.description = %Q{TODO: longer description of your gem}
- gem.email = "sergio@rubio.name"
+ gem.summary = %Q{Thin wrapper around evernote ruby api}
+ gem.description = %Q{Thin wrapper around evernote ruby api}
+ gem.email = "rubiojr@frameos.org"
gem.authors = ["Sergio Rubio"]
# Include your dependencies below. Runtime dependencies are required when using your gem,
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
- # gem.add_runtime_dependency 'jabber4r', '> 0.1'
+ gem.add_runtime_dependency 'thrift_client', '= 0.6.0'
+ gem.add_runtime_dependency 'evernote', '>= 1.0'
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
end
Jeweler::RubygemsDotOrgTasks.new
@@ -33,21 +37,14 @@ Rake::TestTask.new(:test) do |test|
test.verbose = true
end
-require 'rcov/rcovtask'
-Rcov::RcovTask.new do |test|
- test.libs << 'test'
- test.pattern = 'test/**/test_*.rb'
- test.verbose = true
-end
-
-task :default => :test
+task :default => :build
require 'rake/rdoctask'
Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
rdoc.rdoc_dir = 'rdoc'
- rdoc.title = "evertone #{version}"
+ rdoc.title = "everton #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
View
12 examples/add_image.rb
@@ -0,0 +1,12 @@
+config = {
+ :username => 'myuser',
+ :password => 'mypass',
+ :consumer_key => 'key',
+ :consumer_secret => 'secret',
+ :user_store_url => 'http://sandbox.evernote.com/edam/user'
+}
+
+Everton::Remote.authenticate config
+
+# Add image to notebook 'bar'
+Everton::Notebook.find('bar').add_image 'note title', 'note content', '/home/rubiojr/Desktop/guns.jpg'
View
14 examples/add_text.rb
@@ -0,0 +1,14 @@
+require 'lib/everton'
+
+config = {
+ :username => 'myuser',
+ :password => 'mypass',
+ :consumer_key => 'key',
+ :consumer_secret => 'secret',
+ :user_store_url => 'http://sandbox.evernote.com/edam/user'
+}
+
+Everton::Remote.authenticate config
+
+# Add text note to notebook 'bar'
+Everton::Notebook.find('bar').add_note 'note title', 'note text'
View
30 examples/basics.rb
@@ -0,0 +1,30 @@
+require 'lib/everton'
+
+config = {
+ :username => 'myuser',
+ :password => 'mypass',
+ :consumer_key => 'key',
+ :consumer_secret => 'secret',
+ :user_store_url => 'http://sandbox.evernote.com/edam/user'
+}
+
+# Authenticate
+Everton::Remote.authenticate config
+
+
+# Iterate over all the netbooks and print the notebook name
+Everton::Notebook.all.each do |n|
+ puts n.name
+end
+
+# Get the first notebook
+notebook = Everton::Notebook.all.first
+
+# Get the notebook named 'bar'
+bar_notebook = Everton::Notebook.find('bar')
+
+# Add image to notebook 'bar'
+bar_notebook.add_image 'note title', 'note content', '/home/rubiojr/Desktop/guns.jpg'
+
+# Add a text note
+bar_notebook.add_note 'note title', 'anothe note, only text'
View
98 lib/everton.rb
@@ -0,0 +1,98 @@
+require 'rubygems'
+require 'evernote'
+require 'yaml'
+require 'uri'
+
+#
+# Great example fetched Evernote Forum at:
+# http://forum.evernote.com/phpbb/viewtopic.php?f=43&t=27547
+#
+
+module Everton
+ VERSION = '0.1'
+
+ class Remote
+
+ class << self
+ attr_reader :user_store, :note_store, :access_token
+ end
+
+ def self.authenticate config
+ if config.is_a? Hash
+ cfg = config
+ else
+ cfg = YAML.load_file config
+ end
+ @user_store = Evernote::UserStore.new(cfg[:user_store_url], cfg)
+ auth_result = user_store.authenticate
+ @user = auth_result.user
+ @access_token = auth_result.authenticationToken
+ uri = URI.parse cfg[:user_store_url]
+ host = uri.host
+ scheme = uri.scheme
+ @note_store_url = "#{scheme}://#{host}/edam/note/#{@user.shardId}"
+ @note_store = Evernote::NoteStore.new(@note_store_url)
+ end
+ end
+
+ class ::Evernote::EDAM::Type::Notebook
+
+ def add_note(title, text)
+ note = Evernote::EDAM::Type::Note.new()
+ note.title = title
+ note.notebookGuid = self.guid
+ note.content = '<?xml version="1.0" encoding="UTF-8"?>' +
+ '<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd"><en-note>' +
+ text +
+ '</en-note>'
+ Everton::Remote.note_store.createNote(Everton::Remote.access_token, note)
+ end
+
+ def add_image(title, text, filename)
+ image = File.open(filename, "rb") { |io| io.read }
+ hashFunc = Digest::MD5.new
+ hashHex = hashFunc.hexdigest(image)
+
+ data = Evernote::EDAM::Type::Data.new()
+ data.size = image.size
+ data.bodyHash = hashHex
+ 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
+
+ note = Evernote::EDAM::Type::Note.new()
+ note.title = title
+ note.notebookGuid = self.guid
+ note.content = '<?xml version="1.0" encoding="UTF-8"?>' +
+ '<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">' +
+ '<en-note>' + text +
+ '<en-media type="image/png" hash="' + hashHex + '"/>' +
+ '</en-note>'
+ note.resources = [ resource ]
+
+ Everton::Remote.note_store.createNote(Everton::Remote.access_token, note)
+
+ end
+
+ end
+
+ class Notebook
+ def self.all
+ Remote.note_store.listNotebooks(Remote.access_token)
+ end
+
+ def self.find(name)
+ all.each do |n|
+ return n if n.name == name
+ end
+ nil
+ end
+ end
+
+end
+
+
View
0  lib/evertone.rb
No changes.
View
18 test/helper.rb
@@ -1,18 +0,0 @@
-require 'rubygems'
-require 'bundler'
-begin
- Bundler.setup(:default, :development)
-rescue Bundler::BundlerError => e
- $stderr.puts e.message
- $stderr.puts "Run `bundle install` to install missing gems"
- exit e.status_code
-end
-require 'test/unit'
-require 'shoulda'
-
-$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
-$LOAD_PATH.unshift(File.dirname(__FILE__))
-require 'evertone'
-
-class Test::Unit::TestCase
-end
View
7 test/test_evertone.rb
@@ -1,7 +0,0 @@
-require 'helper'
-
-class TestEvertone < Test::Unit::TestCase
- should "probably rename this file and start testing for real" do
- flunk "hey buddy, you should probably rename this file and start testing for real"
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.