Zend Framework: Zend_Service_Twitter Component Proposal
| Proposed Component Name | Zend_Service_Twitter |
|---|---|
| Developer Notes | http://framework.zend.com/wiki/display/ZFDEV/Zend_Service_Twitter |
| Proposers | Matthew Weier O'Phinney and Jon Whitcraft |
| Revision | 1.1 - 25 October 2007: Initial proposal creation (wiki revision: 5) |
Table of Contents
1. Overview
Zend_Service_Twitter is a full implementation of the Twitter API.
2. References
3. Component Requirements, Constraints, and Acceptance Criteria
- This component will implement the full Twitter API.
- This component should namespace the various API methods according to the groupings in the Twitter API documentation.
- This component will allow re-using an object with multiple user/pass combinations.
- This component will use a single format for all return values.
4. Dependencies on Other Framework Components
- Zend_Rest_Client
- Zend_Service_Exception
5. Theory of Operation
Zend_Service_Twitter will allow a developer to interact with the Twitter API, supporting such actions as updating status, retrieving status lists, sending and receiving direct messages, and creating and removing friendship status. To simplify operation, all methods are namespaced according to the various method groupings on the official API documentation.
6. Milestones / Tasks
- Milestone 1: [DONE] Design notes will be published here
- Milestone 2: Working prototype checked into the incubator supporting use cases
- Milestone 3: Unit tests exist, work, and are checked into SVN.
- Milestone 4: Initial documentation exists.
7. Class Index
- Zend_Service_Twitter
- Zend_Service_Twitter_Search
- Zend_Service_TWitter_Exception
8. Use Cases
| UC-01 |
|---|
9. Class Skeletons
I haven't contacted them about it as of yet, but was aware of the upcoming authentication changes. I'll address those in Zend_Service_Twitter once they have confirmed what they will use.
It looks great
. And it's a service I'd love to see implemented.
On the authorisation scheme, it was confirmed in mid October as OAuth Core 1.0 using the HMAC-SHA1 method for signing messages (we have HMAC in Incubator
). They already have a Token Provider up and running, and users are able to generate unique Tokens for each application they intend authorising. So the scheme is in operation right now. I know Ed Finkler got an ASAP message for his Spaz AIR client about OAuth (haven't seen a Javascript implementation just yet).
I won't be implementing the Zend_Service_OAuth proposal until mid-November so I wouldn't let it hold you up - make it a future feature maybe. A Consumer is not very complex though, the main thing is that the User needs to interact with Twitter.com to give their consent in granting initial authorisation (you may smell a backend datastore). You may want to consider such a server trip (and redirect back) in terms of how a final Service component would work API wise. Some users would need it (OpenID), others might still opt for the username/password.
I have the feeling that the method names are far from being optimal. Most of them really feel like strangers. This is strange because even the API methods are not called that way. For example statusUpdate() should of course be Zend_Service_Twitter::updateStatus() etc. pp.
I wrote a service client for twitter too. What I did different was the encapsulation of the API results. In my implementation I have a client-, user-, and tweet-object. The tweet-object always contains a user (the author of the tweet). When I call getFriendsTimeline() I receive a list of tweets, each of the tweets having a user object attached (for performance reasons the client acts as a flyweight, to make sure every unique user and every unique tweet is just instanciated once). The API flow is really natural then:
$client = new TwitterClient($user, $password);
$timeline = $client->getFriendsTimeline();
foreach ($timline as $tweet) {
echo "{$tweet->getUser()>getName()} says: {$tweet>getText()}";
}
After talking with Matthew at ZendCon08 about the Twitter Service and his lack of being able to work on it, he and I agreed that someone else should take over the development of it. That is going to be me. I have Matthew's code and I have gotten it working again with the updated API.
I will continue to post my status here as I get more done.
Good news!
To update a prior comment I made - Twitter OAuth support will turn up late this year, or early next year. Definitely not on the cards in the short term, but still worth noting for when it makes an eventual second debut. Zend_Oauth should be finished and released well before that happens.
Look forward to seeing this in a ZF release
.
If you want an updated class and tests you can download it here http://code.bombdiggity.net/phly_twitter.tar.gz. I have about 70% code coverage in the test and I hope to have more done by mid-day tomorrow. I'm also going to implement a Zend_Service_Twitter_Search so you can query the search API but that will be next week.
I have just made this aviable on github.com located here: http://github.com/sidhighwind/phly_twitter/tree/master
ZF Home Page
Code Browser
Wiki Dashboard
From what I hear, Twitter will implement OpenID/OAuth - for which a proposal is in the works. Personally, I find this a lot more interesting than standard username/password authorization because for the user this requires a lot of trust to hand out than the other. I know they are no specifics yet, but I am asking anyway if you e.g. contacted twitter about it.
This aside, I like your __get() and __set() usage. Makes sense to me.