Skip to content

Instantly share code, notes, and snippets.

Created October 21, 2020 16:45
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
# for sending the request
require "uri"
require "net/http"
require "json"
# for loading our environment variables
require "dotenv/load"
# for scraping our blog
require "open-uri"
require "nokogiri"
root = ""
page = "/2020/07/fingerprinting-ii/"
doc = Nokogiri::HTML( + page))
# article = doc.css('article')[0].to_s
article = doc.css('article')[0]
article.css('[src^="/"]').each do |i|
i["src"] = root + i["src"]
article.css('[href^="/"]').each do |i|
i["href"] = root + i["href"]
url = URI("{ENV["USER_ID"]}/posts")
https =, url.port);
https.use_ssl = true
request =
request["Authorization"] = "Bearer #{ENV["AUTH_TOKEN"]}"
request["Content-Type"] = "application/json"
body = {
title: "fingerprinting-ii-test",
content: article,
contentFormat: "html",
tags: ["hello", "goodbye"],
publishStatus: "draft",
canonicalUrl: root + page,
request.body = body.to_json
response = https.request(request)
puts response.read_body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment