{-# 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.CodeStarConnections.ListHosts
-- 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)
--
-- Lists the hosts associated with your account.
module Amazonka.CodeStarConnections.ListHosts
  ( -- * Creating a Request
    ListHosts (..),
    newListHosts,

    -- * Request Lenses
    listHosts_nextToken,
    listHosts_maxResults,

    -- * Destructuring the Response
    ListHostsResponse (..),
    newListHostsResponse,

    -- * Response Lenses
    listHostsResponse_hosts,
    listHostsResponse_nextToken,
    listHostsResponse_httpStatus,
  )
where

import Amazonka.CodeStarConnections.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:/ 'newListHosts' smart constructor.
data ListHosts = ListHosts'
  { -- | The token that was returned from the previous @ListHosts@ call, which
    -- can be used to return the next set of hosts in the list.
    ListHosts -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The maximum number of results to return in a single call. To retrieve
    -- the remaining results, make another call with the returned @nextToken@
    -- value.
    ListHosts -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural
  }
  deriving (ListHosts -> ListHosts -> Bool
(ListHosts -> ListHosts -> Bool)
-> (ListHosts -> ListHosts -> Bool) -> Eq ListHosts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListHosts -> ListHosts -> Bool
$c/= :: ListHosts -> ListHosts -> Bool
== :: ListHosts -> ListHosts -> Bool
$c== :: ListHosts -> ListHosts -> Bool
Prelude.Eq, ReadPrec [ListHosts]
ReadPrec ListHosts
Int -> ReadS ListHosts
ReadS [ListHosts]
(Int -> ReadS ListHosts)
-> ReadS [ListHosts]
-> ReadPrec ListHosts
-> ReadPrec [ListHosts]
-> Read ListHosts
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListHosts]
$creadListPrec :: ReadPrec [ListHosts]
readPrec :: ReadPrec ListHosts
$creadPrec :: ReadPrec ListHosts
readList :: ReadS [ListHosts]
$creadList :: ReadS [ListHosts]
readsPrec :: Int -> ReadS ListHosts
$creadsPrec :: Int -> ReadS ListHosts
Prelude.Read, Int -> ListHosts -> ShowS
[ListHosts] -> ShowS
ListHosts -> String
(Int -> ListHosts -> ShowS)
-> (ListHosts -> String)
-> ([ListHosts] -> ShowS)
-> Show ListHosts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListHosts] -> ShowS
$cshowList :: [ListHosts] -> ShowS
show :: ListHosts -> String
$cshow :: ListHosts -> String
showsPrec :: Int -> ListHosts -> ShowS
$cshowsPrec :: Int -> ListHosts -> ShowS
Prelude.Show, (forall x. ListHosts -> Rep ListHosts x)
-> (forall x. Rep ListHosts x -> ListHosts) -> Generic ListHosts
forall x. Rep ListHosts x -> ListHosts
forall x. ListHosts -> Rep ListHosts x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListHosts x -> ListHosts
$cfrom :: forall x. ListHosts -> Rep ListHosts x
Prelude.Generic)

-- |
-- Create a value of 'ListHosts' 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:
--
-- 'nextToken', 'listHosts_nextToken' - The token that was returned from the previous @ListHosts@ call, which
-- can be used to return the next set of hosts in the list.
--
-- 'maxResults', 'listHosts_maxResults' - The maximum number of results to return in a single call. To retrieve
-- the remaining results, make another call with the returned @nextToken@
-- value.
newListHosts ::
  ListHosts
newListHosts :: ListHosts
newListHosts =
  ListHosts' :: Maybe Text -> Maybe Natural -> ListHosts
ListHosts'
    { $sel:nextToken:ListHosts' :: Maybe Text
nextToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:maxResults:ListHosts' :: Maybe Natural
maxResults = Maybe Natural
forall a. Maybe a
Prelude.Nothing
    }

-- | The token that was returned from the previous @ListHosts@ call, which
-- can be used to return the next set of hosts in the list.
listHosts_nextToken :: Lens.Lens' ListHosts (Prelude.Maybe Prelude.Text)
listHosts_nextToken :: (Maybe Text -> f (Maybe Text)) -> ListHosts -> f ListHosts
listHosts_nextToken = (ListHosts -> Maybe Text)
-> (ListHosts -> Maybe Text -> ListHosts)
-> Lens ListHosts ListHosts (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListHosts' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListHosts' :: ListHosts -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListHosts
s@ListHosts' {} Maybe Text
a -> ListHosts
s {$sel:nextToken:ListHosts' :: Maybe Text
nextToken = Maybe Text
a} :: ListHosts)

