{-# 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.IoT1ClickDevices.GetDeviceMethods
-- 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)
--
-- Given a device ID, returns the invokable methods associated with the
-- device.
module Amazonka.IoT1ClickDevices.GetDeviceMethods
  ( -- * Creating a Request
    GetDeviceMethods (..),
    newGetDeviceMethods,

    -- * Request Lenses
    getDeviceMethods_deviceId,

    -- * Destructuring the Response
    GetDeviceMethodsResponse (..),
    newGetDeviceMethodsResponse,

    -- * Response Lenses
    getDeviceMethodsResponse_deviceMethods,
    getDeviceMethodsResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.IoT1ClickDevices.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:/ 'newGetDeviceMethods' smart constructor.
data GetDeviceMethods = GetDeviceMethods'
  { -- | The unique identifier of the device.
    GetDeviceMethods -> Text
deviceId :: Prelude.Text
  }
  deriving (GetDeviceMethods -> GetDeviceMethods -> Bool
(GetDeviceMethods -> GetDeviceMethods -> Bool)
-> (GetDeviceMethods -> GetDeviceMethods -> Bool)
-> Eq GetDeviceMethods
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetDeviceMethods -> GetDeviceMethods -> Bool
$c/= :: GetDeviceMethods -> GetDeviceMethods -> Bool
== :: GetDeviceMethods -> GetDeviceMethods -> Bool
$c== :: GetDeviceMethods -> GetDeviceMethods -> Bool
Prelude.Eq, ReadPrec [GetDeviceMethods]
ReadPrec GetDeviceMethods
Int -> ReadS GetDeviceMethods
ReadS [GetDeviceMethods]
(Int -> ReadS GetDeviceMethods)
-> ReadS [GetDeviceMethods]
-> ReadPrec GetDeviceMethods
-> ReadPrec [GetDeviceMethods]
-> Read GetDeviceMethods
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetDeviceMethods]
$creadListPrec :: ReadPrec [GetDeviceMethods]
readPrec :: ReadPrec GetDeviceMethods
$creadPrec :: ReadPrec GetDeviceMethods
readList :: ReadS [GetDeviceMethods]
$creadList :: ReadS [GetDeviceMethods]
readsPrec :: Int -> ReadS GetDeviceMethods
$creadsPrec :: Int -> ReadS GetDeviceMethods
Prelude.Read, Int -> GetDeviceMethods -> ShowS
[GetDeviceMethods] -> ShowS
GetDeviceMethods -> String
(Int -> GetDeviceMethods -> ShowS)
-> (GetDeviceMethods -> String)
-> ([GetDeviceMethods] -> ShowS)
-> Show GetDeviceMethods
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetDeviceMethods] -> ShowS
$cshowList :: [GetDeviceMethods] -> ShowS
show :: GetDeviceMethods -> String
$cshow :: GetDeviceMethods -> String
showsPrec :: Int -> GetDeviceMethods -> ShowS
$cshowsPrec :: Int -> GetDeviceMethods -> ShowS
Prelude.Show, (forall x. GetDeviceMethods -> Rep GetDeviceMethods x)
-> (forall x. Rep GetDeviceMethods x -> GetDeviceMethods)
-> Generic GetDeviceMethods
forall x. Rep GetDeviceMethods x -> GetDeviceMethods
forall x. GetDeviceMethods -> Rep GetDeviceMethods x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetDeviceMethods x -> GetDeviceMethods
$cfrom :: forall x. GetDeviceMethods -> Rep GetDeviceMethods x
Prelude.Generic)

-- |
-- Create a value of 'GetDeviceMethods' 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', 'getDeviceMethods_deviceId' - The unique identifier of the device.
newGetDeviceMethods ::
  -- | 'deviceId'
  Prelude.Text ->
  GetDeviceMethods
newGetDeviceMethods :: Text -> GetDeviceMethods
newGetDeviceMethods Text
pDeviceId_ =
  GetDeviceMethods' :: Text -> GetDeviceMethods
GetDeviceMethods' {$sel:deviceId:GetDeviceMethods' :: Text
deviceId = Text
pDeviceId_}

