Ooh, shiny! (CLI Twitter client part 1.)
I’ve wanted to use Thor since I first heard about it, 5 whole days ago now (which is nearly forever in intarwebs time!)
Since I love command line utilities, and I love twitter, the choice was obvious. Now, fair warning; there are already a billion (or 4,180,000) or so options out there in the CLI Twitter space.
Also, there are no guarantees that there will ever been anything beyond a part 1 here. But, I owe you a blog post that doesn’t suck, and while I should be doing work, my predilection for slacking off has me in a serious stranglehold right now. So, I’m hacking on something else, and you, dear citizen of the net, are the beneficiary!
So install Thor, in the obvious fashion, with
$ gem install thor.
Next, install the ruby twitter gem with
$ gem install twitter.
A good place to start here might be in your “prototypes” repository. You do have a “prototypes” repo, don’t you? Check out geemus’ talk from Ruby Midwest 2010 for more details. If I get a video link I’ll hook you up.
$ mkdir -p Sources/prototypes
(I keep my codes in a Sources folder.)
$ cd Sources/prototypes
$ vi twitter.thor
By all means, feel free to replace ‘vi’ in that last command with your editor of choice.
class Twitter < Thor
desc "read [USER]", "Read tweets from users you follow, or optionally, from [USER]"
def read(user = "")
puts "it works!"
If that works, when you give the command
$ thor list, you should see the following output:
$ thor list
/home/[you]/.rvm/gems/ruby-1.8.7-p299/bin/thor twitter:read [USER] # Read tweets from users ...
Pretty impressive, you already have a pretty solid self documenting CLI util. Running it should result in the following:
$ thor twitter:read
Since I spent a decent chunk of the night working on Thor documentation instead of this post (hopefully they’ll accept my pull request…) this is about as far as I’m gonna get on this in part 1. It’s also about as far as I want to go without writing any tests. So, look forward to that in part 2. If ever there is such a thing. No promises.
But, ruminate on what’s there so far, read through the Thor docs, and hopefully we will hack on this again soon. Until then, be well, and happy hacking!