evernote_utils 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d685d866c342871313bfa2097b429070eb85cf19
4
+ data.tar.gz: b9409c88a0a1be45349cf917325748accd29b3bf
5
+ SHA512:
6
+ metadata.gz: d31b657e16fb0d7813c8b6bca8ec57409d45959280d94de99f0db7620157fe108d320fca00873352d8b77bfff08804239f059393b53e48ba530b187b6c1c3b00
7
+ data.tar.gz: 864fcfe1cedf797ac4cc7ba59e669aa42f5978dac084cdc4101918f83a119c388472e55ac8a7517d3349945a0933e0b4d3d87014bcc47533a5805f08931cd0ac
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in evernote_utils.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 memerelics
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,92 @@
1
+ # EvernoteUtils
2
+
3
+ A thin OOP-friendly wrapper of Evernote Ruby SDK.
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'evernote_utils'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install evernote_utils
19
+
20
+
21
+ ## Requirement
22
+
23
+ If you don't have your Evernote API Key yet, get it from [Evernote Developers Page](http://dev.evernote.com/doc/).
24
+
25
+ Note that you should send "Activation Request" to access productionn data. Please check [Frequently Ask Questions - Evernote Developers](http://dev.evernote.com/support/faq.php#activatekey).
26
+
27
+ Then authenticate user's Evernote account via OAuth. Instruction is here: [Getting Started with the Evernote API - Evernote Developers](http://dev.evernote.com/doc/start/ruby.php)
28
+
29
+
30
+ EvenoteUtils don't support authentication feature, because dominant other options are available. For instance:
31
+
32
+ * [evernote_oauth](https://github.com/fourfour/evernote_oauth)
33
+ * [omniauth-evernote](https://github.com/szimek/omniauth-evernote)
34
+
35
+
36
+ ## Usage
37
+
38
+ First, initialize ENUtils with an OAuth token credential identifier.
39
+
40
+ enutils = ENUtils::Core.new('oauth-token-credential-identifier')
41
+
42
+ # If you use sandbox token, pass 2nd argument false.
43
+ enutils = ENUtils::Core.new('oauth-token-credential-identifier', false)
44
+
45
+ OAuth token credential identifier looks something like:
46
+
47
+ S=s4:U=a1:E=12bfd68c6b6:C=12bf8426ab8:P=7:A=en_oauth_test:H=3df9cf6c0d7bc410824c80231e64dbe1
48
+
49
+ Then you can access Evernote resources.
50
+
51
+ enutils.notes(words: 'Clojure', limit: 5, order: :updated)
52
+
53
+ It returns `ENUtils::Note` instances. `ENUtils::Note` is a thin wrapper of `Evernote::EDAM::Type::Tag`.
54
+
55
+ And here, `ENUtils#notes` accepts following options:
56
+
57
+ * notebook
58
+ * tag, tags
59
+ * words (fulltext search api)
60
+ * order (`:created, :updated, :relevance, :update_sequence_number, :title`)
61
+ * asc (true/false)
62
+ * offset (default is 0)
63
+ * limit (default is 10)
64
+
65
+ `ENUtils#notebooks` and `ENUtils#tags` accept name filtering. You can use String or Regexp.
66
+
67
+ enutils.notebooks(name: 'Twitter')
68
+ enutils.tags(name: /ruby/i)
69
+
70
+ These methods return array of `ENUtils::Notebook` and `ENUtils::Tag` respectively, which available to filter notes.
71
+
72
+ notebook = enutils.notebooks(name: /Book/).first
73
+ tag = enutils.tags(name: 'language').first
74
+ enutils.notes(notebook: notebook, tag: tag)
75
+
76
+ # or, you can use multiple tags
77
+ enutils.notes(notebook: notebook, tags: [tagA, tagB, tagC])
78
+
79
+
80
+ ## Planning to do
81
+
82
+ * relationships: notebook.notes, note.tags, tag.notes
83
+ * counting result notes
84
+
85
+
86
+ ## Contributing
87
+
88
+ 1. Fork it
89
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
90
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
91
+ 4. Push to the branch (`git push origin my-new-feature`)
92
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs.push 'spec'
6
+ t.pattern = 'spec/**/*_spec.rb'
7
+ t.verbose = true
8
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'evernote_utils/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "evernote_utils"
8
+ spec.version = ENUtils::VERSION
9
+ spec.authors = ["memerelics"]
10
+ spec.email = ["takuya21hashimoto@gmail.com"]
11
+ spec.description = %q{simple wrapper for evernote api}
12
+ spec.summary = %q{simple wrapper for evernote api}
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_dependency 'evernote-thrift', '~>1.25.1'
22
+ spec.add_dependency 'activesupport', '~>4.0.2'
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "pry"
27
+ spec.add_development_dependency "minitest"
28
+ spec.add_development_dependency "mocha"
29
+ end
@@ -0,0 +1,47 @@
1
+ require "evernote_utils/version"
2
+
3
+ require 'evernote-thrift'
4
+ require "evernote_utils/note"
5
+ require "evernote_utils/notebook"
6
+ require "evernote_utils/tag"
7
+
8
+ module ENUtils
9
+ class InvalidVersion < StandardError; end
10
+
11
+ class Core
12
+ attr_accessor :token, :notestore
13
+
14
+ def initialize(token, production=true)
15
+
16
+ userStoreUrl = "https://#{production ? 'www' : 'sandbox'}.evernote.com/edam/user"
17
+ userStoreTransport = Thrift::HTTPClientTransport.new(userStoreUrl)
18
+ userStoreProtocol = Thrift::BinaryProtocol.new(userStoreTransport)
19
+ userStore = Evernote::EDAM::UserStore::UserStore::Client.new(userStoreProtocol)
20
+
21
+ versionOK = userStore.checkVersion("Evernote EDAMTest (Ruby)",
22
+ Evernote::EDAM::UserStore::EDAM_VERSION_MAJOR,
23
+ Evernote::EDAM::UserStore::EDAM_VERSION_MINOR)
24
+ raise InvalidVersion unless versionOK
25
+
26
+ noteStoreUrl = userStore.getNoteStoreUrl(token)
27
+
28
+ noteStoreTransport = Thrift::HTTPClientTransport.new(noteStoreUrl)
29
+ noteStoreProtocol = Thrift::BinaryProtocol.new(noteStoreTransport)
30
+ @notestore = Evernote::EDAM::NoteStore::NoteStore::Client.new(noteStoreProtocol)
31
+
32
+ @token = token
33
+ end
34
+
35
+ def notes(options={})
36
+ Note.where(self, options)
37
+ end
38
+
39
+ def notebooks(options={})
40
+ Notebook.where(self, options)
41
+ end
42
+
43
+ def tags(options={})
44
+ Tag.where(self, options)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,71 @@
1
+ require 'active_support/core_ext/object'
2
+
3
+ module ENUtils
4
+ class Note < Evernote::EDAM::Type::Note
5
+
6
+ DEFAULT_LIMIT = 10
7
+
8
+ # Evernote::EDAM::Type::Note fields
9
+ # guid:"f1df2a4d-5852-4cb6-82f7-6240ee4e2b5c"
10
+ # title:"Note title"
11
+ # contentHash:eeeeeeee6bxxxxxxxxxxxxxxxa889ca7
12
+ # contentLength:2246
13
+ # created:1266881336000
14
+ # updated:1266881347000
15
+ # active:true
16
+ # updateSequenceNum:2653
17
+ # notebookGuid:"4xxxxxda-xxxx-xxxx-xxxx-zzzzzzzzzzzz"
18
+ # attributes:<Evernote::EDAM::Type::NoteAttributes >
19
+
20
+ attr_reader :guid, :title, :contentHash, :contentLength, :created, :updated, :active, :updateSequenceNum, :notebookGuid, :attributes
21
+
22
+ # created: 1, updated: 2, relevance: 3, update_sequence_number: 4, title: 5
23
+ OrderFields = Evernote::EDAM::Type::NoteSortOrder::VALUE_MAP.reduce({}){|accum, pair|
24
+ accum.merge(pair.last.downcase.to_sym => pair.first)
25
+ }
26
+
27
+ def initialize(edam_note)
28
+ @guid = edam_note.guid
29
+ @title = edam_note.title
30
+ @contentHash = edam_note.contentHash
31
+ @contentLength = edam_note.contentLength
32
+ @created = Time.at(edam_note.created/1000)
33
+ @updated = Time.at(edam_note.updated/1000)
34
+ @active = edam_note.active
35
+ @updateSequenceNum = edam_note.updateSequenceNum
36
+ @notebookGuid = edam_note.notebookGuid
37
+ @attributes = edam_note.attributes
38
+ end
39
+
40
+ def self.where(core, options={})
41
+ offset = options.delete(:offset) || 0
42
+ limit = options.delete(:limit) || DEFAULT_LIMIT
43
+ core.notestore.findNotes(core.token, build_filter(options), offset, limit)
44
+ .notes.map{|n| new(n) }
45
+ end
46
+
47
+ private
48
+
49
+ def self.build_filter(options={})
50
+ filter = Evernote::EDAM::NoteStore::NoteFilter.new
51
+ if (notebook = options[:notebook])
52
+ notebook_guid = notebook.is_a?(ENUtils::Notebook) ? notebook.guid : notebook
53
+ filter.notebookGuid = notebook_guid
54
+ end
55
+ if (tags = options[:tags]) || (tag = options[:tag])
56
+ tag_guids = (tags || [tag]).map{|t| t.is_a?(ENUtils::Tag) ? t.guid : t }
57
+ filter.tagGuids = tag_guids
58
+ end
59
+ filter.words = options[:words] if options[:words]
60
+ filter.order = OrderFields[options[:order].to_sym] if available_order?(options[:order])
61
+ filter.ascending = options[:asc] if options[:asc]
62
+ filter
63
+ end
64
+
65
+ def self.available_order?(value)
66
+ return false if value.nil?
67
+ OrderFields.keys.include?(value.to_sym)
68
+ end
69
+
70
+ end
71
+ end
@@ -0,0 +1,39 @@
1
+ module ENUtils
2
+ class Notebook < Evernote::EDAM::Type::Notebook
3
+
4
+ # Evernote::EDAM::Type::Notebook fields
5
+ # guid:"afa4ba59-xxxx-42ed-xxxx-zzzzzzzzzzzz"
6
+ # name:"Books"
7
+ # updateSequenceNum:24108
8
+ # defaultNotebook:false
9
+ # serviceCreated:1297607548000
10
+ # serviceUpdated:1387262389000
11
+ # restrictions:<Evernote::EDAM::Type::NotebookRestrictions ...>
12
+
13
+ attr_reader :guid, :name, :updateSequenceNum, :defaultNotebook, :serviceCreated, :serviceUpdated, :restrictions
14
+
15
+ def initialize(edam_notebook)
16
+ @guid = edam_notebook.guid
17
+ @name = edam_notebook.name
18
+ @updateSequenceNum = edam_notebook.updateSequenceNum
19
+ @defaultNotebook = edam_notebook.defaultNotebook
20
+ @serviceCreated = Time.at(edam_notebook.serviceCreated/1000)
21
+ @serviceUpdated = Time.at(edam_notebook.serviceUpdated/1000)
22
+ @restrictions = edam_notebook.restrictions
23
+ end
24
+
25
+ def self.where(core, options={})
26
+ notebooks = core.notestore.listNotebooks(core.token).map{|nb| new(nb) }
27
+ return notebooks if options.empty?
28
+ case options[:name]
29
+ when String
30
+ notebooks.select{|nb| options[:name] == nb.name }
31
+ when Regexp
32
+ notebooks.select{|nb| options[:name] =~ nb.name }
33
+ else
34
+ notebooks
35
+ end
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,30 @@
1
+ module ENUtils
2
+ class Tag < Evernote::EDAM::Type::Tag
3
+
4
+ # Evernote::EDAM::Type::Tag fields
5
+ # guid:"xxxxxxxx-xxxx-xxxx-xxxx-zzzzzzzzzzzz",
6
+ # name:"MyTag",
7
+ # updateSequenceNum:4378
8
+ attr_reader :guid, :name, :updateSequenceNum
9
+
10
+ def initialize(edam_tag)
11
+ @guid = edam_tag.guid
12
+ @name = edam_tag.name
13
+ @updateSequenceNum = edam_tag.updateSequenceNum
14
+ end
15
+
16
+ def self.where(core, options={})
17
+ tags = core.notestore.listTags(core.token).map{|t| new(t) }
18
+ return tags if options.empty?
19
+ case options[:name]
20
+ when String
21
+ tags.select{|t| options[:name] == t.name }
22
+ when Regexp
23
+ tags.select{|t| options[:name] =~ t.name }
24
+ else
25
+ tags
26
+ end
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module ENUtils
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe EvernoteUtils::Core do
4
+ before do
5
+ Thrift::HTTPClientTransport.stubs(new: nil)
6
+ Thrift::BinaryProtocol.stubs(new: nil)
7
+
8
+ us = mock('Evernote::EDAM::UserStore::UserStore::Client')
9
+ Evernote::EDAM::UserStore::UserStore::Client.stubs(new: us)
10
+ us.stubs(checkVersion: true,
11
+ getNoteStoreUrl: 'http://note_store_url/')
12
+ end
13
+ it {
14
+ EvernoteUtils::Core.new('dummy_token').must_be_instance_of EvernoteUtils::Core
15
+ }
16
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ require 'minitest/spec'
3
+ require 'minitest/autorun'
4
+ require 'mocha/setup'
5
+
6
+ require 'evernote_utils'
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: evernote_utils
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - memerelics
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: evernote-thrift
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 1.25.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 1.25.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 4.0.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 4.0.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: mocha
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: simple wrapper for evernote api
112
+ email:
113
+ - takuya21hashimoto@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - Gemfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - evernote_utils.gemspec
124
+ - lib/evernote_utils.rb
125
+ - lib/evernote_utils/note.rb
126
+ - lib/evernote_utils/notebook.rb
127
+ - lib/evernote_utils/tag.rb
128
+ - lib/evernote_utils/version.rb
129
+ - spec/evernote_utils_spec.rb
130
+ - spec/spec_helper.rb
131
+ homepage: ''
132
+ licenses:
133
+ - MIT
134
+ metadata: {}
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - '>='
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 2.0.14
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: simple wrapper for evernote api
155
+ test_files:
156
+ - spec/evernote_utils_spec.rb
157
+ - spec/spec_helper.rb