View on GitHub

Flickrie

An object-oriented wrapper for the Flickr API.

About

Your first words are probably:

There is already a gem for that.

This documentation will try its best to justify to you why this gem is not "just another Flickr API wrapper".

Firstly, this library is object-oriented. This is a big advantage, because your code will be much more elegant and much prettier. OO also makes room for additional methods that Flickr doesn't provide, which do the API-specific logic for you.

Secondly, this library parses the JSON response from Flickr. What I mean is, JSON has to represent objects like dates and booleans in a way that is not native to Ruby. With this library, date attributes like #updated_at, instead of returning Strings, will return Time objects, which is something you can work with. And boolean attributes like #ispro, instead of returning 1 (true) and 0 (false), will return true or false. This library attempts to take care of all these little things internally, so that you as a developer can concentrate on more important things.

Thirdly, the attributes are renamed to names you're used to. For example, the #lastupdate attribute is renamed to #updated_at, and the #ispro attribute is renamed to #pro?.

Fourthly, this gem is aware of the fact that Flickr can also host videos. And it's really smart about it.

Now you're probably thinking:

Whoa, this library seems like some hardcore shit. Show me some usage examples.

Installation

$ gem install flickrie

Usage

Single photo:

photo = Flickrie.get_photo_info(1337) # 1337 is the photo's ID
photo.title       #=> "Rock climbing"
photo.has_people? #=> true
photo.updated_at  #=> 2012-06-01 23:27:40 +0200
photo.views_count #=> 4

Multiple photos:

photos = Flickrie.photos_from_set(28473, include_sizes: true)
photo = photos.first
photo.small(320).source_url #=> "http://farm8.staticflickr.com/7094/7316710626_cf80b743d9_n.jpg"

painting

photo.medium(500).source_url #=> "http://farm8.staticflickr.com/7094/7316710626_cf80b743d9.jpg"

painting

Videos:

video = Flickrie.get_video_info(42374)
video.duration #=> 34
video.ready?   #=> true

Pagination:

photos = Flickrie.photos_from_set(32445, :per_page => 20, :page => 3)
photos.per_page      #=> 20
photos.current_page  #=> 3
photos.total_pages   #=> 7
photos.total_entries #=> 140

Sets:

set = Flickrie.get_set_info(23345)
set.created_at               #=> 2012-06-01 23:27:40 +0200
set.photos                   # makes an HTTP request
set.photos.first.restricted? #=> true

Users:

user = Flickrie.get_user_info("67131352@N04")
user.nsid           #=> "67131352@N04"
user.buddy_icon_url # constructed from #icon_server and #icon_farm
user.pro?           #=> false

These are just some of the features. Be sure to visit the GitHub page for additional links and more examples. Feedback is welcome :)