Skip to content

Commit

Permalink
Add User-Agent header (see #5), new options for update-notifier, fix …
Browse files Browse the repository at this point in the history
…to download all assignments, upgrade to v0.0.5
  • Loading branch information
szekelymilan committed Apr 8, 2020
1 parent 61d53a8 commit accc546
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 33 deletions.
7 changes: 3 additions & 4 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,10 @@ async function interactive() {
}

(async () => {
let noFlag = true;

updateNotifier({ pkg: utils.pkg }).notify();
updateNotifier({ pkg: utils.pkg, updateCheckInterval: 1000 * 60 * 60 * 3 }).notify({
isGlobal: true,
});

await doTask(cli.input[0]);

process.exit();
})();
62 changes: 52 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "e-kreta-cli",
"version": "0.0.4",
"version": "0.0.5",
"description": "Check your electronic diary - from right inside your terminal.",
"main": "cli.js",
"scripts": {},
Expand All @@ -12,14 +12,14 @@
"author": "Milan Szekely <szekelymilan1125@gmail.com> (https://szekelymilan.eu)",
"license": "MIT",
"dependencies": {
"chalk": "^3.0.0",
"chalk": "^4.0.0",
"configstore": "^5.0.1",
"fuse.js": "^3.6.1",
"fuse.js": "^5.1.0",
"inquirer": "^7.1.0",
"inquirer-autocomplete-prompt": "^1.0.2",
"js-base64": "^2.5.2",
"meow": "^6.1.0",
"mkdirp": "^1.0.3",
"mkdirp": "^1.0.4",
"ora": "^4.0.3",
"request": "^2.88.2",
"request-promise-native": "^1.0.8",
Expand Down
11 changes: 7 additions & 4 deletions src/assignments.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ const fs = require('fs');
const mkdirp = require('mkdirp');
const path = require('path');
const ora = require('ora');
const request = require('request-promise-native');

const utils = require('./utils');
const request = utils.request;

module.exports = async directory => {
const spinner = ora('Downloading...').start();
Expand All @@ -17,9 +17,12 @@ module.exports = async directory => {
mkdirp.sync(directory);

const lessons = JSON.parse(
await request.get(`https://${utils.conf.get('institute')}.e-kreta.hu/mapi/api/v1/Lesson`, {
auth: { bearer: accessToken },
}),
await request.get(
`https://${utils.conf.get('institute')}.e-kreta.hu/mapi/api/v1/Lesson?fromDate=1970-01-01`,
{
auth: { bearer: accessToken },
},
),
);

const wasAssignment = {};
Expand Down
2 changes: 1 addition & 1 deletion src/averages.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { bold, red, green, white, gray } = require('chalk');
const configstore = require('configstore');
const request = require('request-promise-native');

const utils = require('./utils');
const request = utils.request;

module.exports = async () => {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ const fs = require('fs');
const mkdirp = require('mkdirp');
const path = require('path');
const ora = require('ora');
const request = require('request-promise-native');

const utils = require('./utils');
const request = utils.request;

module.exports = async directory => {
const spinner = ora('Downloading...').start();
Expand Down
23 changes: 14 additions & 9 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
const { Base64 } = require('js-base64');
const { bold, red } = require('chalk');
const configstore = require('configstore');
const request = require('request-promise-native');
const request = require('request-promise-native').defaults({
headers: { 'User-Agent': 'Kreta.Ellenorzo/2.9.11.2020033003 (Android; 0.0)' },
});

exports.pkg = require('../package.json');
exports.conf = new configstore(exports.pkg.name);
exports.request = request;

exports.getInstitutes = async () => {
const response = await request.get('https://kretaglobalmobileapi.ekreta.hu/api/v1/Institute', {
headers: { apiKey: '7856d350-1fda-45f5-822d-e1a2f3f1acf0' },
});
return JSON.parse(response);
return JSON.parse(
await request.get('https://kretaglobalmobileapi.ekreta.hu/api/v1/Institute', {
headers: { apiKey: '7856d350-1fda-45f5-822d-e1a2f3f1acf0' },
}),
);
};

async function loginUtil(institute, username, password) {
try {
const response = await request.post(`https://${institute}.e-kreta.hu/idp/api/v1/Token`, {
body: `institute_code=${institute}&userName=${username}&password=${password}&grant_type=password&client_id=919e0c1c-76a2-4646-a2fb-7085bbbf3c56`,
});
return JSON.parse(response);
return JSON.parse(
await request.post(`https://${institute}.e-kreta.hu/idp/api/v1/Token`, {
body: `institute_code=${institute}&userName=${username}&password=${password}&grant_type=password&client_id=919e0c1c-76a2-4646-a2fb-7085bbbf3c56`,
}),
);
} catch (e) {
return e.statusCode || -1;
}
Expand Down

0 comments on commit accc546

Please sign in to comment.