{-# 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 #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.IoTData.GetThingShadow
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Gets the shadow for the specified thing.
--
-- Requires permission to access the
-- <https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiot.html#awsiot-actions-as-permissions GetThingShadow>
-- action.
--
-- For more information, see
-- <http://docs.aws.amazon.com/iot/latest/developerguide/API_GetThingShadow.html GetThingShadow>
-- in the IoT Developer Guide.
module Amazonka.IoTData.GetThingShadow
  ( -- * Creating a Request
    GetThingShadow (..),
    newGetThingShadow,

    -- * Request Lenses
    getThingShadow_shadowName,
    getThingShadow_thingName,

    -- * Destructuring the Response
    GetThingShadowResponse (..),
    newGetThingShadowResponse,

    -- * Response Lenses
    getThingShadowResponse_payload,
    getThingShadowResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.IoTData.Types
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | The input for the GetThingShadow operation.
--
-- /See:/ 'newGetThingShadow' smart constructor.
data GetThingShadow = GetThingShadow'
  { -- | The name of the shadow.
    GetThingShadow -> Maybe Text
shadowName :: Prelude.Maybe Prelude.Text,
    -- | The name of the thing.
    GetThingShadow -> Text
thingName :: Prelude.Text
  }
  deriving (GetThingShadow -> GetThingShadow -> Bool
(GetThingShadow -> GetThingShadow -> Bool)
-> (GetThingShadow -> GetThingShadow -> Bool) -> Eq GetThingShadow
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetThingShadow -> GetThingShadow -> Bool
$c/= :: GetThingShadow -> GetThingShadow -> Bool
== :: GetThingShadow -> GetThingShadow -> Bool
$c== :: GetThingShadow -> GetThingShadow -> Bool
Prelude.Eq, ReadPrec [GetThingShadow]
ReadPrec GetThingShadow
Int -> ReadS GetThingShadow
ReadS [GetThingShadow]
(Int -> ReadS GetThingShadow)
-> ReadS [GetThingShadow]
-> ReadPrec GetThingShadow
-> ReadPrec [GetThingShadow]
-> Read GetThingShadow
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetThingShadow]
$creadListPrec :: ReadPrec [GetThingShadow]
readPrec :: ReadPrec GetThingShadow
$creadPrec :: ReadPrec GetThingShadow
readList :: ReadS [GetThingShadow]
$creadList :: ReadS [GetThingShadow]
readsPrec :: Int -> ReadS GetThingShadow
$creadsPrec :: Int -> ReadS GetThingShadow
Prelude.Read, Int -> GetThingShadow -> ShowS
[GetThingShadow] -> ShowS
GetThingShadow -> String
(Int -> GetThingShadow -> ShowS)
-> (GetThingShadow -> String)
-> ([GetThingShadow] -> ShowS)
-> Show GetThingShadow
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetThingShadow] -> ShowS
$cshowList :: [GetThingShadow] -> ShowS
show :: GetThingShadow -> String
$cshow :: GetThingShadow -> String
showsPrec :: Int -> GetThingShadow -> ShowS
$cshowsPrec :: Int -> GetThingShadow -> ShowS
Prelude.Show, (forall x. GetThingShadow -> Rep GetThingShadow x)
-> (forall x. Rep GetThingShadow x -> GetThingShadow)
-> Generic GetThingShadow
forall x. Rep GetThingShadow x -> GetThingShadow
forall x. GetThingShadow -> Rep GetThingShadow x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetThingShadow x -> GetThingShadow
$cfrom :: forall x. GetThingShadow -> Rep GetThingShadow x
Prelude.Generic)

-- |
-- Create a value of 'GetThingShadow' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'shadowName', 'getThingShadow_shadowName' - The name of the shadow.
--
-- 'thingName', 'getThingShadow_thingName' - The name of the thing.
newGetThingShadow ::
  -- | 'thingName'
  Prelude.Text ->
  GetThingShadow
newGetThingShadow :: Text -> GetThingShadow
newGetThingShadow Text
pThingName_ =
  GetThingShadow' :: Maybe Text -> Text -> GetThingShadow
GetThingShadow'
    { $sel:shadowName:GetThingShadow' :: Maybe Text
shadowName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:thingName:GetThingShadow' :: Text
thingName = Text
pThingName_
    }

