{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}
module Network.AWS.AlexaBusiness.SearchDevices
(
searchDevices
, SearchDevices
, sdFilters
, sdSortCriteria
, sdNextToken
, sdMaxResults
, searchDevicesResponse
, SearchDevicesResponse
, sdrsNextToken
, sdrsDevices
, sdrsTotalCount
, sdrsResponseStatus
) where
import Network.AWS.AlexaBusiness.Types
import Network.AWS.AlexaBusiness.Types.Product
import Network.AWS.Lens
import Network.AWS.Pager
import Network.AWS.Prelude
import Network.AWS.Request
import Network.AWS.Response
data SearchDevices = SearchDevices'
{ _sdFilters :: !(Maybe [Filter])
, _sdSortCriteria :: !(Maybe [Sort])
, _sdNextToken :: !(Maybe Text)
, _sdMaxResults :: !(Maybe Nat)
} deriving (Eq, Read, Show, Data, Typeable, Generic)
searchDevices
:: SearchDevices
searchDevices =
SearchDevices'
{ _sdFilters = Nothing
, _sdSortCriteria = Nothing
, _sdNextToken = Nothing
, _sdMaxResults = Nothing
}
sdFilters :: Lens' SearchDevices [Filter]
sdFilters = lens _sdFilters (\ s a -> s{_sdFilters = a}) . _Default . _Coerce
sdSortCriteria :: Lens' SearchDevices [Sort]
sdSortCriteria = lens _sdSortCriteria (\ s a -> s{_sdSortCriteria = a}) . _Default . _Coerce
sdNextToken :: Lens' SearchDevices (Maybe Text)
sdNextToken = lens _sdNextToken (\ s a -> s{_sdNextToken = a})
sdMaxResults :: Lens' SearchDevices (Maybe Natural)
sdMaxResults = lens _sdMaxResults (\ s a -> s{_sdMaxResults = a}) . mapping _Nat
instance AWSPager SearchDevices where
page rq rs
| stop (rs ^. sdrsNextToken) = Nothing
| stop (rs ^. sdrsDevices) = Nothing
| otherwise =
Just $ rq & sdNextToken .~ rs ^. sdrsNextToken
instance AWSRequest SearchDevices where
type Rs SearchDevices = SearchDevicesResponse
request = postJSON alexaBusiness
response
= receiveJSON
(\ s h x ->
SearchDevicesResponse' <$>
(x .?> "NextToken") <*> (x .?> "Devices" .!@ mempty)
<*> (x .?> "TotalCount")
<*> (pure (fromEnum s)))
instance Hashable SearchDevices where
instance NFData SearchDevices where
instance ToHeaders SearchDevices where
toHeaders
= const
(mconcat
["X-Amz-Target" =#
("AlexaForBusiness.SearchDevices" :: ByteString),
"Content-Type" =#
("application/x-amz-json-1.1" :: ByteString)])
instance ToJSON SearchDevices where
toJSON SearchDevices'{..}
= object
(catMaybes
[("Filters" .=) <$> _sdFilters,
("SortCriteria" .=) <$> _sdSortCriteria,
("NextToken" .=) <$> _sdNextToken,
("MaxResults" .=) <$> _sdMaxResults])
instance ToPath SearchDevices where
toPath = const "/"
instance ToQuery SearchDevices where
toQuery = const mempty
data SearchDevicesResponse = SearchDevicesResponse'
{ _sdrsNextToken :: !(Maybe Text)
, _sdrsDevices :: !(Maybe [DeviceData])
, _sdrsTotalCount :: !(Maybe Int)
, _sdrsResponseStatus :: !Int
} deriving (Eq, Read, Show, Data, Typeable, Generic)
searchDevicesResponse
:: Int
-> SearchDevicesResponse
searchDevicesResponse pResponseStatus_ =
SearchDevicesResponse'
{ _sdrsNextToken = Nothing
, _sdrsDevices = Nothing
, _sdrsTotalCount = Nothing
, _sdrsResponseStatus = pResponseStatus_
}
sdrsNextToken :: Lens' SearchDevicesResponse (Maybe Text)
sdrsNextToken = lens _sdrsNextToken (\ s a -> s{_sdrsNextToken = a})
sdrsDevices :: Lens' SearchDevicesResponse [DeviceData]
sdrsDevices = lens _sdrsDevices (\ s a -> s{_sdrsDevices = a}) . _Default . _Coerce
sdrsTotalCount :: Lens' SearchDevicesResponse (Maybe Int)
sdrsTotalCount = lens _sdrsTotalCount (\ s a -> s{_sdrsTotalCount = a})
sdrsResponseStatus :: Lens' SearchDevicesResponse Int
sdrsResponseStatus = lens _sdrsResponseStatus (\ s a -> s{_sdrsResponseStatus = a})
instance NFData SearchDevicesResponse where