-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: lib.js szétdarabolva osztályokra, process.env helyett Config modellt használunk már, új logger.js - részletek: ld. JSDoc
- Loading branch information
Showing
20 changed files
with
830 additions
and
428 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ szamlak/ | |
temp/ | ||
.env | ||
error.log | ||
src/_OLD |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
#!/usr/bin/env node | ||
const SingleInstance = require('single-instance'); | ||
const Logger = require('./src/logger'); | ||
const { start } = require('./src/main'); | ||
const { handleError } = require('./src/err'); | ||
|
||
new SingleInstance('dijnet-bot').lock().then(start).catch(error => { | ||
handleError(error.stack ? error : 'A Díjnet bot már fut, és nem futtatható több példányban.'); | ||
try { | ||
new Logger().error(error.stack ? error : 'A Díjnet bot már fut, és nem futtatható több példányban.'); | ||
} catch (error2) { // in case Logger is also dead | ||
console.log(error2); | ||
} | ||
process.exit(1); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Represents a bill's downloadable file. | ||
*/ | ||
class BillFile { | ||
/** | ||
* @param {string} name Display name | ||
* @param {string} dijnetPath Díjnet path, relative to `DijnetBrowser`'s `baseUrl` | ||
*/ | ||
constructor(name, dijnetPath) { | ||
this.name = name; | ||
this.dijnetPath = dijnetPath; | ||
} | ||
} | ||
|
||
module.exports = BillFile; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Represents bill metadata. | ||
*/ | ||
class Bill { | ||
/** | ||
* @param {Bill} data Bill metadata available on Díjnet | ||
* @param {string} data.rowId Row ID in search results | ||
* @param {string} data.serviceProvider Service provider | ||
* @param {string} data.billIssuerId Bill issuer ID | ||
* @param {string} data.billId Bill ID | ||
* @param {string} data.dateOfIssue Date of issue | ||
* @param {string} data.finalAmount Final amount | ||
* @param {string} data.dueDate Due date | ||
* @param {string} data.payable Payable | ||
* @param {string} data.status Status | ||
*/ | ||
constructor(data) { | ||
data = data || {}; | ||
this.rowId = data.rowId; | ||
this.serviceProvider = data.serviceProvider; | ||
this.billIssuerId = data.billIssuerId; | ||
this.billId = data.billId; | ||
this.dateOfIssue = data.dateOfIssue; | ||
this.finalAmount = data.finalAmount; | ||
this.dueDate = data.dueDate; | ||
this.payable = data.payable; | ||
this.status = data.status; | ||
} | ||
} | ||
|
||
module.exports = Bill; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const got = require('got'); | ||
const { CookieJar } = require('tough-cookie'); | ||
|
||
/** | ||
* Wrapper around `got` HTTP client. Adds a cookie jar and stores the last successful response. | ||
*/ | ||
class Browser { | ||
constructor() { | ||
this.cookieJar = new CookieJar(); | ||
/** @type {got.Response} */ | ||
this.lastNavigationResponse = null; | ||
} | ||
|
||
/** | ||
* Sends a HTTP request to the given URL. | ||
* | ||
* @param {string} url Requested URL | ||
* @param {got.GotJSONOptions} options Request options (method, headers, body, encoding, etc.) | ||
* @returns {got.GotPromise<got.Response>} Response | ||
*/ | ||
async request(url, options) { | ||
return got(url, Object.assign({ cookieJar: this.cookieJar }, options)); | ||
} | ||
|
||
/** | ||
* Sends a GET request to the given URL, then stores the response in `lastNavigationResponse`. | ||
* | ||
* @param {string} url Requested URL | ||
* @param {got.GotJSONOptions} options Request options (headers, encoding, etc.) | ||
* @returns {got.GotPromise<got.Response>} Response | ||
*/ | ||
async navigate(url, options) { | ||
this.lastNavigationResponse = await this.request(url, Object.assign({ method: 'GET' }, options)); | ||
return this.lastNavigationResponse; | ||
} | ||
|
||
/** | ||
* Sends a POST request to the given URL, then stores the response in `lastNavigationResponse`. | ||
* | ||
* @param {string} url Requested URL | ||
* @param {got.GotJSONOptions} options Request options (body, headers, encoding, etc.) | ||
* @returns {got.GotPromise<got.Response>} Response | ||
*/ | ||
async submit(url, options) { | ||
this.lastNavigationResponse = await this.request(url, Object.assign({ method: 'POST' }, options)); | ||
return this.lastNavigationResponse; | ||
} | ||
} | ||
|
||
module.exports = Browser; |
Oops, something went wrong.