本文整理汇总了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);
}
开发者ID:sarthakfx,项目名称:BotFramework-Emulator,代码行数:19,代码来源:emulator.ts
示例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);
});
});
开发者ID:2fd,项目名称:graphdoc,代码行数:20,代码来源:http.ts
示例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);
}
});
});
开发者ID:consumr-project,项目名称:cp,代码行数:20,代码来源:recaptcha.ts
示例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}`));
}
});
});
开发者ID:murraypaul,项目名称:mangarack,代码行数:20,代码来源:httpService.ts
示例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()
));
}
}
});
});
开发者ID:cyrilpanicker,项目名称:stock-scope,代码行数:20,代码来源:yahooService.ts
示例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);
}
});
});
开发者ID:ahejlsberg,项目名称:typescript-build2016-demos,代码行数:20,代码来源:promisified-io.ts
示例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);
});
});
});
});
开发者ID:sagume,项目名称:Misskey-Web,代码行数:41,代码来源:update.ts
示例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');
}
});
});
开发者ID:syuilo,项目名称:ssmato.me,代码行数:21,代码来源:recaptcha.ts
示例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()
})
})
开发者ID:ghmoore,项目名称:desktop,代码行数:21,代码来源:publish.ts
示例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();
}
},
);
});
开发者ID:simonjoom,项目名称:react-native-project,代码行数:21,代码来源:ApolloServer.test.ts
注:本文中的request类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论