-- | The name of the shadow.
getThingShadow_shadowName :: Lens.Lens' GetThingShadow (Prelude.Maybe Prelude.Text)
getThingShadow_shadowName :: (Maybe Text -> f (Maybe Text))
-> GetThingShadow -> f GetThingShadow
getThingShadow_shadowName = (GetThingShadow -> Maybe Text)
-> (GetThingShadow -> Maybe Text -> GetThingShadow)
-> Lens GetThingShadow GetThingShadow (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetThingShadow' {Maybe Text
shadowName :: Maybe Text
$sel:shadowName:GetThingShadow' :: GetThingShadow -> Maybe Text
shadowName} -> Maybe Text
shadowName) (\s :: GetThingShadow
s@GetThingShadow' {} Maybe Text
a -> GetThingShadow
s {$sel:shadowName:GetThingShadow' :: Maybe Text
shadowName = Maybe Text
a} :: GetThingShadow)

-- | The name of the thing.
getThingShadow_thingName :: Lens.Lens' GetThingShadow Prelude.Text
getThingShadow_thingName :: (Text -> f Text) -> GetThingShadow -> f GetThingShadow
getThingShadow_thingName = (GetThingShadow -> Text)
-> (GetThingShadow -> Text -> GetThingShadow)
-> Lens GetThingShadow GetThingShadow Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetThingShadow' {Text
thingName :: Text
$sel:thingName:GetThingShadow' :: GetThingShadow -> Text
thingName} -> Text
thingName) (\s :: GetThingShadow
s@GetThingShadow' {} Text
a -> GetThingShadow
s {$sel:thingName:GetThingShadow' :: Text
thingName = Text
a} :: GetThingShadow)

instance Core.AWSRequest GetThingShadow where
  type
    AWSResponse GetThingShadow =
      GetThingShadowResponse
  request :: GetThingShadow -> Request GetThingShadow
request = Service -> GetThingShadow -> Request GetThingShadow
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy GetThingShadow
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetThingShadow)))
response =
    (Int
 -> ResponseHeaders
 -> ByteString
 -> Either String (AWSResponse GetThingShadow))
-> Logger
-> Service
-> Proxy GetThingShadow
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetThingShadow)))
forall (m :: * -> *) a.
MonadResource m =>
(Int
 -> ResponseHeaders -> ByteString -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveBytes
      ( \Int
s ResponseHeaders
h ByteString
x ->
          Maybe ByteString -> Int -> GetThingShadowResponse
GetThingShadowResponse'
            (Maybe ByteString -> Int -> GetThingShadowResponse)
-> Either String (Maybe ByteString)
-> Either String (Int -> GetThingShadowResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Maybe ByteString -> Either String (Maybe ByteString)
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (ByteString -> Maybe ByteString
forall a. a -> Maybe a
Prelude.Just (ByteString -> ByteString
Prelude.coerce ByteString
x)))
            Either String (Int -> GetThingShadowResponse)
-> Either String Int -> Either String GetThingShadowResponse
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 GetThingShadow

instance Prelude.NFData GetThingShadow

instance Core.ToHeaders GetThingShadow where
  toHeaders :: GetThingShadow -> ResponseHeaders
toHeaders = ResponseHeaders -> GetThingShadow -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

instance Core.ToPath GetThingShadow where
  toPath :: GetThingShadow -> ByteString
toPath GetThingShadow' {Maybe Text
Text
thingName :: Text
shadowName :: Maybe Text
$sel:thingName:GetThingShadow' :: GetThingShadow -> Text
$sel:shadowName:GetThingShadow' :: GetThingShadow -> Maybe Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/things/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
thingName, ByteString
"/shadow"]

instance Core.ToQuery GetThingShadow where
  toQuery :: GetThingShadow -> QueryString
toQuery GetThingShadow' {Maybe Text
Text
thingName :: Text
shadowName :: Maybe Text
$sel:thingName:GetThingShadow' :: GetThingShadow -> Text
$sel:shadowName:GetThingShadow' :: GetThingShadow -> Maybe Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"name" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
shadowName]

