{-# 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.Mobile.ExportProject
-- 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)
--
-- Exports project configuration to a snapshot which can be downloaded and
-- shared. Note that mobile app push credentials are encrypted in exported
-- projects, so they can only be shared successfully within the same AWS
-- account.
module Amazonka.Mobile.ExportProject
  ( -- * Creating a Request
    ExportProject (..),
    newExportProject,

    -- * Request Lenses
    exportProject_projectId,

    -- * Destructuring the Response
    ExportProjectResponse (..),
    newExportProjectResponse,

    -- * Response Lenses
    exportProjectResponse_shareUrl,
    exportProjectResponse_downloadUrl,
    exportProjectResponse_snapshotId,
    exportProjectResponse_httpStatus,
  )
where

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

-- | Request structure used in requests to export project configuration
-- details.
--
-- /See:/ 'newExportProject' smart constructor.
data ExportProject = ExportProject'
  { -- | Unique project identifier.
    ExportProject -> Text
projectId :: Prelude.Text
  }
  deriving (ExportProject -> ExportProject -> Bool
(ExportProject -> ExportProject -> Bool)
-> (ExportProject -> ExportProject -> Bool) -> Eq ExportProject
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ExportProject -> ExportProject -> Bool
$c/= :: ExportProject -> ExportProject -> Bool
== :: ExportProject -> ExportProject -> Bool
$c== :: ExportProject -> ExportProject -> Bool
Prelude.Eq, ReadPrec [ExportProject]
ReadPrec ExportProject
Int -> ReadS ExportProject
ReadS [ExportProject]
(Int -> ReadS ExportProject)
-> ReadS [ExportProject]
-> ReadPrec ExportProject
-> ReadPrec [ExportProject]
-> Read ExportProject
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ExportProject]
$creadListPrec :: ReadPrec [ExportProject]
readPrec :: ReadPrec ExportProject
$creadPrec :: ReadPrec ExportProject
readList :: ReadS [ExportProject]
$creadList :: ReadS [ExportProject]
readsPrec :: Int -> ReadS ExportProject
$creadsPrec :: Int -> ReadS ExportProject
Prelude.Read, Int -> ExportProject -> ShowS
[ExportProject] -> ShowS
ExportProject -> String
(Int -> ExportProject -> ShowS)
-> (ExportProject -> String)
-> ([ExportProject] -> ShowS)
-> Show ExportProject
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ExportProject] -> ShowS
$cshowList :: [ExportProject] -> ShowS
show :: ExportProject -> String
$cshow :: ExportProject -> String
showsPrec :: Int -> ExportProject -> ShowS
$cshowsPrec :: Int -> ExportProject -> ShowS
Prelude.Show, (forall x. ExportProject -> Rep ExportProject x)
-> (forall x. Rep ExportProject x -> ExportProject)
-> Generic ExportProject
forall x. Rep ExportProject x -> ExportProject
forall x. ExportProject -> Rep ExportProject x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ExportProject x -> ExportProject
$cfrom :: forall x. ExportProject -> Rep ExportProject x
Prelude.Generic)

-- |
-- Create a value of 'ExportProject' 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:
--
-- 'projectId', 'exportProject_projectId' - Unique project identifier.
newExportProject ::
  -- | 'projectId'
  Prelude.Text ->
  ExportProject
newExportProject :: Text -> ExportProject
newExportProject Text
pProjectId_ =
  ExportProject' :: Text -> ExportProject
ExportProject' {$sel:projectId:ExportProject' :: Text
projectId = Text
pProjectId_}

-- | Unique project identifier.
exportProject_projectId :: Lens.Lens' ExportProject Prelude.Text
exportProject_projectId :: (Text -> f Text) -> ExportProject -> f ExportProject
exportProject_projectId = (ExportProject -> Text)
-> (ExportProject -> Text -> ExportProject)
-> Lens ExportProject ExportProject Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ExportProject' {Text
projectId :: Text
$sel:projectId:ExportProject' :: ExportProject -> Text
projectId} -> Text
projectId) (\s :: ExportProject
s@ExportProject' {} Text
a -> ExportProject
s {$sel:projectId:ExportProject' :: Text
projectId = Text
a} :: ExportProject)

instance Core.AWSRequest ExportProject where
  type
    AWSResponse ExportProject =
      ExportProjectResponse
  request :: ExportProject -> Request ExportProject
request = Service -> ExportProject -> Request ExportProject
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy ExportProject
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ExportProject)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse ExportProject))
-> Logger
-> Service
-> Proxy ExportProject
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ExportProject)))
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 Text
-> Maybe Text -> Maybe Text -> Int -> ExportProjectResponse
ExportProjectResponse'
            (Maybe Text
 -> Maybe Text -> Maybe Text -> Int -> ExportProjectResponse)
-> Either String (Maybe Text)
-> Either
     String (Maybe Text -> Maybe Text -> Int -> ExportProjectResponse)
