Sha256: 6a22a5fe933384ee3a9bb5416eeaebd1edb887ab64ffaa2715d9ce1383d03fc5
Contents?: true
Size: 1.97 KB
Versions: 1
Compression:
Stored size: 1.97 KB
Contents
require "net/http" require "xmlsimple" module Picasa class WebAlbums def initialize(user) Picasa.config.google_user = user if user raise ArgumentError.new("You must specify google_user") unless Picasa.config.google_user end def albums(options = {}) data = connect("/data/feed/api/user/#{Picasa.config.google_user}", options) xml = XmlSimple.xml_in(data) albums = [] xml["entry"].each do |album| attributes = {} attributes[:id] = album["id"][1] attributes[:title] = album["title"][0]["content"] attributes[:summary] = album["summary"][0]["content"] attributes[:photos_count] = album["numphotos"][0].to_i attributes[:photo] = album["group"][0]["content"]["url"] attributes[:thumbnail] = album["group"][0]["thumbnail"][0]["url"] attributes[:slideshow] = album["link"][1]["href"] + "#slideshow" albums << attributes end if xml["entry"] albums end def photos(album_id, options = {}) data = connect("/data/feed/api/user/#{Picasa.config.google_user}/albumid/#{album_id}", options) xml = XmlSimple.xml_in(data) photos = [] xml["entry"].each do |photo| attributes = {} attributes[:id] = photo["id"][1] attributes[:title] = photo["group"][0]["description"][0]["content"] attributes[:thumbnail_1] = photo["group"][0]["thumbnail"][0]["url"] attributes[:thumbnail_2] = photo["group"][0]["thumbnail"][1]["url"] attributes[:thumbnail_3] = photo["group"][0]["thumbnail"][2]["url"] attributes[:photo] = photo["content"]["src"] photos << attributes end if xml["entry"] {:photos => photos, :slideshow => xml["link"][1]["href"] + "#slideshow"} end private def connect(url, options = {}) full_url = "http://picasaweb.google.com" + url full_url += "?" + URI.encode_www_form(options) unless options.empty? Net::HTTP.get(URI.parse(full_url)) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
picasa-0.3.2 | lib/picasa/web_albums.rb |