A Twitter Clone
I consumed Twitter's API to create a better way to tweet.
Sweeter Tweeter was an individual project completed over four days. My first experience with APIs, I used OAuth to authenticate users and the Twitter gem to pull data directly from a user's account.
Anyone can log on to Sweeter Tweeter by authorizing the app through their Twitter account. Once logged in, users may view their profiles, post new tweets and favorite the statuses of other users.
Testing an API is tricky.
Not only can your tests be non-deterministic due to the reliance on an external service, the tests are also brittle to changes in the API. Plus, you may run into issues with rate limits if your tests communicate with the API each time you run your test suite.
The solution is VCR. Each test is wrapped by a VCR command to record the first response from the API in a cassette. After the initial response is recorded, VCR will run the test against the data in the cassette rather than send a request to the API. When using VCR, it's a good habit to create an automated way of deleting the cassettes every week (or every day) so your tests remain current.
Sweeter Tweeter uses OAuth to authenticate users and authorize the app when a visitor logs in.
If no one is logged in, the homepage asks the visitor to do so. Otherwise, the homepage welcomes the user by name and directs him or her to the profile page.
Sweeter Tweeter sends GET requests for the following data from the Twitter API:
- Number of tweets favorited
- Number of updates tweeted
- Number of people the user is following
- Number of people following the user
- Home feed
In addition to displaying the above information, Sweeter Tweeter can send POST requests to Twitter to create or favorite a tweet.