Skip to content

Instantly share code, notes, and snippets.

@coolaj86
Last active December 18, 2015 18:19
Show Gist options
  • Save coolaj86/5825156 to your computer and use it in GitHub Desktop.
Save coolaj86/5825156 to your computer and use it in GitHub Desktop.
Ruby Flickr Pickr

Get pictures from flickr

If you have the flickr code from the morning code-along, delete it:

rm -rf ~/Code/wk1d4/flickr

Now clone the code again

mkdir -p ~/Code/wk1d4/
git clone https://gist.github.com/5825156.git ~/Code/wk1d4/flickr
pushd ~/Code/wk1d4/flickr

Inside homework.rb you will find the instructions you need to follow as comments

Watch some awesome videos

Watch Volume 1 and Section 8 of the Crockford on JS series

Warning: The first video is in mov format. You may need to use Safari, or VLC and File -> Open Network..., or download the file first.

require('open-uri')
require('json')
class GaFlickr
def self.load()
url = "http://api.flickr.com/services/feeds/photos_public.gne?format=json"
options = {
"Accept" => "application/json"
}
open(url, options) { |f|
text = f.read()
text.gsub!(/jsonFlickrFeed\(/, '')
text = text[0..-2] #gsub!(/\)/, '')
return JSON.parse(text)
}
end
end
require('./ga-flickr')
require('./image')
data = GaFlickr.load()
# in the data you will find that there is an array of items
# Create an array of images (i.e. `images << Image.new(hash)`)
# For each image print the results of the html_tag method (i.e. `puts(image.html_tag())`)
# Bonus
# Look at ga-flickr.rb and write on your blog explaining how it works
class Image
# create accessors for the title, the direct link to the image, and the tags as an array
# Hint: there's a method on the string class to help you do this
# create an html_tag method which returns a string with an html img tag
# Hint: you can see what an img tag looks like in the description
# Bonus create a new method to_img on the Array class
# that will each over its elements and return a string containing all html img tags
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment