{-# 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.ApiGatewayV2.GetApis
-- 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 a collection of Api resources.
--
-- This operation returns paginated results.
module Amazonka.ApiGatewayV2.GetApis
  ( -- * Creating a Request
    GetApis (..),
    newGetApis,

    -- * Request Lenses
    getApis_nextToken,
    getApis_maxResults,

    -- * Destructuring the Response
    GetApisResponse (..),
    newGetApisResponse,

    -- * Response Lenses
    getApisResponse_items,
    getApisResponse_nextToken,
    getApisResponse_httpStatus,
  )
where

import Amazonka.ApiGatewayV2.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:/ 'newGetApis' smart constructor.
data GetApis = GetApis'
  { -- | The next page of elements from this collection. Not valid for the last
    -- element of the collection.
    GetApis -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The maximum number of elements to be returned for this resource.
    GetApis -> Maybe Text
maxResults :: Prelude.Maybe Prelude.Text
  }
  deriving (GetApis -> GetApis -> Bool
(GetApis -> GetApis -> Bool)
-> (GetApis -> GetApis -> Bool) -> Eq GetApis
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetApis -> GetApis -> Bool
$c/= :: GetApis -> GetApis -> Bool
== :: GetApis -> GetApis -> Bool
$c== :: GetApis -> GetApis -> Bool
Prelude.Eq, ReadPrec [GetApis]
ReadPrec GetApis
Int -> ReadS GetApis
ReadS [GetApis]
(Int -> ReadS GetApis)
-> ReadS [GetApis]
-> ReadPrec GetApis
-> ReadPrec [GetApis]
-> Read GetApis
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetApis]
$creadListPrec :: ReadPrec [GetApis]
readPrec :: ReadPrec GetApis
$creadPrec :: ReadPrec GetApis
readList :: ReadS [GetApis]
$creadList :: ReadS [GetApis]
readsPrec :: Int -> ReadS GetApis
$creadsPrec :: Int -> ReadS GetApis
Prelude.Read, Int -> GetApis -> ShowS
[GetApis] -> ShowS
GetApis -> String
(Int -> GetApis -> ShowS)
-> (GetApis -> String) -> ([GetApis] -> ShowS) -> Show GetApis
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetApis] -> ShowS
$cshowList :: [GetApis] -> ShowS
show :: GetApis -> String
$cshow :: GetApis -> String
showsPrec :: Int -> GetApis -> ShowS
$cshowsPrec :: Int -> GetApis -> ShowS
Prelude.Show, (forall x. GetApis -> Rep GetApis x)
-> (forall x. Rep GetApis x -> GetApis) -> Generic GetApis
forall x. Rep GetApis x -> GetApis
forall x. GetApis -> Rep GetApis x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetApis x -> GetApis
$cfrom :: forall x. GetApis -> Rep GetApis x
Prelude.Generic)

-- |
-- Create a value of 'GetApis' 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', 'getApis_nextToken' - The next page of elements from this collection. Not valid for the last
-- element of the collection.
--
-- 'maxResults', 'getApis_maxResults' - The maximum number of elements to be returned for this resource.
newGetApis ::
  GetApis
newGetApis :: GetApis
newGetApis =
  GetApis' :: Maybe Text -> Maybe Text -> GetApis
GetApis'
    { $sel:nextToken:GetApis' :: Maybe Text
nextToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:maxResults:GetApis' :: Maybe Text
maxResults = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The next page of elements from this collection. Not valid for the last
-- element of the collection.
getApis_nextToken :: Lens.Lens' GetApis (Prelude.Maybe Prelude.Text)
getApis_nextToken :: (Maybe Text -> f (Maybe Text)) -> GetApis -> f GetApis
getApis_nextToken = (GetApis -> Maybe Text)
-> (GetApis -> Maybe Text -> GetApis)
-> Lens GetApis GetApis (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetApis' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:GetApis' :: GetApis -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: GetApis
s@GetApis' {} Maybe Text
a -> GetApis
s {$sel:nextToken:GetApis' :: Maybe Text
nextToken = Maybe Text
a} :: GetApis)

-- | The maximum number of elements to be returned for this resource.
getApis_maxResults :: Lens.Lens' GetApis (Prelude.Maybe Prelude.Text)
getApis_maxResults :: (Maybe Text -> f (Maybe Text)) -> GetApis -> f GetApis
getApis_maxResults = (GetApis -> Maybe Text)
-> (GetApis -> Maybe Text -> GetApis)
-> Lens GetApis GetApis (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetApis' {Maybe Text
maxResults :: Maybe Text
$sel:maxResults:GetApis' :: GetApis -> Maybe Text
maxResults} -> Maybe Text
maxResults) (\s :: GetApis
s@GetApis' {} Maybe Text
a -> GetApis
s {$sel:maxResults:GetApis' :: Maybe Text
maxResults = Maybe Text
a} :: GetApis)

instance Core.AWSPager GetApis where
  page :: GetApis -> AWSResponse GetApis -> Maybe GetApis
