本文整理汇总了TypeScript中superagent.get函数的典型用法代码示例。如果您正苦于以下问题:TypeScript get函数的具体用法?TypeScript get怎么用?TypeScript get使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: reject
return new Promise<any>((resolve, reject) => {
if (_this.auth) {
superagent.get(_this.couchdb + "/" + _id).set('Content-Type', 'application/json').auth(_this.auth.user, _this.auth.password).end((err, res) => {
if (err) {
reject(err);
} else {
resolve(JSON.parse(res.text));
}
})
} else {
superagent.get(_this.couchdb + "/" + _id).set('Content-Type', 'application/json').end((err, res) => {
if (err) {
reject(err);
} else {
resolve(JSON.parse(res.text));
}
})
}
})
示例2: next
app.get('/', (req, res, next) => {
superagent.get('https://cnodejs.org/')
.end((err, sres) => {
// 常规的错误处理
if (err) {
return next(err);
}
// sres.text 里面存储着网页的html内容,将它传给cheerio.load 之后
// 就可以得到一个实现了jquery 接口的变量,我们习惯性地将它命名为‘$’
// 剩下的就是jquery 的内容
var $ = cheerio.load(sres.text);
var items = [];
$('#main .topic_title').each((index, element) => {
var $element = $(element);
// attr href title
items.push({
title: $element.attr('title'),
href: $element.attr('href'),
text:$element.text()
});
});
res.send(items);
});
});
示例3: deleteVirtualStudy
deleteVirtualStudy(id:string){
return request
.get(`${getVirtualStudyServiceUrl()}/delete/${id}`)
// @ts-ignore: this method comes from caching plugin and isn't in typing
.forceUpdate(true)
}
示例4: is_user_verified
request.get(request_api_user).query({access_token}).end(async (err, result) => {
let data = provider === 'github' ? result.body : JSON.parse(result.text)
let user:any = { id: data.id, email: data.email }
user.name = provider === 'github' ? data.login : data.name
user.verified = is_user_verified(provider, data)
if(provider === 'github' && !user.email) {
let resp_email = await request.get(EMAIL_API_GITHUB).query({access_token})
user.email = await get_primary_email(resp_email.body)
}
let found_user = await pendingUser.get(user.id)
const encryptedSocialEmail = CryptoJS.AES.encrypt(user.email, process.env.DECRYPT_KEY);
if(found_user) {
found_user.social_verified = user.verified
found_user.social_email = encryptedSocialEmail;
found_user.social_name = user.name
await found_user.save()
res.status(200).json({user: found_user, access_token})
} else {
let salt = generate_rnd_string(4)
user = await pendingUser.create({ social_name: user.name, social_id: user.id, social_verified: user.verified, social_email: encryptedSocialEmail, social_provider: provider, salt })
res.status(200).json({user, access_token})
}
})
示例5:
topicUrls.forEach((topicUrl) => {
superagent.get(topicUrl)
.end((err, res) => {
console.log('fetch ' + topicUrl + ' successful');
ep.emit('topic_html', [topicUrl, res.text]);
});
});
示例6: request
export function request(req, res, next) {
console.log('request');
var request = require('superagent');
// example of giving res.data precedence
var url = res.data.url || this.config.url;
if(url) {
request.get(url).end(function(ret) {
if(ret.ok) {
//res.data.context = JSON.parse(ret.text ? ret.text : ret.body);
// in case of json, we set .context
res.data.context = Object.keys(ret.body).length ? ret.body : ret.text;
} else {
res.data.context = { status: 'error', message: ret.text };
}
next();
});
} else {
res.data.context = { status: 'error', message: "request needs a config.url" };
next();
}
};
示例7: it
it("verificate working of 2 localization", function (done) {
superagent.get("https://emnetserver.kernel.online/auth/authorize/couchdb/testemnet/testemnet0101").end((err, res) => {
if (err) {
done(Error(err));
} else if (res && res.body && !res.body.error) {
const obj = res.body;
token = obj.token;
loc.setPosition(latlng2, token).then((c) => {
expect(loc.state).to.be.an('Object');
expect(c).to.be.an('Array');
expect(c[0]).to.be.an('Object');
expect(c[0].nativeName).to.be.a('string');
done()
}).catch((c) => {
done(Error(c))
})
} else {
done(Error(res.body.error))
}
})
})
示例8: return
return (dispatch: Redux.Dispatch) => {
superagent.get(`http://api.coindesk.com/v1/bpi/currentprice/${currency}.json`)
.end((err : Error, body : any) => {
if (!err && (body && body.text)) {
dispatch(ActionsCreators.getCurrentPrice(JSON.parse(body.text)));
}
});
};
示例9: co
return co(function *getAddressInfoFromExplorer() {
const addrInfo = yield request.get(this.recoveryBlockchainExplorerUrl(`/addr/${addressBase58}`)).result();
addrInfo.txCount = addrInfo.txApperances;
addrInfo.totalBalance = addrInfo.balanceSat;
return addrInfo;
}).call(this);