{-# 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.APIGatewayManagementAPI.GetConnection
-- 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)
--
-- Get information about the connection with the provided id.
module Amazonka.APIGatewayManagementAPI.GetConnection
  ( -- * Creating a Request
    GetConnection (..),
    newGetConnection,

    -- * Request Lenses
    getConnection_connectionId,

    -- * Destructuring the Response
    GetConnectionResponse (..),
    newGetConnectionResponse,

    -- * Response Lenses
    getConnectionResponse_connectedAt,
    getConnectionResponse_lastActiveAt,
    getConnectionResponse_identity,
    getConnectionResponse_httpStatus,
  )
where

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

-- | /See:/ 'newGetConnection' smart constructor.
data GetConnection = GetConnection'
  { GetConnection -> Text
connectionId :: Prelude.Text
  }
  deriving (GetConnection -> GetConnection -> Bool
(GetConnection -> GetConnection -> Bool)
-> (GetConnection -> GetConnection -> Bool) -> Eq GetConnection
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetConnection -> GetConnection -> Bool
$c/= :: GetConnection -> GetConnection -> Bool
== :: GetConnection -> GetConnection -> Bool
$c== :: GetConnection -> GetConnection -> Bool
Prelude.Eq, ReadPrec [GetConnection]
ReadPrec GetConnection
Int -> ReadS GetConnection
ReadS [GetConnection]
(Int -> ReadS GetConnection)
-> ReadS [GetConnection]
-> ReadPrec GetConnection
-> ReadPrec [GetConnection]
-> Read GetConnection
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetConnection]
$creadListPrec :: ReadPrec [GetConnection]
readPrec :: ReadPrec GetConnection
$creadPrec :: ReadPrec GetConnection
readList :: ReadS [GetConnection]
$creadList :: ReadS [GetConnection]
readsPrec :: Int -> ReadS GetConnection
$creadsPrec :: Int -> ReadS GetConnection
Prelude.Read, Int -> GetConnection -> ShowS
[GetConnection] -> ShowS
GetConnection -> String
(Int -> GetConnection -> ShowS)
-> (GetConnection -> String)
-> ([GetConnection] -> ShowS)
-> Show GetConnection
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetConnection] -> ShowS
$cshowList :: [GetConnection] -> ShowS
show :: GetConnection -> String
$cshow :: GetConnection -> String
showsPrec :: Int -> GetConnection -> ShowS
$cshowsPrec :: Int -> GetConnection -> ShowS
Prelude.Show, (forall x. GetConnection -> Rep GetConnection x)
-> (forall x. Rep GetConnection x -> GetConnection)
-> Generic GetConnection
forall x. Rep GetConnection x -> GetConnection
forall x. GetConnection -> Rep GetConnection x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetConnection x -> GetConnection
$cfrom :: forall x. GetConnection -> Rep GetConnection x
Prelude.Generic)

-- |
-- Create a value of 'GetConnection' 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:
--
-- 'connectionId', 'getConnection_connectionId' - Undocumented member.
newGetConnection ::
  -- | 'connectionId'
  Prelude.Text ->
  GetConnection
newGetConnection :: Text -> GetConnection
newGetConnection Text
pConnectionId_ =
  GetConnection' :: Text -> GetConnection
GetConnection' {$sel:connectionId:GetConnection' :: Text
connectionId = Text
pConnectionId_}

-- | Undocumented member.
getConnection_connectionId :: Lens.Lens' GetConnection Prelude.Text
getConnection_connectionId :: (Text -> f Text) -> GetConnection -> f GetConnection
getConnection_connectionId = (GetConnection -> Text)
-> (GetConnection -> Text -> GetConnection)
-> Lens GetConnection GetConnection Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetConnection' {Text
connectionId :: Text
$sel:connectionId:GetConnection' :: GetConnection -> Text
connectionId} -> Text
connectionId) (\s :: GetConnection
s@GetConnection' {} Text
a -> GetConnection
s {$sel:connectionId:GetConnection' :: Text
connectionId = Text
a} :: GetConnection)

instance Core.AWSRequest GetConnection where
  type
    AWSResponse GetConnection =
      GetConnectionResponse
  request :: GetConnection -> Request GetConnection
request = Service -> GetConnection -> Request GetConnection
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy GetConnection
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetConnection)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetConnection))
-> Logger
-> Service
-> Proxy GetConnection
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetConnection)))
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 POSIX
-> Maybe POSIX -> Maybe Identity -> Int -> GetConnectionResponse
GetConnectionResponse'
            (Maybe POSIX
 -> Maybe POSIX -> Maybe Identity -> Int -> GetConnectionResponse)
-> Either String (Maybe POSIX)
-> Either
     String
     (Maybe POSIX -> Maybe Identity -> Int -> GetConnectionResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe POSIX)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"connectedAt")
            Either
  String
  (Maybe POSIX -> Maybe Identity -> Int -> GetConnectionResponse)
