{-# 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.CognitoSync.RegisterDevice
-- 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)
--
-- Registers a device to receive push sync notifications.
--
-- This API can only be called with temporary credentials provided by
-- Cognito Identity. You cannot call this API with developer credentials.
module Amazonka.CognitoSync.RegisterDevice
  ( -- * Creating a Request
    RegisterDevice (..),
    newRegisterDevice,

    -- * Request Lenses
    registerDevice_identityPoolId,
    registerDevice_identityId,
    registerDevice_platform,
    registerDevice_token,

    -- * Destructuring the Response
    RegisterDeviceResponse (..),
    newRegisterDeviceResponse,

    -- * Response Lenses
    registerDeviceResponse_deviceId,
    registerDeviceResponse_httpStatus,
  )
where

import Amazonka.CognitoSync.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

-- | A request to RegisterDevice.
--
-- /See:/ 'newRegisterDevice' smart constructor.
data RegisterDevice = RegisterDevice'
  { -- | A name-spaced GUID (for example,
    -- us-east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
    -- Cognito. Here, the ID of the pool that the identity belongs to.
    RegisterDevice -> Text
identityPoolId :: Prelude.Text,
    -- | The unique ID for this identity.
    RegisterDevice -> Text
identityId :: Prelude.Text,
    -- | The SNS platform type (e.g. GCM, SDM, APNS, APNS_SANDBOX).
    RegisterDevice -> Platform
platform :: Platform,
    -- | The push token.
    RegisterDevice -> Text
token :: Prelude.Text
  }
  deriving (RegisterDevice -> RegisterDevice -> Bool
(RegisterDevice -> RegisterDevice -> Bool)
-> (RegisterDevice -> RegisterDevice -> Bool) -> Eq RegisterDevice
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RegisterDevice -> RegisterDevice -> Bool
$c/= :: RegisterDevice -> RegisterDevice -> Bool
== :: RegisterDevice -> RegisterDevice -> Bool
$c== :: RegisterDevice -> RegisterDevice -> Bool
Prelude.Eq, ReadPrec [RegisterDevice]
ReadPrec RegisterDevice
Int -> ReadS RegisterDevice
ReadS [RegisterDevice]
(Int -> ReadS RegisterDevice)
-> ReadS [RegisterDevice]
-> ReadPrec RegisterDevice
-> ReadPrec [RegisterDevice]
-> Read RegisterDevice
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RegisterDevice]
$creadListPrec :: ReadPrec [RegisterDevice]
readPrec :: ReadPrec RegisterDevice
$creadPrec :: ReadPrec RegisterDevice
readList :: ReadS [RegisterDevice]
$creadList :: ReadS [RegisterDevice]
readsPrec :: Int -> ReadS RegisterDevice
$creadsPrec :: Int -> ReadS RegisterDevice
Prelude.Read, Int -> RegisterDevice -> ShowS
[RegisterDevice] -> ShowS
RegisterDevice -> String
(Int -> RegisterDevice -> ShowS)
-> (RegisterDevice -> String)
-> ([RegisterDevice] -> ShowS)
-> Show RegisterDevice
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RegisterDevice] -> ShowS
$cshowList :: [RegisterDevice] -> ShowS
show :: RegisterDevice -> String
$cshow :: RegisterDevice -> String
showsPrec :: Int -> RegisterDevice -> ShowS
$cshowsPrec :: Int -> RegisterDevice -> ShowS
Prelude.Show, (forall x. RegisterDevice -> Rep RegisterDevice x)
-> (forall x. Rep RegisterDevice x -> RegisterDevice)
-> Generic RegisterDevice
forall x. Rep RegisterDevice x -> RegisterDevice
forall x. RegisterDevice -> Rep RegisterDevice x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RegisterDevice x -> RegisterDevice
$cfrom :: forall x. RegisterDevice -> Rep RegisterDevice x
Prelude.Generic)

-- |
-- Create a value of 'RegisterDevice' 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:
--
-- 'identityPoolId', 'registerDevice_identityPoolId' - A name-spaced GUID (for example,
-- us-east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
-- Cognito. Here, the ID of the pool that the identity belongs to.
--
-- 'identityId', 'registerDevice_identityId' - The unique ID for this identity.
--
-- 'platform', 'registerDevice_platform' - The SNS platform type (e.g. GCM, SDM, APNS, APNS_SANDBOX).
--
-- 'token', 'registerDevice_token' - The push token.
newRegisterDevice ::
  -- | 'identityPoolId'
  Prelude.Text ->
  -- | 'identityId'
  Prelude.Text ->
  -- | 'platform'
  Platform ->
  -- | 'token'
  Prelude.Text ->
  RegisterDevice
newRegisterDevice :: Text -> Text -> Platform -> Text -> RegisterDevice
newRegisterDevice
  Text
pIdentityPoolId_
  Text
pIdentityId_
  Platform
pPlatform_
  Text
pToken_ =
    RegisterDevice' :: Text -> Text -> Platform -> Text -> RegisterDevice
RegisterDevice'
      { $sel:identityPoolId:RegisterDevice' :: Text
identityPoolId = Text
pIdentityPoolId_,
        $sel:identityId:RegisterDevice' :: Text
identityId = Text
pIdentityId_,
        $sel:platform:RegisterDevice' :: Platform
platform = Platform
pPlatform_,
        $sel:token:RegisterDevice' :: Text
token = Text
pToken_
      }

-- | A name-spaced GUID (for example,
-- us-east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
-- Cognito. Here, the ID of the pool that the identity belongs to.
registerDevice_identityPoolId :: Lens.Lens' RegisterDevice Prelude.Text
registerDevice_identityPoolId :: (Text -> f Text) -> RegisterDevice -> f RegisterDevice
registerDevice_identityPoolId = (RegisterDevice -> Text)
-> (RegisterDevice -> Text -> RegisterDevice)
-> Lens RegisterDevice RegisterDevice Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterDevice' {Text
identityPoolId :: Text
$sel:identityPoolId:RegisterDevice' :: RegisterDevice -> Text
identityPoolId} -> Text
identityPoolId) (\s :: RegisterDevice
s@RegisterDevice' {} Text
a -> RegisterDevice
s {$sel:identityPoolId:RegisterDevice' :: Text
identityPoolId = Text
a} :: RegisterDevice)

-- | The unique ID for this identity.
registerDevice_identityId :: Lens.Lens' RegisterDevice Prelude.Text
registerDevice_identityId :: (Text -> f Text) -> RegisterDevice -> f RegisterDevice
registerDevice_identityId = (RegisterDevice -> Text)
-> (RegisterDevice -> Text -> RegisterDevice)
-> Lens RegisterDevice RegisterDevice Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterDevice' {Text
identityId :: Text
$sel:identityId:RegisterDevice' :: RegisterDevice -> Text
identityId} -> Text
identityId) (\s :: RegisterDevice
s@RegisterDevice' {} Text
a -> RegisterDevice
s {$sel:identityId:RegisterDevice' :: Text
identityId = Text
a} :: RegisterDevice)

-- | The SNS platform type (e.g. GCM, SDM, APNS, APNS_SANDBOX).
registerDevice_platform :: Lens.Lens' RegisterDevice Platform
registerDevice_platform :: (Platform -> f Platform) -> RegisterDevice -> f RegisterDevice
registerDevice_platform = (RegisterDevice -> Platform)
-> (RegisterDevice -> Platform -> RegisterDevice)
-> Lens RegisterDevice RegisterDevice Platform Platform
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterDevice' {Platform
platform :: Platform
$sel:platform:RegisterDevice' :: RegisterDevice -> Platform
platform} -> Platform
platform) (\s :: RegisterDevice
s@RegisterDevice' {} Platform
a -> RegisterDevice
s {$sel:platform:RegisterDevice' :: Platform
platform = Platform
a} :: RegisterDevice)

