{-# 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.SNS.GetEndpointAttributes
-- 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)
--
-- Retrieves the endpoint attributes for a device on one of the supported
-- push notification services, such as GCM (Firebase Cloud Messaging) and
-- APNS. For more information, see
-- <https://docs.aws.amazon.com/sns/latest/dg/SNSMobilePush.html Using Amazon SNS Mobile Push Notifications>.
module Amazonka.SNS.GetEndpointAttributes
  ( -- * Creating a Request
    GetEndpointAttributes (..),
    newGetEndpointAttributes,

    -- * Request Lenses
    getEndpointAttributes_endpointArn,

    -- * Destructuring the Response
    GetEndpointAttributesResponse (..),
    newGetEndpointAttributesResponse,

    -- * Response Lenses
    getEndpointAttributesResponse_attributes,
    getEndpointAttributesResponse_httpStatus,
  )
where

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
import Amazonka.SNS.Types

-- | Input for GetEndpointAttributes action.
--
-- /See:/ 'newGetEndpointAttributes' smart constructor.
data GetEndpointAttributes = GetEndpointAttributes'
  { -- | EndpointArn for GetEndpointAttributes input.
    GetEndpointAttributes -> Text
endpointArn :: Prelude.Text
  }
  deriving (GetEndpointAttributes -> GetEndpointAttributes -> Bool
(GetEndpointAttributes -> GetEndpointAttributes -> Bool)
-> (GetEndpointAttributes -> GetEndpointAttributes -> Bool)
-> Eq GetEndpointAttributes
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetEndpointAttributes -> GetEndpointAttributes -> Bool
$c/= :: GetEndpointAttributes -> GetEndpointAttributes -> Bool
== :: GetEndpointAttributes -> GetEndpointAttributes -> Bool
$c== :: GetEndpointAttributes -> GetEndpointAttributes -> Bool
Prelude.Eq, ReadPrec [GetEndpointAttributes]
ReadPrec GetEndpointAttributes
Int -> ReadS GetEndpointAttributes
ReadS [GetEndpointAttributes]
(Int -> ReadS GetEndpointAttributes)
-> ReadS [GetEndpointAttributes]
-> ReadPrec GetEndpointAttributes
-> ReadPrec [GetEndpointAttributes]
-> Read GetEndpointAttributes
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetEndpointAttributes]
$creadListPrec :: ReadPrec [GetEndpointAttributes]
readPrec :: ReadPrec GetEndpointAttributes
$creadPrec :: ReadPrec GetEndpointAttributes
readList :: ReadS [GetEndpointAttributes]
$creadList :: ReadS [GetEndpointAttributes]
readsPrec :: Int -> ReadS GetEndpointAttributes
$creadsPrec :: Int -> ReadS GetEndpointAttributes
Prelude.Read, Int -> GetEndpointAttributes -> ShowS
[GetEndpointAttributes] -> ShowS
GetEndpointAttributes -> String
(Int -> GetEndpointAttributes -> ShowS)
-> (GetEndpointAttributes -> String)
-> ([GetEndpointAttributes] -> ShowS)
-> Show GetEndpointAttributes
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetEndpointAttributes] -> ShowS
$cshowList :: [GetEndpointAttributes] -> ShowS
show :: GetEndpointAttributes -> String
$cshow :: GetEndpointAttributes -> String
showsPrec :: Int -> GetEndpointAttributes -> ShowS
$cshowsPrec :: Int -> GetEndpointAttributes -> ShowS
Prelude.Show, (forall x. GetEndpointAttributes -> Rep GetEndpointAttributes x)
-> (forall x. Rep GetEndpointAttributes x -> GetEndpointAttributes)
-> Generic GetEndpointAttributes
forall x. Rep GetEndpointAttributes x -> GetEndpointAttributes
forall x. GetEndpointAttributes -> Rep GetEndpointAttributes x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetEndpointAttributes x -> GetEndpointAttributes
$cfrom :: forall x. GetEndpointAttributes -> Rep GetEndpointAttributes x
Prelude.Generic)

-- |
-- Create a value of 'GetEndpointAttributes' 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:
--
-- 'endpointArn', 'getEndpointAttributes_endpointArn' - EndpointArn for GetEndpointAttributes input.
newGetEndpointAttributes ::
  -- | 'endpointArn'
  Prelude.Text ->
  GetEndpointAttributes
newGetEndpointAttributes :: Text -> GetEndpointAttributes
newGetEndpointAttributes Text
pEndpointArn_ =
  GetEndpointAttributes' :: Text -> GetEndpointAttributes
GetEndpointAttributes' {$sel:endpointArn:GetEndpointAttributes' :: Text
endpointArn = Text
pEndpointArn_}

-- | EndpointArn for GetEndpointAttributes input.
getEndpointAttributes_endpointArn :: Lens.Lens' GetEndpointAttributes Prelude.Text
getEndpointAttributes_endpointArn :: (Text -> f Text)
-> GetEndpointAttributes -> f GetEndpointAttributes
getEndpointAttributes_endpointArn = (GetEndpointAttributes -> Text)
-> (GetEndpointAttributes -> Text -> GetEndpointAttributes)
-> Lens GetEndpointAttributes GetEndpointAttributes Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetEndpointAttributes' {Text
endpointArn :: Text
$sel:endpointArn:GetEndpointAttributes' :: GetEndpointAttributes -> Text
endpointArn} -> Text
endpointArn) (\s :: GetEndpointAttributes
s@GetEndpointAttributes' {} Text
a -> GetEndpointAttributes
s {$sel:endpointArn:GetEndpointAttributes' :: Text
endpointArn = Text
a} :: GetEndpointAttributes)

instance Core.AWSRequest GetEndpointAttributes where
  type
    AWSResponse GetEndpointAttributes =
      GetEndpointAttributesResponse
  request :: GetEndpointAttributes -> Request GetEndpointAttributes
request = Service -> GetEndpointAttributes -> Request GetEndpointAttributes
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy GetEndpointAttributes
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetEndpointAttributes)))
response =
    Text
-> (Int
    -> ResponseHeaders
    -> [Node]
    -> Either String (AWSResponse GetEndpointAttributes))
-> Logger
-> Service
-> Proxy GetEndpointAttributes
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetEndpointAttributes)))
forall (m :: * -> *) a.
MonadResource m =>
Text
-> (Int
    -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXMLWrapper
      Text
"GetEndpointAttributesResult"
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Maybe (HashMap Text Text) -> Int -> GetEndpointAttributesResponse
GetEndpointAttributesResponse'
            (Maybe (HashMap Text Text) -> Int -> GetEndpointAttributesResponse)
-> Either String (Maybe (HashMap Text Text))
-> Either String (Int -> GetEndpointAttributesResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( [Node]
x [Node] -> Text -> Either String (Maybe [Node])
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Attributes" Either String (Maybe [Node]) -> [Node] -> Either String [Node]
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ [Node]
forall a. Monoid a => a
Prelude.mempty
                            Either String [Node]
-> ([Node] -> Either String (Maybe (HashMap Text Text)))
-> Either String (Maybe (HashMap Text Text))
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= ([Node] -> Either String (HashMap Text Text))
-> [Node] -> Either String (Maybe (HashMap Text Text))
forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (Text -> Text -> Text -> [Node] -> Either String (HashMap Text Text)
forall k v.
(Eq k, Hashable k, FromText k, FromXML v) =>
Text -> Text -> Text -> [Node] -> Either String (HashMap k v)
Core.parseXMLMap Text
"entry" Text
"key" Text
"value")
                        )
            Either String (Int -> GetEndpointAttributesResponse)
-> Either String Int -> Either String GetEndpointAttributesResponse
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 GetEndpointAttributes

instance Prelude.NFData GetEndpointAttributes

instance Core.ToHeaders GetEndpointAttributes where
  toHeaders :: GetEndpointAttributes -> ResponseHeaders
toHeaders = ResponseHeaders -> GetEndpointAttributes -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

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

instance Core.ToQuery GetEndpointAttributes where
  toQuery :: GetEndpointAttributes -> QueryString
toQuery GetEndpointAttributes' {Text
endpointArn :: Text
$sel:endpointArn:GetEndpointAttributes' :: GetEndpointAttributes -> Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"GetEndpointAttributes" :: Prelude.ByteString),
        ByteString
"Version"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"2010-03-31" :: Prelude.ByteString),
        ByteString
"EndpointArn" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
endpointArn
      ]

-- | Response from GetEndpointAttributes of the EndpointArn.
--
-- /See:/ 'newGetEndpointAttributesResponse' smart constructor.
data GetEndpointAttributesResponse = GetEndpointAttributesResponse'
  { -- | Attributes include the following:
    --
    -- -   @CustomUserData@ – arbitrary user data to associate with the
    --     endpoint. Amazon SNS does not use this data. The data must be in
    --     UTF-8 format and less than 2KB.
    --
    -- -   @Enabled@ – flag that enables\/disables delivery to the endpoint.
    --     Amazon SNS will set this to false when a notification service
    --     indicates to Amazon SNS that the endpoint is invalid. Users can set
    --     it back to true, typically after updating Token.
    --
    -- -   @Token@ – device token, also referred to as a registration id, for
    --     an app and mobile device. This is returned from the notification
    --     service when an app and mobile device are registered with the
    --     notification service.
    --
    --     The device token for the iOS platform is returned in lowercase.
    GetEndpointAttributesResponse -> Maybe (HashMap Text Text)
attributes :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | The response's http status code.
    GetEndpointAttributesResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetEndpointAttributesResponse
-> GetEndpointAttributesResponse -> Bool
(GetEndpointAttributesResponse
 -> GetEndpointAttributesResponse -> Bool)
-> (GetEndpointAttributesResponse
    -> GetEndpointAttributesResponse -> Bool)
-> Eq GetEndpointAttributesResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetEndpointAttributesResponse
-> GetEndpointAttributesResponse -> Bool
$c/= :: GetEndpointAttributesResponse
-> GetEndpointAttributesResponse -> Bool
== :: GetEndpointAttributesResponse
-> GetEndpointAttributesResponse -> Bool
$c== :: GetEndpointAttributesResponse
-> GetEndpointAttributesResponse -> Bool
Prelude.Eq, ReadPrec [GetEndpointAttributesResponse]
ReadPrec GetEndpointAttributesResponse
Int -> ReadS GetEndpointAttributesResponse
ReadS [GetEndpointAttributesResponse]
(Int -> ReadS GetEndpointAttributesResponse)
-> ReadS [GetEndpointAttributesResponse]
-> ReadPrec GetEndpointAttributesResponse
-> ReadPrec [GetEndpointAttributesResponse]
-> Read GetEndpointAttributesResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetEndpointAttributesResponse]
$creadListPrec :: ReadPrec [GetEndpointAttributesResponse]
readPrec :: ReadPrec GetEndpointAttributesResponse
$creadPrec :: ReadPrec GetEndpointAttributesResponse
readList :: ReadS [GetEndpointAttributesResponse]
$creadList :: ReadS [GetEndpointAttributesResponse]
readsPrec :: Int -> ReadS GetEndpointAttributesResponse
$creadsPrec :: Int -> ReadS GetEndpointAttributesResponse
Prelude.Read, Int -> GetEndpointAttributesResponse -> ShowS
[GetEndpointAttributesResponse] -> ShowS
GetEndpointAttributesResponse -> String
(Int -> GetEndpointAttributesResponse -> ShowS)
-> (GetEndpointAttributesResponse -> String)
-> ([GetEndpointAttributesResponse] -> ShowS)
-> Show GetEndpointAttributesResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetEndpointAttributesResponse] -> ShowS
$cshowList :: [GetEndpointAttributesResponse] -> ShowS
show :: GetEndpointAttributesResponse -> String
$cshow :: GetEndpointAttributesResponse -> String
showsPrec :: Int -> GetEndpointAttributesResponse -> ShowS
$cshowsPrec :: Int -> GetEndpointAttributesResponse -> ShowS
Prelude.Show, (forall x.
 GetEndpointAttributesResponse
 -> Rep GetEndpointAttributesResponse x)
