Lab 2: APIs and Picos
- Due Jan 29, 2018 by 11:59pm
- Points 100
- Submitting a text entry box, a website url, a media recording, or a file upload
Objective
The objective of this lab is learn how to
- use modules in KRL
- wrap an external API call and make it available from a module
- use the
key
pragma for API keys
Reading and Reference
Read the following:
You may find the following resources useful:
- KRL Manual
- Developer Tips for the Pico Engine
- Twilio API Explorer Links to an external site. (you need to already have an account with Twilio first)
Prerequisites
You should have completed:
Implementation Notes
- The best way to use the KRL documentation is to search since you may not always appreciate how it's organized (or isn't).
- Read carefully how key modules work. Specifically, be sure you're providing the keys to the right RID so your module can see them. This is a security precaution to ensure only rulesets that should see the keys can request them.
- Modules can provide a KRL interface for an API. They encapsulate the complexity and hide the details of the API so that other rulesets can more easily use them.
- You'll have to create a number on Twlio. If you have problems with this, be sure to ask one of the TAs.
- An example of how to clean up HTTP get requests with decode in KRL can be found here Links to an external site..
- Note that the Twilio API wants you to use a POST for sending messages. This is consistent with good API design (don't use GET for requests that affect resource state). The HTTP library in KRL (Links to an external site.) supports http:post() as an action.
Do This
- Sign up for a developer account at Twilio Links to an external site..
- Find your Twilio keys in the Twilio account. You'll need the SID and the auth token.
- Create a key module with the Twilio keys. Don't put this on Github!!!
- Create a Twilio module that uses the key module created above and includes the action from the Modules and External APIs lesson. This can be on Github.
- Write a ruleset to use and test your Twilio module by using the action to send an SMS to yourself or a friend. Read the Twilio docs to understand the prerequisites for sending SMS messages.
- Extend your module to have a
messages()
function that uses the Twilio SMS API to retrieve one or more messages (see message logs in the Twilio documentation):- The function should return all messages if no argument is given. Be sure to include optional arguments for controlling pagination of long lists of data.
- Include a means of filtering the result set by sending and receiving number. You can ignore filtering by date.
- Modify your ruleset to test your
messages()
function.
Deliverables
Turn in the following:
- URLs for the Twilio module and test ruleset.
- Short screencast (with sound) showing:
- Key module
- Twilio module with
messages()
function. - Test rule
- Several interactions with the test rule with results
- Answers to the following questions:
- If you wanted to create a new module for a different API, in which cases would you create another key module for the keys from that API and in which would you use the same key module?
- Why does this assignment ask you to create a function for messages but an action for sending the SMS message? What's the difference?