
For a couple of years I have been using the Yandex. Photos service for storing all my photos, and recently there was a desire on my homepage to display the last n photos uploaded to Yandex. Photos, thereby killing several birds with one stone:
- homepage does not require administration;
- image storage and management is not required;
- no need to resize images for previews, etc.
No sooner said than done. It turned out that the Photos provide a fairly convenient
API via the AtomPub protocol. Because I planned to make a page on the Ruby on Rails platform, after a brief search I found a good library for working with
feedzirra . The library was installed in a completely standard way:
gem sources -a gems.github.com gem install pauldix-feedzirra
gem sources -a gems.github.com gem install pauldix-feedzirra
gem sources -a gems.github.com gem install pauldix-feedzirra
and further in ruby it is enough to register its use:
- require 'feedzirra'
It's time to explore the API provided.
Having studied the API provided by Yandex, it turned out that the list of the photos recently published by the user can be obtained at the following URL:
api-fotki.yandex.ru/api/users < _ > /photos/published/?limit= < __ >
besides authorization for this operation is not required. The documentation was an example of the output XML, but it turned out that it does not quite correspond to reality. The method of close debag problem was solved.
So I created some kind of wrapper class for the image.
- class ImageBundle
- attr_accessor: url,: album_link,: title,: xxl_url
- end
here url is the address of a preview of a square-shaped picture, album_link is a link to an album, title is the name of a picture, xxl_url is an address of a large-format picture.
')
Further in the controller I filled the collection of the received data.
- feed = Feedzirra :: Feed.fetch_and_parse ( "http://api-fotki.yandex.ru/api/users/ligrimp/photos/published/?limit=35" )
- @images = Array. new
- for image in feed.entries
- image_url = image.links [3]
- i = ImageBundle. new
- i.xxl_url = image_url.clone
- image_url [ "XL" ] = "XXS"
- i.url = image_url
- i.album_link = image.links [2]
- i.title = image.title
- @images << i
- end
The output to the UI turned out to be a matter of technique, using
HAML for markup and
iLoad , I got something like the following:
- - for image in @images
- % a {: href => image.xxl_url,: target => "_blank" ,: rel => "iLoad :: Yandex.fotki",: title => image.title}
- % img {: src => image.url,: title => image.title}