当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript sync-request.default函数代码示例

本文整理汇总了TypeScript中sync-request.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了default函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: request

                (session: any, results: any) => {
                    session.send('Ok!');
                    session.send('Here is the nearest store I have found. A seller will be able to answer your questions. :)');
                    var address = "3 bis, rue rottembourg 75012 PARIS" //results.response;
                    var res = request('GET', 'http://dev.virtualearth.net/REST/v1/Locations?countryRegion=FR&key=AsiCMSmOq6O3MzsI4F7HqUXmB2JY7E76gdaCgtlranURBYOHgbariAXQxJURoTE8&addressLine=' + address);
                    var bing = JSON.parse(res.getBody('utf8'));
                    if (bing.resourceSets[0].estimatedTotal) {
                        let lat = bing.resourceSets[0].resources[0].point.coordinates[0];
                        let lng = bing.resourceSets[0].resources[0].point.coordinates[1];
                        this._store = [Number.MAX_SAFE_INTEGER, null];
                        for (let i = 0, len = this._stores.length; i < len; i++) {
                            let distance = this._geolocalisation.getDistanceFromLatLonInKm(lat, lng, this._stores[i].localisation.lat, this._stores[i].localisation.lng)
                            if (distance < this._store[0]) {
                                this._store[0] = distance;
                                this._store[1] = this._stores[i];
                            }
                        }

                        var msg = new builder.Message(session)
                            .textFormat(builder.TextFormat.xml)
                            .attachmentLayout(builder.AttachmentLayout.carousel)
                            .attachments([
                                new builder.HeroCard(session)
                                    .title(this._store[1].name)
                                    .text("12 Rue Halévy, 75009 Paris")
                                    .images([
                                        builder.CardImage.create(session, "http://www.timstanleyphoto.com/HDR/2012/i-GrS2b37/0/L/MicrosoftStore-L.jpg")
                                            .tap(builder.CardAction.showImage(session, "http://www.timstanleyphoto.com/HDR/2012/i-GrS2b37/0/L/MicrosoftStore-L.jpg")),
                                    ])
                                    .buttons([
                                        builder.CardAction.openUrl(session, "http://bing.com/maps/default.aspx?rtp=adr." + "39%20quai%20du%20president%20roosevelt%2092130%20issy%20les%20moulineaux" + "~adr." + "12 Rue Halévy, 75009 Paris" + "&rtop=0~1~0", "Bing Direction"),
                                        builder.CardAction.imBack(session, "Let's go !", "Go")
                                    ])
                            ]);
                        builder.Prompts.choice(session, msg, "Let's go !");

                    } else {
                        session.send('I cannot find a store near you, try with a different address');
                    }
                },
开发者ID:DXFrance,项目名称:botretail,代码行数:40,代码来源:retailbot.dialogsManager.ts

示例2: request

    function request(method, url, opts: IOpts): IResponse {
        if(!opts) {
            opts = {
                headers: null,
                body: null,
            };
        }

        // For convenience prepend 'http://' automatically.
        var parts = urllib.parse(url);
        if(!parts.protocol) url = 'http://' + url;

        return requestlib(method, url, opts);
    }
开发者ID:streamich,项目名称:jssh-api-jssh,代码行数:14,代码来源:REQUEST.ts

示例3: it

 it("the cache time is just one day", () => {
   let theUrl = scriptUrl;
   for (let i = 0; i < 3; ++i) {
     const response = syncRequest('GET', theUrl);
     const headers = response.headers;
     if (headers['cache-control'] !== desiredCacheHeader) {  // [2WBKP46]
       console.log("Bad es-comments.min.js cache time, look at the cache header:\n" +
           JSON.stringify(headers));
       assert(false);
     }
     if (i === 0) theUrl = scriptUrl2;
     else theUrl = scriptUrl3;
   }
 });
开发者ID:,项目名称:,代码行数:14,代码来源:

示例4: getOrDie

function getOrDie(url) {
  dieIf(!settings.e2eTestPassword, "No E2E test password specified [EsE7YKF2]");
  logMessage('GET ' + url);

  var passwordParam =
      (url.indexOf('?') === -1 ? '?' : '&') + 'e2eTestPassword=' + settings.e2eTestPassword;

  var response = syncRequest('GET', url + passwordParam, { headers: {
    'X-XSRF-TOKEN': xsrfTokenAndCookies[0],
    'Cookie': xsrfTokenAndCookies[1]
  }});

  dieIf(response.statusCode !== 200, "GET request failed to " + url + " [EsE8JYT4]",
      showResponse(response));
  return response;
}
开发者ID:istrwei,项目名称:debiki-server,代码行数:16,代码来源:server.ts

示例5: postOrDie

