Created
October 21, 2020 16:45
-
-
Save elliott-king/1bd37bb3a01686a083e5e815974c36b4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# 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