Last active
August 29, 2015 14:14
-
-
Save TrevorBasinger/cb8db0dde836eb6ddee2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var | |
Future = require ('data.future'), | |
Evernote = require ('evernote').Evernote, | |
R = require ('ramda'), | |
M = require ('control.monads'), | |
chain = R.chain, | |
curry = R.curry, | |
compose = R.compose, | |
eq = R.eq, | |
filter = R.filter, | |
flatten = R.flatten, | |
get = R.get, | |
head = R.head, | |
length = R.length, | |
map = R.map, | |
I = function (x) { return x; }, | |
log = console.log, | |
logI = function (x) { log (x); return x; }, | |
logMsg = curry (function (msg, o) { log (msg); log (o); }), | |
handlerDefault = curry (function (reject, resolve, err, data) { | |
if (err) { return reject (err); } | |
return resolve (Array.prototype.slice.call (arguments, 3)); | |
}), | |
future = function (f) { | |
return new Future (function (reject, resolve) { | |
f (handlerDefault (reject, resolve)); | |
}); | |
}, | |
futureA1 = curry (function (f, a) { | |
return new Future (function (reject, resolve) { | |
f (a, handlerDefault (reject, resolve)); | |
}); | |
}), | |
futureA2 = curry (function (f, b, a) { | |
return new Future (function (reject, resolve) { | |
f (a, b, handlerDefault (reject, resolve)); | |
}); | |
}), | |
futureA3 = curry (function (f, c, b, a) { | |
return new Future (function (reject, resolve) { | |
f (a, b, c, handlerDefault (reject, resolve)); | |
}); | |
}), | |
futureA4 = curry (function (f, d, c, b, a) { | |
return new Future (function (reject, resolve) { | |
f (a, b, c, d, handlerDefault (reject, resolve)); | |
}); | |
}), | |
futureA5 = curry (function (f, e, d, c, b, a) { | |
return new Future (function (reject, resolve) { | |
f (a, b, c, d, e, handlerDefault (reject, resolve)); | |
}); | |
}), | |
filterNoteBookByGuid = function (guid) { | |
return filter (compose (eq (guid), get ('guid'))); | |
}, | |
filterNotebookByName = function (name) { | |
return filter (compose (eq (name), get ('name'))); | |
}, | |
createNoteFilterByGuid = function (guid) { | |
return new Evernote.NoteFilter ({ | |
notebookGuid: guid | |
}); | |
}, | |
noteStoreUrl = 'https://sandbox.evernote.com/shard/s1/notestore', | |
developerToken = 'S=s1:U=9017f:E=151d5578947:C=14a7da65b30:P=1cd:A=en-devtoken:V=2:H=4da3bded8054798923949c2d054592c4', | |
ResultSpecAll = new Evernote.NotesMetadataResultSpec ({ | |
includeTitle: true, | |
includeContentLength: true, | |
includeCreated: true, | |
includeUpdated: true, | |
includeDeleted: false, | |
includeUpdateSequenceNum: true, | |
includeNotebookGuid: true, | |
includeTagGuids: true, | |
includeAttributes: true, | |
includeLargestResourceMime: true, | |
includeLargestResourceSize: true | |
}), | |
client = new Evernote.Client ({token: developerToken}), | |
noteStore = client.getNoteStore (noteStoreUrl), | |
fetchNotebooks = future (noteStore.listNotebooks), | |
// fetchNotesByNotebook :: String -> Future [Notes] | |
fetchNotesByNotebook = function (name) { | |
return fetchNotebooks | |
.map (compose (head, filterNotebookByName (name), head)) | |
.map (compose (createNoteFilterByGuid, get ('guid'))) | |
.chain (futureA4 (noteStore.findNotesMetadata, ResultSpecAll, 10, 0)) | |
.map (compose (get ('notes'), head)); | |
}, | |
// getNote :: Guid -> Future Note | |
getNote = futureA5 (noteStore.getNote, true, true, true, true), | |
// getNotesContents :: Note -> Future [Note] | |
getNotesContents = compose (map (chain (flatten)), | |
M.sequence (Future), | |
map (compose (getNote, get ('guid')))), | |
// getNotebookNames :: [Notebook] -> [String] | |
getNotebookNames = map (get ('name')), | |
nil = null; | |
//------------------------------------------------------------------------------ | |
//--------------------------------IMPURE CODE----------------------------------- | |
//------------------------------------------------------------------------------ | |
//fetchNotebooks.fork (log, compose (logI, head)); | |
fetchNotesByNotebook ('Inbox') | |
.chain (getNotesContents) | |
.map (map (get ('title'))) | |
.fork (log, log); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment