{-# 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.Glue.StartCrawler
-- 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)
--
-- Starts a crawl using the specified crawler, regardless of what is
-- scheduled. If the crawler is already running, returns a
-- <https://docs.aws.amazon.com/glue/latest/dg/aws-glue-api-exceptions.html#aws-glue-api-exceptions-CrawlerRunningException CrawlerRunningException>.
module Amazonka.Glue.StartCrawler
  ( -- * Creating a Request
    StartCrawler (..),
    newStartCrawler,

    -- * Request Lenses
    startCrawler_name,

    -- * Destructuring the Response
    StartCrawlerResponse (..),
    newStartCrawlerResponse,

    -- * Response Lenses
    startCrawlerResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.Glue.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

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

-- |
-- Create a value of 'StartCrawler' 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:
--
-- 'name', 'startCrawler_name' - Name of the crawler to start.
newStartCrawler ::
  -- | 'name'
  Prelude.Text ->
  StartCrawler
newStartCrawler :: Text -> StartCrawler
newStartCrawler Text
pName_ = StartCrawler' :: Text -> StartCrawler
StartCrawler' {$sel:name:StartCrawler' :: Text
name = Text
pName_}

-- | Name of the crawler to start.
startCrawler_name :: Lens.Lens' StartCrawler Prelude.Text
startCrawler_name :: (Text -> f Text) -> StartCrawler -> f StartCrawler
startCrawler_name = (StartCrawler -> Text)
-> (StartCrawler -> Text -> StartCrawler)
-> Lens StartCrawler StartCrawler Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartCrawler' {Text
name :: Text
$sel:name:StartCrawler' :: StartCrawler -> Text
name} -> Text
name) (\s :: StartCrawler
s@StartCrawler' {} Text
a -> StartCrawler
s {$sel:name:StartCrawler' :: Text
name = Text
a} :: StartCrawler)

instance Core.AWSRequest StartCrawler where
  type AWSResponse StartCrawler = StartCrawlerResponse
  request :: StartCrawler -> Request StartCrawler
request = Service -> StartCrawler -> Request StartCrawler
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy StartCrawler
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse StartCrawler)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse StartCrawler))
-> Logger
-> Service
-> Proxy StartCrawler
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse StartCrawler)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> StartCrawlerResponse
StartCrawlerResponse'
            (Int -> StartCrawlerResponse)
-> Either String Int -> Either String StartCrawlerResponse
forall (f :: * -> *) a b. Functor 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 StartCrawler

instance Prelude.NFData StartCrawler

instance Core.ToHeaders StartCrawler where
  toHeaders :: StartCrawler -> ResponseHeaders
toHeaders =
    ResponseHeaders -> StartCrawler -> 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
"AWSGlue.StartCrawler" :: 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 StartCrawler where
  toJSON :: StartCrawler -> Value
toJSON StartCrawler' {Text
name :: Text
$sel:name:StartCrawler' :: StartCrawler -> 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
"Name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name)]
      )

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

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

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

-- |
-- Create a value of 'StartCrawlerResponse' 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:
--
-- 'httpStatus', 'startCrawlerResponse_httpStatus' - The response's http status code.
newStartCrawlerResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  StartCrawlerResponse
newStartCrawlerResponse :: Int -> StartCrawlerResponse
newStartCrawlerResponse Int
pHttpStatus_ =
  StartCrawlerResponse' :: Int -> StartCrawlerResponse
StartCrawlerResponse' {$sel:httpStatus:StartCrawlerResponse' :: Int
httpStatus = Int
pHttpStatus_}

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

instance Prelude.NFData StartCrawlerResponse