From 2afd62a9dd5ce53637e39e15eb5545b42f25d68d Mon Sep 17 00:00:00 2001 From: Aaron Sparks Date: Mon, 11 Apr 2016 15:28:13 -0700 Subject: [PATCH 1/2] Modified the README.md to include a second example Modified the README.md to include a second example where the account SID and auth token are embedded in the code rather than stored as environmental variables. This would allow a developer to compile a self-contained executable that could be run by end users without the need to create or understand environment variables. Also modified both examples to define sending and receiving phone number bindings to make it easier for the developer to read/configure. --- README.md | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3dc8876..8f17ce5 100644 --- a/README.md +++ b/README.md @@ -14,10 +14,10 @@ Documentation soon to be available on Hackage. For now, see [markandrus.github.i For TwiML, see [twiml-haskell](http://github.com/markandrus/twiml-haskell). -Example +Example 1 - using environment variables ------- -You can create a REST API client and fetch the calls resources as follows +You can create a REST API client, fetch the calls, or send a message as follows: ```hs {-#LANGUAGE OverloadedStrings #-} @@ -38,11 +38,53 @@ main = runTwilio' (getEnv "ACCOUNT_SID") liftIO $ print calls -- Send a Message. - let body = PostMessage "+14158059869" "+14158059869" "Oh, hai" + let receivingPhone = "+14158059869" + let sendingPhone = "+14158059869" + let body = PostMessage receivingPhone sendingPhone "Oh, hai" message <- post body liftIO $ print message ``` +Example 2 - using SID and secret embedded in the code +------- + +You can create a REST API client and send a message as follows: + +```hs +{-#LANGUAGE OverloadedStrings #-} + +module Main where +import Twilio.Types.SID +import Control.Monad.IO.Class (liftIO) +import Twilio +import Twilio.Messages +import qualified Data.Text as T + +parseCredentials :: T.Text -> T.Text -> Maybe Credentials +parseCredentials accountSID authToken = + case parseAuthToken authToken of + Just authToken -> + (case parseSID accountSID of + Just accountSID -> + Just (accountSID, authToken) + Nothing -> Nothing) + Nothing -> Nothing + +main :: IO () +main = + let accountSID = "youraccountSID" + authToken = "yourauthToken" + in case parseCredentials accountSID authToken of + Just credentialsPassed -> + runTwilio ( credentialsPassed ) $ do + let receivingPhone = "+14158059869" + let sendingPhone = "+14158059869" + let body = PostMessage receivingPhone sendingPhone "Oh, hai" + message <- post body + liftIO $ print message + Nothing -> print "Something bad happened, you have poorly formed credentials." +``` + Contributing ------------ From 0db82b6c5333eb24d7df6885a53ae22508987aca Mon Sep 17 00:00:00 2001 From: Aaron Sparks Date: Mon, 11 Apr 2016 20:29:49 -0700 Subject: [PATCH 2/2] Cleared the review notes for commit 2afd62a Cleared the review notes for commit 2afd62a (modified README for a second example). Modified the following: * Used to/from on phone bindings to match with Twilio's RESTful API * Alphabetized the imports * Used simpler Data.Text (Text) rather than qualified * Switched to 2 space indent from 4 --- README.md | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 8f17ce5..1010d5d 100644 --- a/README.md +++ b/README.md @@ -38,8 +38,8 @@ main = runTwilio' (getEnv "ACCOUNT_SID") liftIO $ print calls -- Send a Message. - let receivingPhone = "+14158059869" - let sendingPhone = "+14158059869" + let fromPhone = "+14158059869" + let toPhone = "+14158059869" let body = PostMessage receivingPhone sendingPhone "Oh, hai" message <- post body liftIO $ print message @@ -54,35 +54,36 @@ You can create a REST API client and send a message as follows: {-#LANGUAGE OverloadedStrings #-} module Main where -import Twilio.Types.SID + import Control.Monad.IO.Class (liftIO) +import Data.Text (Text) import Twilio import Twilio.Messages -import qualified Data.Text as T +import Twilio.Types.SID -parseCredentials :: T.Text -> T.Text -> Maybe Credentials +parseCredentials :: Text -> Text -> Maybe Credentials parseCredentials accountSID authToken = - case parseAuthToken authToken of - Just authToken -> - (case parseSID accountSID of - Just accountSID -> - Just (accountSID, authToken) - Nothing -> Nothing) - Nothing -> Nothing + case parseAuthToken authToken of + Just authToken -> + (case parseSID accountSID of + Just accountSID -> + Just (accountSID, authToken) + Nothing -> Nothing) + Nothing -> Nothing main :: IO () main = - let accountSID = "youraccountSID" - authToken = "yourauthToken" - in case parseCredentials accountSID authToken of - Just credentialsPassed -> - runTwilio ( credentialsPassed ) $ do - let receivingPhone = "+14158059869" - let sendingPhone = "+14158059869" - let body = PostMessage receivingPhone sendingPhone "Oh, hai" - message <- post body - liftIO $ print message - Nothing -> print "Something bad happened, you have poorly formed credentials." + let accountSID = "youraccountSID" + authToken = "yourauthToken" + in case parseCredentials accountSID authToken of + Just credentialsPassed -> + runTwilio ( credentialsPassed ) $ do + let fromPhone = "+14158059869" + let toPhone = "+14158059869" + let body = PostMessage receivingPhone sendingPhone "Oh, hai" + message <- post body + liftIO $ print message + Nothing -> print "Something bad happened, you have poorly formed credentials." ``` Contributing