本文整理汇总了TypeScript中request-promise.get函数的典型用法代码示例。如果您正苦于以下问题:TypeScript get函数的具体用法?TypeScript get怎么用?TypeScript get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getProfileAsync
public async getProfileAsync(accessToken: string, personFields: PersonField[] = ["names"]): Promise<any> {
let options = {
url: `${meProfileUrl}?personFields=${personFields.join(",")}`,
json: true,
headers: {
"Authorization": `Bearer ${accessToken}`,
},
};
return await request.get(options);
}
示例2: getProfileAsync
public async getProfileAsync(accessToken: string): Promise<any> {
let options = {
url: graphProfileUrl,
json: true,
headers: {
"Authorization": `Bearer ${accessToken}`,
},
};
return await request.get(options);
}
示例3: getIP
async function getIP(): Promise<string> {
try {
let data = await rp.get({url: 'http://ipinfo.io/ip'});
return data;
} catch (err) {
console.log(err);
return undefined;
}
}
示例4: getMenu
export async function getMenu(req?: MenuRequest): Promise<GustavusMenu> {
let finalUrl: string
if (req) {
finalUrl = `${url}/${req.date}`
} else {
finalUrl = url
}
let html = await request.get(finalUrl)
return parseHTML(html)
}
示例5: main
async function main() {
const writer = fs.createWriteStream(path.join(__dirname, 'address.json'))
const api_url = 'http://maps.ottawa.ca/arcgis/rest/services/Property_Parcels/MapServer/0/query'
let count = 0
let first = false
const max = 250
const features: Array<GeoJSON.Feature<GeoJSON.Point>> = []
// Write Feature Collection Header
writer.write(`{
"type": "FeatureCollection",
"features": [
`)
while (true) {
const params = {
objectIds: range(count, count + max).join(','),
geometryType: 'esriGeometryEnvelope',
spatialRel: 'esriSpatialRelIntersects',
outFields: '*',
returnGeometry: 'true',
returnTrueCurves: 'false',
returnIdsOnly: 'false',
returnCountOnly: 'false',
returnDistinctValues: 'false',
outSR: 4326,
f: 'pjson',
}
const url = `${ api_url }?${ encodeData(params)}`
const r:InterfaceESRIResults = await rp.get(url)
.then(data => JSON.parse(data))
r.features.map(feature => {
const attributes = {
source: 'City of Ottawa'
}
const point = turf.point([feature.geometry.x, feature.geometry.y], feature.attributes)
if (!first) {
writer.write(` ${ JSON.stringify(point)}`)
first = true
} else writer.write(`,\n ${ JSON.stringify(point)}`)
})
// Stop or Start over
if (!r.features.length) break
console.log(count)
count += max
// if (count > 1000) break
}
writer.write(`
]
}`)
}
示例6: getProfileAsync
public async getProfileAsync(accessToken: string, fields?: ProfileField[]): Promise<any> {
let fieldsString = "";
if (fields && fields.length) {
fieldsString = `:(${fields.join(",")})`;
}
let options = {
url: `${apiBaseUrl}/people/~${fieldsString}?format=json`,
json: true,
headers: {
"Authorization": `Bearer ${accessToken}`,
},
};
return await request.get(options);
}
示例7: get
private async get(url:string, dtoContract:any, param?:any) {
if (typeof param === 'object') {
// Classical URL params (a=1&b=2&...)
param = '?' + Object.keys(param).map((k) => [k, param[k]].join('=')).join('&');
}
try {
const json = await rp.get({
url: Contacter.protocol(this.port) + this.fullyQualifiedHost + url + (param !== undefined ? param : ''),
json: true,
timeout: this.options.timeout
});
// Prevent JSON injection
return sanitize(json, dtoContract);
} catch (e) {
throw e.error;
}
}
示例8: async
return async (req: express.Request, res: express.Response) => {
let encodedToken = res.locals.encodedToken;
let token = res.locals.token;
let tenantId = token["tid"];
let graphAccessToken: string;
// The version of the endpoint to use for OBO flow must match the one used to get the initial token
switch (token.ver) {
case "1.0":
{
// AAD v1 endpoint token
let tokenEndpoint = `https://login.microsoftonline.com/${tenantId}/oauth2/token`;
let params = {
grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
assertion: encodedToken,
client_id: this.clientId,
client_secret: this.clientSecret,
resource: "https://graph.microsoft.com",
requested_token_use: "on_behalf_of",
scope: "openid",
} as any;
let tokenResponse = await request.post({ url: tokenEndpoint, form: params, json: true });
graphAccessToken = tokenResponse.access_token;
break;
}
case "2.0":
{
// AAD v2 endpoint token
let tokenEndpoint = `https://login.microsoftonline.com/${tenantId}/oauth2/v2.0/token`;
let params = {
grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
assertion: encodedToken,
client_id: this.clientId,
client_secret: this.clientSecret,
requested_token_use: "on_behalf_of",
scope: "https://graph.microsoft.com/User.Read",
} as any;
let tokenResponse = await request.post({ url: tokenEndpoint, form: params, json: true });
graphAccessToken = tokenResponse.access_token;
break;
}
default:
throw new Error(`Unsupported Azure AD endpoint version ${token.ver}`);
}
// The OBO grant flow can fail with error interaction_required if there are Conditional Access policies set.
// This example does not handle that. See https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-v2-protocols-oauth-on-behalf-of#error-response-example
// Get user profile from Graph
let options = {
url: "https://graph.microsoft.com/v1.0/me",
json: true,
headers: {
"Authorization": `Bearer ${graphAccessToken}`,
},
};
let profile = await request.get(options);
// Return profile as response
res.status(200).send(profile);
};
示例9: main
async function main() {
const writer = fs.createWriteStream(path.join(__dirname, 'ottawa-buildings.geojson'))
const api_url = 'http://maps.ottawa.ca/arcgis/rest/services/TopographicMapping/MapServer/3/query'
let count = 0
let first = false
let blank = 0
const max = 250
const features: Array<GeoJSON.Feature<GeoJSON.Polygon>> = []
// Write Feature Collection Header
writer.write(`{
"type": "FeatureCollection",
"features": [
`)
while (true) {
const params = {
objectIds: range(count, count + max).join(','),
geometryType: 'esriGeometryEnvelope',
spatialRel: 'esriSpatialRelIntersects',
returnGeometry: 'true',
returnTrueCurves: 'false',
returnIdsOnly: 'false',
returnCountOnly: 'false',
returnDistinctValues: 'false',
outSR: 4326,
f: 'pjson',
}
const url = `${ api_url }?${ encodeData(params)}`
const results:InterfaceESRIResults = await rp.get(url)
.then(data => JSON.parse(data))
.catch(error => console.log(error))
// Iterate over result
results.features.map(feature => {
const attributes = {
building: 'yes',
source: 'City of Ottawa'
}
const poly = turf.polygon(feature.geometry.rings, attributes)
if (!first) {
writer.write(` ${ JSON.stringify(poly)}`)
first = true
} else writer.write(`,\n ${ JSON.stringify(poly)}`)
})
// Stop or Start over process
if (!results.features.length) {
blank ++
console.log('blank')
}
if (blank > 50) {
console.log('break')
break
}
console.log(count)
count += max
}
writer.write(`
]
}`)
}
示例10: getJsonDataAsPromise
function getJsonDataAsPromise(url: string) {
return rp.get(url, {
json: true
}).promise();
}