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

microsoft/ghrequestor: A resilient, rate-limit aware GitHub API client.

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

开源软件名称:

microsoft/ghrequestor

开源软件地址:

https://github.com/microsoft/ghrequestor

开源编程语言:

JavaScript 100.0%

开源软件介绍:

Version License Downloads

GHRequestor

A simple, resilient GitHub API client that:

  • Is great for bulk fetching of resources from the GitHub API.
  • Retries on errors and various forms of rate-limiting.
  • Backs off as you reach your API limit.
  • Automatically fetches all pages of a multi-page resource.
  • Uses etags to conserve API tokens and be kind to GitHub.
  • Reports comprehensive data on number of pages fetched, retry attempts, and length of delays.

GHRequestor is a relatively low-level facility intended for traversing large graphs of GitHub resources. Its primary usecase is GHCrawler, an engine that walks subsections of GitHub collecting related resources. This not intended to replace great modules like octonode or github.

Usage

The API is modelled after the standard node request libarary and the underlying requestretry library. It works with promises or callbacks and allows you to create pre-initialized requestor instances (with options setup) for injection into subsystems etc.

Simple GET of a single page

const ghrequestor = require('ghrequestor');
ghrequestor.get('https://api.github.com/repos/Microsoft/ghrequestor').then(response => {
  console.log(response.body);
});

GET a resource that spans multiple pages and flatten the responses into a single array. Notice the result includes an activity property detailing the requests and responses that went into getting the final result. You can swap getAll with getAllResponses to get back the raw responses rather than flattened array of values.

const ghrequestor = require('ghrequestor');
ghrequestor.getAll('https://api.github.com/repos/Microsoft/ghrequestor/commits').then(result => {
  console.log(result.length);
  console.log(result.activity.length);
  console.log(result.activity[0].attempts);
});

GET with a set of etags and a content supplier that has the etagged resources. With this you can integrate an in-memory or persistent cache of GitHub resources and let ghrequestor optimize the fetching and your use of API tokens. It's nicer on the GitHub infrastructure as well. Notice that the etag value include the "s.

const ghrequestor = require('ghrequestor');
const url = <some url>;
ghrequestor.getAllResponses(url, { etags: ['"42"']}).then(responses => {
  const supplier = url => { return yourContentLookupCode(); };
  return ghrequestor.flattenResponses(responses, supplier).then(results => {
    console.log(results.length);
  });
});

Authentication

Authentication is handled the same as with Node's request when using optoins and headers. You can either pass the authorization header in with each call or create a request template that has the authorization header set.

ghrequestor.get(url, { authorization: 'token <my token here>' });

Or

const requestorTemplate = ghrequestor.defaults({ authorization: 'token <my token here>' });
requestorTemplate.get(url);

Logging

ghrequestor takes a winston-style logger as a logger option. Set that option on each call or in a template

const winston = require('winston');
const requestorTemplate = ghrequestor.defaults({ logger: winston });
requestorTemplate.get(url);

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.




鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
jigalin/portfolio-landing-page: 发布时间:2022-06-11
下一篇:
vkamiansky/github-supervision-api: An API gateway for GitHub project activities ...发布时间:2022-06-11
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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