6
6
module Ever2boost
7
7
class EvernoteAuthorizer
8
8
EVERNOTE_HOST = "www.evernote.com"
9
- DEFAULT_DIR_PATH = "#{ ENV [ 'HOME' ] } /ever2boost_store"
10
9
11
10
attr_accessor :developer_token , :note_store
12
11
@@ -23,27 +22,37 @@ def initialize(developer_token)
23
22
@note_store = note_store
24
23
end
25
24
26
- def fetch_notes ( number_of_notes )
27
- FileUtils . mkdir_p ( DEFAULT_DIR_PATH ) unless FileTest . exist? ( DEFAULT_DIR_PATH )
25
+ def fetch_notes ( output_dir )
26
+ FileUtils . mkdir_p ( output_dir ) unless FileTest . exist? ( output_dir )
28
27
29
- start_index = 0
30
28
note_store = self . note_store
31
29
notebook_list = note_store . listNotebooks ( self . developer_token )
32
30
notebook_guids = notebook_list . map ( &:guid )
33
31
lists = notebook_list . map { |nl | Ever2boost ::NoteList . new ( title : nl . name , hash : hash , guid : nl . guid ) }
34
- Ever2boost ::JsonGenerator . generate_boostnote_json ( lists )
35
- filter = Evernote ::EDAM ::NoteStore ::NoteFilter . new
36
- filter . notebookGuid = notebook_guids . first
37
- note_list = note_store . findNotes ( self . developer_token , filter , start_index , number_of_notes )
38
- # TODO: note_listのtitleからboostnote.jsonを作成する。
39
- note_guids = note_list . notes . map ( &:guid )
40
- # TODO: assign the booleans
41
- en_notes = note_guids . map { |note_guid | note_store . getNote ( self . developer_token , note_guid , true , true , false , false ) }
42
- notes = en_notes . map { |note | Note . new ( title : note . title , content : note . content , notebook_guid : note . notebookGuid ) }
43
- notes . each do |note |
44
- lists . each do |list |
45
- # TODO: break if note found
46
- CsonGenerator . generate ( list . hash , note ) if list . guid == note . notebook_guid
32
+ Ever2boost ::JsonGenerator . generate_boostnote_json ( lists , output_dir )
33
+
34
+ notebook_guids . each do |notebook_guid |
35
+ filter = Evernote ::EDAM ::NoteStore ::NoteFilter . new
36
+ filter . notebookGuid = notebook_guid
37
+
38
+ spec = Evernote ::EDAM ::NoteStore ::NotesMetadataResultSpec . new ( includeTitle : true , includeNotebookGuid : true )
39
+
40
+ # get latest 250 notes
41
+ note_counts_hash = note_store . findNoteCounts ( self . developer_token , filter , true ) . notebookCounts
42
+ number_of_notes = note_counts_hash . values . last || 0
43
+ # TODO: display message like "ignored first #{(number_of_notes - 250).to_s} notes due to EvernoteAPI access limitation" if number_of_notes > 250
44
+ start_index = number_of_notes > 250 ? number_of_notes - 250 : 0
45
+ note_list = note_store . findNotesMetadata ( self . developer_token , filter , start_index , 15 , spec )
46
+
47
+ note_guids = note_list . notes . map ( &:guid )
48
+ # TODO: assign the booleans
49
+ en_notes = note_guids . map { |note_guid | note_store . getNote ( self . developer_token , note_guid , true , true , false , false ) }
50
+ notes = en_notes . map { |note | Note . new ( title : note . title , content : note . content , notebook_guid : note . notebookGuid ) }
51
+ notes . each do |note |
52
+ lists . each do |list |
53
+ # TODO: break if note found
54
+ CsonGenerator . generate ( list . hash , note , output_dir ) if list . guid == note . notebook_guid
55
+ end
47
56
end
48
57
end
49
58
end
0 commit comments