page GetApis
rq AWSResponse GetApis
rs
    | Maybe Text -> Bool
forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse GetApis
GetApisResponse
rs
            GetApisResponse
-> Getting (First Text) GetApisResponse Text -> Maybe Text
forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? (Maybe Text -> Const (First Text) (Maybe Text))
-> GetApisResponse -> Const (First Text) GetApisResponse
Lens' GetApisResponse (Maybe Text)
getApisResponse_nextToken ((Maybe Text -> Const (First Text) (Maybe Text))
 -> GetApisResponse -> Const (First Text) GetApisResponse)
-> ((Text -> Const (First Text) Text)
    -> Maybe Text -> Const (First Text) (Maybe Text))
-> Getting (First Text) GetApisResponse Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (Text -> Const (First Text) Text)
-> Maybe Text -> Const (First Text) (Maybe Text)
forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
        ) =
      Maybe GetApis
forall a. Maybe a
Prelude.Nothing
    | Maybe [Api] -> Bool
forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse GetApis
GetApisResponse
rs
            GetApisResponse
-> Getting (First [Api]) GetApisResponse [Api] -> Maybe [Api]
forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? (Maybe [Api] -> Const (First [Api]) (Maybe [Api]))
-> GetApisResponse -> Const (First [Api]) GetApisResponse
Lens' GetApisResponse (Maybe [Api])
getApisResponse_items ((Maybe [Api] -> Const (First [Api]) (Maybe [Api]))
 -> GetApisResponse -> Const (First [Api]) GetApisResponse)
-> (([Api] -> Const (First [Api]) [Api])
    -> Maybe [Api] -> Const (First [Api]) (Maybe [Api]))
-> Getting (First [Api]) GetApisResponse [Api]
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Api] -> Const (First [Api]) [Api])
-> Maybe [Api] -> Const (First [Api]) (Maybe [Api])
forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
        ) =
      Maybe GetApis
forall a. Maybe a
Prelude.Nothing
    | Bool
Prelude.otherwise =
      GetApis -> Maybe GetApis
forall a. a -> Maybe a
Prelude.Just (GetApis -> Maybe GetApis) -> GetApis -> Maybe GetApis
forall a b. (a -> b) -> a -> b
Prelude.$
        GetApis
rq
          GetApis -> (GetApis -> GetApis) -> GetApis
forall a b. a -> (a -> b) -> b
Prelude.& (Maybe Text -> Identity (Maybe Text))
-> GetApis -> Identity GetApis
Lens GetApis GetApis (Maybe Text) (Maybe Text)
getApis_nextToken
          ((Maybe Text -> Identity (Maybe Text))
 -> GetApis -> Identity GetApis)
-> Maybe Text -> GetApis -> GetApis
forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse GetApis
GetApisResponse
rs
          GetApisResponse
-> Getting (First Text) GetApisResponse Text -> Maybe Text
forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? (Maybe Text -> Const (First Text) (Maybe Text))
-> GetApisResponse -> Const (First Text) GetApisResponse
Lens' GetApisResponse (Maybe Text)
getApisResponse_nextToken ((Maybe Text -> Const (First Text) (Maybe Text))
 -> GetApisResponse -> Const (First Text) GetApisResponse)
-> ((Text -> Const (First Text) Text)
    -> Maybe Text -> Const (First Text) (Maybe Text))
-> Getting (First Text) GetApisResponse Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (Text -> Const (First Text) Text)
-> Maybe Text -> Const (First Text) (Maybe Text)
forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just

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

instance Prelude.NFData GetApis

instance Core.ToHeaders GetApis where
  toHeaders :: GetApis -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetApis -> 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 GetApis where
  toPath :: GetApis -> ByteString
toPath = ByteString -> GetApis -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/v2/apis"

instance Core.ToQuery GetApis where
  toQuery :: GetApis -> QueryString
toQuery GetApis' {Maybe Text
maxResults :: Maybe Text
nextToken :: Maybe Text
$sel:maxResults:GetApis' :: GetApis -> Maybe Text
$sel:nextToken:GetApis' :: GetApis -> Maybe Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"nextToken" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
nextToken,
        ByteString
"maxResults" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
maxResults
      ]

