module Twilio.Accounts
(
Accounts(..)
, Twilio.Accounts.get
, Twilio.Accounts.post
, createSubAccount
) where
import Control.Applicative
import Control.Monad.Catch
import Data.Aeson
import Data.Maybe
import Data.Text (Text)
import Data.Text.Encoding
import Control.Monad.Twilio
import Twilio.Account
import Twilio.Internal.Request
import Twilio.Internal.Resource as Resource
import Twilio.Types
data Accounts = Accounts
{ pagingInformation :: !PagingInformation
, list :: ![Account]
} deriving (Show, Eq, Ord)
instance List Accounts Account where
getListWrapper = wrap (Accounts . fromJust)
getList = list
getPlural = Const "accounts"
instance FromJSON Accounts where
parseJSON = parseJSONToList
instance Get0 Accounts where
get0 = request parseJSONFromResponse =<< makeTwilioRequest' "/Accounts.json"
get :: MonadThrow m => TwilioT m Accounts
get = Resource.get
instance Post0 Account where
post0
= request parseJSONFromResponse =<< makeTwilioPOSTRequest' "/Accounts.json" []
instance Post1 Text Account where
post1 friendlyName
= request parseJSONFromResponse =<< makeTwilioPOSTRequest' "/Accounts.json"
[ ("FriendlyName", encodeUtf8 friendlyName ) ]
instance Post1 (Maybe Text) Account where
post1 Nothing = post0
post1 (Just friendlyName) = post1 friendlyName
post :: MonadThrow m => Maybe Text -> TwilioT m Account
post = Resource.post
createSubAccount :: MonadThrow m
=> Maybe Text
-> TwilioT m Account
createSubAccount = Twilio.Accounts.post