webhook

package
v0.0.0-...-e9ebf91 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2018 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package webhook provides types and utility functions for handling Lyft webhooks.

Index

Constants

View Source
const (
	RideStatusUpdated = "ride.status.updated"
	RideReceiptReady  = "ride.receipt.ready"
)

Event types.

View Source
const SandboxEventPrefix = "sandboxevent"

Variables

View Source
var ErrVerify = errors.New("failed to verify request")

ErrVerify is returned by DecodeEvent if the request could not be verified to have been originating from Lyft.

Functions

func Signature

func Signature(h http.Header) string

Signature returns the value of "X-Lyft-Signature" from an incoming webhook request header. The "sha256=" prefix will have been trimmed in the returned string.

func Verify

func Verify(requestBody, signature, verificationToken []byte) (bool, error)

Verify checks whether the incoming webhook request originated from Lyft. The signature is the value of the X-Lyft-Signature header value with the "sha256=" prefix already trimmed. The verification token can be be found in the Lyft Developer Portal.

Types

type Event

type Event struct {
	EventID   string
	URL       string
	Occurred  time.Time
	EventType string
	// Some fields may not be set.
	// See details for each event type: https://developer.lyft.com/v1/docs/webhooks
	Detail lyft.RideDetail
}

Event represents an event from a Lyft webhook. It implements json.Unmarshaler in a manner suitable for decoding incoming webhook request bodies.

func DecodeEvent

func DecodeEvent(requestBody io.ReadCloser, h http.Header, verificationToken []byte) (Event, error)

DecodeEvent decodes an incoming webhook request's body and header into an Event. DecodeEvent will verify that the request was received from Lyft. The error will be ErrVerify if verification fails. The request body will always be drained and closed, even if an error is returned. Errors from draining and closing are not reported.

func (*Event) IsSandbox

func (e *Event) IsSandbox() bool

func (*Event) UnmarshalJSON

func (e *Event) UnmarshalJSON(p []byte) error

Jump to

Keyboard shortcuts

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