{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}
module Amazonka.MachineLearning.Predict
(
Predict (..),
newPredict,
predict_mLModelId,
predict_record,
predict_predictEndpoint,
PredictResponse (..),
newPredictResponse,
predictResponse_prediction,
predictResponse_httpStatus,
)
where
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.MachineLearning.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response
data Predict = Predict'
{
Predict -> Text
mLModelId :: Prelude.Text,
Predict -> HashMap Text Text
record :: Prelude.HashMap Prelude.Text Prelude.Text,
Predict -> Text
predictEndpoint :: Prelude.Text
}
deriving (Predict -> Predict -> Bool
(Predict -> Predict -> Bool)
-> (Predict -> Predict -> Bool) -> Eq Predict
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Predict -> Predict -> Bool
$c/= :: Predict -> Predict -> Bool
== :: Predict -> Predict -> Bool
$c== :: Predict -> Predict -> Bool
Prelude.Eq, ReadPrec [Predict]
ReadPrec Predict
Int -> ReadS Predict
ReadS [Predict]
(Int -> ReadS Predict)
-> ReadS [Predict]
-> ReadPrec Predict
-> ReadPrec [Predict]
-> Read Predict
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Predict]
$creadListPrec :: ReadPrec [Predict]
readPrec :: ReadPrec Predict
$creadPrec :: ReadPrec Predict
readList :: ReadS [Predict]
$creadList :: ReadS [Predict]
readsPrec :: Int -> ReadS Predict
$creadsPrec :: Int -> ReadS Predict
Prelude.Read, Int -> Predict -> ShowS
[Predict] -> ShowS
Predict -> String
(Int -> Predict -> ShowS)
-> (Predict -> String) -> ([Predict] -> ShowS) -> Show Predict
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Predict] -> ShowS
$cshowList :: [Predict] -> ShowS
show :: Predict -> String
$cshow :: Predict -> String
showsPrec :: Int -> Predict -> ShowS
$cshowsPrec :: Int -> Predict -> ShowS
Prelude.Show, (forall x. Predict -> Rep Predict x)
-> (forall x. Rep Predict x -> Predict) -> Generic Predict
forall x. Rep Predict x -> Predict
forall x. Predict -> Rep Predict x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Predict x -> Predict
$cfrom :: forall x. Predict -> Rep Predict x
Prelude.Generic)
newPredict ::
Prelude.Text ->
Prelude.Text ->
Predict
newPredict :: Text -> Text -> Predict
newPredict Text
pMLModelId_ Text
pPredictEndpoint_ =
Predict' :: Text -> HashMap Text Text -> Text -> Predict
Predict'
{ $sel:mLModelId:Predict' :: Text
mLModelId = Text
pMLModelId_,
$sel:record:Predict' :: HashMap Text Text
record = HashMap Text Text
forall a. Monoid a => a
Prelude.mempty,
$sel:predictEndpoint:Predict' :: Text
predictEndpoint = Text
pPredictEndpoint_
}
predict_mLModelId :: Lens.Lens' Predict Prelude.Text
predict_mLModelId :: (Text -> f Text) -> Predict -> f Predict
predict_mLModelId = (Predict -> Text)
-> (Predict -> Text -> Predict) -> Lens Predict Predict Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Predict' {Text
mLModelId :: Text
$sel:mLModelId:Predict' :: Predict -> Text
mLModelId} -> Text
mLModelId) (\s :: Predict
s@Predict' {} Text
a -> Predict
s {$sel:mLModelId:Predict' :: Text
mLModelId = Text
a} :: Predict)
predict_record :: Lens.Lens' Predict (Prelude.HashMap Prelude.Text Prelude.Text)
predict_record :: (HashMap Text Text -> f (HashMap Text Text))
-> Predict -> f Predict
predict_record = (Predict -> HashMap Text Text)
-> (Predict -> HashMap Text Text -> Predict)
-> Lens Predict Predict (HashMap Text Text) (HashMap Text Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Predict' {HashMap Text Text
record :: HashMap Text Text
$sel:record:Predict' :: Predict -> HashMap Text Text
record} -> HashMap Text Text
record) (\s :: Predict
s@Predict' {} HashMap Text Text
a -> Predict
s {$sel:record:Predict' :: HashMap Text Text
record = HashMap Text Text
a} :: Predict) ((HashMap Text Text -> f (HashMap Text Text))
-> Predict -> f Predict)
-> ((HashMap Text Text -> f (HashMap Text Text))
-> HashMap Text Text -> f (HashMap Text Text))
-> (HashMap Text Text -> f (HashMap Text Text))
-> Predict
-> f Predict
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (HashMap Text Text -> f (HashMap Text Text))
-> HashMap Text Text -> f (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced
predict_predictEndpoint :: Lens.Lens' Predict Prelude.Text
predict_predictEndpoint :: (Text -> f Text) -> Predict -> f Predict
predict_predictEndpoint = (Predict -> Text)
-> (Predict -> Text -> Predict) -> Lens Predict Predict Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Predict' {Text
predictEndpoint :: Text
$sel:predictEndpoint:Predict' :: Predict -> Text
predictEndpoint} -> Text
predictEndpoint) (\s :: Predict
s@Predict' {} Text
a -> Predict
s {$sel:predictEndpoint:Predict' :: Text
predictEndpoint = Text
a} :: Predict)
instance Core.AWSRequest Predict where
type AWSResponse Predict = PredictResponse
request :: Predict -> Request Predict
request = Service -> Predict -> Request Predict
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
response :: Logger
-> Service
-> Proxy Predict
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse Predict)))
response =
(Int
-> ResponseHeaders
-> Object
-> Either String (AWSResponse Predict))
-> Logger
-> Service
-> Proxy Predict
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse Predict)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
( \Int
s ResponseHeaders
h Object
x ->
Maybe Prediction -> Int -> PredictResponse
PredictResponse'
(Maybe Prediction -> Int -> PredictResponse)
-> Either String (Maybe Prediction)
-> Either String (Int -> PredictResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Prediction)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Prediction")
Either String (Int -> PredictResponse)
-> Either String Int -> Either String PredictResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
)
instance Prelude.Hashable Predict
instance Prelude.NFData Predict
instance Core.ToHeaders Predict where
toHeaders :: Predict -> ResponseHeaders
toHeaders =
ResponseHeaders -> Predict -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
[ HeaderName
"X-Amz-Target"
HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# (ByteString
"AmazonML_20141212.Predict" :: Prelude.ByteString),
HeaderName
"Content-Type"
HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
Prelude.ByteString
)
]
)
instance Core.ToJSON Predict where
toJSON :: Predict -> Value
toJSON Predict' {Text
HashMap Text Text
predictEndpoint :: Text
record :: HashMap Text Text
mLModelId :: Text
$sel:predictEndpoint:Predict' :: Predict -> Text
$sel:record:Predict' :: Predict -> HashMap Text Text
$sel:mLModelId:Predict' :: Predict -> Text
..} =
[Pair] -> Value
Core.object
( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
[ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"MLModelId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
mLModelId),
Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Record" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= HashMap Text Text
record),
Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
(Text
"PredictEndpoint" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
predictEndpoint)
]
)
instance Core.ToPath Predict where
toPath :: Predict -> ByteString
toPath = ByteString -> Predict -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"
instance Core.ToQuery Predict where
toQuery :: Predict -> QueryString
toQuery = QueryString -> Predict -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty
data PredictResponse = PredictResponse'
{ PredictResponse -> Maybe Prediction
prediction :: Prelude.Maybe Prediction,
PredictResponse -> Int
httpStatus :: Prelude.Int
}
deriving (PredictResponse -> PredictResponse -> Bool
(PredictResponse -> PredictResponse -> Bool)
-> (PredictResponse -> PredictResponse -> Bool)
-> Eq PredictResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PredictResponse -> PredictResponse -> Bool
$c/= :: PredictResponse -> PredictResponse -> Bool
== :: PredictResponse -> PredictResponse -> Bool
$c== :: PredictResponse -> PredictResponse -> Bool
Prelude.Eq, ReadPrec [PredictResponse]
ReadPrec PredictResponse
Int -> ReadS PredictResponse
ReadS [PredictResponse]
(Int -> ReadS PredictResponse)
-> ReadS [PredictResponse]
-> ReadPrec PredictResponse
-> ReadPrec [PredictResponse]
-> Read PredictResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PredictResponse]
$creadListPrec :: ReadPrec [PredictResponse]
readPrec :: ReadPrec PredictResponse
$creadPrec :: ReadPrec PredictResponse
readList :: ReadS [PredictResponse]
$creadList :: ReadS [PredictResponse]
readsPrec :: Int -> ReadS PredictResponse
$creadsPrec :: Int -> ReadS PredictResponse
Prelude.Read, Int -> PredictResponse -> ShowS
[PredictResponse] -> ShowS
PredictResponse -> String
(Int -> PredictResponse -> ShowS)
-> (PredictResponse -> String)
-> ([PredictResponse] -> ShowS)
-> Show PredictResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PredictResponse] -> ShowS
$cshowList :: [PredictResponse] -> ShowS
show :: PredictResponse -> String
$cshow :: PredictResponse -> String
showsPrec :: Int -> PredictResponse -> ShowS
$cshowsPrec :: Int -> PredictResponse -> ShowS
Prelude.Show, (forall x. PredictResponse -> Rep PredictResponse x)
-> (forall x. Rep PredictResponse x -> PredictResponse)
-> Generic PredictResponse
forall x. Rep PredictResponse x -> PredictResponse
forall x. PredictResponse -> Rep PredictResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PredictResponse x -> PredictResponse
$cfrom :: forall x. PredictResponse -> Rep PredictResponse x
Prelude.Generic)
newPredictResponse ::
Prelude.Int ->
PredictResponse
newPredictResponse :: Int -> PredictResponse
newPredictResponse Int
pHttpStatus_ =
PredictResponse' :: Maybe Prediction -> Int -> PredictResponse
PredictResponse'
{ $sel:prediction:PredictResponse' :: Maybe Prediction
prediction = Maybe Prediction
forall a. Maybe a
Prelude.Nothing,
$sel:httpStatus:PredictResponse' :: Int
httpStatus = Int
pHttpStatus_
}
predictResponse_prediction :: Lens.Lens' PredictResponse (Prelude.Maybe Prediction)
predictResponse_prediction :: (Maybe Prediction -> f (Maybe Prediction))
-> PredictResponse -> f PredictResponse
predictResponse_prediction = (PredictResponse -> Maybe Prediction)
-> (PredictResponse -> Maybe Prediction -> PredictResponse)
-> Lens
PredictResponse
PredictResponse
(Maybe Prediction)
(Maybe Prediction)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PredictResponse' {Maybe Prediction
prediction :: Maybe Prediction
$sel:prediction:PredictResponse' :: PredictResponse -> Maybe Prediction
prediction} -> Maybe Prediction
prediction) (\s :: PredictResponse
s@PredictResponse' {} Maybe Prediction
a -> PredictResponse
s {$sel:prediction:PredictResponse' :: Maybe Prediction
prediction = Maybe Prediction
a} :: PredictResponse)
predictResponse_httpStatus :: Lens.Lens' PredictResponse Prelude.Int
predictResponse_httpStatus :: (Int -> f Int) -> PredictResponse -> f PredictResponse
predictResponse_httpStatus = (PredictResponse -> Int)
-> (PredictResponse -> Int -> PredictResponse)
-> Lens PredictResponse PredictResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PredictResponse' {Int
httpStatus :: Int
$sel:httpStatus:PredictResponse' :: PredictResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: PredictResponse
s@PredictResponse' {} Int
a -> PredictResponse
s {$sel:httpStatus:PredictResponse' :: Int
httpStatus = Int
a} :: PredictResponse)
instance Prelude.NFData PredictResponse