Created
April 8, 2010 22:35
-
-
Save kineticac/360631 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'open-uri' | |
require 'net/http' | |
# example with a Flickr image | |
require 'flickraw' | |
FlickRaw.api_key=FLICKR_API_KEY | |
FlickRaw.shared_secret=FLICKR_SECRET | |
# grab the most interesting unrestricted image from Flickr | |
photos = flickr.photos.search :per_page => 1, :page => 1, :content_type => 1, :license => 7, :sort => 'interestingness-desc' | |
# form the url to the image | |
image_url = "http://farm#{photo.farm}.static.flickr.com/#{photo.server}/#{photo.id}_#{photo.secret}_s.jpg" | |
# open the image to a file | |
file = open image_url | |
# find a user | |
user = User.find :first | |
# set his favorite photo, where favorite_photo is | |
# already setup in the user model as | |
# has_attached_file :favorite_photo | |
user.favorite_photo = file | |
user.save | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment