-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require "uri" | ||
require "json" | ||
require "net/http" | ||
|
||
SERPER_API_KEY = ENV.fetch('SERPER_API_KEY',nil) | ||
$stderr.puts("Note: this API KEY has a monthly cap. Consider doing some caching and using sparingly.") | ||
$stderr.puts("Tip: Try feeding STDOUT to `jq` for nicer output.") | ||
raise "ENV[SERPER_API_KEY] not provided! Get one here://serper.dev/" unless SERPER_API_KEY | ||
|
||
url = URI("https://google.serper.dev/search") | ||
|
||
https = Net::HTTP.new(url.host, url.port) | ||
https.use_ssl = true | ||
|
||
request = Net::HTTP::Post.new(url) | ||
request["X-API-KEY"] = SERPER_API_KEY | ||
request["Content-Type"] = "application/json" | ||
request.body = JSON.dump({ | ||
"q": "Riccardo Carlesso" | ||
}) | ||
|
||
response = https.request(request) | ||
puts response.read_body |