Skip to content

Instantly share code, notes, and snippets.

@fermion
Created June 23, 2009 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fermion/134480 to your computer and use it in GitHub Desktop.
Save fermion/134480 to your computer and use it in GitHub Desktop.
usage example of smugmugr for a Rails 2.3.2 app
# /config/environment.rb
config.gem "fermion-smugmugr",
:lib => 'smugmugr',
:source => 'http://gems.github.com',
:version => "=0.2.0"
# /config/initializers/smugmugr.rb
SMUG_CONFIG = {
:email => 'rob.sterner@gmail.com',
:password => '*****************',
:api_key => '**********************'
}
# /app/models/cached_album.rb
me = Smugmugr::User.new(SMUG_CONFIG[:api_key], :email => SMUG_CONFIG[:email], :password => SMUG_CONFIG[:password])
# followed by something like:
CachedAlbum.transaction do
smug_albums = me.albums(:LastUpdated, :ImageCount, :Description, :Public, :Password, :PasswordHint)
smug_albums.each{ |smug_album|
next unless smug_album.category.name == "Blog"
if CachedAlbum.exists?(:album_id => smug_album.id)
ca = CachedAlbum.find_by_album_id(smug_album.id)
if out_of_sync?(ca, smug_album)
ca.update_attributes(extract_attributes!(smug_album))
CachedAsset.sync(ca, smug_album)
end
else
# create
ca = CachedAlbum.create(extract_attributes!(smug_album))
CachedAsset.sync(ca, smug_album)
end
}
# cleanup deleted albums
if smug_albums.any?
CachedAlbum.all(:conditions => "album_id NOT IN (#{smug_albums.collect(&:id).join(',')})").each(&:destroy)
else
CachedAlbum.destroy_all
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment