{-# 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.Pricing.GetProducts
(
getProducts
, GetProducts
, gpFilters
, gpFormatVersion
, gpNextToken
, gpServiceCode
, gpMaxResults
, getProductsResponse
, GetProductsResponse
, gprsFormatVersion
, gprsNextToken
, gprsPriceList
, gprsResponseStatus
) where
import Network.AWS.Lens
import Network.AWS.Pager
import Network.AWS.Prelude
import Network.AWS.Pricing.Types
import Network.AWS.Pricing.Types.Product
import Network.AWS.Request
import Network.AWS.Response
data GetProducts = GetProducts'
{ _gpFilters :: !(Maybe [Filter])
, _gpFormatVersion :: !(Maybe Text)
, _gpNextToken :: !(Maybe Text)
, _gpServiceCode :: !(Maybe Text)
, _gpMaxResults :: !(Maybe Nat)
} deriving (Eq, Read, Show, Data, Typeable, Generic)
getProducts
:: GetProducts
getProducts =
GetProducts'
{ _gpFilters = Nothing
, _gpFormatVersion = Nothing
, _gpNextToken = Nothing
, _gpServiceCode = Nothing
, _gpMaxResults = Nothing
}
gpFilters :: Lens' GetProducts [Filter]
gpFilters = lens _gpFilters (\ s a -> s{_gpFilters = a}) . _Default . _Coerce
gpFormatVersion :: Lens' GetProducts (Maybe Text)
gpFormatVersion = lens _gpFormatVersion (\ s a -> s{_gpFormatVersion = a})
gpNextToken :: Lens' GetProducts (Maybe Text)
gpNextToken = lens _gpNextToken (\ s a -> s{_gpNextToken = a})
gpServiceCode :: Lens' GetProducts (Maybe Text)
gpServiceCode = lens _gpServiceCode (\ s a -> s{_gpServiceCode = a})
gpMaxResults :: Lens' GetProducts (Maybe Natural)
gpMaxResults = lens _gpMaxResults (\ s a -> s{_gpMaxResults = a}) . mapping _Nat
instance AWSPager GetProducts where
page rq rs
| stop (rs ^. gprsNextToken) = Nothing
| stop (rs ^. gprsPriceList) = Nothing
| otherwise =
Just $ rq & gpNextToken .~ rs ^. gprsNextToken
instance AWSRequest GetProducts where
type Rs GetProducts = GetProductsResponse
request = postJSON pricing
response
= receiveJSON
(\ s h x ->
GetProductsResponse' <$>
(x .?> "FormatVersion") <*> (x .?> "NextToken") <*>
(x .?> "PriceList" .!@ mempty)
<*> (pure (fromEnum s)))
instance Hashable GetProducts where
instance NFData GetProducts where
instance ToHeaders GetProducts where
toHeaders
= const
(mconcat
["X-Amz-Target" =#
("AWSPriceListService.GetProducts" :: ByteString),
"Content-Type" =#
("application/x-amz-json-1.1" :: ByteString)])
instance ToJSON GetProducts where
toJSON GetProducts'{..}
= object
(catMaybes
[("Filters" .=) <$> _gpFilters,
("FormatVersion" .=) <$> _gpFormatVersion,
("NextToken" .=) <$> _gpNextToken,
("ServiceCode" .=) <$> _gpServiceCode,
("MaxResults" .=) <$> _gpMaxResults])
instance ToPath GetProducts where
toPath = const "/"
instance ToQuery GetProducts where
toQuery = const mempty
data GetProductsResponse = GetProductsResponse'
{ _gprsFormatVersion :: !(Maybe Text)
, _gprsNextToken :: !(Maybe Text)
, _gprsPriceList :: !(Maybe [Text])
, _gprsResponseStatus :: !Int
} deriving (Eq, Read, Show, Data, Typeable, Generic)
getProductsResponse
:: Int
-> GetProductsResponse
getProductsResponse pResponseStatus_ =
GetProductsResponse'
{ _gprsFormatVersion = Nothing
, _gprsNextToken = Nothing
, _gprsPriceList = Nothing
, _gprsResponseStatus = pResponseStatus_
}
gprsFormatVersion :: Lens' GetProductsResponse (Maybe Text)
gprsFormatVersion = lens _gprsFormatVersion (\ s a -> s{_gprsFormatVersion = a})
gprsNextToken :: Lens' GetProductsResponse (Maybe Text)
gprsNextToken = lens _gprsNextToken (\ s a -> s{_gprsNextToken = a})
gprsPriceList :: Lens' GetProductsResponse [Text]
gprsPriceList = lens _gprsPriceList (\ s a -> s{_gprsPriceList = a}) . _Default . _Coerce
gprsResponseStatus :: Lens' GetProductsResponse Int
gprsResponseStatus = lens _gprsResponseStatus (\ s a -> s{_gprsResponseStatus = a})
instance NFData GetProductsResponse where