As Ramon Leon says, one of the neat things about having your own blog server is that you can always write about little tweaks you make, and there are always more tweaks possible. So - I've had the server sending updated to Twitter every time I post for awhile now. The implementation was pretty lame though - I dropped two methods directly into my BlogEntry class and had it do the update. I finally decided that this was a smelly, and built a small package (MiniTwit in the public store.) There are two classes - a Settings class, to make it possible to set up a simple ini file, and the class that does the work. The code is dead simple:
"now send update"
ifc := TwitterInterface
username: username
password: password.
ifc possiblySendTwitterUpdateFor: 'Sent from VisualWorks 7.6 - Testing'.
The code for the method that does the work is pretty simple as well:
possiblySendTwitterUpdateFor: string
| update client |
self canSendTwitterUpdate ifFalse: [^self].
update := Net.URI encode: string.
client := HttpClient new.
client
username: self settings twitterUsername
password: self settings twitterPassword.
[[client
post: (self settings twitterBaseUrl, update)
contents: '']
on: self httpExceptions
do: [:ex | nil]] fork
Pretty simple stuff, and in the case of an HTTP error, it just silently fails with a nil (not sending to Twitter is hardly the stuff of tragedy :) )
So now in my BlogEntry class, I just use that, and I have the Twitter code nicely isolated.
Now Listening to: Winterblue (Album Version) by Heather Nova from: Siren
Technorati Tags:
twitter