Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions bin/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,20 @@ function extractData(fields, data) {
}
return outArr;
}

function getSplittedKeys(inString){
if(inString.indexOf(keySeparator)!=-1){
return inString.split(keySeparator);
}else {
//Backward support for old separator
const tokens = inString.split("-");
if(tokens.length==2){
return tokens;
}else{
return null;
}
}
}
module.exports.drawTable = drawTable;
module.exports.timeStampToLocaleString = timeStampToLocaleString;
module.exports.md5Sum = md5Sum;
Expand All @@ -235,5 +249,6 @@ module.exports.decryptAndGet=decryptAndGet;
module.exports.encryptAndStore=encryptAndStore;
module.exports.hereAccountLogin=hereAccountLogin;
module.exports.keySeparator=keySeparator;
module.exports.getSplittedKeys=getSplittedKeys;
module.exports.xyzRoot = function() {return xyzRoot}

38 changes: 21 additions & 17 deletions bin/here-geocode.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,27 @@ function toFeature(result){

function geoCode(locationString){
common.decryptAndGet("appDetails").then((dataStr) =>{
const appInfo = dataStr.split(common.keySeparator);
var geocodeURL = 'https://geocoder.cit.api.here.com/6.2/geocode.json' +
'?app_id=' + appInfo[0] +
'&app_code=' + appInfo[1] +
'&searchtext=' + locationString;
request.get(geocodeURL, (error, response, body) => {
if (error)
throw error;
if (response.statusCode !== 200)
throw new Error(response.body);
let geocodeJson = JSON.parse(body);
if(geocodeJson.Response.View.length==0){
console.log("Could not geocode the place '"+locationString+"'");
}else{
console.log(JSON.stringify(toGeoJson(geocodeJson),null,2));
}
});
const appInfo = common.getSplittedKeys(dataStr);
if(appInfo){
var geocodeURL = 'https://geocoder.cit.api.here.com/6.2/geocode.json' +
'?app_id=' + appInfo[0] +
'&app_code=' + appInfo[1] +
'&searchtext=' + locationString;
request.get(geocodeURL, (error, response, body) => {
if (error)
throw error;
if (response.statusCode !== 200)
throw new Error(response.body);
let geocodeJson = JSON.parse(body);
if(geocodeJson.Response.View.length==0){
console.log("Could not geocode the place '"+locationString+"'");
}else{
console.log(JSON.stringify(toGeoJson(geocodeJson),null,2));
}
});
}else{
console.log("Account information needs to be updated. Retry after executing the command 'here configure'.");
}
}).catch(function (error) {
console.log(error.message);
});
Expand Down
58 changes: 31 additions & 27 deletions bin/here-xyz.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,33 +448,37 @@ program
.action(function (id) {
common.decryptAndGet("accountInfo","No here account configure found. Try running 'here configure account'").then((dataStr) =>{
if(dataStr){
const appInfo = dataStr.split(common.keySeparator);
sso.executeWithCookie(appInfo[0],appInfo[1]).then(cookie=>{
const options = {
url: common.xyzRoot()+"/token-api/token",
method: 'GET',
headers: {
"Cookie":cookie,
"Content-Type":"application/json"
}
};
return new Promise(function(resolve, reject) {
request(options, function(error, response, body) {
var statusCode = response && response.statusCode;
if (statusCode != 200) {
reject(new Error("Error while fetching maxrights :"+body));
}else{
var tokenInfo = JSON.parse(body);
common.decryptAndGet("keyInfo","No token found").then((currentToken) =>{
console.log("====================================================");
console.log("Current CLI token is : "+currentToken);
console.log("====================================================");
common.drawTable(tokenInfo.tokens,["id","type","iat","description"]);
});
}
});
});
});
const appInfo = common.getSplittedKeys(dataStr);
if(appInfo){
sso.executeWithCookie(appInfo[0],appInfo[1]).then(cookie=>{
const options = {
url: common.xyzRoot()+"/token-api/token",
method: 'GET',
headers: {
"Cookie":cookie,
"Content-Type":"application/json"
}
};
return new Promise(function(resolve, reject) {
request(options, function(error, response, body) {
var statusCode = response && response.statusCode;
if (statusCode != 200) {
reject(new Error("Error while fetching maxrights :"+body));
}else{
var tokenInfo = JSON.parse(body);
common.decryptAndGet("keyInfo","No token found").then((currentToken) =>{
console.log("====================================================");
console.log("Current CLI token is : "+currentToken);
console.log("====================================================");
common.drawTable(tokenInfo.tokens,["id","type","iat","description"]);
});
}
});
});
});
}else{
console.log("Account information needs to be updated. Retry after executing the command 'here configure account'.");
}
}
});
});
Expand Down