• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript common.request函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: sendJobState

  sendJobState(jobId: string, data: JobState): CancellablePromise<void> {
    const payload = JSON.stringify({
      status: data.status || data.success ? 'completed' : 'error'
    });

    const url = `https://www.browserstack.com/automate/sessions/${jobId}.json`;
    return request(url, {
      method: 'put',
      data: payload,
      headers: {
        'Content-Length': String(Buffer.byteLength(payload, 'utf8')),
        'Content-Type': 'application/json'
      },
      password: this.accessKey,
      username: this.username,
      proxy: this.proxy
    }).then<void>(response => {
      if (response.status < 200 || response.status >= 300) {
        return response.text().then(text => {
          throw new Error(
            text || `Server reported ${response.status} with no other data.`
          );
        });
      }
    });
  }
开发者ID:theintern,项目名称:digdug,代码行数:26,代码来源:BrowserStackTunnel.ts


示例2: loadText

/**
 * Load a text resource
 */
function loadText(path: string): CancellablePromise<any> {
  return request(path).then(response => {
    if (!response.ok) {
      throw new Error('Request failed: ' + response.status);
    }
    return response.text();
  });
}
开发者ID:edhager,项目名称:intern,代码行数:11,代码来源:util.ts


示例3: sendJobState

  sendJobState(jobId: string, data: JobState): CancellablePromise<void> {
    const params: { [key: string]: string | number } = {};

    if (data.success != null) {
      params['test[success]'] = String(data.success ? 1 : 0);
    }
    if (data.status) {
      params['test[status_message]'] = data.status;
    }
    if (data.name) {
      params['test[name]'] = data.name;
    }
    if (data.extra) {
      params['test[extra]'] = JSON.stringify(data.extra);
    }
    if (data.tags && data.tags.length) {
      params['groups'] = data.tags.join(',');
    }

    const url = `https://api.testingbot.com/v1/tests/${jobId}`;
    const payload = stringify(params);
    return request(url, {
      method: 'put',
      data: payload,
      headers: {
        'Content-Length': String(Buffer.byteLength(payload, 'utf8')),
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      password: this.accessKey,
      username: this.username,
      proxy: this.proxy
    }).then(function(response) {
      return response.text().then(text => {
        if (text) {
          const data = JSON.parse(text);

          if (data.error) {
            throw new Error(data.error);
          } else if (!data.success) {
            throw new Error('Job data failed to save.');
          } else if (response.status !== 200) {
            throw new Error(`Server reported ${response.status} with: ${text}`);
          }
        } else {
          throw new Error(
            `Server reported ${response.status} with no other data.`
          );
        }
      });
    });
  }
开发者ID:theintern,项目名称:digdug,代码行数:51,代码来源:TestingBotTunnel.ts


示例4: _sendMessages

  /**
   * Some testing services have problems handling large message POSTs, so
   * limit the maximum size of each POST body to maxPostSize bytes. Always
   * send at least one message, even if it's more than maxPostSize bytes.
   */
  protected _sendMessages(): CancellablePromise<any> | undefined {
    const messages = this._messageBuffer;
    if (messages.length === 0) {
      return;
    }

    const block = [messages.shift()!];

    let size = block[0].message.length;
    while (
      messages.length > 0 &&
      size + messages[0].message.length < this._maxPostSize
    ) {
      size += messages[0].message.length;
      block.push(messages.shift()!);
    }

    this._activeRequest = request(this.url, {
      method: 'post',
      headers: { 'Content-Type': 'application/json' },
      data: block.map(entry => entry.message)
    })
      .then(response => {
        if (response.status === 200) {
          return response.json<any[]>();
        } else if (response.status === 204) {
          return [];
        } else {
          throw new Error(response.statusText);
        }
      })
      .then((results: any[]) => {
        block.forEach((entry, index) => {
          entry.resolve(results[index]);
        });
      })
      .catch(error => {
        block.forEach(entry => {
          entry.reject(error);
        });
      })
      .finally(() => {
        this._activeRequest = undefined;
        if (messages.length > 0) {
          return this._sendMessages();
        }
      });

    return this._activeRequest;
  }
开发者ID:edhager,项目名称:intern,代码行数:55,代码来源:Http.ts


示例5: sendJobState

  sendJobState(jobId: string, data: JobState): CancellablePromise<void> {
    let url = parseUrl(this.restUrl || 'https://saucelabs.com/rest/v1/');
    url.auth = this.username + ':' + this.accessKey;
    url.pathname += this.username + '/jobs/' + jobId;

    const payload = JSON.stringify({
      build: data.buildId,
      'custom-data': data.extra,
      name: data.name,
      passed: data.success,
      public: data.visibility,
      tags: data.tags
    });

    return request(formatUrl(url), {
      method: 'put',
      data: payload,
      headers: {
        'Content-Length': String(Buffer.byteLength(payload, 'utf8')),
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      password: this.accessKey,
      username: this.username,
      proxy: this.proxy
    }).then(function(response) {
      return response.text().then(text => {
        if (text) {
          const data = JSON.parse(text);

          if (data.error) {
            throw new Error(data.error);
          }

          if (response.status !== 200) {
            throw new Error(`Server reported ${response.status} with: ${text}`);
          }
        } else {
          throw new Error(
            `Server reported ${response.status} with no other data.`
          );
        }
      });
    });
  }
开发者ID:theintern,项目名称:digdug,代码行数:44,代码来源:SauceLabsTunnel.ts


示例6: sendJobState

  sendJobState(jobId: string, data: JobState): CancellablePromise<void> {
    const payload = JSON.stringify({
      action: 'set_score',
      score: data.status || data.success ? 'pass' : 'fail'
    });

    const url = `https://crossbrowsertesting.com/api/v3/selenium/${jobId}`;
    return request(url, {
      method: 'put',
      data: payload,
      headers: {
        'Content-Length': String(Buffer.byteLength(payload, 'utf8')),
        'Content-Type': 'application/json'
      },
      username: this.username,
      password: this.accessKey,
      proxy: this.proxy
    }).then<void>(response => {
      if (response.status !== 200) {
        return response.text().then(text => {
          if (text) {
            const data = JSON.parse(text);

            if (data.status) {
              throw new Error(`Could not save test status (${data.message})`);
            }

            throw new Error(`Server reported ${response.status} with: ${text}`);
          } else {
            throw new Error(
              `Server reported ${response.status} with no other data.`
            );
          }
        });
      }
    });
  }
开发者ID:theintern,项目名称:digdug,代码行数:37,代码来源:CrossBrowserTestingTunnel.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript common.CancellablePromise类代码示例发布时间:2022-05-28
下一篇:
TypeScript uri.toString函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap