-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
093b0c5
commit 3d67227
Showing
7 changed files
with
163 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{-#LANGUAGE FlexibleInstances #-} | ||
{-#LANGUAGE MultiParamTypeClasses #-} | ||
{-#LANGUAGE OverloadedStrings #-} | ||
{-#LANGUAGE ViewPatterns #-} | ||
|
||
module Twilio.APIKey | ||
( -- * Resource | ||
APIKey(..) | ||
, APIKeySID | ||
, Twilio.APIKey.get | ||
) where | ||
|
||
import Control.Applicative | ||
import Control.Monad | ||
import Control.Monad.Catch | ||
import Data.Aeson | ||
import Data.Monoid | ||
import Data.Text (Text) | ||
import Data.Time.Clock | ||
import Network.URI | ||
|
||
import Control.Monad.Twilio | ||
import Twilio.Internal.Parser | ||
import Twilio.Internal.Request | ||
import Twilio.Internal.Resource as Resource | ||
import Twilio.Types | ||
|
||
{- Resource -} | ||
|
||
data APIKey = APIKey | ||
{ sid :: !APIKeySID | ||
, friendlyName :: !Text | ||
, secret :: !(Maybe Text) | ||
, dateCreated :: !UTCTime | ||
, dateUpdated :: !UTCTime | ||
} deriving (Show, Eq, Ord) | ||
|
||
instance FromJSON APIKey where | ||
parseJSON (Object v) = APIKey | ||
<$> v .: "sid" | ||
<*> v .: "friendly_name" | ||
<*> v .:? "secret" | ||
<*> (v .: "date_created" >>= parseDateTime) | ||
<*> (v .: "date_updated" >>= parseDateTime) | ||
parseJSON _ = mzero | ||
|
||
instance Get1 APIKeySID APIKey where | ||
get1 (getSID -> sid) = request parseJSONFromResponse =<< makeTwilioRequest | ||
("/Keys/" <> sid <> ".json") | ||
|
||
get :: MonadThrow m => APIKeySID -> TwilioT m APIKey | ||
get = Resource.get |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
{-#LANGUAGE FlexibleInstances #-} | ||
{-#LANGUAGE MultiParamTypeClasses #-} | ||
{-#LANGUAGE OverloadedStrings #-} | ||
{-#LANGUAGE RankNTypes #-} | ||
|
||
module Twilio.APIKeys | ||
( -- * Resource | ||
APIKeys(..) | ||
, Twilio.APIKeys.get | ||
) 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.APIKey | ||
import Twilio.Internal.Request | ||
import Twilio.Internal.Resource as Resource | ||
import Twilio.Types | ||
|
||
{- Resource -} | ||
|
||
data APIKeys = APIKeys | ||
{ pagingInformation :: !PagingInformation | ||
, list :: ![APIKey] | ||
} deriving (Show, Eq, Ord) | ||
|
||
instance List APIKeys APIKey where | ||
getListWrapper = wrap (APIKeys . fromJust) | ||
getList = list | ||
getPlural = Const "keys" | ||
|
||
instance FromJSON APIKeys where | ||
parseJSON = parseJSONToList | ||
|
||
instance Get0 APIKeys where | ||
get0 = request parseJSONFromResponse =<< makeTwilioRequest "/Keys.json" | ||
|
||
{- | Get 'APIKeys'. | ||
For example, you can fetch the 'APIKeys' resource in the 'IO' monad as follows: | ||
>module Main where | ||
> | ||
>import Control.Monad.IO.Class (liftIO) | ||
>import System.Environment (getEnv) | ||
>import Twilio.APIKeys as APIKeys | ||
>import Twilio.Types | ||
> | ||
>-- | Print API Keys. | ||
>main :: IO () | ||
>main = runTwilio' (getEnv "ACCOUNT_SID") | ||
> (getEnv "AUTH_TOKEN") | ||
> $ APIKeys.get >>= liftIO . print | ||
-} | ||
get :: MonadThrow m => TwilioT m APIKeys | ||
get = Resource.get |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters