Skip to content

Instantly share code, notes, and snippets.

@elliott-king
Created October 21, 2020 16:45
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 elliott-king/1bd37bb3a01686a083e5e815974c36b4 to your computer and use it in GitHub Desktop.
Save elliott-king/1bd37bb3a01686a083e5e815974c36b4 to your computer and use it in GitHub Desktop.
# 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 = "https://elliott-king.github.io"
page = "/2020/07/fingerprinting-ii/"
doc = Nokogiri::HTML(URI.open(root + page))
# article = doc.css('article')[0].to_s
article = doc.css('article')[0]
article.css('[src^="/"]').each do |i|
i["src"] = root + i["src"]
end
article.css('[href^="/"]').each do |i|
i["href"] = root + i["href"]
end
url = URI("https://api.medium.com/v1/users/#{ENV["USER_ID"]}/posts")
https = Net::HTTP.new(url.host, url.port);
https.use_ssl = true
request = Net::HTTP::Post.new(url)
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