-- | The push token.
registerDevice_token :: Lens.Lens' RegisterDevice Prelude.Text
registerDevice_token :: (Text -> f Text) -> RegisterDevice -> f RegisterDevice
registerDevice_token = (RegisterDevice -> Text)
-> (RegisterDevice -> Text -> RegisterDevice)
-> Lens RegisterDevice RegisterDevice Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterDevice' {Text
token :: Text
$sel:token:RegisterDevice' :: RegisterDevice -> Text
token} -> Text
token) (\s :: RegisterDevice
s@RegisterDevice' {} Text
a -> RegisterDevice
s {$sel:token:RegisterDevice' :: Text
token = Text
a} :: RegisterDevice)

instance Core.AWSRequest RegisterDevice where
  type
    AWSResponse RegisterDevice =
      RegisterDeviceResponse
  request :: RegisterDevice -> Request RegisterDevice
request = Service -> RegisterDevice -> Request RegisterDevice
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy RegisterDevice
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse RegisterDevice)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse RegisterDevice))
-> Logger
-> Service
-> Proxy RegisterDevice
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse RegisterDevice)))
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 -> Int -> RegisterDeviceResponse
RegisterDeviceResponse'
            (Maybe Text -> Int -> RegisterDeviceResponse)
-> Either String (Maybe Text)
-> Either String (Int -> RegisterDeviceResponse)
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
"DeviceId")
            Either String (Int -> RegisterDeviceResponse)
-> Either String Int -> Either String RegisterDeviceResponse
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 RegisterDevice

instance Prelude.NFData RegisterDevice

instance Core.ToHeaders RegisterDevice where
  toHeaders :: RegisterDevice -> ResponseHeaders
toHeaders =
    ResponseHeaders -> RegisterDevice -> 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 RegisterDevice where
  toJSON :: RegisterDevice -> Value
toJSON RegisterDevice' {Text
Platform
token :: Text
platform :: Platform
identityId :: Text
identityPoolId :: Text
$sel:token:RegisterDevice' :: RegisterDevice -> Text
$sel:platform:RegisterDevice' :: RegisterDevice -> Platform
$sel:identityId:RegisterDevice' :: RegisterDevice -> Text
$sel:identityPoolId:RegisterDevice' :: RegisterDevice -> 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
"Platform" Text -> Platform -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Platform
platform),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Token" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
token)
          ]
      )

instance Core.ToPath RegisterDevice where
  toPath :: RegisterDevice -> ByteString
toPath RegisterDevice' {Text
Platform
token :: Text
platform :: Platform
identityId :: Text
identityPoolId :: Text
$sel:token:RegisterDevice' :: RegisterDevice -> Text
$sel:platform:RegisterDevice' :: RegisterDevice -> Platform
$sel:identityId:RegisterDevice' :: RegisterDevice -> Text
$sel:identityPoolId:RegisterDevice' :: RegisterDevice -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/identitypools/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
identityPoolId,
        ByteString
"/identity/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
identityId,
        ByteString
"/device"
      ]

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

