Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sondnm
Created April 12, 2019 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sondnm/2842ef145778a74bd48672046ab0a6f3 to your computer and use it in GitHub Desktop.
Save sondnm/2842ef145778a74bd48672046ab0a6f3 to your computer and use it in GitHub Desktop.
Recache API client for prerender.io
require 'net/http'
require 'json'
require 'uri'
class Prerender
ENDPOINTS = "https://api.prerender.io".freeze
def initialize(url, prerender_token)
@url = url
@prerender_token = prerender_token
end
def recache
post_params = {
url: url,
prerenderToken: prerender_token
}
res = Net::HTTP.post(
URI("#{ENDPOINTS}/recache"),
post_params.to_json,
'Content-Type' => 'application/json'
)
if res.code == '200'
puts "Successfully recache URL #{url}"
else
puts res.body
end
end
private
attr_reader :url, :prerender_token
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment