evertils-common 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 42326ec018f0701d23ba49e474118d000ef4491a
4
- data.tar.gz: ecdca53983daa495dddbc27680bf44735d7983c5
3
+ metadata.gz: c4cc17e04641ec490aa5de9a35b33aa7502f9684
4
+ data.tar.gz: 9032cdf13af63676c409263ad33403effef91a7a
5
5
  SHA512:
6
- metadata.gz: 0d3dde52024e517d0f7cc9c2af2b1a19dc4543fad82dbb73925775d463da2e0e159e1481fb5074fc434067c7243d4118415473aa1fcfbdf17d07644ae3f553a1
7
- data.tar.gz: 662cc08ffd1538b57093d5bf95fdbb31c96d4936a33e32fc2da7db8944b10d8cc07b6d9143161b61511846d3fad9734484df95be79045d2dd9cd8b6dd00b1541
6
+ metadata.gz: e3c1737b5d15fb1adbd7fb840f0cea9e5b6af624574ca71f8961c83905e888e93d19cf24cd205216160395f2c8bfa730c4febcfcf96dc003781dd798a5e005e8
7
+ data.tar.gz: c6f8021ea4040a8f0d399a0dad57c3431a970e781218dde5662fbb98d14e4317a9c97a50eec52c612630379fb138ce9b13b5979739bbdef729d7f97261ce7fbf
@@ -0,0 +1,34 @@
1
+ module Evertils
2
+ module Common
3
+ class ENML
4
+ attr_reader :element, :embeddable_element
5
+
6
+ def initialize(file = nil)
7
+ @file = file
8
+ @element = enml_element
9
+
10
+ if !@element.nil?
11
+ @embeddable_element = "<hr/>Attachment with hash #{@element.data.bodyHash}<br /><en-media type=\"#{@element.mime}\" hash=\"#{@element.data.bodyHash}\" /><br /><br />"
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def enml_element
18
+ if @file
19
+ read_file = File.open(@file, 'rb') { |io| io.read }
20
+
21
+ el = ::Evernote::EDAM::Type::Resource.new()
22
+ el.mime = MIME::Types.type_for(@file)[0].content_type
23
+ el.data = ::Evernote::EDAM::Type::Data.new()
24
+ el.data.size = read_file.size
25
+ el.data.bodyHash = Digest::MD5.hexdigest(read_file)
26
+ el.data.body = read_file
27
+ el.attributes = ::Evernote::EDAM::Type::ResourceAttributes.new()
28
+ el.attributes.fileName = @file # temporary for now, the actual file name
29
+ el
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,4 +1,6 @@
1
+ require 'yaml'
1
2
  require 'evertils/common/authentication'
3
+ require 'evertils/common/enml'
2
4
 
3
5
  module Evertils
4
6
  module Common
@@ -15,7 +17,7 @@ module Evertils
15
17
  @evernote.store.listTags(Evertils::Common::EVERNOTE_DEVELOPER_TOKEN)
16
18
  end
17
19
 
18
- def notebook_by_name(name = command)
20
+ def notebook_by_name(name)
19
21
  output = {}
20
22
  notebooks.each do |notebook|
21
23
  if notebook.name == name.to_s.capitalize
@@ -70,6 +72,56 @@ module Evertils
70
72
  output
71
73
  end
72
74
 
75
+ def create_stack_from(full_path)
76
+ if File.exists? full_path
77
+ conf = YAML::load(File.open(full_path))
78
+ required = %w(name children)
79
+
80
+ if has_required_fields(conf, required)
81
+ if !conf["children"].nil?
82
+ conf["children"].each do |name|
83
+ create_notebook(name, conf["name"])
84
+ end
85
+ end
86
+ else
87
+ raise ArgumentError, 'Configuration file is missing some required fields'
88
+ end
89
+ else
90
+ raise ArgumentError, "File not found: #{full_path}"
91
+ end
92
+ end
93
+
94
+ def create_note_from(full_path)
95
+ if File.exists? full_path
96
+ conf = YAML::load(File.open(full_path))
97
+ required = %w(title body)
98
+
99
+ if has_required_fields(conf, required)
100
+ create_note(conf['title'], conf['body'], conf['parent'])
101
+ else
102
+ raise ArgumentError, 'Configuration file is missing some required fields'
103
+ end
104
+ else
105
+ raise ArgumentError, "File not found: #{full_path}"
106
+ end
107
+ end
108
+
109
+ def create_stack(name)
110
+ create_notebook(name)
111
+ end
112
+
113
+ def create_notebook(name, stack = nil)
114
+ notebook = ::Evernote::EDAM::Type::Notebook.new
115
+ notebook.name = name
116
+
117
+ if !stack.nil?
118
+ notebook.stack = stack
119
+ notebook.name = "#{stack}/#{name}"
120
+ end
121
+
122
+ @evernote.store.createNotebook(Evertils::Common::EVERNOTE_DEVELOPER_TOKEN, notebook)
123
+ end
124
+
73
125
  def find_note(title_filter = nil, notebook_filter = nil)
74
126
  filter = ::Evernote::EDAM::NoteStore::NoteFilter.new
75
127
  filter.words = "intitle:#{title_filter}" if title_filter
@@ -106,7 +158,7 @@ module Evertils
106
158
  results.should_eval_to(false)
107
159
  end
108
160
 
109
- def create_note(title = command.capitalize, body = template_contents, p_notebook_name = nil, file = nil, share_note = false, created_on = nil)
161
+ def create_note(title, body = template_contents, p_notebook_name = nil, file = nil, share_note = false, created_on = nil)
110
162
  # final output
111
163
  output = {}
112
164
 
@@ -122,7 +174,7 @@ module Evertils
122
174
 
123
175
  # a file was requested, lets prepare it for storage
124
176
  if !file.nil?
125
- media_resource = EvernoteENML.new(file)
177
+ media_resource = ENML.new(file)
126
178
  body.concat(media_resource.embeddable_element)
127
179
  our_note.resources << media_resource.element
128
180
  end
@@ -136,11 +188,7 @@ module Evertils
136
188
  our_note.content = n_body
137
189
  our_note.created = created_on if !created_on.nil?
138
190
 
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
191
+ parent_notebook = notebook_by_name(p_notebook_name)
144
192
 
145
193
  ## parent_notebook is optional; if omitted, default notebook is used
146
194
  if parent_notebook.is_a? ::Evernote::EDAM::Type::Notebook
@@ -175,6 +223,14 @@ module Evertils
175
223
 
176
224
  output
177
225
  end
226
+
227
+ private
228
+
229
+ def has_required_fields(hash, required)
230
+ hash.keys.each do |key|
231
+ required.include? key
232
+ end
233
+ end
178
234
  end
179
235
  end
180
236
  end
@@ -1,5 +1,5 @@
1
1
  module Evertils
2
2
  module Common
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -1,4 +1,5 @@
1
1
  require 'evernote-thrift'
2
+ require 'notifaction'
2
3
  require 'evertils/common/version'
3
4
  require 'evertils/common/evernote'
4
5
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evertils-common
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Priebe
@@ -85,6 +85,7 @@ files:
85
85
  - evertils-common.gemspec
86
86
  - lib/evertils/common.rb
87
87
  - lib/evertils/common/authentication.rb
88
+ - lib/evertils/common/enml.rb
88
89
  - lib/evertils/common/evernote.rb
89
90
  - lib/evertils/common/version.rb
90
91
  homepage: http://rubygems.org/gems/evertils-common