dp wiz avatar dp wiz committed 0c92306

Sentry interfaces: user.

Comments (0)

Files changed (2)

lookout/src/System/Log/Lookout/Interfaces.hs

     , exception
       -- ** Http
     , http, HttpArgs(..)
+      -- ** User
+    , user
       -- * Generic interface helpers
     , interface
     , fields, (.=:), fromMaybe, fromAssoc
         fromHttpArgs (RawArgs s) = "data" .=: s
         fromHttpArgs (QueryArgs kvs) = "data" .=: HM.fromList kvs
 
+-- | 'sentry.interfaces.User':
+--   An interface which describes the authenticated User for a request.
+--
+-- > let upd = SI.user "unique_id" [ ("username", "my_user")
+-- >                               , ("email", "foo@example.com") ]
+user :: String             -- ^ User's unique identifier
+     -> [(String, String)] -- ^ Optional user data
+     -> SentryRecord       -- ^ Record to update
+     -> SentryRecord
+user uid kwargs = interface "sentry.interfaces.User" info
+    where
+        info = HM.fromList $ ("id", uid) : kwargs
+
 -- | Generic interface helper.
 interface :: (ToJSON v) => String -> v -> SentryRecord -> SentryRecord
 interface k v rec =

lookout/test/Test.hs

 
         send r
 
+    it "registers User data" $ do
+        r <- make $ SI.user "0" [ ("username", "root")
+                                , ("email", "root@localhost")
+                                , ("is_superuser", "True") -- wart
+                                ]
+        let ex = object [ "id"           .= ("0" :: String)
+                        , "username"     .= ("root" :: String)
+                        , "email"        .= ("root@localhost" :: String)
+                        , "is_superuser" .= ("True" :: String)
+                        ]
+        HM.lookup "sentry.interfaces.User" (srInterfaces r) `shouldBe` Just ex
+
+        send r
+
 dsn = "http://public_key:secret_key@example.com/sentry/project-id"
 
 ss = SentrySettings {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.