everton 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "bundler", "~> 1.0.0"
10
+ gem "jeweler", "~> 1.5.2"
11
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Sergio Rubio
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Everton #
2
+
3
+ Thin wrapper around Evernote ruby client library (https://github.com/cgs/evernote)
4
+
5
+ # Installing #
6
+
7
+ gem install evertone
8
+
9
+ # Usage #
10
+
11
+ require 'rubygems'
12
+ require 'everton'
13
+
14
+ config = {
15
+ :username => 'myuser',
16
+ :password => 'mypass',
17
+ :consumer_key => 'key',
18
+ :consumer_secret => 'secret',
19
+ :user_store_url => 'http://sandbox.evernote.com/edam/user'
20
+ }
21
+
22
+ # Authenticate
23
+ Everton::Remote.authenticate config
24
+
25
+
26
+ # Iterate over all the netbooks and print the notebook name
27
+ Everton::Notebook.all.each do |n|
28
+ puts n.name
29
+ end
30
+
31
+ # Get the first notebook
32
+ notebook = Everton::Notebook.all.first
33
+
34
+ # Get the notebook named 'bar'
35
+ bar_notebook = Everton::Notebook.find('bar')
36
+
37
+ # Add image to notebook 'bar'
38
+ bar_notebook.add_image 'note title', 'note content', '/home/rubiojr/Desktop/guns.jpg'
39
+
40
+ # Add a text note
41
+ bar_notebook.add_note 'note title', 'anothe note, only text'
42
+
43
+
44
+ # Copyright #
45
+
46
+ Copyright (c) 2011 Sergio Rubio. See LICENSE.txt for
47
+ further details.
48
+
data/Rakefile ADDED
@@ -0,0 +1,50 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ require 'lib/everton'
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.puts e.message
8
+ $stderr.puts "Run `bundle install` to install missing gems"
9
+ exit e.status_code
10
+ end
11
+ require 'rake'
12
+
13
+ require 'jeweler'
14
+ Jeweler::Tasks.new do |gem|
15
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
16
+ gem.version = Everton::VERSION
17
+ gem.name = "everton"
18
+ gem.homepage = "http://github.com/rubiojr/everton"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Thin wrapper around evernote ruby api}
21
+ gem.description = %Q{Thin wrapper around evernote ruby api}
22
+ gem.email = "rubiojr@frameos.org"
23
+ gem.authors = ["Sergio Rubio"]
24
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
25
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
26
+ gem.add_runtime_dependency 'thrift_client', '= 0.6.0'
27
+ gem.add_runtime_dependency 'evernote', '>= 1.0'
28
+
29
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
30
+ end
31
+ Jeweler::RubygemsDotOrgTasks.new
32
+
33
+ require 'rake/testtask'
34
+ Rake::TestTask.new(:test) do |test|
35
+ test.libs << 'lib' << 'test'
36
+ test.pattern = 'test/**/test_*.rb'
37
+ test.verbose = true
38
+ end
39
+
40
+ task :default => :build
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
45
+
46
+ rdoc.rdoc_dir = 'rdoc'
47
+ rdoc.title = "everton #{version}"
48
+ rdoc.rdoc_files.include('README*')
49
+ rdoc.rdoc_files.include('lib/**/*.rb')
50
+ end
@@ -0,0 +1,12 @@
1
+ config = {
2
+ :username => 'myuser',
3
+ :password => 'mypass',
4
+ :consumer_key => 'key',
5
+ :consumer_secret => 'secret',
6
+ :user_store_url => 'http://sandbox.evernote.com/edam/user'
7
+ }
8
+
9
+ Everton::Remote.authenticate config
10
+
11
+ # Add image to notebook 'bar'
12
+ Everton::Notebook.find('bar').add_image 'note title', 'note content', '/home/rubiojr/Desktop/guns.jpg'
@@ -0,0 +1,14 @@
1
+ require 'lib/everton'
2
+
3
+ config = {
4
+ :username => 'myuser',
5
+ :password => 'mypass',
6
+ :consumer_key => 'key',
7
+ :consumer_secret => 'secret',
8
+ :user_store_url => 'http://sandbox.evernote.com/edam/user'
9
+ }
10
+
11
+ Everton::Remote.authenticate config
12
+
13
+ # Add text note to notebook 'bar'
14
+ Everton::Notebook.find('bar').add_note 'note title', 'note text'
@@ -0,0 +1,30 @@
1
+ require 'lib/everton'
2
+
3
+ config = {
4
+ :username => 'myuser',
5
+ :password => 'mypass',
6
+ :consumer_key => 'key',
7
+ :consumer_secret => 'secret',
8
+ :user_store_url => 'http://sandbox.evernote.com/edam/user'
9
+ }
10
+
11
+ # Authenticate
12
+ Everton::Remote.authenticate config
13
+
14
+
15
+ # Iterate over all the netbooks and print the notebook name
16
+ Everton::Notebook.all.each do |n|
17
+ puts n.name
18
+ end
19
+
20
+ # Get the first notebook
21
+ notebook = Everton::Notebook.all.first
22
+
23
+ # Get the notebook named 'bar'
24
+ bar_notebook = Everton::Notebook.find('bar')
25
+
26
+ # Add image to notebook 'bar'
27
+ bar_notebook.add_image 'note title', 'note content', '/home/rubiojr/Desktop/guns.jpg'
28
+
29
+ # Add a text note
30
+ bar_notebook.add_note 'note title', 'anothe note, only text'
data/lib/everton.rb ADDED
@@ -0,0 +1,98 @@
1
+ require 'rubygems'
2
+ require 'evernote'
3
+ require 'yaml'
4
+ require 'uri'
5
+
6
+ #
7
+ # Great example fetched Evernote Forum at:
8
+ # http://forum.evernote.com/phpbb/viewtopic.php?f=43&t=27547
9
+ #
10
+
11
+ module Everton
12
+ VERSION = '0.1'
13
+
14
+ class Remote
15
+
16
+ class << self
17
+ attr_reader :user_store, :note_store, :access_token
18
+ end
19
+
20
+ def self.authenticate config
21
+ if config.is_a? Hash
22
+ cfg = config
23
+ else
24
+ cfg = YAML.load_file config
25
+ end
26
+ @user_store = Evernote::UserStore.new(cfg[:user_store_url], cfg)
27
+ auth_result = user_store.authenticate
28
+ @user = auth_result.user
29
+ @access_token = auth_result.authenticationToken
30
+ uri = URI.parse cfg[:user_store_url]
31
+ host = uri.host
32
+ scheme = uri.scheme
33
+ @note_store_url = "#{scheme}://#{host}/edam/note/#{@user.shardId}"
34
+ @note_store = Evernote::NoteStore.new(@note_store_url)
35
+ end
36
+ end
37
+
38
+ class ::Evernote::EDAM::Type::Notebook
39
+
40
+ def add_note(title, text)
41
+ note = Evernote::EDAM::Type::Note.new()
42
+ note.title = title
43
+ note.notebookGuid = self.guid
44
+ note.content = '<?xml version="1.0" encoding="UTF-8"?>' +
45
+ '<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd"><en-note>' +
46
+ text +
47
+ '</en-note>'
48
+ Everton::Remote.note_store.createNote(Everton::Remote.access_token, note)
49
+ end
50
+
51
+ def add_image(title, text, filename)
52
+ image = File.open(filename, "rb") { |io| io.read }
53
+ hashFunc = Digest::MD5.new
54
+ hashHex = hashFunc.hexdigest(image)
55
+
56
+ data = Evernote::EDAM::Type::Data.new()
57
+ data.size = image.size
58
+ data.bodyHash = hashHex
59
+ data.body = image
60
+
61
+ resource = Evernote::EDAM::Type::Resource.new()
62
+ resource.mime = "image/png"
63
+ resource.data = data;
64
+ resource.attributes = Evernote::EDAM::Type::ResourceAttributes.new()
65
+ resource.attributes.fileName = filename
66
+
67
+ note = Evernote::EDAM::Type::Note.new()
68
+ note.title = title
69
+ note.notebookGuid = self.guid
70
+ note.content = '<?xml version="1.0" encoding="UTF-8"?>' +
71
+ '<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">' +
72
+ '<en-note>' + text +
73
+ '<en-media type="image/png" hash="' + hashHex + '"/>' +
74
+ '</en-note>'
75
+ note.resources = [ resource ]
76
+
77
+ Everton::Remote.note_store.createNote(Everton::Remote.access_token, note)
78
+
79
+ end
80
+
81
+ end
82
+
83
+ class Notebook
84
+ def self.all
85
+ Remote.note_store.listNotebooks(Remote.access_token)
86
+ end
87
+
88
+ def self.find(name)
89
+ all.each do |n|
90
+ return n if n.name == name
91
+ end
92
+ nil
93
+ end
94
+ end
95
+
96
+ end
97
+
98
+
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: everton
3
+ version: !ruby/object:Gem::Version
4
+ hash: 9
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ version: "0.1"
10
+ platform: ruby
11
+ authors:
12
+ - Sergio Rubio
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-07-12 00:00:00 Z
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ version_requirements: &id001 !ruby/object:Gem::Requirement
21
+ none: false
22
+ requirements:
23
+ - - ~>
24
+ - !ruby/object:Gem::Version
25
+ hash: 23
26
+ segments:
27
+ - 1
28
+ - 0
29
+ - 0
30
+ version: 1.0.0
31
+ type: :development
32
+ requirement: *id001
33
+ prerelease: false
34
+ name: bundler
35
+ - !ruby/object:Gem::Dependency
36
+ version_requirements: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ hash: 7
42
+ segments:
43
+ - 1
44
+ - 5
45
+ - 2
46
+ version: 1.5.2
47
+ type: :development
48
+ requirement: *id002
49
+ prerelease: false
50
+ name: jeweler
51
+ - !ruby/object:Gem::Dependency
52
+ version_requirements: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - "="
56
+ - !ruby/object:Gem::Version
57
+ hash: 7
58
+ segments:
59
+ - 0
60
+ - 6
61
+ - 0
62
+ version: 0.6.0
63
+ type: :runtime
64
+ requirement: *id003
65
+ prerelease: false
66
+ name: thrift_client
67
+ - !ruby/object:Gem::Dependency
68
+ version_requirements: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 15
74
+ segments:
75
+ - 1
76
+ - 0
77
+ version: "1.0"
78
+ type: :runtime
79
+ requirement: *id004
80
+ prerelease: false
81
+ name: evernote
82
+ description: Thin wrapper around evernote ruby api
83
+ email: rubiojr@frameos.org
84
+ executables: []
85
+
86
+ extensions: []
87
+
88
+ extra_rdoc_files:
89
+ - LICENSE.txt
90
+ - README.md
91
+ files:
92
+ - .document
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - examples/add_image.rb
98
+ - examples/add_text.rb
99
+ - examples/basics.rb
100
+ - lib/everton.rb
101
+ homepage: http://github.com/rubiojr/everton
102
+ licenses:
103
+ - MIT
104
+ post_install_message:
105
+ rdoc_options: []
106
+
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ hash: 3
124
+ segments:
125
+ - 0
126
+ version: "0"
127
+ requirements: []
128
+
129
+ rubyforge_project:
130
+ rubygems_version: 1.8.5
131
+ signing_key:
132
+ specification_version: 3
133
+ summary: Thin wrapper around evernote ruby api
134
+ test_files:
135
+ - examples/add_image.rb
136
+ - examples/add_text.rb
137
+ - examples/basics.rb