Skip to content

Commit

Permalink
Modified the README.md to include a second example
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
asparks1805 committed Apr 11, 2016
1 parent 0adc5f1 commit 2afd62a
Showing 1 changed file with 45 additions and 3 deletions.
48 changes: 45 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 #-}
Expand All @@ -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
------------

Expand Down

0 comments on commit 2afd62a

Please # to comment.