From 820783e793d8fee771536a6a79671209353c172b Mon Sep 17 00:00:00 2001 From: Mihai Blaga Date: Tue, 10 Dec 2019 23:39:23 +0100 Subject: [PATCH] added force for vehicle.getStatus and caching, added documentation for vehicle --- README.md | 2 ++ docs/CNAME | 1 - docs/content/readme.html | 1 + docs/js/docma-web.js | 2 +- src/helpers/vehicle.js | 53 +++++++++++++++++++++++++++++++++++++--- 5 files changed, 53 insertions(+), 6 deletions(-) delete mode 100644 docs/CNAME diff --git a/README.md b/README.md index 1356d4e5..09e8770f 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,6 @@ JavaScript implementation of the BMW's ConnectedDrive API +Example: [BMWStatus](https://github.com/mihaiblaga89/bmw-status-app) + @todo write documentation diff --git a/docs/CNAME b/docs/CNAME deleted file mode 100644 index f04a716b..00000000 --- a/docs/CNAME +++ /dev/null @@ -1 +0,0 @@ -bmwapi.mihaiblaga.dev \ No newline at end of file diff --git a/docs/content/readme.html b/docs/content/readme.html index 274220a7..42d21b8d 100644 --- a/docs/content/readme.html +++ b/docs/content/readme.html @@ -5,5 +5,6 @@ Actions Status CodeFactor

JavaScript implementation of the BMW's ConnectedDrive API

+

Example: BMWStatus

@todo write documentation