-- | The unique identifier of the device.
getDeviceMethods_deviceId :: Lens.Lens' GetDeviceMethods Prelude.Text
getDeviceMethods_deviceId :: (Text -> f Text) -> GetDeviceMethods -> f GetDeviceMethods
getDeviceMethods_deviceId = (GetDeviceMethods -> Text)
-> (GetDeviceMethods -> Text -> GetDeviceMethods)
-> Lens GetDeviceMethods GetDeviceMethods Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetDeviceMethods' {Text
deviceId :: Text
$sel:deviceId:GetDeviceMethods' :: GetDeviceMethods -> Text
deviceId} -> Text
deviceId) (\s :: GetDeviceMethods
s@GetDeviceMethods' {} Text
a -> GetDeviceMethods
s {$sel:deviceId:GetDeviceMethods' :: Text
deviceId = Text
a} :: GetDeviceMethods)

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

instance Prelude.NFData GetDeviceMethods

instance Core.ToHeaders GetDeviceMethods where
  toHeaders :: GetDeviceMethods -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetDeviceMethods -> 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 GetDeviceMethods where
  toPath :: GetDeviceMethods -> ByteString
toPath GetDeviceMethods' {Text
deviceId :: Text
$sel:deviceId:GetDeviceMethods' :: GetDeviceMethods -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/devices/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
deviceId, ByteString
"/methods"]

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

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

-- |
-- Create a value of 'GetDeviceMethodsResponse' 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:
--
-- 'deviceMethods', 'getDeviceMethodsResponse_deviceMethods' - List of available device APIs.
--
-- 'httpStatus', 'getDeviceMethodsResponse_httpStatus' - The response's http status code.
newGetDeviceMethodsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetDeviceMethodsResponse
newGetDeviceMethodsResponse :: Int -> GetDeviceMethodsResponse
newGetDeviceMethodsResponse Int
pHttpStatus_ =
  GetDeviceMethodsResponse' :: Maybe [DeviceMethod] -> Int -> GetDeviceMethodsResponse
GetDeviceMethodsResponse'
    { $sel:deviceMethods:GetDeviceMethodsResponse' :: Maybe [DeviceMethod]
deviceMethods =
        Maybe [DeviceMethod]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetDeviceMethodsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | List of available device APIs.
getDeviceMethodsResponse_deviceMethods :: Lens.Lens' GetDeviceMethodsResponse (Prelude.Maybe [DeviceMethod])
getDeviceMethodsResponse_deviceMethods :: (Maybe [DeviceMethod] -> f (Maybe [DeviceMethod]))
-> GetDeviceMethodsResponse -> f GetDeviceMethodsResponse
getDeviceMethodsResponse_deviceMethods = (GetDeviceMethodsResponse -> Maybe [DeviceMethod])
-> (GetDeviceMethodsResponse
    -> Maybe [DeviceMethod] -> GetDeviceMethodsResponse)
-> Lens
     GetDeviceMethodsResponse
     GetDeviceMethodsResponse
     (Maybe [DeviceMethod])
     (Maybe [DeviceMethod])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetDeviceMethodsResponse' {Maybe [DeviceMethod]
deviceMethods :: Maybe [DeviceMethod]
$sel:deviceMethods:GetDeviceMethodsResponse' :: GetDeviceMethodsResponse -> Maybe [DeviceMethod]
deviceMethods} -> Maybe [DeviceMethod]
deviceMethods) (\s :: GetDeviceMethodsResponse
s@GetDeviceMethodsResponse' {} Maybe [DeviceMethod]
a -> GetDeviceMethodsResponse
s {$sel:deviceMethods:GetDeviceMethodsResponse' :: Maybe [DeviceMethod]
deviceMethods = Maybe [DeviceMethod]
a} :: GetDeviceMethodsResponse) ((Maybe [DeviceMethod] -> f (Maybe [DeviceMethod]))
 -> GetDeviceMethodsResponse -> f GetDeviceMethodsResponse)
-> ((Maybe [DeviceMethod] -> f (Maybe [DeviceMethod]))
    -> Maybe [DeviceMethod] -> f (Maybe [DeviceMethod]))
-> (Maybe [DeviceMethod] -> f (Maybe [DeviceMethod]))
-> GetDeviceMethodsResponse
-> f GetDeviceMethodsResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [DeviceMethod] [DeviceMethod] [DeviceMethod] [DeviceMethod]
-> Iso
     (Maybe [DeviceMethod])
     (Maybe [DeviceMethod])
     (Maybe [DeviceMethod])
     (Maybe [DeviceMethod])
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 [DeviceMethod] [DeviceMethod] [DeviceMethod] [DeviceMethod]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData GetDeviceMethodsResponse