tweet – Sheep Guarding Llama https://sheepguardingllama.com Scott Alan Miller :: A Life Online Sat, 15 Nov 2008 17:21:45 +0000 en-US hourly 1 https://wordpress.org/?v=6.9.1 Simple Ruby Twitter Client – Tweet [Ruby] https://sheepguardingllama.com/2008/10/simple-ruby-twitter-client-tweet-ruby/ https://sheepguardingllama.com/2008/10/simple-ruby-twitter-client-tweet-ruby/#comments Fri, 31 Oct 2008 18:41:58 +0000 http://www.sheepguardingllama.com/?p=2833 Continue reading "Simple Ruby Twitter Client – Tweet [Ruby]"

]]>
This is my simple, Ruby based Twitter client using Curl designed for UNIX systems like Linux, Mac OSX, FreeBSD, Solaris, etc.  The only requirements are Curl and Ruby.

In order to use Tweet, simply copy all of the included code into your favourite text editor (I use vi) and save as ‘Tweet’.  Don’t forget to “chmod a+x tweet” so that it is executable.  I suggest moving Tweet into your path (perhaps you should consider /usr/local/bin as a recommended directory) to make it easier to use.  I have designed Tweet to be useful to users on a multi-user UNIX system.  It is a command-line utility that simply accepts text input and posts that text, maximum of 144 characters, to your Twitter account.  An existing Twitter account is necessary so sign up if you do not have one already.

There is very little to know in order to use Tweet [Ruby].  (Should I name this RTweet perhaps?)  The one thing that is needed is to set your username and password.  Tweet [Ruby] is designed to accept username and password data from the system environmental variables $tweetuser and $tweetpass.  This design decision was made because it makes it extremely simple to have multiple users on the same system be able to use Tweet [Ruby] transparently from one another.  If you desire, you can bypass this setting by changing the “unset” user and pass settings in the code to your username and password.  This hardcoding is not recommended but is available if needed.

Once you have your username and password set (you can see what your settings currently are by using the -t option) all you need to do is enter the text that you want to publish.  Here is an example:

tweet ‘This is my first post from Tweet [Ruby].  Thanks Scott, this is great.’

Here is the code, go crazy.

#!/usr/bin/ruby -w
#Scott Alan Miller's "Tweet" - Twitter Command Line Script

text = ARGV[0].chomp
user = "unset"         #Supplied Username
pass = "unset"         #Supplied Password
url  = "http://twitter.com/statuses/update.xml"
ver  = "1.0"

user = ENV['tweetuser'] if ENV['tweetuser']
pass = ENV['tweetpass'] if ENV['tweetpass']

if    text.length <= 0
  puts "Please enter text to post."
elsif text.length >= 144
  puts "Please limit post to 144 chars."
elsif text == "-v"  # Version Message
  puts "Current Version of Tweet [Ruby] is " + ver
elsif text == "-h"  # Help Message
  puts "Tweet [Ruby] Help: \n"
  puts "To set environmental username and password:"
  puts "  export tweetuser=yourusername"
  puts "  export tweetpass=yourpassword\n"
  puts "Usage:"
  puts "  tweet \'This is my message.\'"
elsif text == "-t"  # Variable Test
  puts "Username: " + user
  puts "Password: " + pass
else
  result = %x[curl -s -S -u #{user}:#{pass} -d status="#{text}" #{url}]
  puts "Update Failure" if result.grep(/text/) == nil
end

If you end up using my little Twitter client, please send me a Tweet to let me know!

tweet ‘@scottalanmiller Using Tweet, best Twitter client ever.  Ruby rulz.’

]]>
https://sheepguardingllama.com/2008/10/simple-ruby-twitter-client-tweet-ruby/feed/ 5
Twitter from the Linux Command Line https://sheepguardingllama.com/2008/10/twitter-from-the-linux-command-line/ https://sheepguardingllama.com/2008/10/twitter-from-the-linux-command-line/#comments Fri, 31 Oct 2008 14:52:47 +0000 http://www.sheepguardingllama.com/?p=2820 Continue reading "Twitter from the Linux Command Line"

]]>
Okay, so you are a crazy BASH or Korn shell nut (DASH, ASH, TCSH, CSH, ZSH, etc., etc. yes, I mean all of you) and you totally want to be able to Tweet on your Twitter feed without going to one of those krufty GUI utilities.  Such overkill for such a simple task.  I feel your pain.  When I found this little nugget of command line coolness I just had to share it with all of you.  Special thanks to Marco Kotrotsos from Incredicorp who published this on IBM Developer Works.

If you have curl installed, all you need to do is:

curl -u username:pass -d status=”text” http://twitter.com/statuses/update.xml

So, to give you a real world example, if you are “bobtheuser” and your password is “pass1234” and you want to say “Hey, my first UNIX Shell Tweet.” then you just need to:

curl -u bobtheuser:pass1234 -d status="Hey, my first UNIX Shell Tweet." \
http://twitter.com/statuses/update.xml

You will get some feedback in the form of a response XML file. Happy Tweeting!

Disclaimer: I realize that using “Linux” in the subject is misleading.  This is not a Linux specific post but will apply to FreeBSD, OpenBSD, NetBSD, Mac OSX, UNIX, Solaris, AIX, Windows with Cygwin or just about any system with a command line and the curl utility installed.

I use this as the basis for my Ruby based Twitter Client for the command line.

]]>
https://sheepguardingllama.com/2008/10/twitter-from-the-linux-command-line/feed/ 1