-> Either String (Maybe POSIX)
-> Either String (Maybe Identity -> Int -> GetConnectionResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe POSIX)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"lastActiveAt")
            Either String (Maybe Identity -> Int -> GetConnectionResponse)
-> Either String (Maybe Identity)
-> Either String (Int -> GetConnectionResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe Identity)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"identity")
            Either String (Int -> GetConnectionResponse)
-> Either String Int -> Either String GetConnectionResponse
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 GetConnection

instance Prelude.NFData GetConnection

instance Core.ToHeaders GetConnection where
  toHeaders :: GetConnection -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetConnection -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ 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.ToPath GetConnection where
  toPath :: GetConnection -> ByteString
toPath GetConnection' {Text
connectionId :: Text
$sel:connectionId:GetConnection' :: GetConnection -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/@connections/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
connectionId]

instance Core.ToQuery GetConnection where
  toQuery :: GetConnection -> QueryString
toQuery = QueryString -> GetConnection -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newGetConnectionResponse' smart constructor.
data GetConnectionResponse = GetConnectionResponse'
  { -- | The time in ISO 8601 format for when the connection was established.
    GetConnectionResponse -> Maybe POSIX
connectedAt :: Prelude.Maybe Core.POSIX,
    -- | The time in ISO 8601 format for when the connection was last active.
    GetConnectionResponse -> Maybe POSIX
lastActiveAt :: Prelude.Maybe Core.POSIX,
    GetConnectionResponse -> Maybe Identity
identity :: Prelude.Maybe Identity,
    -- | The response's http status code.
    GetConnectionResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetConnectionResponse -> GetConnectionResponse -> Bool
(GetConnectionResponse -> GetConnectionResponse -> Bool)
-> (GetConnectionResponse -> GetConnectionResponse -> Bool)
-> Eq GetConnectionResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetConnectionResponse -> GetConnectionResponse -> Bool
$c/= :: GetConnectionResponse -> GetConnectionResponse -> Bool
== :: GetConnectionResponse -> GetConnectionResponse -> Bool
$c== :: GetConnectionResponse -> GetConnectionResponse -> Bool
Prelude.Eq, ReadPrec [GetConnectionResponse]
ReadPrec GetConnectionResponse
Int -> ReadS GetConnectionResponse
ReadS [GetConnectionResponse]
(Int -> ReadS GetConnectionResponse)
-> ReadS [GetConnectionResponse]
-> ReadPrec GetConnectionResponse
-> ReadPrec [GetConnectionResponse]
-> Read GetConnectionResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetConnectionResponse]
$creadListPrec :: ReadPrec [GetConnectionResponse]
readPrec :: ReadPrec GetConnectionResponse
$creadPrec :: ReadPrec GetConnectionResponse
readList :: ReadS [GetConnectionResponse]
$creadList :: ReadS [GetConnectionResponse]
readsPrec :: Int -> ReadS GetConnectionResponse
$creadsPrec :: Int -> ReadS GetConnectionResponse
Prelude.Read, Int -> GetConnectionResponse -> ShowS
[GetConnectionResponse] -> ShowS
GetConnectionResponse -> String
(Int -> GetConnectionResponse -> ShowS)
-> (GetConnectionResponse -> String)
-> ([GetConnectionResponse] -> ShowS)
-> Show GetConnectionResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetConnectionResponse] -> ShowS
$cshowList :: [GetConnectionResponse] -> ShowS
show :: GetConnectionResponse -> String
$cshow :: GetConnectionResponse -> String
showsPrec :: Int -> GetConnectionResponse -> ShowS
$cshowsPrec :: Int -> GetConnectionResponse -> ShowS
Prelude.Show, (forall x. GetConnectionResponse -> Rep GetConnectionResponse x)
-> (forall x. Rep GetConnectionResponse x -> GetConnectionResponse)
-> Generic GetConnectionResponse
forall x. Rep GetConnectionResponse x -> GetConnectionResponse
forall x. GetConnectionResponse -> Rep GetConnectionResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetConnectionResponse x -> GetConnectionResponse
$cfrom :: forall x. GetConnectionResponse -> Rep GetConnectionResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetConnectionResponse' 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:
--
-- 'connectedAt', 'getConnectionResponse_connectedAt' - The time in ISO 8601 format for when the connection was established.
--
-- 'lastActiveAt', 'getConnectionResponse_lastActiveAt' - The time in ISO 8601 format for when the connection was last active.
--
-- 'identity', 'getConnectionResponse_identity' - Undocumented member.
--
-- 'httpStatus', 'getConnectionResponse_httpStatus' - The response's http status code.
newGetConnectionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetConnectionResponse
newGetConnectionResponse :: Int -> GetConnectionResponse
newGetConnectionResponse Int
pHttpStatus_ =
  GetConnectionResponse' :: Maybe POSIX
