greenhouseio

package module
v0.0.0-...-be68522 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2023 License: MIT Imports: 10 Imported by: 0

README

Greenhouse IO

A Go interface to Greenhouse.io's API

Useage

Creating the Client

NewClient accepts:

  • A context; used for any HTTP requests made using the client.
  • Any struct implementing the httpClient interface; this allows for useage of other HTTP clients, like go-retryablehttp.
  • The API token.
client, err := greenhouseio.NewClient(
  context.Background(),
  &http.Client{
    Timeout: httpTimeout,
  },
  os.Getenv("GREENHOUSE_API_KEY"),
)
Single Request

All candidates

candidates, err := client.Candidates().Fetch()

All candidates created before

candidates, err := client.Candidates().CreatedBefore(time.Now()).Fetch()
Streaming

Streaming puts each resource loaded into a given consumer channel while following the next URL found in each response header. When an error occurs or no next URL is found, an error or nil is sent to a given close signal channel.

All candidates

candidates, closeSignal := make(chan *models.Candidate), make(chan error)
go client.Candidates().Stream(candidates, closeSignal)

for {
	select {
	case err := <-closeSignal:
		if err != nil {
			log.Fatalf("error streaming candidates: %v", err)
		}

		os.Exit(0)
	case candidate := <-candidates:
		log.Default().Println("streamed", candidate.ID)
	}
}

API Documentation

Documentation for the Harvest and Job Board web APIs can be found at developers.greenhouse.io.

Development

Prerequisites

Install Docker.

Linting and tests are run within a golangci-lint container.

Commands

Linting

make lint

Run tests

make test

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CandidatesRequest

type CandidatesRequest struct {
	// contains filtered or unexported fields
}

func (*CandidatesRequest) CreatedBefore

func (r *CandidatesRequest) CreatedBefore(timestamp time.Time) *CandidatesRequest

func (*CandidatesRequest) Fetch

func (r *CandidatesRequest) Fetch() ([]*models.Candidate, error)

Fetch gets a slice of candidates using the built query params.

func (*CandidatesRequest) Stream

func (r *CandidatesRequest) Stream(consumer chan *models.Candidate, closeSignal chan error)

Stream fetches a page of candidates, outputs the them into the given consumer channel, and attempts to fetch the next page.

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(ctx context.Context, httpClient httpClient, apiToken string) (*Client, error)

func (*Client) Candidates

func (c *Client) Candidates() *CandidatesRequest

Candidates returns a candidates request builder.

type QueryBuilder

type QueryBuilder interface {
	Len() int
	WriteString(string) (int, error)
}

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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