-- | The maximum number of results to return in a single call. To retrieve
-- the remaining results, make another call with the returned @nextToken@
-- value.
listHosts_maxResults :: Lens.Lens' ListHosts (Prelude.Maybe Prelude.Natural)
listHosts_maxResults :: (Maybe Natural -> f (Maybe Natural)) -> ListHosts -> f ListHosts
listHosts_maxResults = (ListHosts -> Maybe Natural)
-> (ListHosts -> Maybe Natural -> ListHosts)
-> Lens ListHosts ListHosts (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListHosts' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListHosts' :: ListHosts -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListHosts
s@ListHosts' {} Maybe Natural
a -> ListHosts
s {$sel:maxResults:ListHosts' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListHosts)

instance Core.AWSRequest ListHosts where
  type AWSResponse ListHosts = ListHostsResponse
  request :: ListHosts -> Request ListHosts
request = Service -> ListHosts -> Request ListHosts
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy ListHosts
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListHosts)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse ListHosts))
-> Logger
-> Service
-> Proxy ListHosts
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListHosts)))
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 [Host] -> Maybe Text -> Int -> ListHostsResponse
ListHostsResponse'
            (Maybe [Host] -> Maybe Text -> Int -> ListHostsResponse)
-> Either String (Maybe [Host])
-> Either String (Maybe Text -> Int -> ListHostsResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe (Maybe [Host]))
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Hosts" Either String (Maybe (Maybe [Host]))
-> Maybe [Host] -> Either String (Maybe [Host])
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ Maybe [Host]
forall a. Monoid a => a
Prelude.mempty)
            Either String (Maybe Text -> Int -> ListHostsResponse)
-> Either String (Maybe Text)
-> Either String (Int -> ListHostsResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"NextToken")
            Either String (Int -> ListHostsResponse)
-> Either String Int -> Either String ListHostsResponse
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 ListHosts

instance Prelude.NFData ListHosts

instance Core.ToHeaders ListHosts where
  toHeaders :: ListHosts -> ResponseHeaders
toHeaders =
    ResponseHeaders -> ListHosts -> 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
"com.amazonaws.codestar.connections.CodeStar_connections_20191201.ListHosts" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.0" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON ListHosts where
  toJSON :: ListHosts -> Value
toJSON ListHosts' {Maybe Natural
Maybe Text
maxResults :: Maybe Natural
nextToken :: Maybe Text
$sel:maxResults:ListHosts' :: ListHosts -> Maybe Natural
$sel:nextToken:ListHosts' :: ListHosts -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"NextToken" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
nextToken,
            (Text
"MaxResults" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
maxResults
          ]
      )

instance Core.ToPath ListHosts where
  toPath :: ListHosts -> ByteString
toPath = ByteString -> ListHosts -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

-- | /See:/ 'newListHostsResponse' smart constructor.
data ListHostsResponse = ListHostsResponse'
  { -- | A list of hosts and the details for each host, such as status, endpoint,
    -- and provider type.
    ListHostsResponse -> Maybe [Host]
hosts :: Prelude.Maybe [Host],
    -- | A token that can be used in the next @ListHosts@ call. To view all items
    -- in the list, continue to call this operation with each subsequent token
    -- until no more @nextToken@ values are returned.
    ListHostsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ListHostsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListHostsResponse -> ListHostsResponse -> Bool
(ListHostsResponse -> ListHostsResponse -> Bool)
-> (ListHostsResponse -> ListHostsResponse -> Bool)
-> Eq ListHostsResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListHostsResponse -> ListHostsResponse -> Bool
$c/= :: ListHostsResponse -> ListHostsResponse -> Bool
== :: ListHostsResponse -> ListHostsResponse -> Bool
$c== :: ListHostsResponse -> ListHostsResponse -> Bool
Prelude.Eq, ReadPrec [ListHostsResponse]
ReadPrec ListHostsResponse
Int -> ReadS ListHostsResponse
ReadS [ListHostsResponse]
(Int -> ReadS ListHostsResponse)
-> ReadS [ListHostsResponse]
-> ReadPrec ListHostsResponse
-> ReadPrec [ListHostsResponse]
-> Read ListHostsResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListHostsResponse]
$creadListPrec :: ReadPrec [ListHostsResponse]
readPrec :: ReadPrec ListHostsResponse
$creadPrec :: ReadPrec ListHostsResponse
readList :: ReadS [ListHostsResponse]
$creadList :: ReadS [ListHostsResponse]
readsPrec :: Int -> ReadS ListHostsResponse
$creadsPrec :: Int -> ReadS ListHostsResponse
Prelude.Read, Int -> ListHostsResponse -> ShowS
[ListHostsResponse] -> ShowS
ListHostsResponse -> String
(Int -> ListHostsResponse -> ShowS)
-> (ListHostsResponse -> String)
-> ([ListHostsResponse] -> ShowS)
-> Show ListHostsResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListHostsResponse] -> ShowS
$cshowList :: [ListHostsResponse] -> ShowS
show :: ListHostsResponse -> String
$cshow :: ListHostsResponse -> String
showsPrec :: Int -> ListHostsResponse -> ShowS
$cshowsPrec :: Int -> ListHostsResponse -> ShowS
Prelude.Show, (forall x. ListHostsResponse -> Rep ListHostsResponse x)
-> (forall x. Rep ListHostsResponse x -> ListHostsResponse)
-> Generic ListHostsResponse
forall x. Rep ListHostsResponse x -> ListHostsResponse
forall x. ListHostsResponse -> Rep ListHostsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListHostsResponse x -> ListHostsResponse
$cfrom :: forall x. ListHostsResponse -> Rep ListHostsResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListHostsResponse' 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:
--
-- 'hosts', 'listHostsResponse_hosts' - A list of hosts and the details for each host, such as status, endpoint,
-- and provider type.
--
-- 'nextToken', 'listHostsResponse_nextToken' - A token that can be used in the next @ListHosts@ call. To view all items
-- in the list, continue to call this operation with each subsequent token
-- until no more @nextToken@ values are returned.
--
-- 'httpStatus', 'listHostsResponse_httpStatus' - The response's http status code.
newListHostsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListHostsResponse
newListHostsResponse :: Int -> ListHostsResponse
newListHostsResponse Int
pHttpStatus_ =
  ListHostsResponse' :: Maybe [Host] -> Maybe Text -> Int -> ListHostsResponse
