evernote_utils 0.0.4 → 0.0.9

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: 49f1ce1d6ba7eb482686b02c7fbab61a5b69544a
4
- data.tar.gz: 1a5aab22da6f5dc08498269656cd305e7be44663
3
+ metadata.gz: f356220e4344d4dbc251b94ded74db09f122c0e2
4
+ data.tar.gz: 6c49ec6ecb152ada1d78da0719f28f2fb0f36248
5
5
  SHA512:
6
- metadata.gz: 80ff2b4f18fd00b09fb64c69c53e1bb21654b5417a93aa00b2e9321eb05ccd6354f6b028aa552683ca7725e5c5bb575f978be600e14f0d307c880ac81d822932
7
- data.tar.gz: 68097bc431430a63bd807c6867055498be45f51cc13f05ee5e009cbc67aca396364fbcda5e66857234d327e6077ca2a36b6d9d0dc4f32912cd22c889a7a880ed
6
+ metadata.gz: f195ccea97cf381c923d6ded9419a78f5e2d5a006702b913aee906d533a0b688cc3310f1b72ac5ec6d9f369c881d224c21686718f1fc3df5a236651ab8d7ae25
7
+ data.tar.gz: b10c826989e81e22822aa0569832774344788153560b8fa1a34cb78cc500c67ec74612b3edc9bcb495f7693bcc65ff9c96c5dbdeb0fad730c39c461756f0f7b5
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ coverage
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.2
data/README.md CHANGED
@@ -1,3 +1,6 @@
1
+ [![Build Status](https://travis-ci.org/memerelics/evernote_utils.svg?branch=master)](https://travis-ci.org/memerelics/evernote_utils)
2
+ [![Coverage Status](https://coveralls.io/repos/memerelics/evernote_utils/badge.png?branch=master)](https://coveralls.io/r/memerelics/evernote_utils?branch=master)
3
+
1
4
  # EvernoteUtils
2
5
 
3
6
  A thin OOP-friendly wrapper of Evernote Ruby SDK.
@@ -35,6 +38,8 @@ EvenoteUtils don't support authentication feature, because dominant other option
35
38
 
36
39
  ## Usage
37
40
 
41
+ ### get
42
+
38
43
  First, initialize ENUtils with an OAuth token credential identifier.
39
44
 
40
45
  ```ruby
@@ -112,6 +117,24 @@ tag = enutils.tags(name: 'language').first
112
117
  enutils.notes(notebook: notebook, tag: tag, words: 'beginners\' guide')
113
118
  ```
114
119
 
120
+
121
+ ### update
122
+
123
+ ```ruby
124
+ notebook = enutils.notebook('Inbox')
125
+ tags = enutils.tags.take(2)
126
+
127
+ # set ENUtils::Notebook instance or notebookGuid
128
+ note.notebook = notebook
129
+ # set ENUtils::Tag instances or tagGuids
130
+ note.tags = tags
131
+
132
+ note.title = 'some new title'
133
+
134
+ note.save #=> save to Evernote Cloud
135
+ ````
136
+
115
137
  ## Planning to do
116
138
 
117
- * update notes
139
+ * create note
140
+ * `ENutils::Note#content` simple access
data/Rakefile CHANGED
@@ -1,44 +1,3 @@
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
9
-
10
- # CSV.open('output.csv', 'w') do |w|
11
- # CSV.open('words.csv', 'r') do |r|
12
- # reader.each do |row|
13
- # # extract plain text from ENUtils::Note#content, which is an ENML document.
14
- # w << [row[0], row[1], Nokogiri::XML(row[2]).elements.first.text.gsub(/^\n|\n$/,')]
15
- # end
16
- # end
17
- # end
18
-
19
- ###################################################
20
- require 'rubygems'
21
- require 'bundler/setup'
22
- Bundler.require
23
- require 'pry'
24
- require 'evernote_utils'
25
-
26
- e = ENUtils::Core.new("xxxxxxxxxxx")
27
-
28
- binding.pry
29
-
30
- # notebook_archive = e.notebooks(name: 'Archive').first
31
- # tag_english = e.tags(name: 'english').first
32
- # results = []
33
- # results << e.notes(notebook: notebook_archive, tag: tag_english, limit: 50, offset: 0)
34
- # results << e.notes(notebook: notebook_archive, tag: tag_english, limit: 50, offset: 50)
35
- # results << e.notes(notebook: notebook_archive, tag: tag_english, limit: 50, offset: 100)
36
- # results.flatten!
37
- # results.each{|n| n.set_content! }
38
- #
39
- # require 'csv'
40
- # CSV.open('hoge.csv', 'w') do |csv|
41
- # results.each do |n|
42
- # csv << [n.created, n.title, n.content]
43
- # end
44
- # end
1
+ require 'rspec/core/rake_task'
2
+ RSpec::Core::RakeTask.new(:spec)
3
+ task default: :spec
@@ -19,13 +19,15 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency 'evernote-thrift', '~>1.25.1'
22
- spec.add_dependency 'activesupport', '~>3.2.13'
22
+ spec.add_dependency 'activesupport'
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.3"
25
25
  spec.add_development_dependency "rake"
26
26
  spec.add_development_dependency "pry"
27
27
  spec.add_development_dependency "rspec", "~>3.0.0.beta"
28
+ spec.add_development_dependency "factory_girl", "~> 4.0"
28
29
  spec.add_development_dependency "rb-readline"
29
30
  spec.add_development_dependency "guard-rspec"
30
31
  spec.add_development_dependency "mocha"
32
+ spec.add_development_dependency "coveralls"
31
33
  end
@@ -35,7 +35,17 @@ module ENUtils
35
35
  end
36
36
 
37
37
  def notes(options={})
38
- Note.where(self, options)
38
+ Note.where(self, options.reverse_merge(order: :updated))
39
+ end
40
+
41
+ def find_note(guid, with_content: false,
42
+ with_resources_data: false,
43
+ with_resources_recognition: false,
44
+ with_resources_alternate_data: false)
45
+ self.notestore.getNote(self.token, guid, with_content,
46
+ with_resources_data,
47
+ with_resources_recognition,
48
+ with_resources_alternate_data)
39
49
  end
40
50
 
41
51
  def notebook(name=nil)
@@ -1,8 +1,8 @@
1
1
  require 'active_support/core_ext/object'
2
- require "evernote_utils/notelist"
2
+ require 'evernote_utils/notelist'
3
3
 
4
4
  module ENUtils
5
- class Note < Evernote::EDAM::Type::Note
5
+ class Note
6
6
 
7
7
  DEFAULT_LIMIT = 10
8
8
 
@@ -18,24 +18,13 @@ module ENUtils
18
18
  # notebookGuid:"4xxxxxda-xxxx-xxxx-xxxx-zzzzzzzzzzzz"
19
19
  # attributes:<Evernote::EDAM::Type::NoteAttributes >
20
20
 
21
- attr_reader :guid, :title, :contentHash, :contentLength, :created, :updated, :active, :updateSequenceNum, :notebookGuid, :tagGuids, :attributes
22
- attr_accessor :content
21
+ attr_reader :edam_note
23
22
 
24
- def initialize(core, edam_note)
25
- @core = core
26
-
27
- @guid = edam_note.guid
28
- @title = edam_note.title
29
- @contentHash = edam_note.contentHash
30
- @contentLength = edam_note.contentLength
31
- @created = Time.at(edam_note.created/1000)
32
- @updated = Time.at(edam_note.updated/1000)
33
- @active = edam_note.active
34
- @updateSequenceNum = edam_note.updateSequenceNum
35
- @notebookGuid = edam_note.notebookGuid
36
- @tagGuids = edam_note.tagGuids
37
- @attributes = edam_note.attributes
38
- end
23
+ delegate :guid, :title, :contentHash, :contentLength, :deleted,
24
+ :active, :updateSequenceNum, :notebookGuid, :tagGuids, :resources, :attributes, :tagNames,
25
+ :active=, :contentLength=, :deleted=, :notebookGuid=, :tagGuids=, :title=, :updated=,
26
+ :attributes=, :contentHash=, :created=, :guid=, :resources=, :tagNames=, :updateSequenceNum=,
27
+ :to => :edam_note
39
28
 
40
29
  def self.where(core, options={})
41
30
  offset = options.delete(:offset) || 0
@@ -44,18 +33,63 @@ module ENUtils
44
33
  NoteList.new(core, result, options)
45
34
  end
46
35
 
47
- def set_content!
48
- # getNote(token, guid, withContent, withResourcesData, withResourcesRecognition, withResourcesAlternateData)
49
- @content ||= @core.notestore.getNote(@core.token, guid, true, false, false, false).content
36
+ def initialize(core, edam_note)
37
+ @core = core
38
+ @edam_note = edam_note
39
+ end
40
+
41
+ def inspect
42
+ "<#{self.class} @edam_note=#{@edam_note.inspect}>"
43
+ end
44
+
45
+ # not delegated methods
46
+ def created; Time.at(@edam_note.created/1000); end
47
+ def updated; Time.at(@edam_note.updated/1000); end
48
+
49
+ def content
50
+ @content ||= remote_content
51
+ end
52
+
53
+ def content=(val)
54
+ @content = @edam_note.content = val
50
55
  end
51
56
 
52
57
  def notebook
53
58
  @notebook ||= Notebook.find_by_guid(@core, notebookGuid)
54
59
  end
55
60
 
61
+ def notebook=(val)
62
+ case val
63
+ when ENUtils::Notebook
64
+ self.notebookGuid = val.guid
65
+ when String
66
+ self.notebookGuid = val
67
+ end
68
+ end
69
+
56
70
  def tags
57
71
  return nil unless tagGuids
58
72
  @tags ||= tagGuids.map{|guid| Tag.find_by_guid(@core, guid) }.compact
59
73
  end
74
+
75
+ def tags=(val)
76
+ return false unless val.is_a? Array
77
+ if val.all?{|v| v.is_a? ENUtils::Tag }
78
+ self.tagGuids = val.map(&:guid)
79
+ elsif val.all?{|v| v.is_a? String }
80
+ self.tagGuids = val
81
+ end
82
+ end
83
+
84
+ def save
85
+ @edam_note.updated = Time.now.to_i * 1000
86
+ @core.notestore.updateNote(@core.token, @edam_note)
87
+ true
88
+ end
89
+
90
+ private
91
+ def remote_content
92
+ @core.find_note(guid, with_content: true).content
93
+ end
60
94
  end
61
95
  end
@@ -1,3 +1,3 @@
1
1
  module ENUtils
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -1,8 +1,70 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ENUtils::Note do
4
+ let(:edam) { build(:edam_note) }
5
+ let(:core) { build(:core) }
6
+ let(:note) { ENUtils::Note.new(core, edam) }
7
+
4
8
  before do
9
+ allow_any_instance_of(Evernote::EDAM::UserStore::UserStore::Client)
10
+ .to receive(:getNoteStoreUrl).and_return('notestoreurl')
11
+ note
12
+ end
13
+
14
+ it { expect(edam).to be_instance_of Evernote::EDAM::Type::Note }
15
+ it { expect(note.title).to be_instance_of String }
16
+
17
+ describe '.where' do
18
+ before do
19
+ allow(core).to receive_message_chain(:notestore, :findNotes, :notes, :map)
20
+ .and_return(result)
21
+ end
22
+ let(:result) { [] }
23
+ it { expect(ENUtils::Note.where(core)).to be_instance_of ENUtils::NoteList }
24
+ end
25
+
26
+ describe '#inspect' do
27
+ it { expect(note.inspect).to match('@edam_note=') }
28
+ end
29
+
30
+ describe '#created, #updated' do
31
+ it { expect(note.created).to be_instance_of Time }
32
+ it { expect(note.updated).to be_instance_of Time }
5
33
  end
6
- describe 'could change parent notebook' do
34
+
35
+ describe '#notebook=' do
36
+ before do
37
+ note.notebook = val
38
+ end
39
+ [FactoryGirl.build(:notebook, guid: 'updated_guid'), 'updated_guid'].each do |val|
40
+ context { let(:val) { val }
41
+ it { expect(note.notebookGuid).to eq 'updated_guid' } }
42
+ end
43
+ end
44
+
45
+ describe '#tags=' do
46
+ before do
47
+ note.tags = [val]
48
+ end
49
+ [FactoryGirl.build(:tag, guid: 'updated_guid'), 'updated_guid'].each do |val|
50
+ context { let(:val) { val }
51
+ it { expect(note.tagGuids).to eq ['updated_guid'] } }
52
+ end
53
+ end
54
+
55
+ describe '#tags' do
56
+ before do
57
+ allow(note).to receive(:tagGuids).and_return(['weiwei'])
58
+ allow(note).to receive_message_chain(:tagGuids, :map, :compact)
59
+ .and_return([build(:tag)])
60
+ end
61
+ it { expect(note.tags.first).to be_instance_of ENUtils::Tag }
62
+ end
63
+
64
+ describe '#save' do
65
+ before do
66
+ allow(core).to receive_message_chain(:notestore, :updateNote).and_return(true)
67
+ end
68
+ it { expect(note.save).to eq true }
7
69
  end
8
70
  end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe ENUtils::Notebook do
4
+ let(:edam) { build(:edam_notebook) }
5
+ let(:core) { build(:core) }
6
+ let(:notebook) { ENUtils::Notebook.new(core, edam) }
7
+
8
+ before do
9
+ allow_any_instance_of(Evernote::EDAM::UserStore::UserStore::Client)
10
+ .to receive(:getNoteStoreUrl).and_return('notestoreurl')
11
+ notebook
12
+ end
13
+
14
+ it { expect(edam).to be_instance_of Evernote::EDAM::Type::Notebook }
15
+ it { expect(notebook.name).to be_instance_of String }
16
+
17
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe ENUtils::Tag do
4
+ let(:edam) { build(:edam_tag) }
5
+ let(:core) { build(:core) }
6
+ let(:tag) { ENUtils::Tag.new(core, edam) }
7
+
8
+ before do
9
+ allow_any_instance_of(Evernote::EDAM::UserStore::UserStore::Client)
10
+ .to receive(:getNoteStoreUrl).and_return('notestoreurl')
11
+ tag
12
+ end
13
+
14
+ it { expect(edam).to be_instance_of Evernote::EDAM::Type::Tag }
15
+ it { expect(tag.name).to be_instance_of String }
16
+
17
+ describe '#notes' do
18
+ before do
19
+ allow(core).to receive_message_chain(:notestore, :findNotes, :notes, :map)
20
+ .and_return([])
21
+ end
22
+ it { expect(tag.notes).to be_instance_of ENUtils::NoteList }
23
+ end
24
+
25
+ describe '.find_by_guid' do
26
+ before do
27
+ allow(core).to receive_message_chain(:notestore, :listTags, :find)
28
+ .and_return(build(:edam_tag))
29
+ end
30
+ it { expect(ENUtils::Tag.find_by_guid(core, 'guidddd')).to be_instance_of ENUtils::Tag }
31
+ end
32
+
33
+ describe '.find_by_name' do
34
+ before do
35
+ allow(core).to receive_message_chain(:notestore, :listTags)
36
+ .and_return([build(:edam_tag, name: 'book')])
37
+ end
38
+ it { expect(ENUtils::Tag.find_by_name(core, 'book')).to be_instance_of ENUtils::Tag }
39
+ end
40
+
41
+ describe '.where' do
42
+ before do
43
+ allow(core).to receive_message_chain(:notestore, :listTags)
44
+ .and_return([build(:edam_tag, name: 'book')])
45
+ end
46
+ subject { ENUtils::Tag.where(core, options) }
47
+ [/oo/, 'book'].each do |name|
48
+ let(:options) { {name: name} }
49
+ it { expect(subject).to be_instance_of Array }
50
+ it { expect(subject.first).to be_instance_of ENUtils::Tag }
51
+ end
52
+ end
53
+
54
+ end
data/spec/factories.rb ADDED
@@ -0,0 +1,53 @@
1
+ FactoryGirl.define do
2
+
3
+ factory :core, class: ENUtils::Core do
4
+ token 'hogehoge'
5
+ notestore 'hoge'
6
+ initialize_with { new(token, false) }
7
+ end
8
+
9
+ factory :notestore, class: Evernote::EDAM::NoteStore::NoteStore::Client do
10
+ end
11
+
12
+ factory :edam_note, class: Evernote::EDAM::Type::Note do
13
+ guid 'f1df2a4d-5852-4cb6-82f7-6240ee4e2b5c'
14
+ title 'title'
15
+ content nil
16
+ contentHash 'eeeeeeee6bxxxxxxxxxxxxxxxa889ca7'
17
+ contentLength 2246
18
+ created 1266881336000
19
+ updated 1266881347000
20
+ active true
21
+ updateSequenceNum 2653
22
+ notebookGuid '4xxxxxda-xxxx-xxxx-xxxx-zzzzzzzzzzzz'
23
+ attributes nil
24
+ end
25
+
26
+ factory :edam_notebook, class: Evernote::EDAM::Type::Notebook do
27
+ guid 'afa4ba59-xxxx-42ed-xxxx-zzzzzzzzzzzz'
28
+ name 'Books'
29
+ updateSequenceNum 24108
30
+ defaultNotebook false
31
+ serviceCreated 1297607548000
32
+ serviceUpdated 1387262389000
33
+ restrictions nil
34
+ end
35
+
36
+ factory :notebook, class: ENUtils::Notebook do
37
+ core 'core'
38
+ edam_notebook { build(:edam_notebook) }
39
+ initialize_with { new(core, edam_notebook) }
40
+ end
41
+
42
+ factory :edam_tag, class: Evernote::EDAM::Type::Tag do
43
+ guid 'aaaaaaaaaaa'
44
+ name 'tagName'
45
+ updateSequenceNum 1234
46
+ end
47
+
48
+ factory :tag, class: ENUtils::Tag do
49
+ core 'core'
50
+ edam_tag { FactoryGirl.build(:edam_tag) }
51
+ initialize_with { new(core, edam_tag) }
52
+ end
53
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,2 +1,13 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
1
4
  require 'rubygems'
2
5
  require 'evernote_utils'
6
+ require 'factory_girl'
7
+
8
+ RSpec.configure do |config|
9
+ config.include FactoryGirl::Syntax::Methods
10
+ end
11
+
12
+ FactoryGirl.definition_file_paths << Pathname.new("../factories.rb")
13
+ FactoryGirl.find_definitions # required
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evernote_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - memerelics
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-13 00:00:00.000000000 Z
11
+ date: 2014-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: evernote-thrift
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 3.2.13
33
+ version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 3.2.13
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 3.0.0.beta
97
+ - !ruby/object:Gem::Dependency
98
+ name: factory_girl
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '4.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '4.0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: rb-readline
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -136,6 +150,20 @@ dependencies:
136
150
  - - ">="
137
151
  - !ruby/object:Gem::Version
138
152
  version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: coveralls
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
139
167
  description: A thin OOP-friendly wrapper of Evernote Ruby SDK.
140
168
  email:
141
169
  - takuya21hashimoto@gmail.com
@@ -143,7 +171,9 @@ executables: []
143
171
  extensions: []
144
172
  extra_rdoc_files: []
145
173
  files:
174
+ - ".coveralls.yml"
146
175
  - ".gitignore"
176
+ - ".travis.yml"
147
177
  - Gemfile
148
178
  - Guardfile
149
179
  - LICENSE.txt
@@ -158,7 +188,10 @@ files:
158
188
  - lib/evernote_utils/tag.rb
159
189
  - lib/evernote_utils/version.rb
160
190
  - spec/evernote_utils/note_spec.rb
191
+ - spec/evernote_utils/notebook_spec.rb
192
+ - spec/evernote_utils/tag_spec.rb
161
193
  - spec/evernote_utils_spec.rb
194
+ - spec/factories.rb
162
195
  - spec/spec_helper.rb
163
196
  homepage: ''
164
197
  licenses:
@@ -186,5 +219,8 @@ specification_version: 4
186
219
  summary: A thin OOP-friendly wrapper of Evernote Ruby SDK.
187
220
  test_files:
188
221
  - spec/evernote_utils/note_spec.rb
222
+ - spec/evernote_utils/notebook_spec.rb
223
+ - spec/evernote_utils/tag_spec.rb
189
224
  - spec/evernote_utils_spec.rb
225
+ - spec/factories.rb
190
226
  - spec/spec_helper.rb