-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modified the README.md to include a second example #40
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since only import Data.Text (Text) Do you mind alphabetizing the imports as well? |
||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here you are pattern matching on the success/failure of the parses to determine the next step. Instead of explicit pattern matching, we can rely on the behavior of Maybe's Functor and Applicative instances to write this more succinctly. For example, parseCredentials :: Text -> Text -> Maybe Credentials
parseCredentials accountSID authToken =
(,) <$> parseAccountSID accountSID <*> parseAuthToken authToken I wonder if such a function should be include the library proper. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, agreed. We saw that you actually have this function built but haven't exported it. Aaron There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, you're right! And it was written with a less-palatable combination of |
||
|
||
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." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mind using a 2-space indent? |
||
``` | ||
|
||
Contributing | ||
------------ | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about using the names
to
andfrom
instead ofreceivingPhone
andsendingPhone
? This would better match the REST API.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, works for me. I'll make the change and update the pull request tomorrow morning.
Aaron