Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

libhub

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

libhub

Libraries.io Simple GitHub Client

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
increased by400%
Maintainers
2
Weekly downloads
 
Created
Source

LibHub

Libraries.io minimalistic GitHub client.

Features

  • Dead simple API
  • Promise based
  • Support for caching + conditional requests (optional)
  • Support for pagination using link headers

Requirements

  • Node.js v4.2.x

Getting Started

  const Client = require('libhub')
  let github = new Client(token)

  // GET
  github.get(`/repos/librariesio/libhub/issues`)
  .then( (issues) => {
    console.log(issues)
  })

  // POST
  github.post(`/repos/librariesio/libhub/issues`, {}, issueBody)
  .then( (issue) => {
    console.log(issue)
  })

Available methods: get, post, patch, put, delete

Error handling

  // 3xx/4xx/5xx errors
  github.get(`/repos/librariesio/${invalidId}`)
  .then( (repo) => {
    // This won't happen
  })
  .catch( (err) => {
    console.log(err.statusCode) // 404
  })

Caching

The Client constructor takes an optional cache object that should have a get and a set method. Both should return a Promise.

  const Client = require('libhub')
  const InMemoryCache = require('./test/cache')
  let github = new Client(token, { cache: InMemoryCache })

  github.get(`/repos/librariesio/libhub/issues`)
  .then( (issues) => {
    console.log(issues)
  })

Pagination

  github.get(`/events`, { allPages: true })
  .then( (events) => {
    console.log(events.length) // All the user public events ~300
  })

Why another GitHub client?

Well, simplicity. Most GitHub clients I used implement unnecessary abstractions. For example, octonode. This means that you need to check GitHub API documentation and Octonode documentation to perform any action. This gets boring pretty quickly.

With LibHub, you just need to lookup the resource URL and use it. Also, ES6 interpolation.

  github.get(`/repos/${owner}/${repo}/branches/${branch}`)

License

MIT

Keywords

FAQs

Package last updated on 11 Oct 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc