hubhub

package module
v0.0.0-...-5b4983b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2019 License: MIT Imports: 12 Imported by: 0

README

GoDoc Build Status

hubhub is a set of utility functions for working with the GitHub API.

It's not a "client library"; but just a few convenience functions that I found myself re-creating a bunch of times in different programs.

Personally, I prefer working with the API "directly", instead of using an elaborate wrapper/client library. YMMV. Check out go-github if you want a full client library.

Documentation

Overview

Package hubhub is a set of utility functions for working with the GitHub API.

It's not a "client library"; but just a few convenience functions that I found myself re-creating a bunch of times in different programs.

Index

Constants

This section is empty.

Variables

View Source
var (
	User      string                     // GitHub username.
	Token     string                     // GitHub access token or password.
	API       = "https://api.github.com" // API base URL.
	DebugURL  = false                    // Show URLs as they're requested.
	DebugBody = false                    // Show body of requests.
	MaxWait   = 30 * time.Second         // Max time to wait on 202 Accepted responses.
)

Global configuration.

View Source
var ErrWait = errors.New("waited longer than MaxWait and still getting 202 Accepted")

ErrWait is used when we've waited longer than MaxWait for 202 Accepted.

Functions

func Paginate

func Paginate(scan interface{}, uri string, nPages int) error

Paginate an index request.

if nPages is higher than zero it will get exactly that number of pages in parallel. If it is zero it will get every page in serial until the last page.

The URL may contain query parameters, but the "page" parameter will be discarded.

TODO: Could be prettier.

func Request

func Request(scan interface{}, method, url string, body io.Reader) (*http.Response, error)

Request something from the GitHub API.

The response body is unmarshaled to scan unless the response code is 204 (No Content).

If the response code is 202 Accepted the HTTP request will be retried every two seconds until it returns a 200 OK. The ErrWait error will be returned if this takes longer than MaxWait.

A response code higher than 399 will return a NotOKError error, but won't affect the behaviour of this function.

The Body on the returned http.Response is closed.

This will use the global User and Token, which must be set.

Types

type NotOKError

type NotOKError struct {
	Method, URL string
	Status      string
	StatusCode  int
}

NotOKError is used when the status code is not 200 OK.

func (NotOKError) Error

func (e NotOKError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL