@@ -10,41 +10,42 @@ This module is mainly used in the [@api-components/api-console-builder](https://
1010
1111Shorthand functions:
1212
13- - ` latestInfo(logger) ` -> ` new ApiConsoleGithubResolver #getLatestInfo() `
14- - ` tagInfo(tag, logger) ` -> ` new ApiConsoleGithubResolver #getTagInfo(tag) `
15- - ` releasesInfo(logger) ` -> ` new ApiConsoleGithubResolver #getReleasesList() `
13+ - ` latestInfo(logger) ` -> ` new GithubResolver #getLatestInfo() `
14+ - ` tagInfo(tag, logger) ` -> ` new GithubResolver #getTagInfo(tag) `
15+ - ` releasesInfo(logger) ` -> ` new GithubResolver #getReleasesList() `
1616
17- The module exposes 2 classes:
17+ The module exposes 4 classes:
1818
19- - [ ApiConsoleTransport] ( lib/transport.js )
20- - [ ApiConsoleGithubResolver] ( lib/github-resolver.js )
19+ - [ Transport] ( lib/Transport.js )
20+ - [ GithubResolver] ( lib/GithubResolver.js )
21+ - [ GithubResolverOptions] ( lib/GithubResolverOptions.js )
22+ - [ GithubCache] ( lib/GithubCache.js )
2123
2224### Example
2325
2426``` javascript
25- const resolver = require ( ' api-console-github-resolver' ) ;
27+ import { latestInfo } from ' @ api-components/api- console-github-resolver' ;
2628
27- resolver . latestInfo (winstonLogger)
28- . then ( info => console . log (info))
29- . catch ( cause => console .error (cause) );
29+ const winstonLogger = new winston.createLogger ({ ... });
30+ const info = await latestInfo (winstonLogger);
31+ console .log (info );
3032```
3133
3234equivalent to
3335
3436``` javascript
35- const { ApiConsoleGithubResolver } = require ( ' api-console-github-resolver' ) ;
37+ import { GithubResolver } from ' @ api-components/api- console-github-resolver' ;
3638
37- const resolver = new ApiConsoleGithubResolver ({
39+ const resolver = new GithubResolver ({
3840 logger: winstonLogger
3941});
40- resolver .getLatestInfo ()
41- .then (info => console .log (info))
42- .catch (cause => console .error (cause));
42+ const info = await resolver .getLatestInfo ();
43+ console .log (info);
4344```
4445
45- ### ApiConsoleTransport
46+ ### Transport
4647
47- GitGub transport class.
48+ GitHub transport class.
4849The transport is based on the HTTPS protocol.
4950
5051#### ` get(resource, headers) `
@@ -57,21 +58,20 @@ Gets a resource from given location. This function fallows redirects.
5758
5859##### Returns ` <Promise> `
5960
60- A promise resolved to a JavaScript ` Object ` if compatible content type is detected
61- or to ` Buffer ` otherwise.
61+ A promise resolved to a JavaScript ` Object ` if compatible content type is detected or to ` Buffer ` otherwise.
6262
6363#### Example
6464
6565``` javascript
66- const { ApiConsoleTransport } = require ( ' api-console-github-resolver' ) ;
67- const winston = require ( ' winston ' );
68- const transport = new ApiConsoleTransport ( createLogger (winston) );
69- transport . get ( ' https://... ' , { ' etag ' : ' abc ' })
70- . then (( response ) => console . log (response))
71- . catch (( cause ) => console .error (response) );
66+ import { Transport } from ' @ api-components/api- console-github-resolver' ;
67+
68+ const winstonLogger = new winston. createLogger ({ ... } );
69+ const transport = new Transport (winstonLogger);
70+ const response = await transport . get ( ' https://... ' , { ' etag ' : ' abc ' });
71+ console .log (response);
7272```
7373
74- ### ApiConsoleGithubResolver
74+ ### GithubResolver
7575
7676A class to resolve GitHub repositories versions. It allows to get latest release
7777version and the url to the release's zip file or list available versions.
@@ -110,16 +110,16 @@ GitHub allows to make up to 60 requests per hour. To increate the limit you can
110110use [ GitHub personal token] ( https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/ ) as an option passed to the ` ApiConsoleGithubResolver ` class constructor.
111111
112112### Example
113+
113114``` javascript
114- const { ApiConsoleGithubResolver } = require ( ' api-console-github-resolver' ) ;
115+ import { GithubResolver } from ' @ api-components/api- console-github-resolver' ;
115116
116- const TOKEN = ' ABCx ' ;
117- const resolver = new ApiConsoleGithubResolver ({
117+ const TOKEN = ' ABC ' ;
118+ const resolver = new GithubResolver ({
118119 token: TOKEN
119120});
120- resolver .getLatestInfo ()
121- .then (info => console .log (info))
122- .catch (cause => console .error (cause));
121+ const info = await resolver .getLatestInfo ();
122+ console .log (info);
123123```
124124
125125Module's shorthand functions reads ` GITHUB_TOKEN ` environmental variable and
@@ -129,14 +129,13 @@ sets it as a configuration option by default.
129129
130130``` javascript
131131// index.js
132- const resolver = require ( ' api-console-github-resolver' ) ;
132+ import { latestInfo } from ' @ api-components/api- console-github-resolver' ;
133133
134- resolver .latestInfo ()
135- .then (info => console .log (info))
136- .catch (cause => console .error (cause));
134+ const info = await latestInfo ();
135+ console .log (info);
137136```
138137
139138``` shell
140- $ export GITHUB_TOKEN=" ABCx "
139+ $ export GITHUB_TOKEN=" ABC "
141140$ node index.js
142141```
0 commit comments