{-# LANGUAGE OverloadedStrings #-}
module Network.Riak.Content
(
Content(..)
, Link.Link(..)
, empty
, binary
, json
, link
) where
import Data.Aeson (encode)
import Data.Aeson.Types (ToJSON)
import Network.Riak.Protocol.Content (Content(..))
import Network.Riak.Types.Internal (Bucket, Key, Tag)
import qualified Data.ByteString.Lazy.Char8 as L
import qualified Data.Sequence as Seq
import qualified Network.Riak.Protocol.Link as Link
link :: Bucket -> Key -> Tag -> Link.Link
link bucket key tag = Link.Link (Just bucket) (Just key) (Just tag)
{-# INLINE link #-}
empty :: Content
empty = Content { value = L.empty
, content_type = Nothing
, charset = Nothing
, content_encoding = Nothing
, vtag = Nothing
, links = Seq.empty
, last_mod = Nothing
, last_mod_usecs = Nothing
, usermeta = Seq.empty
, indexes = Seq.empty
, deleted = Nothing
}
binary :: L.ByteString -> Content
binary bs = empty { value = bs
, content_type = Just "application/octet-stream"
}
json :: ToJSON a => a -> Content
json j = empty { value = encode j
, content_type = Just "application/json"
}