\ No newline at end of file diff --git a/docs/js/docma-web.js b/docs/js/docma-web.js index 3c8e30f6..b441a00f 100644 --- a/docs/js/docma-web.js +++ b/docs/js/docma-web.js @@ -44,6 +44,6 @@ dust.filters=dust.filters||{},dust.filters.$pt=function(e){return DocmaWeb.Utils DocmaWeb.version = "3.2.2"; return DocmaWeb; })(); -var docma = Object.freeze(new DocmaWeb({"version":"3.2.2","routes":[{"id":"api:","type":"api","name":"_def_","path":"?api","contentPath":null,"sourceType":"js"},{"id":"content:readme","type":"content","name":"readme","path":"?content=readme","contentPath":"content/readme.html","sourceType":"md"}],"apis":{"_def_":{"documentation":[{"comment":"","meta":{"range":[448,503],"filename":"index.js","lineno":16,"columnno":4,"path":"/Users/lego/work/personal/bmw-connecteddrive-api/src/api","code":{"id":"astnode100000059","name":"API","type":"MethodDefinition","paramnames":[]},"vars":{"":null}},"undocumented":true,"name":"API","longname":"API","kind":"class","scope":"global","params":[],"$longname":"API","$kind":"constructor","$docmaLink":"?api#API"},{"comment":"/**\n *\n * * Initialization params\n * @typedef {Object} APIInitObject\n * @property {('eu'|'us'|'cn')} region - Region where you have created the ConnectedDrive account\n * @property {string} username - The username (user@example.com)\n * @property {string} password - The password\n * @property {Boolean} [debug=false] - If you want debugging messages shown\n * @property {Boolean} [skipVehicles=false] - If you want to skip the initial request of vehicles and do it manually with API.getVehicles()\n *\n * * Initializes the API\n *\n * @param {APIInitObject}\n * @memberof API\n */","meta":{"filename":"index.js","lineno":20,"columnno":4,"path":"/Users/lego/work/personal/bmw-connecteddrive-api/src/api","code":{}},"description":"* Initialization params","kind":"typedef","name":"APIInitObject","type":{"names":["Object"]},"properties":[{"type":{"names":["Boolean"]},"optional":true,"defaultvalue":false,"description":"If you want debugging messages shown","name":"debug"},{"type":{"names":["string"]},"description":"The password","name":"password"},{"type":{"names":["'eu'","'us'","'cn'"]},"description":"Region where you have created the ConnectedDrive account","name":"region"},{"type":{"names":["Boolean"]},"optional":true,"defaultvalue":false,"description":"If you want to skip the initial request of vehicles and do it manually with API.getVehicles()\n\n* Initializes the API","name":"skipVehicles"},{"type":{"names":["string"]},"description":"The username (user@example.com)","name":"username"}],"params":[{"type":{"names":["APIInitObject"]}}],"memberof":"API","scope":"static","longname":"API.APIInitObject","$longname":"API.APIInitObject","$kind":"typedef","$docmaLink":"?api#API.APIInitObject"},{"comment":"/**\n * Gets your currently stored vehicles\n *\n * @memberof API\n */","meta":{"range":[5070,5216],"filename":"index.js","lineno":153,"columnno":4,"path":"/Users/lego/work/personal/bmw-connecteddrive-api/src/api","code":{"id":"astnode100000512","name":"API#currentVehicles","type":"MethodDefinition","paramnames":[]},"vars":{"":null}},"description":"Gets your currently stored vehicles","memberof":"API","name":"currentVehicles","longname":"API#currentVehicles","kind":"member","scope":"instance","params":[],"$longname":"API#currentVehicles","$kind":"property","$docmaLink":"?api#API#currentVehicles"},{"comment":"/**\n * Gets the auth token from BMW API\n *\n * @memberof API\n */","meta":{"range":[3334,4468],"filename":"index.js","lineno":101,"columnno":4,"path":"/Users/lego/work/personal/bmw-connecteddrive-api/src/api","code":{"id":"astnode100000329","name":"API#getToken","type":"MethodDefinition","paramnames":[]},"vars":{"":null}},"description":"Gets the auth token from BMW API","memberof":"API","name":"getToken","longname":"API#getToken","kind":"function","scope":"instance","params":[],"async":true,"$longname":"API#getToken","$kind":"method","$docmaLink":"?api#API#getToken"},{"comment":"/**\n * Gets or refreshes your vehicles from BMW API and stores them\n *\n * @memberof API\n */","meta":{"range":[4586,4977],"filename":"index.js","lineno":136,"columnno":4,"path":"/Users/lego/work/personal/bmw-connecteddrive-api/src/api","code":{"id":"astnode100000454","name":"API#getVehicles","type":"MethodDefinition","paramnames":[]},"vars":{"":null}},"description":"Gets or refreshes your vehicles from BMW API and stores them","memberof":"API","name":"getVehicles","longname":"API#getVehicles","kind":"function","scope":"instance","params":[],"async":true,"$longname":"API#getVehicles","$kind":"method","$docmaLink":"?api#API#getVehicles"},{"comment":"/**\n * Make a generic request to BMW API\n *\n * @param {String} url\n * @returns {Promise}\n * @memberof API\n */","meta":{"range":[2167,3244],"filename":"index.js","lineno":70,"columnno":4,"path":"/Users/lego/work/personal/bmw-connecteddrive-api/src/api","code":{"id":"astnode100000191","name":"API#requestWithAuth","type":"MethodDefinition","paramnames":["url",""]},"vars":{"":null}},"description":"Make a generic request to BMW API","params":[{"type":{"names":["String"]},"name":"url"}],"returns":[{"type":{"names":["Promise"]}}],"memberof":"API","name":"requestWithAuth","longname":"API#requestWithAuth","kind":"function","scope":"instance","async":true,"$longname":"API#requestWithAuth","$kind":"method","$docmaLink":"?api#API#requestWithAuth"},{"comment":"/**\n * Handles all URLs required by BMW API\n *\n * @class BMWURLs\n */","meta":{"filename":"urls.js","lineno":7,"columnno":0,"path":"/Users/lego/work/personal/bmw-connecteddrive-api/src/helpers","code":{}},"description":"Handles all URLs required by BMW API","kind":"class","name":"BMWURLs","longname":"BMWURLs","scope":"global","$longname":"BMWURLs","$kind":"class","$docmaLink":"?api#BMWURLs","$constructor":{"comment":"/**\n *Creates an instance of BMWURLs.\n * @param {*} region\n * @memberof BMWURLs\n */","meta":{"range":[407,501],"filename":"urls.js","lineno":18,"columnno":4,"path":"/Users/lego/work/personal/bmw-connecteddrive-api/src/helpers","code":{"id":"astnode100000641","name":"BMWURLs","type":"MethodDefinition","paramnames":["region"]},"vars":{"":null}},"description":"Creates an instance of BMWURLs.","params":[{"type":{"names":["*"]},"name":"region"}],"memberof":"BMWURLs","name":"BMWURLs","longname":"BMWURLs.BMWURLs","kind":"class","scope":"static","$longname":"BMWURLs","$kind":"constructor","$docmaLink":"?api#BMWURLs"}},{"comment":"/**\n * Logger class for...logging purposes\n *\n * @class Logger\n */","meta":{"filename":"logger.js","lineno":1,"columnno":0,"path":"/Users/lego/work/personal/bmw-connecteddrive-api/src/helpers","code":{}},"description":"Logger class for...logging purposes","kind":"class","name":"Logger","longname":"Logger","scope":"global","$longname":"Logger","$kind":"class","$docmaLink":"?api#Logger","$members":[{"comment":"/**\n * Initializes the logger\n *\n * @param {Boolean} debug\n * @memberof Logger\n */","meta":{"range":[193,240],"filename":"logger.js","lineno":13,"columnno":4,"path":"/Users/lego/work/personal/bmw-connecteddrive-api/src/helpers","code":{"id":"astnode100000581","name":"Logger#init","type":"MethodDefinition","paramnames":["debug"]},"vars":{"":null}},"description":"Initializes the logger","params":[{"type":{"names":["Boolean"]},"name":"debug"}],"memberof":"Logger","name":"init","longname":"Logger#init","kind":"function","scope":"instance","$longname":"Logger#init","$kind":"method","$docmaLink":"?api#Logger#init"},{"comment":"/**\n * Whatever it's passed to logger will be console.log'ed if the API instance is set to `debug:true`\n *\n * @param {Array|String|Object} args\n * @memberof Logger\n */","meta":{"range":[438,576],"filename":"logger.js","lineno":23,"columnno":4,"path":"/Users/lego/work/personal/bmw-connecteddrive-api/src/helpers","code":{"id":"astnode100000592","name":"Logger#log","type":"MethodDefinition","paramnames":["args"]},"vars":{"":null}},"description":"Whatever it's passed to logger will be console.log'ed if the API instance is set to `debug:true`","params":[{"type":{"names":["Array","String","Object"]},"name":"args","variable":true}],"memberof":"Logger","name":"log","longname":"Logger#log","kind":"function","scope":"instance","$longname":"Logger#log","$kind":"method","$docmaLink":"?api#Logger#log"}]},{"comment":"","meta":{"range":[97,275],"filename":"vehicle.js","lineno":5,"columnno":4,"path":"/Users/lego/work/personal/bmw-connecteddrive-api/src/helpers","code":{"id":"astnode100000800","name":"Vehicle","type":"MethodDefinition","paramnames":["originalData","API"]},"vars":{"":null}},"undocumented":true,"name":"Vehicle","longname":"Vehicle","kind":"class","scope":"global","params":[],"$longname":"Vehicle","$kind":"constructor","$docmaLink":"?api#Vehicle"}],"symbols":["API","API.APIInitObject","API#currentVehicles","API#getToken","API#getVehicles","API#requestWithAuth","BMWURLs","Logger","Logger#init","Logger#log","Vehicle"]}},"app":{"title":"BMW ConnectedDrive API Documentation","entrance":"content:readme","routing":{"method":"query","caseSensitive":true},"server":"github","base":"/","meta":null,"favicon":""},"template":{"name":"docma-template-zebra","description":"Zebra - Default template for Docma. https://github.com/onury/docma","version":"2.3.1","supportedDocmaVersion":">=2.0.0","author":"Onur Yıldırım","license":"MIT","mainHTML":"index.html","options":{"title":{"label":"API","href":"/?api"},"navbar":{"menu":[{"label":"Docs","iconClass":"fas fa-book","href":"./"},{"label":"API","iconClass":"fas fa-mouse-pointer","href":"?api"},{"label":"GitHub","iconClass":"fab fa-github","href":"https://github.com/mihaiblaga89/bmw-connecteddrive-api","target":"_blank"}],"enabled":true,"fixed":true,"dark":false,"animations":true},"logo":null,"sidebar":{"enabled":true,"outline":"tree","collapsed":false,"toolbar":true,"itemsFolded":false,"itemsOverflow":"crop","badges":true,"search":true,"animations":true},"symbols":{"autoLink":true,"params":"list","enums":"list","props":"list","meta":false},"contentView":{"bookmarks":false,"faVersion":"5.5.0","faLibs":"all"}}},"partials":{"api":"docma-api","content":"docma-content","notFound":"docma-404"},"elementID":"docma-main","contentElementID":"docma-content","defaultApiName":"_def_","logsEnabled":false})); +var docma = Object.freeze(new DocmaWeb({"version":"3.2.2","routes":[{"id":"api:","type":"api","name":"_def_","path":"?api","contentPath":null,"sourceType":"js"},{"id":"content:readme","type":"content","name":"readme","path":"?content=readme","contentPath":"content/readme.html","sourceType":"md"}],"apis":{"_def_":{"documentation":[{"comment":"","meta":{"range":[448,503],"filename":"index.js","lineno":16,"columnno":4,"path":"/Users/lego/work/personal/bmw-connecteddrive-api/src/api","code":{"id":"astnode100000059","name":"API","type":"MethodDefinition","paramnames":[]},"vars":{"":null}},"undocumented":true,"name":"API","longname":"API","kind":"class","scope":"global","params":[],"$longname":"API","$kind":"constructor","$docmaLink":"?api#API"},{"comment":"/**\n *\n * * Initialization params\n * @typedef {Object} APIInitObject\n * @property {('eu'|'us'|'cn')} region - Region where you have created the ConnectedDrive account\n * @property {string} username - The username (user@example.com)\n * @property {string} password - The password\n * @property {Boolean} [debug=false] - If you want debugging messages shown\n * @property {Boolean} [skipVehicles=false] - If you want to skip the initial request of vehicles and do it manually with API.getVehicles()\n *\n * * Initializes the API\n *\n * @param {APIInitObject}\n * @memberof API\n */","meta":{"filename":"index.js","lineno":20,"columnno":4,"path":"/Users/lego/work/personal/bmw-connecteddrive-api/src/api","code":{}},"description":"* Initialization params","kind":"typedef","name":"APIInitObject","type":{"names":["Object"]},"properties":[{"type":{"names":["Boolean"]},"optional":true,"defaultvalue":false,"description":"If you want debugging messages shown","name":"debug"},{"type":{"names":["string"]},"description":"The password","name":"password"},{"type":{"names":["'eu'","'us'","'cn'"]},"description":"Region where you have created the ConnectedDrive account","name":"region"},{"type":{"names":["Boolean"]},"optional":true,"defaultvalue":false,"description":"If you want to skip the initial request of vehicles and do it manually with API.getVehicles()\n\n* Initializes the API","name":"skipVehicles"},{"type":{"names":["string"]},"description":"The username (user@example.com)","name":"username"}],"params":[{"type":{"names":["APIInitObject"]}}],"memberof":"API","scope":"static","longname":"API.APIInitObject","$longname":"API.APIInitObject","$kind":"typedef","$docmaLink":"?api#API.APIInitObject"},{"comment":"/**\n * Gets your currently stored vehicles\n *\n * @memberof API\n */","meta":{"range":[5070,5216],"filename":"index.js","lineno":153,"columnno":4,"path":"/Users/lego/work/personal/bmw-connecteddrive-api/src/api","code":{"id":"astnode100000512","name":"API#currentVehicles","type":"MethodDefinition","paramnames":[]},"vars":{"":null}},"description":"Gets your currently stored vehicles","memberof":"API","name":"currentVehicles","longname":"API#currentVehicles","kind":"member","scope":"instance","params":[],"$longname":"API#currentVehicles","$kind":"property","$docmaLink":"?api#API#currentVehicles"},{"comment":"/**\n * Gets the auth token from BMW API\n *\n * @memberof API\n */","meta":{"range":[3334,4468],"filename":"index.js","lineno":101,"columnno":4,"path":"/Users/lego/work/personal/bmw-connecteddrive-api/src/api","code":{"id":"astnode100000329","name":"API#getToken","type":"MethodDefinition","paramnames":[]},"vars":{"":null}},"description":"Gets the auth token from BMW API","memberof":"API","name":"getToken","longname":"API#getToken","kind":"function","scope":"instance","params":[],"async":true,"$longname":"API#getToken","$kind":"method","$docmaLink":"?api#API#getToken"},{"comment":"/**\n * Gets or refreshes your vehicles from BMW API and stores them\n *\n * @memberof API\n */","meta":{"range":[4586,4977],"filename":"index.js","lineno":136,"columnno":4,"path":"/Users/lego/work/personal/bmw-connecteddrive-api/src/api","code":{"id":"astnode100000454","name":"API#getVehicles","type":"MethodDefinition","paramnames":[]},"vars":{"":null}},"description":"Gets or refreshes your vehicles from BMW API and stores them","memberof":"API","name":"getVehicles","longname":"API#getVehicles","kind":"function","scope":"instance","params":[],"async":true,"$longname":"API#getVehicles","$kind":"method","$docmaLink":"?api#API#getVehicles"},{"comment":"/**\n * Make a generic request to BMW API\n *\n * @param {String} url\n * @returns {Promise}\n * @memberof API\n */","meta":{"range":[2167,3244],"filename":"index.js","lineno":70,"columnno":4,"path":"/Users/lego/work/personal/bmw-connecteddrive-api/src/api","code":{"id":"astnode100000191","name":"API#requestWithAuth","type":"MethodDefinition","paramnames":["url",""]},"vars":{"":null}},"description":"Make a generic request to BMW API","params":[{"type":{"names":["String"]},"name":"url"}],"returns":[{"type":{"names":["Promise"]}}],"memberof":"API","name":"requestWithAuth","longname":"API#requestWithAuth","kind":"function","scope":"instance","async":true,"$longname":"API#requestWithAuth","$kind":"method","$docmaLink":"?api#API#requestWithAuth"},{"comment":"/**\n * Handles all URLs required by BMW API\n *\n * @class BMWURLs\n */","meta":{"filename":"urls.js","lineno":7,"columnno":0,"path":"/Users/lego/work/personal/bmw-connecteddrive-api/src/helpers","code":{}},"description":"Handles all URLs required by BMW API","kind":"class","name":"BMWURLs","longname":"BMWURLs","scope":"global","$longname":"BMWURLs","$kind":"class","$docmaLink":"?api#BMWURLs","$constructor":{"comment":"/**\n *Creates an instance of BMWURLs.\n * @param {*} region\n * @memberof BMWURLs\n */","meta":{"range":[407,501],"filename":"urls.js","lineno":18,"columnno":4,"path":"/Users/lego/work/personal/bmw-connecteddrive-api/src/helpers","code":{"id":"astnode100000641","name":"BMWURLs","type":"MethodDefinition","paramnames":["region"]},"vars":{"":null}},"description":"Creates an instance of BMWURLs.","params":[{"type":{"names":["*"]},"name":"region"}],"memberof":"BMWURLs","name":"BMWURLs","longname":"BMWURLs.BMWURLs","kind":"class","scope":"static","$longname":"BMWURLs","$kind":"constructor","$docmaLink":"?api#BMWURLs"}},{"comment":"/**\n * Logger class for...logging purposes\n *\n * @class Logger\n */","meta":{"filename":"logger.js","lineno":1,"columnno":0,"path":"/Users/lego/work/personal/bmw-connecteddrive-api/src/helpers","code":{}},"description":"Logger class for...logging purposes","kind":"class","name":"Logger","longname":"Logger","scope":"global","$longname":"Logger","$kind":"class","$docmaLink":"?api#Logger","$members":[{"comment":"/**\n * Initializes the logger\n *\n * @param {Boolean} debug\n * @memberof Logger\n */","meta":{"range":[193,240],"filename":"logger.js","lineno":13,"columnno":4,"path":"/Users/lego/work/personal/bmw-connecteddrive-api/src/helpers","code":{"id":"astnode100000581","name":"Logger#init","type":"MethodDefinition","paramnames":["debug"]},"vars":{"":null}},"description":"Initializes the logger","params":[{"type":{"names":["Boolean"]},"name":"debug"}],"memberof":"Logger","name":"init","longname":"Logger#init","kind":"function","scope":"instance","$longname":"Logger#init","$kind":"method","$docmaLink":"?api#Logger#init"},{"comment":"/**\n * Whatever it's passed to logger will be console.log'ed if the API instance is set to `debug:true`\n *\n * @param {Array|String|Object} args\n * @memberof Logger\n */","meta":{"range":[438,576],"filename":"logger.js","lineno":23,"columnno":4,"path":"/Users/lego/work/personal/bmw-connecteddrive-api/src/helpers","code":{"id":"astnode100000592","name":"Logger#log","type":"MethodDefinition","paramnames":["args"]},"vars":{"":null}},"description":"Whatever it's passed to logger will be console.log'ed if the API instance is set to `debug:true`","params":[{"type":{"names":["Array","String","Object"]},"name":"args","variable":true}],"memberof":"Logger","name":"log","longname":"Logger#log","kind":"function","scope":"instance","$longname":"Logger#log","$kind":"method","$docmaLink":"?api#Logger#log"}]},{"comment":"/**\n * Vehicle class that handles all the operations for a particular vehicle\n *\n * @class Vehicle\n */","meta":{"filename":"vehicle.js","lineno":3,"columnno":0,"path":"/Users/lego/work/personal/bmw-connecteddrive-api/src/helpers","code":{}},"description":"Vehicle class that handles all the operations for a particular vehicle","kind":"class","name":"Vehicle","longname":"Vehicle","scope":"global","$longname":"Vehicle","$kind":"class","$docmaLink":"?api#Vehicle","$members":[{"comment":"/**\n * Returns the vehicle's model\n *\n * @readonly\n * @returns {String}\n * @memberof Vehicle\n */","meta":{"range":[720,779],"filename":"vehicle.js","lineno":35,"columnno":4,"path":"/Users/lego/work/personal/bmw-connecteddrive-api/src/helpers","code":{"id":"astnode100000850","name":"Vehicle#model","type":"MethodDefinition","paramnames":[]},"vars":{"":null}},"description":"Returns the vehicle's model","readonly":true,"returns":[{"type":{"names":["String"]}}],"memberof":"Vehicle","name":"model","longname":"Vehicle#model","kind":"member","scope":"instance","params":[],"$longname":"Vehicle#model","$kind":"property","$docmaLink":"?api#Vehicle#model"},{"comment":"/**\n * Returns the vehicle's name as a combination of year, brand, bodytype and model\n * Ex. 2017 BMW F30 320d\n *\n * @readonly\n * @returns {String}\n * @memberof Vehicle\n */","meta":{"range":[2334,2504],"filename":"vehicle.js","lineno":85,"columnno":4,"path":"/Users/lego/work/personal/bmw-connecteddrive-api/src/helpers","code":{"id":"astnode100001012","name":"Vehicle#name","type":"MethodDefinition","paramnames":[]},"vars":{"":null}},"description":"Returns the vehicle's name as a combination of year, brand, bodytype and model\nEx. 2017 BMW F30 320d","readonly":true,"returns":[{"type":{"names":["String"]}}],"memberof":"Vehicle","name":"name","longname":"Vehicle#name","kind":"member","scope":"instance","params":[],"$longname":"Vehicle#name","$kind":"property","$docmaLink":"?api#Vehicle#name"},{"comment":"/**\n * Returns the vehicle's VIN\n *\n * @readonly\n * @returns {String}\n * @memberof Vehicle\n */","meta":{"range":[534,589],"filename":"vehicle.js","lineno":24,"columnno":4,"path":"/Users/lego/work/personal/bmw-connecteddrive-api/src/helpers","code":{"id":"astnode100000840","name":"Vehicle#vin","type":"MethodDefinition","paramnames":[]},"vars":{"":null}},"description":"Returns the vehicle's VIN","readonly":true,"returns":[{"type":{"names":["String"]}}],"memberof":"Vehicle","name":"vin","longname":"Vehicle#vin","kind":"member","scope":"instance","params":[],"$longname":"Vehicle#vin","$kind":"property","$docmaLink":"?api#Vehicle#vin"}],"$constructor":{"comment":"","meta":{"range":[199,405],"filename":"vehicle.js","lineno":9,"columnno":4,"path":"/Users/lego/work/personal/bmw-connecteddrive-api/src/helpers","code":{"id":"astnode100000800","name":"Vehicle","type":"MethodDefinition","paramnames":["originalData","API"]},"vars":{"":null}},"undocumented":true,"name":"Vehicle","longname":"Vehicle","kind":"class","scope":"global","params":[],"$longname":"Vehicle","$kind":"constructor","$docmaLink":"?api#Vehicle"}}],"symbols":["API","API.APIInitObject","API#currentVehicles","API#getToken","API#getVehicles","API#requestWithAuth","BMWURLs","Logger","Logger#init","Logger#log","Vehicle","Vehicle#model","Vehicle#name","Vehicle#vin"]}},"app":{"title":"BMW ConnectedDrive API Documentation","entrance":"content:readme","routing":{"method":"query","caseSensitive":true},"server":"github","base":"/","meta":null,"favicon":""},"template":{"name":"docma-template-zebra","description":"Zebra - Default template for Docma. https://github.com/onury/docma","version":"2.3.1","supportedDocmaVersion":">=2.0.0","author":"Onur Yıldırım","license":"MIT","mainHTML":"index.html","options":{"title":{"label":"API","href":"/?api"},"navbar":{"menu":[{"label":"Docs","iconClass":"fas fa-book","href":"./"},{"label":"API","iconClass":"fas fa-mouse-pointer","href":"?api"},{"label":"GitHub","iconClass":"fab fa-github","href":"https://github.com/mihaiblaga89/bmw-connecteddrive-api","target":"_blank"}],"enabled":true,"fixed":true,"dark":false,"animations":true},"logo":null,"sidebar":{"enabled":true,"outline":"tree","collapsed":false,"toolbar":true,"itemsFolded":false,"itemsOverflow":"crop","badges":true,"search":true,"animations":true},"symbols":{"autoLink":true,"params":"list","enums":"list","props":"list","meta":false},"contentView":{"bookmarks":false,"faVersion":"5.5.0","faLibs":"all"}}},"partials":{"api":"docma-api","content":"docma-content","notFound":"docma-404"},"elementID":"docma-main","contentElementID":"docma-content","defaultApiName":"_def_","logsEnabled":false})); !function(){"use strict";var c="path"===docma.app.routing.method;function n(a){return(a.params[1]||"").replace(/\/$/,"")}function a(a,e){var o=n(a)||docma._.defaultApiName,t=docma.createRoute(o,DocmaWeb.Route.Type.API);if(!t||!t.exists())return e();t.apply()}docma.app.base&&page.base(docma.app.base),page.redirect("(/)?"+docma.template.main,""),c&&(page("(/)?api/(.+)",a),page("(/)?api(/)?",a),page("(/)?(.*)",function(a,e){var o=n(a),t=docma.createRoute(o,DocmaWeb.Route.Type.CONTENT);if(!t||!t.exists())return e();t.apply()})),page("(/)?",function(t,n){!function(){if(c){var a=sessionStorage.getItem("redirectPath")||null;if(a)return sessionStorage.removeItem("redirectPath"),docma.info("Redirecting to:",a),page.redirect(a),!0}return!1}()&&setTimeout(function(){var a,e=function(a){var e=a||window.location.search;return/^[?&]/.test(e)&&(e=e.slice(1)),e||null}(t.querystring);if(c){if(e)return n();a=docma._.appEntranceRI}else docma.log("Query-string:",e),a=e?docma.createRouteFromQuery(e):docma._.appEntranceRI;if(!a||!a.exists())return n();function o(){docma._trigger(DocmaWeb.Event.Navigate,[a])}a.isCurrent()?o():a.apply(function(a){200===a&&o()})},100)}),page("*",function(a){docma.warn("Unknown Route:",a.path),docma.log("context:",a),docma.createRoute(null).apply()}),docma.info("Docma SPA Configuration:"),docma.info("App Title: ",docma.app.title),docma.info("Routing Method: ",docma.app.routing.method),docma.info("App Server: ",docma.app.server),docma.info("Base Path: ",docma.app.base),docma.info("Entrance Route ID: ",docma.app.entrance),window.onload=function(){docma._.initialLoad=!0,docma._.appEntranceRI=docma.createRouteFromID(docma.app.entrance),page.start({click:!0,popstate:!0,dispatch:!0,hashbang:!1,decodeURLComponents:!0}),docma.info("Docma SPA loaded!")}}(); \ No newline at end of file diff --git a/src/helpers/vehicle.js b/src/helpers/vehicle.js index 10561cee..a0e85577 100644 --- a/src/helpers/vehicle.js +++ b/src/helpers/vehicle.js @@ -1,26 +1,63 @@ import BMWURLs from './urls'; import { VEHICLE_VIEWS } from '../constants'; - +/** + * Vehicle class that handles all the operations for a particular vehicle + * + * @class Vehicle + */ class Vehicle { constructor(originalData, API) { this.originalData = originalData; this.BMWURLs = new BMWURLs(API.region); this.API = API; this.images = {}; + this.status = null; } + /** + * Returns the vehicle's VIN + * + * @readonly + * @returns {String} + * @memberof Vehicle + */ get vin() { return this.originalData.vin; } + /** + * Returns the vehicle's model + * + * @readonly + * @returns {String} + * @memberof Vehicle + */ get model() { return this.originalData.model; } - getStatus() { - return this.API.requestWithAuth(this.BMWURLs.getVehicleStatusURL(this.vin)); + /** + * + * + * @param {Boolean} force - Force a refresh instead of getting cached data + * @returns {Promise} + * @memberof Vehicle + */ + async getStatus(force) { + if (this.status && !force) return this.status; + this.status = await this.API.requestWithAuth(this.BMWURLs.getVehicleStatusURL(this.vin)); + return this.status; } + /** + * + * + * @param {number} [width=400] + * @param {number} [height=400] + * @param {VEHICLE_VIEWS} [view=VEHICLE_VIEWS.FRONTSIDE] - Must be one of API.VEHICLE_VIEWS.* + * @returns {String} - the image as base64 string + * @memberof Vehicle + */ async getImage(width = 400, height = 400, view = VEHICLE_VIEWS.FRONTSIDE) { if (this.images[`${view}:${width}:${height}`]) { return this.images[`${view}:${width}:${height}`]; @@ -37,9 +74,17 @@ class Vehicle { return this.images[`${view}:${width}:${height}`]; } + /** + * Returns the vehicle's name as a combination of year, brand, bodytype and model + * Ex. 2017 BMW F30 320d + * + * @readonly + * @returns {String} + * @memberof Vehicle + */ get name() { const { yearOfConstruction, model, bodytype, brand } = this.originalData; - return `${yearOfConstruction} ${brand} ${bodytype} ${model}`; // 2017 BMW F30 320d + return `${yearOfConstruction} ${brand} ${bodytype} ${model}`; } }