Back to Parent

#Define unsplash methods to search for images with keywords

def search_unsplash_for response

  Unsplash.configure do |config|
    config.application_access_key = ENV['UNSPLASH_ACCESS_KEY']
    config.application_secret = ENV['UNSPLASH_SECRET']
    config.utm_source = "ExampleAppForClass"

  end

  search_results = Unsplash::Photo.search( response, 1, 1)

  puts search_results.to_json

  images = ""

  puts search_results.size

  search_results.each do |result|
    #puts result.to_json

    puts "Result"

    image_thumb = result["urls"]["thumb"]

    puts result["urls"]["thumb"].to_json
    image_description = result["description"].to_s
    images += "<img src='#{ image_thumb.to_s }' /><br/>"
    images += "<hr/>"

    return image_thumb.to_s
  end
  images
end

#Search 
image = search_unsplash_for( keywords.join( ", ") )
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0