@geogirafe/lib-geoportal
Version:
GeoGirafe is a flexible application to build online geoportals.
36 lines (35 loc) • 1.01 kB
JavaScript
class GmfManager {
constructor(serviceUrl) {
Object.defineProperty(this, "serviceUrl", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this.serviceUrl = serviceUrl;
}
async shortenUrl(longUrl) {
const errorResponse = {
success: false,
shorturl: longUrl
};
const params = new URLSearchParams();
params.append('url', longUrl);
const response = await fetch(this.serviceUrl, {
method: 'POST',
headers: new Headers({
'Content-Type': 'application/x-www-form-urlencoded'
}),
body: params
});
const response_data = (await response.json());
if (response_data) {
return {
success: true,
shorturl: response_data.short_url
};
}
return errorResponse;
}
}
export default GmfManager;