forall (f :: * -> *) a b. Functor 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
"shareUrl")
            Either
  String (Maybe Text -> Maybe Text -> Int -> ExportProjectResponse)
-> Either String (Maybe Text)
-> Either String (Maybe Text -> Int -> ExportProjectResponse)
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
"downloadUrl")
            Either String (Maybe Text -> Int -> ExportProjectResponse)
-> Either String (Maybe Text)
-> Either String (Int -> ExportProjectResponse)
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
"snapshotId")
            Either String (Int -> ExportProjectResponse)
-> Either String Int -> Either String ExportProjectResponse
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 ExportProject

instance Prelude.NFData ExportProject

instance Core.ToHeaders ExportProject where
  toHeaders :: ExportProject -> ResponseHeaders
toHeaders =
    ResponseHeaders -> ExportProject -> 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.ToJSON ExportProject where
  toJSON :: ExportProject -> Value
toJSON = Value -> ExportProject -> Value
forall a b. a -> b -> a
Prelude.const (Object -> Value
Core.Object Object
forall a. Monoid a => a
Prelude.mempty)

instance Core.ToPath ExportProject where
  toPath :: ExportProject -> ByteString
toPath ExportProject' {Text
projectId :: Text
$sel:projectId:ExportProject' :: ExportProject -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"/exports/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
projectId]

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

-- | Result structure used for requests to export project configuration
-- details.
--
-- /See:/ 'newExportProjectResponse' smart constructor.
data ExportProjectResponse = ExportProjectResponse'
  { -- | URL which can be shared to allow other AWS users to create their own
    -- project in AWS Mobile Hub with the same configuration as the specified
    -- project. This URL pertains to a snapshot in time of the project
    -- configuration that is created when this API is called. If you want to
    -- share additional changes to your project configuration, then you will
    -- need to create and share a new snapshot by calling this method again.
    ExportProjectResponse -> Maybe Text
shareUrl :: Prelude.Maybe Prelude.Text,
    -- | URL which can be used to download the exported project configuation
    -- file(s).
    ExportProjectResponse -> Maybe Text
downloadUrl :: Prelude.Maybe Prelude.Text,
    -- | Unique identifier for the exported snapshot of the project
    -- configuration. This snapshot identifier is included in the share URL.
    ExportProjectResponse -> Maybe Text
snapshotId :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ExportProjectResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ExportProjectResponse -> ExportProjectResponse -> Bool
(ExportProjectResponse -> ExportProjectResponse -> Bool)
-> (ExportProjectResponse -> ExportProjectResponse -> Bool)
-> Eq ExportProjectResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ExportProjectResponse -> ExportProjectResponse -> Bool
$c/= :: ExportProjectResponse -> ExportProjectResponse -> Bool
== :: ExportProjectResponse -> ExportProjectResponse -> Bool
$c== :: ExportProjectResponse -> ExportProjectResponse -> Bool
Prelude.Eq, ReadPrec [ExportProjectResponse]
ReadPrec ExportProjectResponse
Int -> ReadS ExportProjectResponse
ReadS [ExportProjectResponse]
(Int -> ReadS ExportProjectResponse)
-> ReadS [ExportProjectResponse]
-> ReadPrec ExportProjectResponse
-> ReadPrec [ExportProjectResponse]
-> Read ExportProjectResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ExportProjectResponse]
$creadListPrec :: ReadPrec [ExportProjectResponse]
readPrec :: ReadPrec ExportProjectResponse
$creadPrec :: ReadPrec ExportProjectResponse
readList :: ReadS [ExportProjectResponse]
$creadList :: ReadS [ExportProjectResponse]
readsPrec :: Int -> ReadS ExportProjectResponse
$creadsPrec :: Int -> ReadS ExportProjectResponse
Prelude.Read, Int -> ExportProjectResponse -> ShowS
[ExportProjectResponse] -> ShowS
ExportProjectResponse -> String
(Int -> ExportProjectResponse -> ShowS)
-> (ExportProjectResponse -> String)
-> ([ExportProjectResponse] -> ShowS)
-> Show ExportProjectResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ExportProjectResponse] -> ShowS
$cshowList :: [ExportProjectResponse] -> ShowS
show :: ExportProjectResponse -> String
$cshow :: ExportProjectResponse -> String
showsPrec :: Int -> ExportProjectResponse -> ShowS
$cshowsPrec :: Int -> ExportProjectResponse -> ShowS
Prelude.Show, (forall x. ExportProjectResponse -> Rep ExportProjectResponse x)
-> (forall x. Rep ExportProjectResponse x -> ExportProjectResponse)
-> Generic ExportProjectResponse
forall x. Rep ExportProjectResponse x -> ExportProjectResponse
forall x. ExportProjectResponse -> Rep ExportProjectResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ExportProjectResponse x -> ExportProjectResponse
$cfrom :: forall x. ExportProjectResponse -> Rep ExportProjectResponse x
Prelude.Generic)

