aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Bangs.hs19
-rw-r--r--src/Main.hs21
2 files changed, 40 insertions, 0 deletions
diff --git a/src/Bangs.hs b/src/Bangs.hs
new file mode 100644
index 0000000..017d03b
--- /dev/null
+++ b/src/Bangs.hs
@@ -0,0 +1,19 @@
+{-# LANGUAGE OverloadedStrings #-}
+
+module Bangs (Bangs) where
+
+import Data.Aeson
+import Data.Aeson.Types (Parser)
+import Data.Text (Text)
+import qualified Data.Map.Strict as M
+
+-- The map stored is equivalent to `HM.HashMap Shortcut URL`.
+-- For now, we're omitting category information as I don't want to force our
+-- own custom bangs to need that info.
+data Bangs = Bangs (M.Map Text Text) deriving (Show)
+instance FromJSON Bangs where
+ parseJSON b = fmap (Bangs . M.fromList) $
+ (parseJSON b :: Parser [Value])
+ >>= mapM (withObject "Bang" $ \ob ->
+ (,) <$> ob .: "t" <*> ob .: "u")
+
diff --git a/src/Main.hs b/src/Main.hs
new file mode 100644
index 0000000..997bbf5
--- /dev/null
+++ b/src/Main.hs
@@ -0,0 +1,21 @@
+{-# LANGUAGE OverloadedStrings #-}
+
+module Main (main) where
+
+import Yesod
+import Data.ByteString (ByteString)
+import Data.IORef
+import Network.HTTP.Simple
+
+import Bangs
+
+data Search = Search {
+ ddgBangs :: IORef Bangs,
+ ownBangs :: IORef Bangs,
+ serializedBangs :: IORef ByteString
+}
+
+main :: IO ()
+main = do
+ ans <- (httpJSON "https://duckduckgo.com/bang.v255.js") :: IO (Response Bangs)
+ print ans