Category: computadora

More Ruby Mechanize Dev

Posted by – August 8, 2006

I’ve been working away at mechanize lately. It seems like my creativity comes in bursts. As soon as I make a small bugfix release, I get inspired and write a whole bunch of stuff. Anyway, Eric pointed out that I didn’t have support for multi-select lists, so I added that for 0.5.2. I’m excited to release 0.5.3 already because I updated it so that when operating on an WWW::Mechanize::List, if the list doesn’t respond to the method being called, it will try it on the first element of the list. So, what does that mean? You can click on links without having to specify the first one all the time. You can do this:

agent.click page.links.text('Something')

Instead of doing this:

agent.click page.links.text('Something').first

But it is still an array, so if you have multiple links with the text ‘Something’, you can index in to the array like so:

agent.click page.links.text('Something')[2]

I’ve also been toying around with adding a “click” or “select” method to most objects. Then you can select the first radio button with either of the following lines:

agent.click form.radiobuttons.first
form.radiobuttons.first.click

I think this may help in the future if I want to get Javascript support. I’ve currently got this working with select lists, so this will select the second option from a dropdown:

form.selectlist.options[2].select

As for WWW::Mechanize 0.6.0, I’ve got Hpricot support in the trunk with all unit tests passing. This means that browsing the web and scraping those pages at the same time will be a breeze! I just hope that Why releases a gem for Hpricot on rubyforge soon! I also want to see if I can get Mechanize working with Selenium IDE so that scripts generated by Selenium IDE can be executed using mechanize and not through the browser.

New Ruby iTunes Client

Posted by – July 9, 2006

I just released a new version of the ruby iTunes client, Net::DAAP::Client version 0.2.1. I also released Digest::M4P as a Gem and made daapclient depend on it. I wasn’t able to release Digest::M4P as a gem until RubyGems version 0.9.0 was released because of a weird bug. But now that 0.9.0 is here, everything works! Too bad the digest code still doesn’t work on windows…….

I need to release my pure ruby MD5 so that I can make Digest::M4P pure ruby and not have to worry about this windows stuff.

Build your own Sonos player with Ruby on Rails

Posted by – June 27, 2006

Hardware you’ll need:

  1. A computer running linux (I used Fedora Core 4)
  2. Nokia 770 (or some other web tablet)
  3. An Airport Express

Software (all installed on the linux server):

  1. Ruby
  2. RubyGems
  3. MySQL
  4. id3lib
  5. id3lib-devel
  6. raop-play (for streaming to the Airport Express)

More

Ruby iTunes Client

Posted by – June 1, 2006

I’m trying to think of cool stuff for a Ruby presentation, so I thought I’d write up a quick tutorial for the Ruby iTunes client here to see how it sounds.

Introduction:
DAAP stands for “Digital Audio Access Protocol”, and is the protocol used by Apple’s iTunes to share music over a network. Hence the name Net::DAAP::Client.
More

Beta Brite Signs

Posted by – May 28, 2006

Probably a year or two ago, I bought a one of those Beta Brite Signs and made a Perl library to interface with it. My perl library wasn’t very good, so I’ve decided to port it to Ruby, and I’ve been able to get the interface even better in Ruby.

require 'betabrite'
require 'serialport'

include Sign

obj = SerialPort.new(0, 9600, 8, 1, SerialPort::NONE)

sign = BetaBrite.new

tf = BetaBrite::TextFile.new
tf.message = "Hello World"
sign.add tf

sign.write { |text|
  obj.write text
}

I still think it can be improved, but I’m getting there. I’ve been able to get all of the colors working, the fonts working, and even draw custom pictures. I’ve submitted a project to RubyForge, and I should be able to release a gem for this soon.

Browsing iTunes Networks with Ruby

Posted by – May 23, 2006

I’ve been working on my ruby DAAP Client lately, and I ran across a thread on the ruby-talk list about a multicast DNS client. Combining the two of those gave me some pretty neat information about the iTunes servers running on our network.

I could easliy get a list of iTunes servers using only mdns-sd like this:

require 'rubygems'
require 'net/dns/mdns-sd'

DNSSD = Net::DNS::MDNSSD

# Find all iTunes servers
browse_service = DNSSD.browse('_daap._tcp') do |r|
  rservice = DNSSD.resolve(r.name, r.type, r.domain) do |res|
    puts res.target
  end
end

$stdin.gets
browse_service.stop

Once I was able to get a list of iTunes servers, listing all available artists was trivial. I just added the DAAP client in, and it worked:

require 'rubygems'
require 'net/daap'
require 'net/dns/mdns-sd'

DNSSD = Net::DNS::MDNSSD

# Find all iTunes servers
browse_service = DNSSD.browse('_daap._tcp') do |r|
  rservice = DNSSD.resolve(r.name, r.type, r.domain) do |res|
    daap = Net::DAAP::Client.new(res.target)
    daap.connect do |dsn|
      daap.databases.each { |db|
        db.artists.each { |a| puts "#{res.target} #{a.name}" }
      }
    end
  end
end

$stdin.gets
browse_service.stop

Combine that with the get method on Net::DAAP::Song, and you have a winning combo! A script that will automatically detect iTunes servers, and download the music. This will be great for backing up the music I keep on my Mac. I just plug it in to the network, and this script will automatically sync it up.