Created
April 12, 2019 13:40
-
-
Save sondnm/2842ef145778a74bd48672046ab0a6f3 to your computer and use it in GitHub Desktop.
Recache API client for prerender.io
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
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