diff --git a/README.md b/README.md index 4d0eef3..d4bd821 100644 --- a/README.md +++ b/README.md @@ -41,16 +41,13 @@ export async function getGithubTopicsFromGithub() { // run the example await getGithubTopicsFromGithub(); -// TODO ... -// if you need a part of the project information -// github-api.project.topics - -// if you need a part of the user information -// github-api.user.avatar_url - --- ``` +## Usage of other APIs + +look in the tests: test.ts + ## github API has a hourly based rate limit if this limit is reached in a hour, then @@ -72,7 +69,9 @@ see [github - rest - resources-in-the-rest-api - rate-limiting](https://docs.git ### getGithubTopics(loginName, projectName, infoLog, isProd) -get project topics as a Array +get github project topics as a Array + +deprecated: use githubApiGetProject() with pathExpression constant GITHUB_PROJECT_TOPICS #### loginName @@ -117,13 +116,13 @@ i.e. look in the tests: test.ts -## API - not yet implemented +## API - new implemented -### github-api(loginName, projectName?, infoLog, isProd) +### githubApiGetProject(loginName, projectName, pathExpression, infoLog, isProd) -get project info or user info +get github project info - reduce with pathExpression constants -Returns a `Promise` with the project info or user info +Returns a `Promise` with the project info #### loginName @@ -131,11 +130,17 @@ Type: `String` The github login name -#### projectName (optional) +#### projectName + +Type: `String` + +The github project name of the project of a user login + +#### pathExpression Type: `String` -The github project namen of the project of a user login +filter the project name of the project of a user login #### infoLog @@ -153,13 +158,47 @@ true Calls fetch to github api, false returns mock data with same structure Returns a `Promise` -with a Json / Object of a project +with a Json / Object of a project reduced with pathExpression -or +see Example answer Json / Object of a project -with a Json / Object of a user login if only loginName is set +### githubApiGetLogin(loginName, pathExpression, infoLog, isProd) -see Example answer Json / Object of a project +get github user info - reduce with pathExpression constants + +Returns a `Promise` with the project info or user info + +#### loginName + +Type: `String` + +The github login name + +#### pathExpression + +Type: `String` + +filter the project namen of the project of a user login + +#### infoLog + +Type: `boolean` + +true Logs group and info into the console + +#### isProd + +Type: `boolean` + +true Calls fetch to github api, false returns mock data with same structure + +#### return + +Returns a `Promise` + +with a Json / Object of a user login reduced with pathExpression + +see Example answer Json / Object of a login of a user ## Example answer Json / Object of a project @@ -173,8 +212,17 @@ Github Meta Data of project 'roebi/01-01-vanilla-HTML5-starter-page' "login": "roebi", ... }, + "html_url": "https://github.com/roebi/01-01-vanilla-HTML5-starter-page", "description": "vanilla HTML 5 starter page - Have you ever heard of this HTML 5 tags ?", ... + "url": "https://api.github.com/repos/roebi/01-01-vanilla-HTML5-starter-page", + ... + "homepage": "https://roebi.github.io/01-01-vanilla-HTML5-starter-page/", + ... + "license": { + "key": "unlicense", + }, + ... "topics": [ "html5", "html5-template", @@ -195,6 +243,9 @@ Github Meta Data of user login 'roebi' ... "avatar_url": "...", ... + "url": "https://api.github.com/users/roebi", + "html_url": "https://github.com/roebi", + ... "location": "Switzerland", ... "bio": "..." diff --git a/consts.d.ts b/consts.d.ts index 06af829..98e332b 100644 --- a/consts.d.ts +++ b/consts.d.ts @@ -1,2 +1,4 @@ +export declare const GITHUB_PROJECT_TOPICS = "$.topics[*]"; +export declare const GITHUB_LOGIN_AVATAR_URL = "$.avatar_url"; export declare const GITHUB_API_BASE_URL = "https://api.github.com/"; export declare const GITHUB_HTML_BASE_URL = "https://github.com/"; diff --git a/consts.js b/consts.js index 90e1772..ea7883e 100644 --- a/consts.js +++ b/consts.js @@ -1,7 +1,15 @@ // Place any global data in this file. // You can import this data from anywhere in your project by using the `import` keyword. +// pathExpression constant for github-api-get-project +export const GITHUB_PROJECT_TOPICS = "$.topics[*]"; +// pathExpression constant for github-api-get-login +export const GITHUB_LOGIN_AVATAR_URL = "$.avatar_url"; +// github constants +// github api base url export const GITHUB_API_BASE_URL = "https://api.github.com/"; +// github HTML base url // example https://github.com/roebi/01-02-Webserver-in-Go-on-Podman export const GITHUB_HTML_BASE_URL = "https://github.com/"; +// examples // export const GITHUB_LOGIN = "roebi"; // export const GITHUB_OWNER_HTML_URL = GITHUB_HTML_BASE_URL + GITHUB_LOGIN + "/"; diff --git a/consts.ts b/consts.ts index d2bf85e..5e255d8 100644 --- a/consts.ts +++ b/consts.ts @@ -1,10 +1,24 @@ // Place any global data in this file. // You can import this data from anywhere in your project by using the `import` keyword. +// pathExpression constant for github-api-get-project + +export const GITHUB_PROJECT_TOPICS = "$.topics[*]"; + +// pathExpression constant for github-api-get-login + +export const GITHUB_LOGIN_AVATAR_URL = "$.avatar_url"; + +// github constants + +// github api base url export const GITHUB_API_BASE_URL = "https://api.github.com/"; +// github HTML base url // example https://github.com/roebi/01-02-Webserver-in-Go-on-Podman export const GITHUB_HTML_BASE_URL = "https://github.com/"; +// examples + // export const GITHUB_LOGIN = "roebi"; // export const GITHUB_OWNER_HTML_URL = GITHUB_HTML_BASE_URL + GITHUB_LOGIN + "/"; diff --git a/coverage/consts.js.html b/coverage/consts.js.html index 4170f40..77251d0 100644 --- a/coverage/consts.js.html +++ b/coverage/consts.js.html @@ -22,7 +22,7 @@

All files consts.js

100% Statements - 7/7 + 15/15
@@ -40,7 +40,7 @@

All files consts.js

100% Lines - 7/7 + 15/15

@@ -63,7 +63,23 @@

All files consts.js

5 6 7 -81x +8 +9 +10 +11 +12 +13 +14 +15 +161x +1x +1x +1x +1x +1x +1x +1x +1x 1x 1x 1x @@ -72,9 +88,17 @@

All files consts.js

1x  
// Place any global data in this file.
 // You can import this data from anywhere in your project by using the `import` keyword.
+// pathExpression constant for github-api-get-project
+export const GITHUB_PROJECT_TOPICS = "$.topics[*]";
+// pathExpression constant for github-api-get-login
+export const GITHUB_LOGIN_AVATAR_URL = "$.avatar_url";
+// github constants
+// github api base url
 export const GITHUB_API_BASE_URL = "https://api.github.com/";
+// github HTML base url
 // example https://github.com/roebi/01-02-Webserver-in-Go-on-Podman
 export const GITHUB_HTML_BASE_URL = "https://github.com/";
+// examples
 // export const GITHUB_LOGIN = "roebi";
 // export const GITHUB_OWNER_HTML_URL = GITHUB_HTML_BASE_URL + GITHUB_LOGIN + "/";
  
@@ -86,7 +110,7 @@

All files consts.js