Source

riak-haskell-client / src / Network / Riak / Content.hs

Full commit
Bryan O'Sullivan d247f08 

Bryan O'Sullivan fa2df44 



Bryan O'Sullivan b02b170 
Bryan O'Sullivan fa2df44 




Bryan O'Sullivan d247f08 

Bryan O'Sullivan fa2df44 
Bryan O'Sullivan e1cd5c3 

Bryan O'Sullivan fa2df44 
Bryan O'Sullivan e1cd5c3 
Bryan O'Sullivan d247f08 
Bryan O'Sullivan 4d611cf 
Bryan O'Sullivan e1cd5c3 
Bryan O'Sullivan d247f08 

Bryan O'Sullivan fa2df44 



Bryan O'Sullivan d247f08 

Bryan O'Sullivan e1cd5c3 
Bryan O'Sullivan d247f08 
Bryan O'Sullivan fa2df44 
Bryan O'Sullivan e1cd5c3 



Bryan O'Sullivan fa2df44 
Bryan O'Sullivan e1cd5c3 









Jay Groven 7041d19 
Bryan O'Sullivan e1cd5c3 
Bryan O'Sullivan d247f08 
Bryan O'Sullivan fa2df44 
Bryan O'Sullivan d247f08 
Bryan O'Sullivan e1cd5c3 


Bryan O'Sullivan 4d611cf 
Bryan O'Sullivan fa2df44 
Bryan O'Sullivan 4d611cf 


{-# LANGUAGE OverloadedStrings #-}

-- |
-- Module:      Network.Riak.Content
-- Copyright:   (c) 2011 MailRank, Inc.
-- License:     Apache
-- Maintainer:  Bryan O'Sullivan <bos@serpentine.com>
-- Stability:   experimental
-- Portability: portable
--
-- Low-level content and link types and functions.

module Network.Riak.Content
    (
    -- * Types
      Content(..)
    , Link.Link(..)
    -- * Functions
    , empty
    , binary
    , json
    , link
    ) where

import Data.Aeson.Encode (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

-- | Create a link.
link :: Bucket -> Key -> Tag -> Link.Link
link bucket key tag = Link.Link (Just bucket) (Just key) (Just tag)
{-# INLINE link #-}

-- | An empty piece of content.
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
                }

-- | Content encoded as @application/octet-stream@.
binary :: L.ByteString -> Content
binary bs = empty { value = bs
                  , content_type = Just "application/octet-stream"
                  }

-- | Content encoded as @application/json@.
json :: ToJSON a => a -> Content
json j = empty { value = encode j
               , content_type = Just "application/json"
               }