packages feed

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

module Data.Bugsnag.Types.Session
  ( Session (..)
  , exampleSession
  , defaultSession
  )
where

import Data.Bugsnag.Types.Prelude

import Data.Bugsnag.Types.SessionEvent

-- | Details of any session information associated with the event.
--
-- This can be used alongside the
-- <https://smartbear.portal.swaggerhub.com/bugsnag/default/bugsnag-session-reporting-api Session Tracking API>
-- to associate the event with a session so that a release\'s crash rate
-- can be determined.
data Session = Session
  { id :: Text
  -- ^ The unique identifier of the session.
  , startedAt :: Text
  -- ^ The time (in <https://en.wikipedia.org/wiki/ISO_8601 ISO 8601> format)
  -- at which the session started.
  , events :: SessionEvent
  }
  deriving stock (Eq, Generic, Show)

instance FromJSON Session where
  parseJSON = genericParseJSON aesonOptions

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

defaultSession :: Text -> Text -> SessionEvent -> Session
defaultSession id startedAt events =
  Session
    { id
    , startedAt
    , events
    }

exampleSession :: Session
exampleSession =
  Session
    { id = "9f65c975-8155-456f-91e5-c4c4b3db0555"
    , startedAt = "2017-01-01T14:30:00.000Z"
    , events = exampleSessionEvent
    }