當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript request-promise.get函數代碼示例

本文整理匯總了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);
 }
開發者ID:billbliss,項目名稱:microsoft-teams-sample-auth-node,代碼行數:10,代碼來源:GoogleProvider.ts

示例2: getProfileAsync

 public async getProfileAsync(accessToken: string): Promise<any> {
     let options = {
         url: graphProfileUrl,
         json: true,
         headers: {
             "Authorization": `Bearer ${accessToken}`,
         },
     };
     return await request.get(options);
 }
開發者ID:billbliss,項目名稱:microsoft-teams-sample-auth-node,代碼行數:10,代碼來源:AzureADv1Provider.ts

示例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;
    }
}
開發者ID:be9,項目名稱:es7test,代碼行數:11,代碼來源:test2.ts

示例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)
}
開發者ID:Tsaude,項目名稱:GustieMenu,代碼行數:12,代碼來源:gustavus-menu.ts

示例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(`
  ]
}`)
}
開發者ID:osmottawa,項目名稱:imports,代碼行數:53,代碼來源:get-data-address.ts

示例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);
    }
開發者ID:billbliss,項目名稱:microsoft-teams-sample-auth-node,代碼行數:15,代碼來源:LinkedInProvider.ts

示例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;
   }
 }
開發者ID:duniter,項目名稱:duniter,代碼行數:17,代碼來源:contacter.ts

示例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);
        };
開發者ID:billbliss,項目名稱:microsoft-teams-sample-auth-node,代碼行數:63,代碼來源:GetProfileFromGraph.ts

示例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(`
  ]
}`)
}
開發者ID:osmottawa,項目名稱:imports,代碼行數:62,代碼來源:get-data-buildings.ts

示例10: getJsonDataAsPromise

function getJsonDataAsPromise(url: string) {
  return rp.get(url, {
    json: true
  }).promise();
}
開發者ID:WBittner,項目名稱:OptimumValor,代碼行數:5,代碼來源:leagueStaticData.ts


注:本文中的request-promise.get函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。