Sunday, June 6, 2010

Data Dynamics Reports And Twitter

Preface
Tips and tricks series continues! In this post I am going to explain how a Data Dynamics Reports report might be set up in order to show the tweets from arbitrary user's public timeline. The live demo is available here. I can imagine the real-world usage of this feature: say I am HR department manager and in the CV overview report I would like to see the last 3 tweets from the public timeline of the candidates for opened job position. Let's see how a developer can implement such a feature using Data Dynamics Reports.

Using XML Data Provider
Data Dynamics Reports includes XML data provider that can load the data from various sources, particularly it supports xml documents that are located in a web-accessible location. In other hand a user's public timeline can be accessed via RSS feed which is xml document that is located in a web-accessible location. I.e. my public timeline can be read on http://twitter.com/statuses/user_timeline/sAbakumoff.rss. RSS feed document has well known structure: each tweet is presented by <item> tag, its child <description> tag has the tweet text. So...displaying user's public timeline in Data Dynamics Report is pretty simple:
1) Add new Data Source in a report. Set Data Source type to XML.
2) Set the connection string of the newly added data source to "xmldoc=http://twitter.com/statuses/user_timeline/USER NAME.rss"(without quotes). Change USER_NAME to the real-world value.
3) Add the new Data Set in the Data Source.
4) Set the Query of the newly added Data Set to "/rss/channel/item"(without quotes).
5) Add the Fields to the newly added data set. Set the name of the field to "title", set the value of the field to "title".
6) Add the List report item in the report, set the DataSetName to the name of the data set that is added in step 3.
7) Drag the field "title" from the data explorer to the newly added List Report Item.
8) Preview the report, hey presto, it shows the user's public timeline!


Advanced techniques
I've used a couple of other features in the live demo:
1) To limit the tweets list for 5 last messages, I used TopN filter of the data set. I've added one more field to the data set, it's pubDate. The filter expression is "=Fields!pubDate.Value", the filter operator is TopN, the filter value is 5.
2) I parametrized data source query to allow set user name using the report parameter value, the connection string is set to
="xmldoc=http://twitter.com/statuses/user_timeline/" & Parameters!TwitterUser.Value & ".rss"
The complete report is available here.

No comments:

Post a Comment