function postOrDie(url, data, opts: { apiUserId?: number, apiSecret?: string,
      retryIfXsrfTokenExpired?: Boolean } = {}): { statusCode: number, headers, bodyJson } {
  dieIf(!settings.e2eTestPassword, "No E2E test password specified [EsE2WKG4]");

  const passwordParam =
      (url.indexOf('?') === -1 ? '?' : '&') + 'e2eTestPassword=' + settings.e2eTestPassword;

  // Authentication headers.
  // Either use Bausic Authentication, if we're doing an API request with an API secret,
  // or include an xsrf cookie if something else.
  const headers = opts.apiUserId
    ? {
        'Authorization': 'Basic ' +
            utils.encodeInBase64(`talkyardId=${opts.apiUserId}:${opts.apiSecret}`)
      }
    : (!xsrfTokenAndCookies ? {} : {
        'X-XSRF-TOKEN': xsrfTokenAndCookies[0],
        'Cookie': xsrfTokenAndCookies[1]
      });

  logMessage(`POST ${url}, headers: ${ JSON.stringify(headers) } ... [TyME2EPOST]`);

  const response = syncRequest('POST', url + passwordParam, { json: data, headers: headers });
  const responseBody = getResponseBodyString(response);

  //console.log('\n\n' + url + '  ——>\n' + responseBody + '\n\n');
  if (response.statusCode !== 200 && responseBody.indexOf('TyEXSRFEXP_') >= 0 &&
      opts.retryIfXsrfTokenExpired !== false) {
    // The xsrf token expires, if we playTime...() too much.
    logMessage("Getting a new xsrf token; the old one has expired ...");
    initOrDie(settings);
    logMessage("... Done getting new xsrf token.");
    return postOrDie(url, data, { ...opts, retryIfXsrfTokenExpired: false });
  }

  dieIf(response.statusCode !== 200, "POST request failed to " + url + " [EsE5GPK02]",
      showResponse(response));

  return {
    statusCode: response.statusCode,
    headers: response.headers,
    bodyJson: function() {
      return JSON.parse(responseBody);
    }
  };
}
开发者ID:,项目名称:,代码行数:46,代码来源:

示例6: loadMetadataUrl

function loadMetadataUrl(urlstr: string): string
{
    var url = require("url");
    var u = url.parse(urlstr);

    if (u.protocol == null || u.protocol.toLowerCase() === 'file' || u.protocol.toLowerCase() ===  'file:')
    {
        var filename = u.pathname;
        return fs.readFileSync(filename, 'utf8');
    }
    else
    {
        var request = require('sync-request');
        var res = request('GET', urlstr);
        var metadata = res.getBody('utf8');
        
        return metadata;
    }
}
开发者ID:tschaumburg,项目名称:BreezeTypedefExtractor,代码行数:19,代码来源:metadata.ts

示例7: postOrDie

function postOrDie(url, data) {
  dieIf(!settings.e2eTestPassword, "No E2E test password specified [EsE2WKG4]");
  logMessage('POST ' + url + ' ...  [EsM5JMMK2]');

  var passwordParam =
      (url.indexOf('?') === -1 ? '?' : '&') + 'e2eTestPassword=' + settings.e2eTestPassword;

  var response = syncRequest('POST', url + passwordParam, { json: data, headers: {
    'X-XSRF-TOKEN': xsrfTokenAndCookies[0],
    'Cookie': xsrfTokenAndCookies[1]
  }});

  dieIf(response.statusCode !== 200, "POST request failed to " + url + " [EsE5GPK02]",
      showResponse(response));
  return {
    statusCode: response.statusCode,
    headers: response.headers,
    bodyJson: function() {
      return JSON.parse(response.getBody('utf8'));
    }
  };
}
开发者ID:istrwei,项目名称:debiki-server,代码行数:22,代码来源:server.ts

示例8: initOrDie

function initOrDie() {
  var response = syncRequest('GET', settings.mainSiteOrigin);
  dieIf(response.statusCode !== 200,
      "Error getting xsrf token and cookies from " + settings.mainSiteOrigin + " [EsE2FKE3]",
      showResponse(response));

  var cookieString = '';
  var xsrfToken = '';
  var cookies = response.headers['set-cookie'];
  _.each(cookies, function(cookie) {
    // A Set-Cookie header value looks like so: "name=value; options"
    var nameValueStr = cookie.split(';')[0];
    var nameAndValue = nameValueStr.split('=');
    var name = nameAndValue[0];
    var value = nameAndValue[1];
    cookieString += nameValueStr + '; ';
    if (name == 'XSRF-TOKEN') {
      xsrfToken = value;
    }
  });
  dieIf(!xsrfToken, "Got no xsrf token from " + settings.mainSiteOrigin + " [EsE8GLK2]");
  xsrfTokenAndCookies = [xsrfToken, cookieString];
}
开发者ID:istrwei,项目名称:debiki-server,代码行数:23,代码来源:server.ts

示例9: getDataFromPageSync

		/**
		 * Loads photo information from a National Geographic page synchronously.
		 * 
		 * @param {string} [url=this.config.baseUrl + 'photography/photo-of-the-dat/'] Set the URL which should be scraped.
		 * @returns {ImageData}
		 */
		public getDataFromPageSync(url: string = this.config.baseUrl + 'photography/photo-of-the-dat/'): photoData {
			return this.getDataFromHtml((syncRequest('GET', url).getBody()));
		}
开发者ID:HarveyWilliams,项目名称:NatGeo,代码行数:9,代码来源:potd.ts

示例10: getLatestArchivedPhotoUrlsSync

		/**
		 * Get URLs for the photo of the day fron the archive, sorted by latest released first.
		 * This method is not recommended as the web page may take a long time to respond.
		 * 
		 * @param {number} page The current page to look at, page 1 holding the most recent photos.
		 */
		public getLatestArchivedPhotoUrlsSync(page: number): string[] {
			let url = this.config.baseUrl + `/photography/photo-of-the-day/archive/?page=${page}&month=None`;

			return this.getArchivedPhotosFromHtml(syncRequest('GET', url).getBody());
		}
开发者ID:HarveyWilliams,项目名称:NatGeo,代码行数:11,代码来源:potd.ts


注:本文中的sync-request.default函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。