posthook

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

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

Go to latest
Published: Sep 28, 2019 License: MIT Imports: 7 Imported by: 0

README

Go client for Posthook API

Implements the API documented at https://docs.posthook.io/

Install with go get -u github.com/pims/posthook

example use:

// create posthook client
ph := posthook.New(os.Getenv("POSTHOOK_API_KEY"))

// verify the endpoint being used
fmt.Println(ph.Endpoint())

// data to be sent back to us when posthook executes the hook
data := map[string]interface{}{
    "foobar": "baz",
}

// Step 1: schedule a hook
hook, err := ph.Schedule("ping", time.Now().Add(1*time.Minute).UTC(), data)
handleErr(err)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Int

func Int(i int) *int

Int is a convenience method for int ptrs

func String

func String(s string) *string

String is a convenience method for string ptrs

func Time

func Time(t time.Time) *time.Time

Time is a convenience method for time ptrs

Types

type Client

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

Client interfaces with the Posthook API: api.posthook.io

func New

func New(apiKey string, opts ...Config) *Client

New creates a new postHook client

func (*Client) Delete

func (c *Client) Delete(id string) error

Delete a Hook. This will stop Posthook from making the request back to your application for this Hook.

func (*Client) Endpoint

func (c *Client) Endpoint() string

Endpoint returns the currently configured endpoint

func (*Client) Get

func (c *Client) Get(id string) (*Hook, error)

Get retrieves a specific Hook.

func (*Client) List

func (c *Client) List(filters Filters) ([]Hook, error)

List retrieves Hooks that have already been scheduled.

func (*Client) Schedule

func (c *Client) Schedule(path string, at time.Time, data interface{}) (*Hook, error)

Schedule creates a new hook to schedule a time for Posthook to make a request to your application.

type Config

type Config func(c *Client)

Config lets users configure the postHook struct

func WithEndpoint

func WithEndpoint(endpoint string) Config

WithEndpoint configures the API endpoint

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) Config

WithHTTPClient replaces the underlying http.DefaultClient

type Filters

type Filters struct {
	Limit         *int       `url:"limit,omitempty"`
	SortBy        *string    `url:"sortBy,omitempty"`
	SortOrder     *string    `url:"sortOrder,omitempty"`
	PostAtBefore  *time.Time `url:"postAtBefore,omitempty"`
	PostAtAfter   *time.Time `url:"postAtAfter,omitempty"`
	CreatedBefore *time.Time `url:"createdBefore,omitempty"`
	CreatedAfter  *time.Time `url:"createdAfter,omitempty"`
}

Filters lets you filter a list query

type Hook

type Hook struct {
	ID        string      `json:"id,omitempty"`
	Path      string      `json:"path"`
	PostAt    time.Time   `json:"postAt"`
	Status    string      `json:"status,omitempty"`
	CreatedAt *time.Time  `json:"createdAt,omitempty"`
	Data      interface{} `json:"data"`
}

Hook represents a Hook

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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