ListHostsResponse'
    { $sel:hosts:ListHostsResponse' :: Maybe [Host]
hosts = Maybe [Host]
forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListHostsResponse' :: Maybe Text
nextToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListHostsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A list of hosts and the details for each host, such as status, endpoint,
-- and provider type.
listHostsResponse_hosts :: Lens.Lens' ListHostsResponse (Prelude.Maybe [Host])
listHostsResponse_hosts :: (Maybe [Host] -> f (Maybe [Host]))
-> ListHostsResponse -> f ListHostsResponse
listHostsResponse_hosts = (ListHostsResponse -> Maybe [Host])
-> (ListHostsResponse -> Maybe [Host] -> ListHostsResponse)
-> Lens
     ListHostsResponse ListHostsResponse (Maybe [Host]) (Maybe [Host])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListHostsResponse' {Maybe [Host]
hosts :: Maybe [Host]
$sel:hosts:ListHostsResponse' :: ListHostsResponse -> Maybe [Host]
hosts} -> Maybe [Host]
hosts) (\s :: ListHostsResponse
s@ListHostsResponse' {} Maybe [Host]
a -> ListHostsResponse
s {$sel:hosts:ListHostsResponse' :: Maybe [Host]
hosts = Maybe [Host]
a} :: ListHostsResponse) ((Maybe [Host] -> f (Maybe [Host]))
 -> ListHostsResponse -> f ListHostsResponse)
-> ((Maybe [Host] -> f (Maybe [Host]))
    -> Maybe [Host] -> f (Maybe [Host]))
-> (Maybe [Host] -> f (Maybe [Host]))
-> ListHostsResponse
-> f ListHostsResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Host] [Host] [Host] [Host]
-> Iso (Maybe [Host]) (Maybe [Host]) (Maybe [Host]) (Maybe [Host])
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 [Host] [Host] [Host] [Host]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A token that can be used in the next @ListHosts@ call. To view all items
-- in the list, continue to call this operation with each subsequent token
-- until no more @nextToken@ values are returned.
listHostsResponse_nextToken :: Lens.Lens' ListHostsResponse (Prelude.Maybe Prelude.Text)
listHostsResponse_nextToken :: (Maybe Text -> f (Maybe Text))
-> ListHostsResponse -> f ListHostsResponse
listHostsResponse_nextToken = (ListHostsResponse -> Maybe Text)
-> (ListHostsResponse -> Maybe Text -> ListHostsResponse)
-> Lens
     ListHostsResponse ListHostsResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListHostsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListHostsResponse' :: ListHostsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListHostsResponse
s@ListHostsResponse' {} Maybe Text
a -> ListHostsResponse
s {$sel:nextToken:ListHostsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListHostsResponse)

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

instance Prelude.NFData ListHostsResponse