Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
request(method: string, path: string, body?: {}, options?: {}, responseOutput?: { response: Response}): Promise {
let requestOptions = extend(true, {headers: {}}, this.defaults || {}, options || {}, {method, body});
let contentType = requestOptions.headers['Content-Type'] || requestOptions.headers['content-type'];
// if body is object, stringify to json or urlencoded depending on content-type
if (typeof body === 'object' && body !== null && contentType) {
requestOptions.body = (/^application\/(.+\+)?json/).test(contentType.toLowerCase())
? JSON.stringify(body)
: buildQueryString(body);
}
return this.client.fetch(path, requestOptions).then((response: Response) => {
if (response.status >= 200 && response.status < 400) {
if (responseOutput) {
responseOutput.response = response;
}
return response.json().catch(() => null);
}
throw response;
});
}
} else {
output += '/';
output += segmentValue;
}
}
if (output.charAt(0) !== '/') {
output = '/' + output;
}
// remove params used in the path and add the rest to the querystring
for (let param in consumed) {
delete routeParams[param];
}
let queryString = buildQueryString(routeParams);
output += queryString ? `?${queryString}` : '';
return output;
}
function buildFullUrl(message) {
let url;
let qs;
// Message URL starts with / - as absolute URL
if (message.url && message.url[0] === '/') {
url = message.url;
} else {
url = join(message.baseUrl, message.url);
}
if (message.params) {
qs = buildQueryString(message.params);
url = qs ? `${url}?${qs}` : url;
}
return url;
}
buildFullUrl(): string {
let absoluteUrl = /^([a-z][a-z0-9+\-.]*:)?\/\//i;
let url = absoluteUrl.test(this.url) ? this.url : join(this.baseUrl, this.url);
if (this.params) {
let qs = buildQueryString(this.params);
url = qs ? url + (this.url.indexOf('?') < 0 ? '?' : '&') + qs : url;
}
return url;
}
}
function buildFullUri(message){
var uri = join(message.baseUrl, message.uri),
qs;
if(message.params){
qs = buildQueryString(message.params);
uri = qs ? `${uri}?${qs}` : uri;
}
message.fullUri = uri;
}
function getRequestPath(resource, traditional, idOrCriteria, criteria) {
let hasSlash = resource.slice(-1) === '/';
if (typeof idOrCriteria === 'string' || typeof idOrCriteria === 'number') {
resource = `${join(resource, String(idOrCriteria))}${hasSlash ? '/' : ''}`;
} else {
criteria = idOrCriteria;
}
if (typeof criteria === 'object' && criteria !== null) {
resource += `?${buildQueryString(criteria, traditional)}`;
} else if (criteria) {
resource += `${hasSlash ? '' : '/'}${criteria}${hasSlash ? '/' : ''}`;
}
return resource;
}
function getRequestPath(resource: string, traditional: boolean, idOrCriteria?: string|number|{}, criteria?: {}) {
let hasSlash = resource.slice(-1) === '/';
if (typeof idOrCriteria === 'string' || typeof idOrCriteria === 'number') {
resource = `${join(resource, String(idOrCriteria))}${hasSlash ? '/' : ''}`;
} else {
criteria = idOrCriteria;
}
if (typeof criteria === 'object' && criteria !== null) {
resource += `?${buildQueryString(criteria, traditional)}`;
} else if (criteria) {
resource += `${hasSlash ? '' : '/'}${criteria}${hasSlash ? '/' : ''}`;
}
return resource;
}
function buildFullUrl(message){
var url = join(message.baseUrl, message.url),
qs;
if(message.params){
qs = buildQueryString(message.params);
url = qs ? `${url}?${qs}` : url;
}
message.fullUrl = url;
}
function buildFullUrl(message) {
let url;
let qs;
if (message.url && message.url[0] === '/') {
url = message.url;
} else {
url = join(message.baseUrl, message.url);
}
if (message.params) {
qs = buildQueryString(message.params);
url = qs ? `${url}?${qs}` : url;
}
return url;
}
if (!this.poolId) {
return;
}
if (this.timeout) {
try {
clearTimeout(this.timeout);
} catch{ }
}
this.error = false;
let options = {
pageSize: this.pageSize,
page: this.currentPageNumber
}
this.apiClientService.http.get(`pools/${this.poolId}/blocks?${buildQueryString(options, true)}`).then((value: HttpResponseMessage) => {
if (value.isSuccess) {
if (this.currentPageNumber === 0) {
this.data = [];
}
this.data = [...this.data, ...value.content];
} else {
this.error = true;
}
}).catch(() => {
this.error = true;
}).then(() => {
this.loading = false;
this.timeout = setTimeout(this.refresh.bind(this), 4000);
})
}
}