本文整理匯總了TypeScript中unirest.get函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript get函數的具體用法?TypeScript get怎麽用?TypeScript get使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了get函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: searchEvents
public searchEvents(options : searchEventOptions,
callback : (err: any, data: searchEventResults) => void)
{
var request = this.base_url + 'events/search?app_key='+ this.app_key;
for(var i in options){
request += '&';
request += i + '=' + options[i];
}
unirest.get(request, (response : any, err : any) => {
if(err){
return callback(err, null);
}
xml2js.parseString(response.body, {explicitArray : false}, (err: any, parsed: any) => {
if(err){
return callback(err, null);
}
return callback(null, parsed);
});
});
}
示例2: MountebankRequestLog
export function MountebankRequestLog(port) {
let deferred = Q.defer();
unirest.get('http://localhost:2525/imposters/' + port).end((res) => {
deferred.resolve(res.body.requests);
});
return deferred.promise;
}
示例3: reject
return new Promise<any>((resolve, reject) => {
unirest.get(this.userInfoEndpoint).headers({ authorization: `Bearer ${accessToken}`}).as.json(res => {
if (res.status >= 400) {
reject(res);
} else {
resolve(res.body);
}
});
});
示例4: reject
return new Promise<WordPress.User>((resolve, reject) => {
unirest
.get(`https://www.aliemu.com/wp-json/wp/v2/users/${userID}`)
.headers(HEADERS)
.query('context=edit')
.end(
res =>
res.error
? reject(new Error('Could not retrieve user.'))
: resolve(res.body)
);
});
示例5: resolve
return new Promise<boolean>((resolve, reject) => {
if (this.userInfoEndpoint) {
resolve(true);
} else {
const openIdConfigUrl = `${this.authority.value}/.well-known/openid-configuration`;
unirest.get(openIdConfigUrl).as.json(res => {
if (res.status >= 400) {
reject(res);
} else {
this.userInfoEndpoint = res.body.userinfo_endpoint;
resolve(true);
}
});
}
});
示例6: listCategories
public listCategories(callback : (err: any, data: categoryResult[]) => void)
{
var request = this.base_url + '/categories/list?app_key='+ this.app_key;
unirest.get(request, (response: any, err: any) => {
if(err){
return callback(err, null);
}
xml2js.parseString(response.body, {explicitArray : false}, (err: any, parsed: any) => {
if(err){
return callback(err, null);
}
return callback(null, parsed.categories.category);
});
});
}
示例7: resolve
return new Promise<DataSource>((resolve) => {
let uri = this.createRequestUrl();
try {
let values: Map<string, ConfigurationItem>;
let request = rest.get(uri)
.headers({ 'Accept': 'application/json' })
.timeout(timeoutInMs);
request = this.prepareRequest(request);
request.end(function (response) {
if (response.status === 200 && response.body) {
if (response.body.error) {
if (!Service.isDevelopment) {
Service.log.info(null, () => `HTTP CONFIG : error when polling properties on ${uri} - ${response.body.error.message}`);
}
}
else {
values = new Map<string, ConfigurationItem>();
let data = response.body;
data.value && data.value.forEach(cfg => values.set(cfg.key, cfg));
self.lastUpdate = Service.nowAsString();
self.mergeChanges(values);
}
}
else {
Service.log.info(null, () => `HTTP CONFIG : error when polling properties on ${uri} - ${(response.error && response.error.message) || response.status}`);
}
resolve((values && new DataSource(values.values())) || null);
});
}
catch (e) {
Service.log.info(null, () => `HTTP CONFIG : error when polling properties on ${uri} - ${e.message}`);
resolve(null);
}
});
示例8: resolve
return new Promise<PollResult>( ( resolve ) =>
{
let uri = this.createRequestUrl();
try {
let values;
let request = rest.get(uri)
.headers({ 'Accept': 'application/json' })
.timeout(timeoutInMs);
request = this.prepareRequest(request);
request.end(function (response) {
if (response.status === 200 && response.body) {
if (response.body.error) {
if (!System.isDevelopment) {
System.log.info(null, ()=>`HTTP CONFIG : error when polling properties on ${uri} - ${response.body.error.message}`);
}
}
else {
values = new Map<string, ConfigurationItem>();
let data = response.body;
data.value && data.value.forEach(cfg => values.set(cfg.key, cfg));
self.lastUpdate = moment.utc().format();
}
}
else {
System.log.info(null, ()=>`HTTP CONFIG : error when polling properties on ${uri} - ${(response.error && response.error.message) || response.status}`);
}
resolve(values && new PollResult(self, values));
});
}
catch (e) {
System.log.info(null, ()=>`HTTP CONFIG : error when polling properties on ${uri} - ${e.message}`);
resolve(null);
}
} );