pageflock, meet Ruby.
The generated Ruby example keeps the key in the environment and includes connection and read timeouts.
Your first connection.
- 01
Use Ruby 3.1 or newer and set WAGGLE_BASE_URL and WAGGLE_API_KEY on the server.
- 02
Copy the example into a script or service object; do not put the key in a browser bundle.
- 03
Handle non-2xx responses before parsing or storing returned page data.
Build the request.
Set the environment variables in your terminal for these code examples. In automation tools, enter the URL and credentials in the tool’s own fields.
require "net/http"
require "uri"
uri = URI(ENV.fetch("WAGGLE_BASE_URL").chomp("/") + "/api/pageflock/v1/scrape")
request = Net::HTTPGenericRequest.new("POST", true, true, uri.request_uri)
request["Authorization"] = "Bearer #{ENV.fetch("WAGGLE_API_KEY")}"
request["Content-Type"] = "application/json"
request.body = "{\n \"url\": \"https://example.com\"\n}"
response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https", open_timeout: 10, read_timeout: 45) { |http| http.request(request) }
abort "pageflock HTTP #{response.code}: #{response.body}" unless response.is_a?(Net::HTTPSuccess)
puts response.bodyThis edits a code example. It does not send a request or use credits.
Run a request in your workspace