-> Maybe POSIX -> Maybe Identity -> Int -> GetConnectionResponse
GetConnectionResponse'
    { $sel:connectedAt:GetConnectionResponse' :: Maybe POSIX
connectedAt =
        Maybe POSIX
forall a. Maybe a
Prelude.Nothing,
      $sel:lastActiveAt:GetConnectionResponse' :: Maybe POSIX
lastActiveAt = Maybe POSIX
forall a. Maybe a
Prelude.Nothing,
      $sel:identity:GetConnectionResponse' :: Maybe Identity
identity = Maybe Identity
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetConnectionResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The time in ISO 8601 format for when the connection was established.
getConnectionResponse_connectedAt :: Lens.Lens' GetConnectionResponse (Prelude.Maybe Prelude.UTCTime)
getConnectionResponse_connectedAt :: (Maybe UTCTime -> f (Maybe UTCTime))
-> GetConnectionResponse -> f GetConnectionResponse
getConnectionResponse_connectedAt = (GetConnectionResponse -> Maybe POSIX)
-> (GetConnectionResponse -> Maybe POSIX -> GetConnectionResponse)
-> Lens
     GetConnectionResponse
     GetConnectionResponse
     (Maybe POSIX)
     (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetConnectionResponse' {Maybe POSIX
connectedAt :: Maybe POSIX
$sel:connectedAt:GetConnectionResponse' :: GetConnectionResponse -> Maybe POSIX
connectedAt} -> Maybe POSIX
connectedAt) (\s :: GetConnectionResponse
s@GetConnectionResponse' {} Maybe POSIX
a -> GetConnectionResponse
s {$sel:connectedAt:GetConnectionResponse' :: Maybe POSIX
connectedAt = Maybe POSIX
a} :: GetConnectionResponse) ((Maybe POSIX -> f (Maybe POSIX))
 -> GetConnectionResponse -> f GetConnectionResponse)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> GetConnectionResponse
-> f GetConnectionResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso POSIX POSIX UTCTime UTCTime
-> Iso (Maybe POSIX) (Maybe POSIX) (Maybe UTCTime) (Maybe UTCTime)
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso POSIX POSIX UTCTime UTCTime
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

-- | The time in ISO 8601 format for when the connection was last active.
getConnectionResponse_lastActiveAt :: Lens.Lens' GetConnectionResponse (Prelude.Maybe Prelude.UTCTime)
getConnectionResponse_lastActiveAt :: (Maybe UTCTime -> f (Maybe UTCTime))
-> GetConnectionResponse -> f GetConnectionResponse
getConnectionResponse_lastActiveAt = (GetConnectionResponse -> Maybe POSIX)
-> (GetConnectionResponse -> Maybe POSIX -> GetConnectionResponse)
-> Lens
     GetConnectionResponse
     GetConnectionResponse
     (Maybe POSIX)
     (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetConnectionResponse' {Maybe POSIX
lastActiveAt :: Maybe POSIX
$sel:lastActiveAt:GetConnectionResponse' :: GetConnectionResponse -> Maybe POSIX
lastActiveAt} -> Maybe POSIX
lastActiveAt) (\s :: GetConnectionResponse
s@GetConnectionResponse' {} Maybe POSIX
a -> GetConnectionResponse
s {$sel:lastActiveAt:GetConnectionResponse' :: Maybe POSIX
lastActiveAt = Maybe POSIX
a} :: GetConnectionResponse) ((Maybe POSIX -> f (Maybe POSIX))
 -> GetConnectionResponse -> f GetConnectionResponse)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> GetConnectionResponse
-> f GetConnectionResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso POSIX POSIX UTCTime UTCTime
-> Iso (Maybe POSIX) (Maybe POSIX) (Maybe UTCTime) (Maybe UTCTime)
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso POSIX POSIX UTCTime UTCTime
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

-- | Undocumented member.
getConnectionResponse_identity :: Lens.Lens' GetConnectionResponse (Prelude.Maybe Identity)
getConnectionResponse_identity :: (Maybe Identity -> f (Maybe Identity))
-> GetConnectionResponse -> f GetConnectionResponse
getConnectionResponse_identity = (GetConnectionResponse -> Maybe Identity)
-> (GetConnectionResponse
    -> Maybe Identity -> GetConnectionResponse)
-> Lens
     GetConnectionResponse
     GetConnectionResponse
     (Maybe Identity)
     (Maybe Identity)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetConnectionResponse' {Maybe Identity
identity :: Maybe Identity
$sel:identity:GetConnectionResponse' :: GetConnectionResponse -> Maybe Identity
identity} -> Maybe Identity
identity) (\s :: GetConnectionResponse
s@GetConnectionResponse' {} Maybe Identity
a -> GetConnectionResponse
s {$sel:identity:GetConnectionResponse' :: Maybe Identity
identity = Maybe Identity
a} :: GetConnectionResponse)

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

instance Prelude.NFData GetConnectionResponse