-- | /See:/ 'newGetApisResponse' smart constructor.
data GetApisResponse = GetApisResponse'
  { -- | The elements from this collection.
    GetApisResponse -> Maybe [Api]
items :: Prelude.Maybe [Api],
    -- | The next page of elements from this collection. Not valid for the last
    -- element of the collection.
    GetApisResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    GetApisResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetApisResponse -> GetApisResponse -> Bool
(GetApisResponse -> GetApisResponse -> Bool)
-> (GetApisResponse -> GetApisResponse -> Bool)
-> Eq GetApisResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetApisResponse -> GetApisResponse -> Bool
$c/= :: GetApisResponse -> GetApisResponse -> Bool
== :: GetApisResponse -> GetApisResponse -> Bool
$c== :: GetApisResponse -> GetApisResponse -> Bool
Prelude.Eq, ReadPrec [GetApisResponse]
ReadPrec GetApisResponse
Int -> ReadS GetApisResponse
ReadS [GetApisResponse]
(Int -> ReadS GetApisResponse)
-> ReadS [GetApisResponse]
-> ReadPrec GetApisResponse
-> ReadPrec [GetApisResponse]
-> Read GetApisResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetApisResponse]
$creadListPrec :: ReadPrec [GetApisResponse]
readPrec :: ReadPrec GetApisResponse
$creadPrec :: ReadPrec GetApisResponse
readList :: ReadS [GetApisResponse]
$creadList :: ReadS [GetApisResponse]
readsPrec :: Int -> ReadS GetApisResponse
$creadsPrec :: Int -> ReadS GetApisResponse
Prelude.Read, Int -> GetApisResponse -> ShowS
[GetApisResponse] -> ShowS
GetApisResponse -> String
(Int -> GetApisResponse -> ShowS)
-> (GetApisResponse -> String)
-> ([GetApisResponse] -> ShowS)
-> Show GetApisResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetApisResponse] -> ShowS
$cshowList :: [GetApisResponse] -> ShowS
show :: GetApisResponse -> String
$cshow :: GetApisResponse -> String
showsPrec :: Int -> GetApisResponse -> ShowS
$cshowsPrec :: Int -> GetApisResponse -> ShowS
Prelude.Show, (forall x. GetApisResponse -> Rep GetApisResponse x)
-> (forall x. Rep GetApisResponse x -> GetApisResponse)
-> Generic GetApisResponse
forall x. Rep GetApisResponse x -> GetApisResponse
forall x. GetApisResponse -> Rep GetApisResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetApisResponse x -> GetApisResponse
$cfrom :: forall x. GetApisResponse -> Rep GetApisResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetApisResponse' 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:
--
-- 'items', 'getApisResponse_items' - The elements from this collection.
--
-- 'nextToken', 'getApisResponse_nextToken' - The next page of elements from this collection. Not valid for the last
-- element of the collection.
--
-- 'httpStatus', 'getApisResponse_httpStatus' - The response's http status code.
newGetApisResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetApisResponse
newGetApisResponse :: Int -> GetApisResponse
newGetApisResponse Int
pHttpStatus_ =
  GetApisResponse' :: Maybe [Api] -> Maybe Text -> Int -> GetApisResponse
GetApisResponse'
    { $sel:items:GetApisResponse' :: Maybe [Api]
items = Maybe [Api]
forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:GetApisResponse' :: Maybe Text
nextToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetApisResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The elements from this collection.
getApisResponse_items :: Lens.Lens' GetApisResponse (Prelude.Maybe [Api])
getApisResponse_items :: (Maybe [Api] -> f (Maybe [Api]))
-> GetApisResponse -> f GetApisResponse
getApisResponse_items = (GetApisResponse -> Maybe [Api])
-> (GetApisResponse -> Maybe [Api] -> GetApisResponse)
-> Lens' GetApisResponse (Maybe [Api])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetApisResponse' {Maybe [Api]
items :: Maybe [Api]
$sel:items:GetApisResponse' :: GetApisResponse -> Maybe [Api]
items} -> Maybe [Api]
items) (\s :: GetApisResponse
s@GetApisResponse' {} Maybe [Api]
a -> GetApisResponse
s {$sel:items:GetApisResponse' :: Maybe [Api]
items = Maybe [Api]
a} :: GetApisResponse) ((Maybe [Api] -> f (Maybe [Api]))
 -> GetApisResponse -> f GetApisResponse)
-> ((Maybe [Api] -> f (Maybe [Api]))
    -> Maybe [Api] -> f (Maybe [Api]))
-> (Maybe [Api] -> f (Maybe [Api]))
-> GetApisResponse
-> f GetApisResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Api] [Api] [Api] [Api]
-> Iso (Maybe [Api]) (Maybe [Api]) (Maybe [Api]) (Maybe [Api])
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 [Api] [Api] [Api] [Api]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The next page of elements from this collection. Not valid for the last
-- element of the collection.
getApisResponse_nextToken :: Lens.Lens' GetApisResponse (Prelude.Maybe Prelude.Text)
getApisResponse_nextToken :: (Maybe Text -> f (Maybe Text))
-> GetApisResponse -> f GetApisResponse
getApisResponse_nextToken = (GetApisResponse -> Maybe Text)
-> (GetApisResponse -> Maybe Text -> GetApisResponse)
-> Lens' GetApisResponse (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetApisResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:GetApisResponse' :: GetApisResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: GetApisResponse
s@GetApisResponse' {} Maybe Text
a -> GetApisResponse
s {$sel:nextToken:GetApisResponse' :: Maybe Text
nextToken = Maybe Text
a} :: GetApisResponse)

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

instance Prelude.NFData GetApisResponse