Skip to content

Commit

Permalink
[#6] Add google client service
Browse files Browse the repository at this point in the history
  • Loading branch information
malparty committed Jun 14, 2021
1 parent 7139952 commit 5a6e2fc
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/services/google_service/client_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module GoogleService
class ClientService
require 'httparty'

def self.query(keyword, lang = 'en')
encoded_keyword = URI.encode(keyword)
uri = URI("https://google.com/search?q=#{encoded_keyword}&hl=#{lang}&gl=#{lang}")
user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) '\
'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36'
HTTParty.get(uri, { headers: { 'User-Agent' => user_agent } })
end
end
end

0 comments on commit 5a6e2fc

Please sign in to comment.