本文整理汇总了TypeScript中request类的典型用法代码示例。如果您正苦于以下问题:TypeScript request类的具体用法?TypeScript request怎么用?TypeScript request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了request类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: paymentComplete
public static paymentComplete(
checkoutSession: Payment.ICheckoutConversationSession,
paymentRequest: Payment.IPaymentRequest,
shippingAddress: Payment.IPaymentAddress,
shippingOptionId: string,
payerEmail: string,
payerPhone: string,
cb: (err, statusCode: number, body: Payment.IPaymentRequestCompleteResult) => void) {
const settings = getSettings();
let options: request.OptionsWithUrl = {
url: `${this.serviceUrl}/emulator/${settings.conversation.conversationId}/invoke/paymentComplete`,
method: "POST",
json: [{ checkoutSession: checkoutSession, request: paymentRequest, shippingAddress: shippingAddress, shippingOptionId: shippingOptionId, payerEmail: payerEmail, payerPhone: payerPhone }],
};
let responseCallback = (err, resp: http.IncomingMessage, body) => {
cb(err, resp.statusCode, body as Payment.IPaymentRequestCompleteResult);
};
request(options, responseCallback);
}
示例2: request
return new Bluebird<Schema>((resolve, reject) => {
request(options, function (error, res, body: Introspection | string) {
if (error)
return reject(error);
if ((res.statusCode as number) >= 400)
return reject(new Error(
'Unexpected HTTP Status Code ' + res.statusCode +
' (' + res.statusMessage + ') from: ' + options.url
));
if (typeof body === 'string')
return reject(new Error(
'Unexpected response from "' + options.url + '": ' + body.slice(0, 10) + '...'
));
return resolve(body.data.__schema);
});
});
示例3: request
return new Promise<boolean>((resolve, reject) => {
request({
method: 'POST',
uri: GOOGLE_RECAPTCHA_ENDPOINT,
formData: { response, remoteip,
secret: GOOGLE_RECAPTCHA_SECRET }
}, (err, res, body) => {
var [ parse_err, check ] = try_func(() => JSON.parse(body));
if (err) {
reject(err);
} else if (parse_err) {
reject(new BadGatewayError(ERR_MSG_PARSING_ERROR('google')));
} else if (!check.success) {
reject(new BadRequestError('failed to verify recaptcha'));
} else {
resolve(true);
}
});
});
示例4: Promise
return new Promise((resolve, reject) => {
let timeout = getTimeoutInMilliseconds(controlType);
let encoding: any = activeType === ActiveType.Blob ? null : 'utf8';
let data = {encoding, form: formData, gzip: true, headers, jar: true, method: activeMethod, timeout, url: address};
request(data, (error, response, body) => {
if (!error && response.statusCode === 200) {
if (activeType === ActiveType.Json) {
// TODO: This parse can throw an error, which is not caught.
resolve(JSON.parse(body));
} else {
resolve(body);
}
} else {
reject(new mio.HttpServiceError({
body: String(body || ''),
statusCode: response.statusCode || 0
}, `Invalid HTTP response: ${address}`));
}
});
});
示例5: request
return new Promise<CandleList>((resolve,reject) => {
request({uri,qs:{env,format,q},json:true},(error, response, body) => {
if(error){
reject(error);
} else if(!body.query || typeof body.query.count === 'undefined' || body.query.count === null){
reject('unexpected-error');
} else if(body.query.count === 0){
resolve(new CandleList([]));
} else {
const data = body.query.results.quote.filter(datum => !!parseFloat(datum.Volume));
if(data.length < CANDLES_TO_FETCH){
reject('insufficient-data');
} else {
resolve(new CandleList(
data.map(datum => transformCandleData(datum)).reverse()
));
}
}
});
});
示例6: request
return new Promise<string>((resolve, reject) => {
let options = {
uri,
headers: {
"User-Agent": "Node Reddit Server v0.4"
}
};
request(options, (error, response, body) => {
if (error) {
reject(error);
}
else if (response.statusCode !== 200) {
reject(response.statusCode);
}
else {
resolve(body);
}
});
});
示例7: request
}, req.user).then((file: any) => {
if (file.dataSize > ((1024 * 1024) * 10)) {
return res.status(500).send('big-data');
}
request({
url: file.url,
encoding: null
}, (getFileErr: any, response: http.IncomingMessage, body: Buffer) => {
if (getFileErr !== null) {
console.error(getFileErr);
return res.status(500).send(getFileErr.body);
}
gm(body, file.name)
.crop(trimW, trimH, trimX, trimY)
.toBuffer('png', (err: Error, buffer: Buffer) => {
if (err !== null) {
console.error(err);
return res.status(500).send('something-happened');
}
requestApi('album/files/upload', {
file: {
value: buffer,
options: {
filename: `${file.name}.cropped.png`,
contentType: 'image/png'
}
}
}, req.user, true).then((albumFile: any) => {
requestApi('account/avatar/update', {
'file-id': albumFile.id
}, req.user).then((me: Object) => {
res.send('success');
}, (updateErr: any) => {
return res.status(500).send(updateErr.body);
});
}, (uploadErr: any) => {
return res.status(500).send(uploadErr.body);
});
});
});
});
示例8: request
return new Promise<void>((resolve, reject) => {
request({
url: 'https://www.google.com/recaptcha/api/siteverify',
method: 'POST',
form: {
'secret': config.recaptchaSecretKey,
'response': response
}
}, (err, response, body) => {
if (err !== null) {
reject('request-failed');
return;
}
const parsed: any = JSON.parse(body);
if (parsed.success) {
resolve();
} else {
reject('recaptcha-failed');
}
});
});
示例9: Promise
return new Promise((resolve, reject) => {
request(options, (error, response, body) => {
if (error) {
reject(error)
return
}
if (response.statusCode !== 200) {
reject(
new Error(
`Received a non-200 response (${
response.statusCode
}): ${JSON.stringify(body)}`
)
)
return
}
resolve()
})
})
示例10: request
return new Promise<http.Server>((resolve, reject) => {
request(
{
url: uri,
method: 'GET',
headers: {
accept:
'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
},
},
(error, response, body) => {
if (error) {
reject(error);
} else {
expect(body).toMatch('GraphQLPlayground');
expect(response.statusCode).toEqual(200);
resolve();
}
},
);
});