Skip to content

Commit

Permalink
Documentation of class methods
Browse files Browse the repository at this point in the history
  • Loading branch information
richfab committed Nov 24, 2023
1 parent 4a372e2 commit 2f00e72
Showing 1 changed file with 55 additions and 6 deletions.
61 changes: 55 additions & 6 deletions gbfs-validator/gbfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ const validatorVersion = process.env.COMMIT_REF
/**
* @typedef {{
* languages: Object,
* file: string,
* url: string,
* required: boolean,
* recommended: boolean,
* exists: boolean,
* file: string,
* hasErrors: boolean
* hasErrors: boolean,
* errors: Object,
* schema: Object,
* version: string
* }} FileValidationResult
*/

Expand All @@ -25,7 +30,7 @@ const validatorVersion = process.env.COMMIT_REF
/**
* This function returns true if the file from a GBFS feed has errors or if the file is required and missing.
* @param {Object} data - The body of a file from a GBFS feed.
* @param {boolean} required - True the file is required.
* @param {boolean} required - True if the file is required.
* @returns {boolean}
*/
function hasErrors(data, required) {
Expand Down Expand Up @@ -228,9 +233,9 @@ function isGBFSFileRequire(version) {
/** Class representing a GBFS feed. */
class GBFS {
/**
*
* @param {string} url - The URL of the gbfs.json file
* @param {Object} param1 - The parameters of the validation
* Creates a GBFS feed.
* @param {string} url - The URL of the gbfs.json file.
* @param {Object} param1 - The parameters of the validation.
*/
constructor(
url,
Expand Down Expand Up @@ -277,6 +282,11 @@ class GBFS {
}
}

/**
* This function returns the FileValidationResult of the gbfs.json file from a generated URL.
* @param {string} url - The URL of the gbfs.json file.
* @returns FileValidationResult
*/
alternativeAutoDiscovery(url) {
return got
.get(url, this.gotOptions)
Expand Down Expand Up @@ -328,6 +338,10 @@ class GBFS {
})
}

/**
* This function returns the FileValidationResult of the gbfs.json file.
* @returns FileValidationResult
*/
checkAutodiscovery() {
return got
.get(this.url, this.gotOptions)
Expand Down Expand Up @@ -380,6 +394,14 @@ class GBFS {
})
}

/**
* This function retrieves the JSON schema and returns the result of the validate function.
* @param {string} version - The version of the GBFS feed.
* @param {string} file - The type of file from a GBFS feed.
* @param {Object} data - The body of a file from a GBFS feed.
* @param {Object} options - An Object that contains an array of JSON Patches.
* @returns {Object}
*/
validateFile(version, file, data, options) {
let schema

Expand All @@ -393,6 +415,12 @@ class GBFS {
return validate(schema, data, options)
}

/**
* This function returns on Object which contains the body of a file from a GBFS feed.
* @param {string} type - The type of file from a GBFS feed.
* @param {boolean} required - True if the file is required.
* @returns {Object}
*/
getFile(type, required) {
if (this.autoDiscovery) {
let urls
Expand Down Expand Up @@ -469,6 +497,15 @@ class GBFS {
}
}

/**
* This function returns the FileValidationResult of a file from a GBFS feed.
* @param {Object} body - The body of a file from a GBFS feed.
* @param {string} version - The version of the GBFS feed.
* @param {string} type - The type of file from a GBFS feed.
* @param {boolean} required - True if the file is required.
* @param {Object} options - An Object that contains an array of JSON Patches.
* @returns FileValidationResult
*/
validationFile(body, version, type, required, options) {
if (Array.isArray(body)) {
body = body
Expand Down Expand Up @@ -498,6 +535,10 @@ class GBFS {
}
}

/**
* This function returns a token to access a GBFS feed.
* @returns {Object}
*/
getToken() {
return got
.post(this.auth.oauthClientCredentialsGrant.tokenUrl, {
Expand All @@ -514,6 +555,10 @@ class GBFS {
})
}

/**
* This function returns an Object that contains all the files from a GBFS feed and the FileValidationResult of the gbfs.json file.
* @returns {Object}
*/
async getFiles() {
if (this.auth && this.auth.type === 'oauth_client_credentials_grant') {
await this.getToken()
Expand Down Expand Up @@ -548,6 +593,10 @@ class GBFS {
}
}

/**
* This function returns an Object that contains the FileValidationResult of all the files from a GBFS feed.
* @returns {Object}
*/
async validation() {
const { gbfsResult, gbfsVersion, files, summary } = await this.getFiles()

Expand Down

0 comments on commit 2f00e72

Please sign in to comment.