lib/philomena.rb
# Picks a random image from a search query.
# @param query [String] Booru query, exactly as you would write it into the search box.
# @param nsfw [Boolean] Whether to use the NSFW filter or not.
# @return [Hashie::Mash, nil] Query result, `nil` if nothing is found.
Picks a random image from a search query.
Picks a random image from a search query .
def random_image(query = 'safe, cute', nsfw = false)
    img = get(url: 'search/images', query: "q=#{query.present? ? CGI.escape(query) : 'safe, cute'}&sf=random&per_page=1", nsfw: nsfw)
    if img
      img_data = img['images'][0]
      image img_data.id, nsfw if img_data
    end
  end
def random_image ( query = 'safe, cute' , nsfw = false ) img = get ( url : 'search/images' , query : "q=#{query.present? ? CGI.escape(query) : 'safe, cute'}&sf=random&per_page=1" , nsfw : nsfw ) if img img_data = img [ 'images' ] [ 0 ] image img_data . id , nsfw if img_data end end
Picks a random image from a search query.
Picks a random image from a search query .
Query result, `nil` if nothing is found.
Query result ` nil ` if nothing is found .
Hashie::Mash, nil
query
Booru query, exactly as you would write it into the search box.
Booru query exactly as you would write it into the search box .
nsfw
Whether to use the NSFW filter or not.
Whether to use the NSFW filter or not .