-- | Response to a RegisterDevice request.
--
-- /See:/ 'newRegisterDeviceResponse' smart constructor.
data RegisterDeviceResponse = RegisterDeviceResponse'
  { -- | The unique ID generated for this device by Cognito.
    RegisterDeviceResponse -> Maybe Text
deviceId :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    RegisterDeviceResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (RegisterDeviceResponse -> RegisterDeviceResponse -> Bool
(RegisterDeviceResponse -> RegisterDeviceResponse -> Bool)
-> (RegisterDeviceResponse -> RegisterDeviceResponse -> Bool)
-> Eq RegisterDeviceResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RegisterDeviceResponse -> RegisterDeviceResponse -> Bool
$c/= :: RegisterDeviceResponse -> RegisterDeviceResponse -> Bool
== :: RegisterDeviceResponse -> RegisterDeviceResponse -> Bool
$c== :: RegisterDeviceResponse -> RegisterDeviceResponse -> Bool
Prelude.Eq, ReadPrec [RegisterDeviceResponse]
ReadPrec RegisterDeviceResponse
Int -> ReadS RegisterDeviceResponse
ReadS [RegisterDeviceResponse]
(Int -> ReadS RegisterDeviceResponse)
-> ReadS [RegisterDeviceResponse]
-> ReadPrec RegisterDeviceResponse
-> ReadPrec [RegisterDeviceResponse]
-> Read RegisterDeviceResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RegisterDeviceResponse]
$creadListPrec :: ReadPrec [RegisterDeviceResponse]
readPrec :: ReadPrec RegisterDeviceResponse
$creadPrec :: ReadPrec RegisterDeviceResponse
readList :: ReadS [RegisterDeviceResponse]
$creadList :: ReadS [RegisterDeviceResponse]
readsPrec :: Int -> ReadS RegisterDeviceResponse
$creadsPrec :: Int -> ReadS RegisterDeviceResponse
Prelude.Read, Int -> RegisterDeviceResponse -> ShowS
[RegisterDeviceResponse] -> ShowS
RegisterDeviceResponse -> String
(Int -> RegisterDeviceResponse -> ShowS)
-> (RegisterDeviceResponse -> String)
-> ([RegisterDeviceResponse] -> ShowS)
-> Show RegisterDeviceResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RegisterDeviceResponse] -> ShowS
$cshowList :: [RegisterDeviceResponse] -> ShowS
show :: RegisterDeviceResponse -> String
$cshow :: RegisterDeviceResponse -> String
showsPrec :: Int -> RegisterDeviceResponse -> ShowS
$cshowsPrec :: Int -> RegisterDeviceResponse -> ShowS
Prelude.Show, (forall x. RegisterDeviceResponse -> Rep RegisterDeviceResponse x)
-> (forall x.
    Rep RegisterDeviceResponse x -> RegisterDeviceResponse)
-> Generic RegisterDeviceResponse
forall x. Rep RegisterDeviceResponse x -> RegisterDeviceResponse
forall x. RegisterDeviceResponse -> Rep RegisterDeviceResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RegisterDeviceResponse x -> RegisterDeviceResponse
$cfrom :: forall x. RegisterDeviceResponse -> Rep RegisterDeviceResponse x
Prelude.Generic)

-- |
-- Create a value of 'RegisterDeviceResponse' 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:
--
-- 'deviceId', 'registerDeviceResponse_deviceId' - The unique ID generated for this device by Cognito.
--
-- 'httpStatus', 'registerDeviceResponse_httpStatus' - The response's http status code.
newRegisterDeviceResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  RegisterDeviceResponse
newRegisterDeviceResponse :: Int -> RegisterDeviceResponse
newRegisterDeviceResponse Int
pHttpStatus_ =
  RegisterDeviceResponse' :: Maybe Text -> Int -> RegisterDeviceResponse
RegisterDeviceResponse'
    { $sel:deviceId:RegisterDeviceResponse' :: Maybe Text
deviceId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:RegisterDeviceResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The unique ID generated for this device by Cognito.
registerDeviceResponse_deviceId :: Lens.Lens' RegisterDeviceResponse (Prelude.Maybe Prelude.Text)
registerDeviceResponse_deviceId :: (Maybe Text -> f (Maybe Text))
-> RegisterDeviceResponse -> f RegisterDeviceResponse
registerDeviceResponse_deviceId = (RegisterDeviceResponse -> Maybe Text)
-> (RegisterDeviceResponse -> Maybe Text -> RegisterDeviceResponse)
-> Lens
     RegisterDeviceResponse
     RegisterDeviceResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterDeviceResponse' {Maybe Text
deviceId :: Maybe Text
$sel:deviceId:RegisterDeviceResponse' :: RegisterDeviceResponse -> Maybe Text
deviceId} -> Maybe Text
deviceId) (\s :: RegisterDeviceResponse
s@RegisterDeviceResponse' {} Maybe Text
a -> RegisterDeviceResponse
s {$sel:deviceId:RegisterDeviceResponse' :: Maybe Text
deviceId = Maybe Text
a} :: RegisterDeviceResponse)

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

instance Prelude.NFData RegisterDeviceResponse