Sha256: b6c44a4436864e89f655c945b3ab53845c37632f90ca0ae9952bb01056ca4045

Contents?: true

Size: 652 Bytes

Versions: 1

Compression:

Stored size: 652 Bytes

Contents

# require "guesswhat/version"
require 'rest-client'

module Guesswhat
  class Product

    def self.image(item)

      #Default URL for finding images from google
      url = "https://www.googleapis.com/customsearch/v1?q=#{item}&cx=008288361057280940904%3Acaao_sbv0xy&fileType=png&filter=1&imgSize=xlarge&num=1&searchType=image&key=AIzaSyBvSuUjfRZ0ImQP6KEgDdQEtdUoB1nWQY8"
      response = JSON.parse(RestClient.get url)

      #Finding the first image from Google Images
      if response["items"][0]["link"] != nil
        image_url = response["items"][0]["link"]
      else
        image_url = nil
      end

      puts image_url
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
guesswhat-1.0.0 lib/guesswhat.rb