evertils-common 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 42326ec018f0701d23ba49e474118d000ef4491a
4
+ data.tar.gz: ecdca53983daa495dddbc27680bf44735d7983c5
5
+ SHA512:
6
+ metadata.gz: 0d3dde52024e517d0f7cc9c2af2b1a19dc4543fad82dbb73925775d463da2e0e159e1481fb5074fc434067c7243d4118415473aa1fcfbdf17d07644ae3f553a1
7
+ data.tar.gz: 662cc08ffd1538b57093d5bf95fdbb31c96d4936a33e32fc2da7db8944b10d8cc07b6d9143161b61511846d3fad9734484df95be79045d2dd9cd8b6dd00b1541
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in evertils-common.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Ryan Priebe
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # Evertils::Common
2
+
3
+ Evertils::Common is an abstraction library for interacting with the Evernote API.
4
+
5
+ ## Installation
6
+
7
+ ```ruby
8
+ gem 'evertils-common'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install evertils-common
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/aapis/evertils-common.
32
+
33
+
34
+ ## License
35
+
36
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
37
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "evertils/common"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'evertils/common/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "evertils-common"
8
+ spec.version = Evertils::Common::VERSION
9
+ spec.authors = ["Ryan Priebe"]
10
+ spec.email = ["rpriebe@me.com"]
11
+
12
+ spec.summary = %q{EN (heart) CLI}
13
+ spec.description = %q{Evernote utilities for your CLI workflow}
14
+ spec.homepage = "http://rubygems.org/gems/evertils-common"
15
+ spec.license = "MIT"
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "bin"
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.10"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+
24
+ spec.add_runtime_dependency "evernote-thrift"
25
+ spec.add_runtime_dependency "notifaction"
26
+ end
@@ -0,0 +1,48 @@
1
+ module Evertils
2
+ module Common
3
+ class Authentication
4
+ attr_accessor :store, :shardId, :version
5
+
6
+ def initialize
7
+ if Evertils::Common::EVERNOTE_DEVELOPER_TOKEN.nil?
8
+ Notify.error("Evernote developer token is not configured properly!\n$EVERTILS_TOKEN == nil")
9
+ end
10
+
11
+ userStoreUrl = "https://#{Evertils::Common::EVERNOTE_HOST}/edam/user"
12
+
13
+ userStoreTransport = Thrift::HTTPClientTransport.new(userStoreUrl)
14
+ userStoreProtocol = Thrift::BinaryProtocol.new(userStoreTransport)
15
+ @@user = ::Evernote::EDAM::UserStore::UserStore::Client.new(userStoreProtocol)
16
+
17
+ versionOK = @@user.checkVersion("evernote-data",
18
+ ::Evernote::EDAM::UserStore::EDAM_VERSION_MAJOR,
19
+ ::Evernote::EDAM::UserStore::EDAM_VERSION_MINOR)
20
+
21
+ @version = "#{::Evernote::EDAM::UserStore::EDAM_VERSION_MAJOR}.#{::Evernote::EDAM::UserStore::EDAM_VERSION_MINOR}"
22
+ @shardId = user.shardId
23
+
24
+ if !versionOK
25
+ Notify.error("Evernote API requires an update. Latest version is #{@version}")
26
+ end
27
+
28
+ noteStoreUrl = @@user.getNoteStoreUrl(Evertils::Common::EVERNOTE_DEVELOPER_TOKEN)
29
+
30
+ noteStoreTransport = Thrift::HTTPClientTransport.new(noteStoreUrl)
31
+ noteStoreProtocol = Thrift::BinaryProtocol.new(noteStoreTransport)
32
+ @store = ::Evernote::EDAM::NoteStore::NoteStore::Client.new(noteStoreProtocol)
33
+ end
34
+
35
+ def info
36
+ {
37
+ :user => "#{user.name} (#{user.username}) - ID##{user.id}",
38
+ :shard => user.shardId,
39
+ :api_version => @version,
40
+ }
41
+ end
42
+
43
+ def user
44
+ @@user.getUser(Evertils::Common::EVERNOTE_DEVELOPER_TOKEN)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,180 @@
1
+ require 'evertils/common/authentication'
2
+
3
+ module Evertils
4
+ module Common
5
+ class Evernote
6
+ def initialize
7
+ @evernote = Evertils::Common::Authentication.new
8
+ end
9
+
10
+ def notebooks
11
+ @evernote.store.listNotebooks(Evertils::Common::EVERNOTE_DEVELOPER_TOKEN)
12
+ end
13
+
14
+ def tags
15
+ @evernote.store.listTags(Evertils::Common::EVERNOTE_DEVELOPER_TOKEN)
16
+ end
17
+
18
+ def notebook_by_name(name = command)
19
+ output = {}
20
+ notebooks.each do |notebook|
21
+ if notebook.name == name.to_s.capitalize
22
+ output = notebook
23
+ end
24
+ end
25
+
26
+ output
27
+ end
28
+
29
+ def notes_by_notebook(name)
30
+ output = {}
31
+ notebooks.each do |notebook|
32
+ if notebook.name.to_s == name.capitalize.to_s
33
+ filter = ::Evernote::EDAM::NoteStore::NoteFilter.new
34
+ filter.notebookGuid = notebook.guid
35
+
36
+ result = ::Evernote::EDAM::NoteStore::NotesMetadataResultSpec.new
37
+ result.includeTitle = true
38
+ result.includeUpdated = true
39
+ result.includeTagGuids = true
40
+
41
+ #output = @evernote.store.findNotesMetadata(Evertils::Common::EVERNOTE_DEVELOPER_TOKEN, filter, 0, 400, result)
42
+ notes(nil, notebook.guid).notes.each do |note|
43
+ output[note.guid] = @evernote.store.getNoteContent(Evertils::Common::EVERNOTE_DEVELOPER_TOKEN, note.guid)
44
+ end
45
+ end
46
+ end
47
+
48
+ output
49
+ end
50
+
51
+ def notebooks_by_stack(stack)
52
+ output = {}
53
+ notebooks.each do |notebook|
54
+ if notebook.stack == stack
55
+ #output[notebook.name] = []
56
+
57
+ filter = ::Evernote::EDAM::NoteStore::NoteFilter.new
58
+ filter.notebookGuid = notebook.guid
59
+
60
+ result = ::Evernote::EDAM::NoteStore::NotesMetadataResultSpec.new
61
+ result.includeTitle = true
62
+ result.includeUpdated = true
63
+ result.includeTagGuids = true
64
+
65
+ notes = @evernote.store.findNotesMetadata(Evertils::Common::EVERNOTE_DEVELOPER_TOKEN, filter, 0, 400, result)
66
+ output[notebook.name] = notes
67
+ end
68
+ end
69
+
70
+ output
71
+ end
72
+
73
+ def find_note(title_filter = nil, notebook_filter = nil)
74
+ filter = ::Evernote::EDAM::NoteStore::NoteFilter.new
75
+ filter.words = "intitle:#{title_filter}" if title_filter
76
+ filter.notebookGuid = notebook_filter if notebook_filter
77
+
78
+ @evernote.store.findNotes(Evertils::Common::EVERNOTE_DEVELOPER_TOKEN, filter, nil, 1)
79
+ end
80
+
81
+ def notes(title_filter = nil, notebook_filter = nil)
82
+ filter = ::Evernote::EDAM::NoteStore::NoteFilter.new
83
+ filter.words = "intitle:#{title_filter}" if title_filter
84
+ filter.notebookGuid = notebook_filter if notebook_filter
85
+
86
+ @evernote.store.findNotes(Evertils::Common::EVERNOTE_DEVELOPER_TOKEN, filter, nil, 300)
87
+ end
88
+
89
+ def note_exists(requested_date = DateTime.now)
90
+ results = Helper::Results.new
91
+ tmpl = date_templates(requested_date)
92
+ template = tmpl[command]
93
+ note = find_note(template)
94
+
95
+ # Evernote's search matches things like the following, so we have to get
96
+ # more specific
97
+ # Daily Log [July 3 - F] == Daily Log [July 10 - F]
98
+ if note.totalNotes > 0
99
+ note.notes.each do |n|
100
+ results.add(n.title != template)
101
+ end
102
+ else
103
+ results.add(true)
104
+ end
105
+
106
+ results.should_eval_to(false)
107
+ end
108
+
109
+ def create_note(title = command.capitalize, body = template_contents, p_notebook_name = nil, file = nil, share_note = false, created_on = nil)
110
+ # final output
111
+ output = {}
112
+
113
+ # Create note object
114
+ our_note = ::Evernote::EDAM::Type::Note.new
115
+ our_note.resources = []
116
+ our_note.tagNames = []
117
+
118
+ # only join when required
119
+ if body.is_a? Array
120
+ body = body.join
121
+ end
122
+
123
+ # a file was requested, lets prepare it for storage
124
+ if !file.nil?
125
+ media_resource = EvernoteENML.new(file)
126
+ body.concat(media_resource.embeddable_element)
127
+ our_note.resources << media_resource.element
128
+ end
129
+
130
+ n_body = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
131
+ n_body += "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">"
132
+ n_body += "<en-note>#{body}</en-note>"
133
+
134
+ # setup note properties
135
+ our_note.title = title
136
+ our_note.content = n_body
137
+ our_note.created = created_on if !created_on.nil?
138
+
139
+ if p_notebook_name.nil?
140
+ parent_notebook = notebook_by_name
141
+ else
142
+ parent_notebook = notebook_by_name(p_notebook_name)
143
+ end
144
+
145
+ ## parent_notebook is optional; if omitted, default notebook is used
146
+ if parent_notebook.is_a? ::Evernote::EDAM::Type::Notebook
147
+ our_note.notebookGuid = parent_notebook.guid
148
+ end
149
+
150
+ ## Attempt to create note in Evernote account
151
+ begin
152
+ output[:note] = @evernote.store.createNote(Evertils::Common::EVERNOTE_DEVELOPER_TOKEN, our_note)
153
+
154
+ if share_note
155
+ shareKey = @evernote.store.shareNote(Evertils::Common::EVERNOTE_DEVELOPER_TOKEN, output[:note].guid)
156
+ output[:share_url] = "https://#{Evertils::Common::EVERNOTE_HOST}/shard/#{@model.shardId}/sh/#{output[:note].guid}/#{shareKey}"
157
+ end
158
+ rescue ::Evernote::EDAM::Error::EDAMUserException => edue
159
+ ## Something was wrong with the note data
160
+ ## See EDAMErrorCode enumeration for error code explanation
161
+ ## http://dev.evernote.com/documentation/reference/Errors.html#Enum_EDAMErrorCode
162
+ Notify.error "EDAMUserException: #{edue}\nCode #{edue.errorCode}: #{edue.parameter}"
163
+ rescue ::Evernote::EDAM::Error::EDAMNotFoundException => ednfe
164
+ ## Parent Notebook GUID doesn't correspond to an actual notebook
165
+ Notify.error "EDAMNotFoundException: Invalid parent notebook GUID"
166
+ end
167
+
168
+ # A parent notebook object exists, otherwise it was saved to the default
169
+ # notebook
170
+ if parent_notebook.is_a? ::Evernote::EDAM::Type::Notebook
171
+ Notify.success("#{parent_notebook.stack}/#{parent_notebook.name}/#{our_note.title} created")
172
+ else
173
+ Notify.success("DEFAULT_NOTEBOOK/#{our_note.title} created")
174
+ end
175
+
176
+ output
177
+ end
178
+ end
179
+ end
180
+ end
@@ -0,0 +1,5 @@
1
+ module Evertils
2
+ module Common
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ require 'evernote-thrift'
2
+ require 'evertils/common/version'
3
+ require 'evertils/common/evernote'
4
+
5
+ module Evertils
6
+ module Common
7
+ EVERNOTE_HOST = 'www.evernote.com'
8
+ EVERNOTE_DEVELOPER_TOKEN = ENV['EVERTILS_TOKEN']
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: evertils-common
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Priebe
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-15 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: evernote-thrift
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: notifaction
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Evernote utilities for your CLI workflow
70
+ email:
71
+ - rpriebe@me.com
72
+ executables:
73
+ - console
74
+ - setup
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - .gitignore
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - evertils-common.gemspec
86
+ - lib/evertils/common.rb
87
+ - lib/evertils/common/authentication.rb
88
+ - lib/evertils/common/evernote.rb
89
+ - lib/evertils/common/version.rb
90
+ homepage: http://rubygems.org/gems/evertils-common
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.0.14
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: EN (heart) CLI
114
+ test_files: []