geeknote 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/command.rb +15 -0
- data/en_oauth.rb +167 -0
- data/evernote_config.rb +15 -0
- data/geeknote.gemspec +23 -0
- data/lib/geeknote.rb +5 -0
- data/lib/geeknote/version.rb +3 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f3fd9b04f895c3e571e012965ba3e0dfd5a53610
|
4
|
+
data.tar.gz: 88011bbe9c9dc7c02a10c687f2070e542f679d2e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9d21d96a139b51dffe3120c8111f89aa58c4dfcccb0a1dcc5c2e84aef2df20e40ef82156f244027cda42578e1b357ecaffbd0f2eb63c6d7bf7fcd05850a0185c
|
7
|
+
data.tar.gz: bce3c204fc4a9d2332aa4dbb6f2b59cdba1d1d6fbf2cb785436ac2c00af61d4092f5a8adb3369f00462044a907b80de978a7f96ad212f66d93671bb2e37215ee
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Ma Lucheng
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Geeknote
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'geeknote'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install geeknote
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/command.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'evernote_oauth'
|
2
|
+
|
3
|
+
auth_token = "S=s1:U=840c1:E=148e577e596:C=1418dc6b999:P=1cd:A=en-devtoken:V=2:H=f597a57e759dfaba5e319931fcad97a2"
|
4
|
+
|
5
|
+
client = EvernoteOAuth::Client.new(token: auth_token)
|
6
|
+
|
7
|
+
note_store = client.note_store
|
8
|
+
|
9
|
+
notebooks = note_store.listNotebooks
|
10
|
+
|
11
|
+
# note = Evernote::EDAM::Type::Note.new
|
12
|
+
# note.title = "hello from Codecademy"
|
13
|
+
# note.content = '<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd"><en-note>Hello Evernote<br/></en-note>'
|
14
|
+
# note_store.createNote(note)
|
15
|
+
p notebooks.map(&:name)
|
data/en_oauth.rb
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
##
|
2
|
+
# Copyright 2012 Evernote Corporation. All rights reserved.
|
3
|
+
##
|
4
|
+
|
5
|
+
require 'sinatra'
|
6
|
+
enable :sessions
|
7
|
+
|
8
|
+
# Load our dependencies and configuration settings
|
9
|
+
$LOAD_PATH.push(File.expand_path(File.dirname(__FILE__)))
|
10
|
+
require "evernote_config.rb"
|
11
|
+
|
12
|
+
##
|
13
|
+
# Verify that you have obtained an Evernote API key
|
14
|
+
##
|
15
|
+
before do
|
16
|
+
if OAUTH_CONSUMER_KEY.empty? || OAUTH_CONSUMER_SECRET.empty?
|
17
|
+
halt '<span style="color:red">Before using this sample code you must edit evernote_config.rb and replace OAUTH_CONSUMER_KEY and OAUTH_CONSUMER_SECRET with the values that you received from Evernote. If you do not have an API key, you can request one from <a href="http://dev.evernote.com/documentation/cloud/">dev.evernote.com/documentation/cloud/</a>.</span>'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
helpers do
|
22
|
+
def auth_token
|
23
|
+
session[:access_token].token if session[:access_token]
|
24
|
+
end
|
25
|
+
|
26
|
+
def client
|
27
|
+
@client ||= EvernoteOAuth::Client.new(token: auth_token, consumer_key:OAUTH_CONSUMER_KEY, consumer_secret:OAUTH_CONSUMER_SECRET, sandbox: SANDBOX)
|
28
|
+
end
|
29
|
+
|
30
|
+
def user_store
|
31
|
+
@user_store ||= client.user_store
|
32
|
+
end
|
33
|
+
|
34
|
+
def note_store
|
35
|
+
@note_store ||= client.note_store
|
36
|
+
end
|
37
|
+
|
38
|
+
def en_user
|
39
|
+
user_store.getUser(auth_token)
|
40
|
+
end
|
41
|
+
|
42
|
+
def notebooks
|
43
|
+
@notebooks ||= note_store.listNotebooks(auth_token)
|
44
|
+
end
|
45
|
+
|
46
|
+
def total_note_count
|
47
|
+
filter = Evernote::EDAM::NoteStore::NoteFilter.new
|
48
|
+
counts = note_store.findNoteCounts(auth_token, filter, false)
|
49
|
+
notebooks.inject(0) do |total_count, notebook|
|
50
|
+
total_count + (counts.notebookCounts[notebook.guid] || 0)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
##
|
56
|
+
# Index page
|
57
|
+
##
|
58
|
+
get '/' do
|
59
|
+
erb :index
|
60
|
+
end
|
61
|
+
|
62
|
+
##
|
63
|
+
# Reset the session
|
64
|
+
##
|
65
|
+
get '/reset' do
|
66
|
+
session.clear
|
67
|
+
redirect '/'
|
68
|
+
end
|
69
|
+
|
70
|
+
##
|
71
|
+
# Obtain temporary credentials
|
72
|
+
##
|
73
|
+
get '/requesttoken' do
|
74
|
+
callback_url = request.url.chomp("requesttoken").concat("callback")
|
75
|
+
begin
|
76
|
+
session[:request_token] = client.request_token(:oauth_callback => callback_url)
|
77
|
+
redirect '/authorize'
|
78
|
+
rescue => e
|
79
|
+
@last_error = "Error obtaining temporary credentials: #{e.message}"
|
80
|
+
erb :error
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
##
|
85
|
+
# Redirect the user to Evernote for authoriation
|
86
|
+
##
|
87
|
+
get '/authorize' do
|
88
|
+
if session[:request_token]
|
89
|
+
redirect session[:request_token].authorize_url
|
90
|
+
else
|
91
|
+
# You shouldn't be invoking this if you don't have a request token
|
92
|
+
@last_error = "Request token not set."
|
93
|
+
erb :error
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
##
|
98
|
+
# Receive callback from the Evernote authorization page
|
99
|
+
##
|
100
|
+
get '/callback' do
|
101
|
+
unless params['oauth_verifier'] || session['request_token']
|
102
|
+
@last_error = "Content owner did not authorize the temporary credentials"
|
103
|
+
halt erb :error
|
104
|
+
end
|
105
|
+
session[:oauth_verifier] = params['oauth_verifier']
|
106
|
+
begin
|
107
|
+
session[:access_token] = session[:request_token].get_access_token(:oauth_verifier => session[:oauth_verifier])
|
108
|
+
redirect '/list'
|
109
|
+
rescue => e
|
110
|
+
@last_error = 'Error extracting access token'
|
111
|
+
erb :error
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
##
|
117
|
+
# Access the user's Evernote account and display account data
|
118
|
+
##
|
119
|
+
get '/list' do
|
120
|
+
begin
|
121
|
+
# Get notebooks
|
122
|
+
session[:notebooks] = notebooks.map(&:name)
|
123
|
+
# Get username
|
124
|
+
session[:username] = en_user.username
|
125
|
+
# Get total note count
|
126
|
+
session[:total_notes] = total_note_count
|
127
|
+
erb :index
|
128
|
+
rescue => e
|
129
|
+
@last_error = "Error listing notebooks: #{e.message}"
|
130
|
+
erb :error
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
__END__
|
136
|
+
|
137
|
+
@@ index
|
138
|
+
<html>
|
139
|
+
<head>
|
140
|
+
<title>Evernote Ruby Example App</title>
|
141
|
+
</head>
|
142
|
+
<body>
|
143
|
+
<a href="/requesttoken">Click here</a> to authenticate this application using OAuth.
|
144
|
+
<% if session[:notebooks] %>
|
145
|
+
<hr />
|
146
|
+
<h3>The current user is <%= session[:username] %> and there are <%= session[:total_notes] %> notes in their account</h3>
|
147
|
+
<br />
|
148
|
+
<h3>Here are the notebooks in this account:</h3>
|
149
|
+
<ul>
|
150
|
+
<% session[:notebooks].each do |notebook| %>
|
151
|
+
<li><%= notebook %></li>
|
152
|
+
<% end %>
|
153
|
+
</ul>
|
154
|
+
<% end %>
|
155
|
+
</body>
|
156
|
+
</html>
|
157
|
+
|
158
|
+
@@ error
|
159
|
+
<html>
|
160
|
+
<head>
|
161
|
+
<title>Evernote Ruby Example App — Error</title>
|
162
|
+
</head>
|
163
|
+
<body>
|
164
|
+
<p>An error occurred: <%= @last_error %></p>
|
165
|
+
<p>Please <a href="/reset">start over</a>.</p>
|
166
|
+
</body>
|
167
|
+
</html>
|
data/evernote_config.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Load libraries required by the Evernote OAuth sample applications
|
2
|
+
require 'oauth'
|
3
|
+
require 'oauth/consumer'
|
4
|
+
|
5
|
+
# Load Thrift & Evernote Ruby libraries
|
6
|
+
require "evernote_oauth"
|
7
|
+
|
8
|
+
# Client credentials
|
9
|
+
# Fill these in with the consumer key and consumer secret that you obtained
|
10
|
+
# from Evernote. If you do not have an Evernote API key, you may request one
|
11
|
+
# from http://dev.evernote.com/documentation/cloud/
|
12
|
+
OAUTH_CONSUMER_KEY = "mlc880926"
|
13
|
+
OAUTH_CONSUMER_SECRET = "6340835b50ea8641"
|
14
|
+
|
15
|
+
SANDBOX = true
|
data/geeknote.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'geeknote/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "geeknote"
|
8
|
+
spec.version = Geeknote::VERSION
|
9
|
+
spec.authors = ["Ma Lucheng"]
|
10
|
+
spec.email = ["mlc880926@gmail.com"]
|
11
|
+
spec.description = %q{geeknote ruby clone}
|
12
|
+
spec.summary = %q{geeknote ruby clone}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
data/lib/geeknote.rb
ADDED
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: geeknote
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ma Lucheng
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: geeknote ruby clone
|
42
|
+
email:
|
43
|
+
- mlc880926@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- command.rb
|
54
|
+
- en_oauth.rb
|
55
|
+
- evernote_config.rb
|
56
|
+
- geeknote.gemspec
|
57
|
+
- lib/geeknote.rb
|
58
|
+
- lib/geeknote/version.rb
|
59
|
+
homepage: ''
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.1.5
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: geeknote ruby clone
|
83
|
+
test_files: []
|