Flickr.rb

An insanely easy Ruby interface to the Flickr photo-sharing service. By Scott Raymond <sco@redgreenblu.com>

Get it

via RubyGems: gem install flickr
...or download the gem: flickr-1.0.0.gem
...or just get the source by itself: flickr.rb

You'll also need a Flickr API key.

Example

require 'flickr'

# basics
flickr = Flickr.new                           # create a flickr client
flickr.login(email, password)                 # log in for actions that require it
flickr.users                                  # get all users currently online
flickr.photos                                 # get the 100 most recent public photos
flickr.tag('red')                             # search for photos tagged with 'red'
flickr.groups                                 # get all active public groups

# working with users
user = flickr.users('sco')                    # lookup a user by username
user = flickr.users('sco@scottraymond.net')   # or email
user.name                                     # get the user's real name
user.location                                 # and location
user.photos                                   # grab their collection of Photo objects...
user.tag('red')                               # search their photos for the tag 'red'
user.groups                                   # ...the groups they're in...
user.contacts                                 # ...their contacts...
user.favorites                                # ...favorite photos...
user.photosets                                # ...their photo sets...
user.tags                                     # ...and their tags

# working with photos
photo = flickr.photos.first                   # get the most recent public photo
photo.url                                     # see the URL for the photo's page...
photo.url('Original')                         # as well as for its various sizes
photo.source                                  # see the URL for the JPEG itself...
photo.source('Small')                         # as well as for its various sizes
photo.title                                   # get its title,
photo.description                             # description,
photo.owner                                   # owner,
photo.owner.name                              # and its owner's name, etc.

# downloading files
File.open(photo.filename, 'w') do |file|
  file.puts photo.file                        # save the photo to a local file
end
flickr.photos.each do |photo|                 # get the last 100 public photos...
  File.open(photo.filename, 'w') do |file|
    file.puts photo.file('Square')            # ...and save a local copy of their square thumbnail
  end
end

# ...and so much more. see the docs for full details.

Documentation

Rdoc Documentation
Also see: Original Flickr API reference

License

MIT License. Attribution and contribution encouraged.

Thanks

Maik Schmidt for XmlSimple, Ludicorp for Flickr, and Premshee Pillai for Flickr-ruby.