module Twilio.Internal.Resource
(
Get(..)
, Get0(..)
, Get1(..)
, Get2(..)
, Post(..)
, Post0(..)
, Post1(..)
, Post2(..)
, Post3(..)
, Delete(..)
, Delete1(..)
, parseJSONFromResponse
) where
import Control.Monad.Catch
import Data.Aeson
import Data.Aeson.Types
import qualified Data.ByteString.Lazy as LBS
import Network.HTTP.Client
import Control.Monad.Twilio
class Get0 r where
get0 :: MonadThrow m => TwilioT m r
class Get1 a r where
get1 :: MonadThrow m => a -> TwilioT m r
class Get2 a b r where
get2 :: MonadThrow m => a -> b -> TwilioT m r
class Get r where
get :: r
instance (MonadThrow m, Get0 r) => Get (TwilioT m r) where
get = get0
instance (MonadThrow m, Get1 a r) => Get (a -> TwilioT m r) where
get = get1
instance (MonadThrow m, Get2 a b r) => Get (a -> b -> TwilioT m r) where
get = get2
class Post0 r where
post0 :: MonadThrow m => TwilioT m r
class Post1 a r where
post1 :: MonadThrow m => a -> TwilioT m r
class Post2 a b r where
post2 :: MonadThrow m => a -> b -> TwilioT m r
class Post3 a b c r where
post3 :: MonadThrow m => a -> b -> c -> TwilioT m r
class Post r where
post :: r
instance (MonadThrow m, Post0 r) => Post (TwilioT m r) where
post = post0
instance (MonadThrow m, Post1 a r) => Post (a -> TwilioT m r) where
post = post1
instance (MonadThrow m, Post2 a b r) => Post (a -> b -> TwilioT m r) where
post = post2
instance (MonadThrow m, Post3 a b c r) => Post (a -> b -> c -> TwilioT m r) where
post = post3
class Delete1 a where
delete1 :: MonadThrow m => a -> TwilioT m ()
class Delete r where
delete :: r
instance (MonadThrow m, Delete1 a) => Delete (a -> TwilioT m ()) where
delete = delete1
parseJSONFromResponse :: (FromJSON a, MonadThrow m) => Response LBS.ByteString -> m a
parseJSONFromResponse response =
case eitherDecode (responseBody response) >>= parseEither parseJSON of
Left _ -> throwM $ UnexpectedResponse response
Right a -> return a