Advertisement
NLinker

DebugMain from FW

May 2nd, 2017
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {-# LANGUAGE OverloadedStrings   #-}
  2. {-# LANGUAGE ScopedTypeVariables #-}
  3.  
  4. {-# OPTIONS_GHC -fno-warn-name-shadowing #-}
  5.  
  6. module DebugMain where
  7.  
  8. import           System.IO.Unsafe        (unsafePerformIO)
  9. import           Vertigo.Config          (getConfig)
  10. import           Vertigo.Config.Auth     (AuthToken, authenticateUser, createToken)
  11. import           Vertigo.Config.SQS      (sendSQS, NotifyMode (..))
  12. import           Vertigo.Config.Types    (Config)
  13. import           Vertigo.Monad           (Vertigo, runApp)
  14. import           Vertigo.Types.Activity  (ActivityTags (..))
  15. import           Vertigo.Types.Content   (ContentId (..))
  16. import           Vertigo.Types.Feed      (FeedItem (..))
  17. import           Vertigo.Types.HashTag   (HashTags (..))
  18. import           Vertigo.Types.Mention   (MentionTag (..), MentionTags (..))
  19. import           Vertigo.Types.Mood      (MoodTags (..))
  20. import           Vertigo.Types.Post      (BroadcastTitle (..), IsRepost (..), Post (..),
  21.                                           PostDeleted (..), PostDescription (..), PostId (..),
  22.                                           PostType (AlbumType), Reposts (..))
  23. import           Vertigo.Types.TimeStamp (TimeStamp (..))
  24. import           Vertigo.Types.User      (UserId (..))
  25. --import           Vertigo.Types.VUUID     (VUUID (..))
  26.  
  27. import           Vertigo.Worker          (pollAndDispatch)
  28.  
  29. import qualified Aws.Sqs                 as Sqs
  30. --import qualified Data.Aeson              as A
  31.  
  32. --dynamoGet ::
  33. --  (FromDynItem b, Log.Logging m, MonadIO m, MonadReader Config m,
  34. --   MonadError Error m, MonadBaseControl IO m) =>
  35. --  GetItem -> m b
  36.  
  37. kick :: IO ()
  38. kick = do
  39. --  let pid = PostId "1834df6f-87b7-4e5e-9834-df6f87b76e5e"
  40. --  (post :: Post) <- runHere config $ dynamoGet (getPost pid)
  41.   print post
  42.   -- (FeedItem,Post,NotifyMode, AuthToken, Bool)
  43.   let msg = (feedItem, post, notifyMode, token uid, True)
  44.   print msg
  45.   rs <- runHere $ sendSQS msg [("DataType", Sqs.UserMessageAttributeString Nothing "FeedItem")]
  46.   print rs
  47.   runHere pollAndDispatch
  48.  
  49. uid :: UserId
  50. uid = UserId "263d83ba-78cd-4583-b86d-b8d53a3fd619"
  51.  
  52. {-# NOINLINE token #-}
  53. token :: UserId -> AuthToken
  54. token uid = unsafePerformIO $ runHere $ do
  55.   t <- createToken uid
  56.   authenticateUser $ Just t
  57.  
  58. {-# NOINLINE config #-}
  59. config :: Config
  60. config = forceEither $ unsafePerformIO getConfig
  61.  
  62. runHere :: Vertigo m -> IO m
  63. runHere op = do
  64.   x <- runApp config op
  65.   case x of
  66.     Left err -> error $ show err
  67.     Right r -> return r
  68.  
  69. notifyMode :: NotifyMode
  70. notifyMode = WithNotifications
  71.  
  72. feedItem :: FeedItem
  73. feedItem = FeedItem
  74.   { feedItemId     = ContentId "1834df6f-87b7-4e5e-9834-df6f87b76e5e"
  75.   , feedItemUserId = UserId "263d83ba-78cd-4583-b86d-b8d53a3fd619"
  76.   }
  77.  
  78. post :: Post
  79. post = Post
  80.   { postPostId = PostId "1834df6f-87b7-4e5e-9834-df6f87b76e5e"
  81.   , postAuthorId = UserId "263d83ba-78cd-4583-b86d-b8d53a3fd619"
  82.   , postIsRepost = IsRepost False
  83.   , postOriginalPostId = Nothing
  84.   , postContentId = ContentId "d2ea4185-ab19-4323-989e-8d7688f86853"
  85.   , postTimestamp = TimeStamp 1490840802667674
  86.   , postContentType = AlbumType
  87.   , postDescription = Just (PostDescription "@justin this is a test")
  88.   , postRepostDescription = Nothing
  89.   , postDeleted = PostDeleted False
  90.   , postRepostCount = Reposts 0
  91.   , postHashes = HashTags []
  92.   , postMentions = MentionTags [MentionTag "justin"]
  93.   , postMoods = MoodTags []
  94.   , postActivities = ActivityTags []
  95.   , postBroadcastTitle = Just (BroadcastTitle "Broadcast Title!")
  96.   }
  97.  
  98. {- | Pulls a "Right" value out of an Either value.  If the Either value is
  99. Left, raises an exception with "error". -}
  100. forceEither :: Show e => Either e a -> a
  101. forceEither (Left x) = error (show x)
  102. forceEither (Right x) = x
  103.  
  104. weirdParse :: String -> (String, String)
  105. weirdParse [] = ([],[])
  106. weirdParse (x:y:zs) = let (xs, ys) = weirdParse zs in (x:xs, y:ys)
  107. weirdParse [x] = ([x], [])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement