{-# LANGUAGE OverloadedStrings #-}
module Network.Riak.Content
(
Proto.RpbContent
, Proto.RpbLink
, empty
, binary
, json
, link
) where
import Data.Aeson (encode)
import Data.Aeson.Types (ToJSON)
import Data.ByteString (ByteString)
import qualified Data.ByteString.Lazy as LazyByteString
import qualified Data.Riak.Proto as Proto
import Network.Riak.Lens
import Network.Riak.Types.Internal (Bucket, Key, Tag)
link :: Bucket -> Key -> Tag -> Proto.RpbLink
link :: Bucket -> Bucket -> Bucket -> RpbLink
link Bucket
bucket Bucket
key Bucket
tag = RpbLink
forall msg. Message msg => msg
Proto.defMessage
RpbLink -> (RpbLink -> RpbLink) -> RpbLink
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbLink Bucket
forall (f :: * -> *) s a.
(Functor f, HasField s "bucket" a) =>
LensLike' f s a
Proto.bucket LensLike' Identity RpbLink Bucket -> Bucket -> RpbLink -> RpbLink
forall s a. Setter s a -> a -> s -> s
.~ Bucket
bucket
RpbLink -> (RpbLink -> RpbLink) -> RpbLink
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbLink Bucket
forall (f :: * -> *) s a.
(Functor f, HasField s "key" a) =>
LensLike' f s a
Proto.key LensLike' Identity RpbLink Bucket -> Bucket -> RpbLink -> RpbLink
forall s a. Setter s a -> a -> s -> s
.~ Bucket
key
RpbLink -> (RpbLink -> RpbLink) -> RpbLink
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbLink Bucket
forall (f :: * -> *) s a.
(Functor f, HasField s "tag" a) =>
LensLike' f s a
Proto.tag LensLike' Identity RpbLink Bucket -> Bucket -> RpbLink -> RpbLink
forall s a. Setter s a -> a -> s -> s
.~ Bucket
tag
{-# INLINE link #-}
empty :: Proto.RpbContent
empty :: RpbContent
empty = RpbContent
forall msg. Message msg => msg
Proto.defMessage
binary :: ByteString -> Proto.RpbContent
binary :: Bucket -> RpbContent
binary Bucket
bs = RpbContent
empty RpbContent -> (RpbContent -> RpbContent) -> RpbContent
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbContent Bucket
forall (f :: * -> *) s a.
(Functor f, HasField s "value" a) =>
LensLike' f s a
Proto.value LensLike' Identity RpbContent Bucket
-> Bucket -> RpbContent -> RpbContent
forall s a. Setter s a -> a -> s -> s
.~ Bucket
bs
RpbContent -> (RpbContent -> RpbContent) -> RpbContent
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbContent Bucket
forall (f :: * -> *) s a.
(Functor f, HasField s "contentType" a) =>
LensLike' f s a
Proto.contentType LensLike' Identity RpbContent Bucket
-> Bucket -> RpbContent -> RpbContent
forall s a. Setter s a -> a -> s -> s
.~ Bucket
"application/octet-stream"
json :: ToJSON a => a -> Proto.RpbContent
json :: a -> RpbContent
json a
j = RpbContent
empty RpbContent -> (RpbContent -> RpbContent) -> RpbContent
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbContent Bucket
forall (f :: * -> *) s a.
(Functor f, HasField s "value" a) =>
LensLike' f s a
Proto.value LensLike' Identity RpbContent Bucket
-> Bucket -> RpbContent -> RpbContent
forall s a. Setter s a -> a -> s -> s
.~ ByteString -> Bucket
LazyByteString.toStrict (a -> ByteString
forall a. ToJSON a => a -> ByteString
encode a
j)
RpbContent -> (RpbContent -> RpbContent) -> RpbContent
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbContent Bucket
forall (f :: * -> *) s a.
(Functor f, HasField s "contentType" a) =>
LensLike' f s a
Proto.contentType LensLike' Identity RpbContent Bucket
-> Bucket -> RpbContent -> RpbContent
forall s a. Setter s a -> a -> s -> s
.~ Bucket
"application/json"