-- | The output from the GetThingShadow operation.
--
-- /See:/ 'newGetThingShadowResponse' smart constructor.
data GetThingShadowResponse = GetThingShadowResponse'
  { -- | The state information, in JSON format.
    GetThingShadowResponse -> Maybe ByteString
payload :: Prelude.Maybe Prelude.ByteString,
    -- | The response's http status code.
    GetThingShadowResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetThingShadowResponse -> GetThingShadowResponse -> Bool
(GetThingShadowResponse -> GetThingShadowResponse -> Bool)
-> (GetThingShadowResponse -> GetThingShadowResponse -> Bool)
-> Eq GetThingShadowResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetThingShadowResponse -> GetThingShadowResponse -> Bool
$c/= :: GetThingShadowResponse -> GetThingShadowResponse -> Bool
== :: GetThingShadowResponse -> GetThingShadowResponse -> Bool
$c== :: GetThingShadowResponse -> GetThingShadowResponse -> Bool
Prelude.Eq, Int -> GetThingShadowResponse -> ShowS
[GetThingShadowResponse] -> ShowS
GetThingShadowResponse -> String
(Int -> GetThingShadowResponse -> ShowS)
-> (GetThingShadowResponse -> String)
-> ([GetThingShadowResponse] -> ShowS)
-> Show GetThingShadowResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetThingShadowResponse] -> ShowS
$cshowList :: [GetThingShadowResponse] -> ShowS
show :: GetThingShadowResponse -> String
$cshow :: GetThingShadowResponse -> String
showsPrec :: Int -> GetThingShadowResponse -> ShowS
$cshowsPrec :: Int -> GetThingShadowResponse -> ShowS
Prelude.Show, (forall x. GetThingShadowResponse -> Rep GetThingShadowResponse x)
-> (forall x.
    Rep GetThingShadowResponse x -> GetThingShadowResponse)
-> Generic GetThingShadowResponse
forall x. Rep GetThingShadowResponse x -> GetThingShadowResponse
forall x. GetThingShadowResponse -> Rep GetThingShadowResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetThingShadowResponse x -> GetThingShadowResponse
$cfrom :: forall x. GetThingShadowResponse -> Rep GetThingShadowResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetThingShadowResponse' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'payload', 'getThingShadowResponse_payload' - The state information, in JSON format.
--
-- 'httpStatus', 'getThingShadowResponse_httpStatus' - The response's http status code.
newGetThingShadowResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetThingShadowResponse
newGetThingShadowResponse :: Int -> GetThingShadowResponse
newGetThingShadowResponse Int
pHttpStatus_ =
  GetThingShadowResponse' :: Maybe ByteString -> Int -> GetThingShadowResponse
GetThingShadowResponse'
    { $sel:payload:GetThingShadowResponse' :: Maybe ByteString
payload = Maybe ByteString
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetThingShadowResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The state information, in JSON format.
getThingShadowResponse_payload :: Lens.Lens' GetThingShadowResponse (Prelude.Maybe Prelude.ByteString)
getThingShadowResponse_payload :: (Maybe ByteString -> f (Maybe ByteString))
-> GetThingShadowResponse -> f GetThingShadowResponse
getThingShadowResponse_payload = (GetThingShadowResponse -> Maybe ByteString)
-> (GetThingShadowResponse
    -> Maybe ByteString -> GetThingShadowResponse)
-> Lens
     GetThingShadowResponse
     GetThingShadowResponse
     (Maybe ByteString)
     (Maybe ByteString)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetThingShadowResponse' {Maybe ByteString
payload :: Maybe ByteString
$sel:payload:GetThingShadowResponse' :: GetThingShadowResponse -> Maybe ByteString
payload} -> Maybe ByteString
payload) (\s :: GetThingShadowResponse
s@GetThingShadowResponse' {} Maybe ByteString
a -> GetThingShadowResponse
s {$sel:payload:GetThingShadowResponse' :: Maybe ByteString
payload = Maybe ByteString
a} :: GetThingShadowResponse)

-- | The response's http status code.
getThingShadowResponse_httpStatus :: Lens.Lens' GetThingShadowResponse Prelude.Int
getThingShadowResponse_httpStatus :: (Int -> f Int)
-> GetThingShadowResponse -> f GetThingShadowResponse
getThingShadowResponse_httpStatus = (GetThingShadowResponse -> Int)
-> (GetThingShadowResponse -> Int -> GetThingShadowResponse)
-> Lens GetThingShadowResponse GetThingShadowResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetThingShadowResponse' {Int
httpStatus :: Int
$sel:httpStatus:GetThingShadowResponse' :: GetThingShadowResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: GetThingShadowResponse
s@GetThingShadowResponse' {} Int
a -> GetThingShadowResponse
s {$sel:httpStatus:GetThingShadowResponse' :: Int
httpStatus = Int
a} :: GetThingShadowResponse)

instance Prelude.NFData GetThingShadowResponse