-- |
-- Create a value of 'ExportProjectResponse' 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:
--
-- 'shareUrl', 'exportProjectResponse_shareUrl' - URL which can be shared to allow other AWS users to create their own
-- project in AWS Mobile Hub with the same configuration as the specified
-- project. This URL pertains to a snapshot in time of the project
-- configuration that is created when this API is called. If you want to
-- share additional changes to your project configuration, then you will
-- need to create and share a new snapshot by calling this method again.
--
-- 'downloadUrl', 'exportProjectResponse_downloadUrl' - URL which can be used to download the exported project configuation
-- file(s).
--
-- 'snapshotId', 'exportProjectResponse_snapshotId' - Unique identifier for the exported snapshot of the project
-- configuration. This snapshot identifier is included in the share URL.
--
-- 'httpStatus', 'exportProjectResponse_httpStatus' - The response's http status code.
newExportProjectResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ExportProjectResponse
newExportProjectResponse :: Int -> ExportProjectResponse
newExportProjectResponse Int
pHttpStatus_ =
  ExportProjectResponse' :: Maybe Text
-> Maybe Text -> Maybe Text -> Int -> ExportProjectResponse
ExportProjectResponse'
    { $sel:shareUrl:ExportProjectResponse' :: Maybe Text
shareUrl = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:downloadUrl:ExportProjectResponse' :: Maybe Text
downloadUrl = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:snapshotId:ExportProjectResponse' :: Maybe Text
snapshotId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ExportProjectResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | URL which can be shared to allow other AWS users to create their own
-- project in AWS Mobile Hub with the same configuration as the specified
-- project. This URL pertains to a snapshot in time of the project
-- configuration that is created when this API is called. If you want to
-- share additional changes to your project configuration, then you will
-- need to create and share a new snapshot by calling this method again.
exportProjectResponse_shareUrl :: Lens.Lens' ExportProjectResponse (Prelude.Maybe Prelude.Text)
exportProjectResponse_shareUrl :: (Maybe Text -> f (Maybe Text))
-> ExportProjectResponse -> f ExportProjectResponse
exportProjectResponse_shareUrl = (ExportProjectResponse -> Maybe Text)
-> (ExportProjectResponse -> Maybe Text -> ExportProjectResponse)
-> Lens
     ExportProjectResponse
     ExportProjectResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ExportProjectResponse' {Maybe Text
shareUrl :: Maybe Text
$sel:shareUrl:ExportProjectResponse' :: ExportProjectResponse -> Maybe Text
shareUrl} -> Maybe Text
shareUrl) (\s :: ExportProjectResponse
s@ExportProjectResponse' {} Maybe Text
a -> ExportProjectResponse
s {$sel:shareUrl:ExportProjectResponse' :: Maybe Text
shareUrl = Maybe Text
a} :: ExportProjectResponse)

-- | URL which can be used to download the exported project configuation
-- file(s).
exportProjectResponse_downloadUrl :: Lens.Lens' ExportProjectResponse (Prelude.Maybe Prelude.Text)
exportProjectResponse_downloadUrl :: (Maybe Text -> f (Maybe Text))
-> ExportProjectResponse -> f ExportProjectResponse
exportProjectResponse_downloadUrl = (ExportProjectResponse -> Maybe Text)
-> (ExportProjectResponse -> Maybe Text -> ExportProjectResponse)
-> Lens
     ExportProjectResponse
     ExportProjectResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ExportProjectResponse' {Maybe Text
downloadUrl :: Maybe Text
$sel:downloadUrl:ExportProjectResponse' :: ExportProjectResponse -> Maybe Text
downloadUrl} -> Maybe Text
downloadUrl) (\s :: ExportProjectResponse
s@ExportProjectResponse' {} Maybe Text
a -> ExportProjectResponse
s {$sel:downloadUrl:ExportProjectResponse' :: Maybe Text
downloadUrl = Maybe Text
a} :: ExportProjectResponse)

-- | Unique identifier for the exported snapshot of the project
-- configuration. This snapshot identifier is included in the share URL.
exportProjectResponse_snapshotId :: Lens.Lens' ExportProjectResponse (Prelude.Maybe Prelude.Text)
exportProjectResponse_snapshotId :: (Maybe Text -> f (Maybe Text))
-> ExportProjectResponse -> f ExportProjectResponse
exportProjectResponse_snapshotId = (ExportProjectResponse -> Maybe Text)
-> (ExportProjectResponse -> Maybe Text -> ExportProjectResponse)
-> Lens
     ExportProjectResponse
     ExportProjectResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ExportProjectResponse' {Maybe Text
snapshotId :: Maybe Text
$sel:snapshotId:ExportProjectResponse' :: ExportProjectResponse -> Maybe Text
snapshotId} -> Maybe Text
snapshotId) (\s :: ExportProjectResponse
s@ExportProjectResponse' {} Maybe Text
a -> ExportProjectResponse
s {$sel:snapshotId:ExportProjectResponse' :: Maybe Text
snapshotId = Maybe Text
a} :: ExportProjectResponse)

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

instance Prelude.NFData ExportProjectResponse