summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/configure.js2
-rw-r--r--lib/courseware.js2
-rw-r--r--lib/initialize.js2
-rw-r--r--lib/login.js49
-rw-r--r--lib/options.js2
-rw-r--r--lib/prompts.js2
-rw-r--r--lib/validate.js2
-rw-r--r--lib/videos.js2
8 files changed, 39 insertions, 24 deletions
diff --git a/lib/configure.js b/lib/configure.js
index c83f2f3..35c5855 100644
--- a/lib/configure.js
+++ b/lib/configure.js
@@ -1,7 +1,7 @@
/*
* mongo-edu
*
- * Copyright (c) 2014-2015 Przemyslaw Pluta
+ * Copyright (c) 2014-2016 Przemyslaw Pluta
* Licensed under the MIT license.
* https://github.com/przemyslawpluta/mongo-edu/blob/master/LICENSE
*/
diff --git a/lib/courseware.js b/lib/courseware.js
index 47d9b41..b2da4f2 100644
--- a/lib/courseware.js
+++ b/lib/courseware.js
@@ -1,7 +1,7 @@
/*
* mongo-edu
*
- * Copyright (c) 2014-2015 Przemyslaw Pluta
+ * Copyright (c) 2014-2016 Przemyslaw Pluta
* Licensed under the MIT license.
* https://github.com/przemyslawpluta/mongo-edu/blob/master/LICENSE
*/
diff --git a/lib/initialize.js b/lib/initialize.js
index 619210b..195423a 100644
--- a/lib/initialize.js
+++ b/lib/initialize.js
@@ -1,7 +1,7 @@
/*
* mongo-edu
*
- * Copyright (c) 2014-2015 Przemyslaw Pluta
+ * Copyright (c) 2014-2016 Przemyslaw Pluta
* Licensed under the MIT license.
* https://github.com/przemyslawpluta/mongo-edu/blob/master/LICENSE
*/
diff --git a/lib/login.js b/lib/login.js
index d99f7ea..ddbbfc4 100644
--- a/lib/login.js
+++ b/lib/login.js
@@ -1,7 +1,7 @@
/*
* mongo-edu
*
- * Copyright (c) 2014-2015 Przemyslaw Pluta
+ * Copyright (c) 2014-2016 Przemyslaw Pluta
* Licensed under the MIT license.
* https://github.com/przemyslawpluta/mongo-edu/blob/master/LICENSE
*/
@@ -12,6 +12,8 @@ var request = require('request'),
_ = require('lodash'),
videoHandler = require('./videos'),
PrettyError = require('pretty-error'),
+ prompts = require('./prompts'),
+ inquirer = require('inquirer'),
coursewareHandler = require('./courseware');
var jar = request.jar(), host = 'https://university.mongodb.com',
@@ -31,7 +33,7 @@ module.exports = {
'use strict';
var url = host,
- bar = new ProgressBar('>'.magenta + ' Searching [:bar] :percent', { complete: '=', incomplete: ' ', width: 20, total: 7 }),
+ bar = new ProgressBar('>'.magenta + ' Searching [:bar] :percent', { complete: '=', incomplete: ' ', width: 20, total: 6 }),
CSRFTokenCookie = '',
login = function login(token) {
@@ -94,6 +96,32 @@ module.exports = {
},
+ courseSection = function courseSection() {
+ var list = prompts.list;
+ list[0].message = 'Select Courses:';
+ list[0].choices = [{name: 'Current', value: 'tab-current'}, {name: 'Completed', value: 'tab-completed'}];
+ return list;
+ },
+
+ processSelection = function processSelection(body, answers, currentProfile, callback) {
+
+ var list = [], $ = cheerio.load(body),
+ current = $('#' + answers.url),
+ link = current.find('div.section-course').children().find('h4').children(),
+ noCourses = current.find('section.section-courses-empty').text(),
+ findNewCourses = current.find('div.section-courses-empty-buttons a').attr('href');
+
+ $(link).each(function each(i, item) {
+ list.push({ name: $(item).text(), value: url + $(item).attr('href').replace(/about|info|syllabus/g, '') + ((!argv.h) ? (argv.cw || argv.cwd) ? 'courseware' : 'course_wiki' : 'syllabus') });
+ });
+
+ if (noCourses) { currentProfile.noCourses = noCourses.trim().split('\n').map(function items(item) {
+ return item.replace(/ +/g, ' ');
+ }).join('').replace(/ +/g, ' ') + ' at ' + url + findNewCourses + '.\n'; }
+
+ return callback(null, list, currentProfile);
+ },
+
checkCourses = function checkCourses(bar, currentProfile) {
bar.tick();
@@ -105,25 +133,12 @@ module.exports = {
if (res.statusCode === 200) {
- var list = [], $ = cheerio.load(body),
- current = $('#tab-current'),
- link = current.find('div.section-course').children().find('h4').children(),
- noCourses = current.find('section.section-courses-empty').text(),
- findNewCourses = current.find('div.section-courses-empty-buttons a').attr('href');
-
bar.tick();
- $(link).each(function each(i, item) {
- list.push({ name: $(item).text(), value: url + $(item).attr('href').replace(/about|info|syllabus/g, '') + ((!argv.h) ? (argv.cw || argv.cwd) ? 'courseware' : 'course_wiki' : 'syllabus') });
+ return inquirer.prompt(courseSection(), function prompt(answers) {
+ processSelection(body, answers, currentProfile, callback);
});
- bar.tick();
-
- if (noCourses) { currentProfile.noCourses = noCourses.trim().split('\n').map(function items(item) {
- return item.replace(/ +/g, ' ');
- }).join('').replace(/ +/g, ' ') + ' at ' + url + findNewCourses + '.\n'; }
-
- return callback(null, list, currentProfile);
}
callback(pe.render(new Error(res.statusCode)));
diff --git a/lib/options.js b/lib/options.js
index 273d7d9..11ae37a 100644
--- a/lib/options.js
+++ b/lib/options.js
@@ -1,7 +1,7 @@
/*
* mongo-edu
*
- * Copyright (c) 2014-2015 Przemyslaw Pluta
+ * Copyright (c) 2014-2016 Przemyslaw Pluta
* Licensed under the MIT license.
* https://github.com/przemyslawpluta/mongo-edu/blob/master/LICENSE
*/
diff --git a/lib/prompts.js b/lib/prompts.js
index e29716d..ac2aa7a 100644
--- a/lib/prompts.js
+++ b/lib/prompts.js
@@ -1,7 +1,7 @@
/*
* mongo-edu
*
- * Copyright (c) 2014-2015 Przemyslaw Pluta
+ * Copyright (c) 2014-2016 Przemyslaw Pluta
* Licensed under the MIT license.
* https://github.com/przemyslawpluta/mongo-edu/blob/master/LICENSE
*/
diff --git a/lib/validate.js b/lib/validate.js
index 4b561d4..2e5ea61 100644
--- a/lib/validate.js
+++ b/lib/validate.js
@@ -1,7 +1,7 @@
/*
* mongo-edu
*
- * Copyright (c) 2014-2015 Przemyslaw Pluta
+ * Copyright (c) 2014-2016 Przemyslaw Pluta
* Licensed under the MIT license.
* https://github.com/przemyslawpluta/mongo-edu/blob/master/LICENSE
*/
diff --git a/lib/videos.js b/lib/videos.js
index 2431a53..b7480fe 100644
--- a/lib/videos.js
+++ b/lib/videos.js
@@ -1,7 +1,7 @@
/*
* mongo-edu
*
- * Copyright (c) 2014-2015 Przemyslaw Pluta
+ * Copyright (c) 2014-2016 Przemyslaw Pluta
* Licensed under the MIT license.
* https://github.com/przemyslawpluta/mongo-edu/blob/master/LICENSE
*/