Skip to content

bots-squad/tentacle-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tentacle-js 🦑

GitHub API + ES2015 + node.js

initial work: https://github.com/github/platform-samples/tree/master/api/javascript/es2015-nodejs

Setup

  • type npm install
  • you need the content of libs/*

Use /libs/GitHubClient.js

This library can work with :octocat:.com and :octocat: Enterprise

Create a GitHub client

  • First, go to your GitHub profile settings and define a Personal access token (https://github.com/settings/tokens)
  • Then, add the token to the environment variables (eg: export TOKEN_GITHUB_DOT_COM=token_string)
  • Now you can get the token like that: process.env.TOKEN_GITHUB_DOT_COM
const GitHubClient = require('../libs/GitHubClient.js').GitHubClient;

let githubCliEnterprise = new GitHubClient({
  baseUri: "http://github.at.home/api/v3",
  token: process.env.TOKEN_GHITHUB_ENTERPRISE
});

let githubCliDotCom = new GitHubClient({
  baseUri:"https://api.github.com",
  token: process.env.TOKEN_GITHUB_DOT_COM
});
  • if you use GitHub Enterprise, baseUri has to be set with http(s)://your_domain_name/api/v3
  • if you use GitHub.com, baseUri has to be set with https://api.github.com

Use the GitHub client

For example, you want to get the information about a user: (see https://developer.github.com/v3/users/#get-a-single-user)

let githubCliEnterprise = new GitHubClient({
  baseUri:"http://github.at.home/api/v3",
  token:process.env.TOKEN_GHITHUB_ENTERPRISE
});

var handle = "k33g";
githubCliEnterprise.getData({path:`/users/${handle}`})
  .then(response => {
    console.log(response.data);
  });

The easier way: adding features

You can add "features" to GitHubClient (like traits):

const GitHubClient = require('../libs/GitHubClient.js').GitHubClient;
const octocat = require('../libs/features/octocat');
const users = require('../libs/features/users');

// add octocat and users features to GitHubClient
let githubCli = new GitHubClient({
  baseUri:"http://github.at.home/api/v3",
  token:process.env.TOKEN_GHITHUB_ENTERPRISE
}, octocat, users);

githubCli.octocat()
  .then(data => {
    // display the Zen of Octocat
    console.log(data);
  })

githubCli.fetchUser({handle:'k33g'})
  .then(user => {
    // all about @k33g
    console.log(user);
  })

Recipes (and features)

See the /recipes directory (more samples to come)

About

GitHub API + ES2015 + node.js

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published