-> (forall x.
    Rep GetEndpointAttributesResponse x
    -> GetEndpointAttributesResponse)
-> Generic GetEndpointAttributesResponse
forall x.
Rep GetEndpointAttributesResponse x
-> GetEndpointAttributesResponse
forall x.
GetEndpointAttributesResponse
-> Rep GetEndpointAttributesResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetEndpointAttributesResponse x
-> GetEndpointAttributesResponse
$cfrom :: forall x.
GetEndpointAttributesResponse
-> Rep GetEndpointAttributesResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetEndpointAttributesResponse' 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:
--
-- 'attributes', 'getEndpointAttributesResponse_attributes' - Attributes include the following:
--
-- -   @CustomUserData@ – arbitrary user data to associate with the
--     endpoint. Amazon SNS does not use this data. The data must be in
--     UTF-8 format and less than 2KB.
--
-- -   @Enabled@ – flag that enables\/disables delivery to the endpoint.
--     Amazon SNS will set this to false when a notification service
--     indicates to Amazon SNS that the endpoint is invalid. Users can set
--     it back to true, typically after updating Token.
--
-- -   @Token@ – device token, also referred to as a registration id, for
--     an app and mobile device. This is returned from the notification
--     service when an app and mobile device are registered with the
--     notification service.
--
--     The device token for the iOS platform is returned in lowercase.
--
-- 'httpStatus', 'getEndpointAttributesResponse_httpStatus' - The response's http status code.
newGetEndpointAttributesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetEndpointAttributesResponse
newGetEndpointAttributesResponse :: Int -> GetEndpointAttributesResponse
newGetEndpointAttributesResponse Int
pHttpStatus_ =
  GetEndpointAttributesResponse' :: Maybe (HashMap Text Text) -> Int -> GetEndpointAttributesResponse
GetEndpointAttributesResponse'
    { $sel:attributes:GetEndpointAttributesResponse' :: Maybe (HashMap Text Text)
attributes =
        Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetEndpointAttributesResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Attributes include the following:
--
-- -   @CustomUserData@ – arbitrary user data to associate with the
--     endpoint. Amazon SNS does not use this data. The data must be in
--     UTF-8 format and less than 2KB.
--
-- -   @Enabled@ – flag that enables\/disables delivery to the endpoint.
--     Amazon SNS will set this to false when a notification service
--     indicates to Amazon SNS that the endpoint is invalid. Users can set
--     it back to true, typically after updating Token.
--
-- -   @Token@ – device token, also referred to as a registration id, for
--     an app and mobile device. This is returned from the notification
--     service when an app and mobile device are registered with the
--     notification service.
--
--     The device token for the iOS platform is returned in lowercase.
getEndpointAttributesResponse_attributes :: Lens.Lens' GetEndpointAttributesResponse (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
getEndpointAttributesResponse_attributes :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> GetEndpointAttributesResponse -> f GetEndpointAttributesResponse
getEndpointAttributesResponse_attributes = (GetEndpointAttributesResponse -> Maybe (HashMap Text Text))
-> (GetEndpointAttributesResponse
    -> Maybe (HashMap Text Text) -> GetEndpointAttributesResponse)
-> Lens
     GetEndpointAttributesResponse
     GetEndpointAttributesResponse
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetEndpointAttributesResponse' {Maybe (HashMap Text Text)
attributes :: Maybe (HashMap Text Text)
$sel:attributes:GetEndpointAttributesResponse' :: GetEndpointAttributesResponse -> Maybe (HashMap Text Text)
attributes} -> Maybe (HashMap Text Text)
attributes) (\s :: GetEndpointAttributesResponse
s@GetEndpointAttributesResponse' {} Maybe (HashMap Text Text)
a -> GetEndpointAttributesResponse
s {$sel:attributes:GetEndpointAttributesResponse' :: Maybe (HashMap Text Text)
attributes = Maybe (HashMap Text Text)
a} :: GetEndpointAttributesResponse) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> GetEndpointAttributesResponse
 -> f GetEndpointAttributesResponse)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> GetEndpointAttributesResponse
-> f GetEndpointAttributesResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
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
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData GetEndpointAttributesResponse