packages feed

bugsnag-types-1.1.1.0: src/Data/Bugsnag/Types/Payload.hs

module Data.Bugsnag.Types.Payload
  ( Payload (..)
  , examplePayload
  , defaultPayload
  )
where

import Data.Bugsnag.Types.Prelude

import Data.Bugsnag.Types.Event
import Data.Bugsnag.Types.Notifier

data Payload = Payload
  { apiKey :: Maybe Text
  -- ^ The API Key associated with the project. Informs BugSnag which project
  -- has generated this error. This is provided for legacy notifiers. It is
  -- preferable to use the @Bugsnag-Api-Key@ header instead.
  , payloadVersion :: Text
  -- ^ The version number of the payload. This is currently @5@. The
  -- @Bugsnag-Payload-Version@ header should be included as well for
  -- compatibility reasons.
  , notifier :: Notifier
  , events :: [Event]
  -- ^ An array of error events that BugSnag should be notified of. A notifier
  -- can choose to group notices into an array to minimize network traffic,
  -- or can notify BugSnag each time an event occurs. Should contain at least
  -- 1 event.
  }
  deriving stock (Eq, Generic, Show)

instance FromJSON Payload where
  parseJSON = genericParseJSON aesonOptions

instance ToJSON Payload where
  toJSON = genericToJSON aesonOptions
  toEncoding = genericToEncoding aesonOptions

defaultPayload :: Text -> Notifier -> [Event] -> Payload
defaultPayload payloadVersion notifier events =
  Payload
    { payloadVersion
    , notifier
    , events
    , apiKey = Nothing
    }

examplePayload :: Payload
examplePayload =
  Payload
    { apiKey = Just "YOUR-NOTIFIER-API-KEY"
    , payloadVersion = "5"
    , notifier = exampleNotifier
    , events = [exampleEvent]
    }