2021-05-01 23:26:48 +02:00
|
|
|
require "json"
|
|
|
|
|
|
|
|
class MediumClient
|
2021-05-15 23:05:28 +02:00
|
|
|
def self.post_data(post_id : String) : PostResponse::Root
|
2021-05-01 23:26:48 +02:00
|
|
|
client = HTTP::Client.new("medium.com", tls: true)
|
2021-05-15 23:05:28 +02:00
|
|
|
response = client.post("/_/graphql", headers: headers, body: body(post_id))
|
|
|
|
PostResponse::Root.from_json(response.body)
|
2021-05-01 23:26:48 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
private def self.headers : HTTP::Headers
|
|
|
|
HTTP::Headers{
|
|
|
|
"Accept" => "application/json",
|
|
|
|
"Content-Type" => "application/json; charset=utf-8",
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
private def self.body(post_id : String) : String
|
|
|
|
query = <<-GRAPHQL
|
|
|
|
query {
|
|
|
|
post(id: "#{post_id}") {
|
|
|
|
title
|
2021-09-04 23:32:27 +02:00
|
|
|
createdAt
|
2021-05-01 23:26:48 +02:00
|
|
|
creator {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
|
|
|
content {
|
|
|
|
bodyModel {
|
|
|
|
paragraphs {
|
2023-03-25 16:16:00 +01:00
|
|
|
name
|
2021-05-01 23:26:48 +02:00
|
|
|
text
|
|
|
|
type
|
2021-08-29 19:02:56 +02:00
|
|
|
href
|
|
|
|
layout
|
2021-05-01 23:26:48 +02:00
|
|
|
markups {
|
2021-08-29 19:02:56 +02:00
|
|
|
title
|
2021-05-01 23:26:48 +02:00
|
|
|
type
|
2021-07-04 23:06:17 +02:00
|
|
|
href
|
2021-07-04 23:37:45 +02:00
|
|
|
userId
|
2021-05-01 23:26:48 +02:00
|
|
|
start
|
|
|
|
end
|
2021-08-29 19:02:56 +02:00
|
|
|
anchorType
|
2021-05-01 23:26:48 +02:00
|
|
|
}
|
|
|
|
iframe {
|
|
|
|
mediaResource {
|
2021-08-08 22:37:56 +02:00
|
|
|
href
|
2021-09-13 19:27:52 +02:00
|
|
|
iframeSrc
|
|
|
|
iframeWidth
|
|
|
|
iframeHeight
|
2021-05-01 23:26:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
metadata {
|
|
|
|
id
|
|
|
|
originalWidth
|
|
|
|
originalHeight
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
GRAPHQL
|
|
|
|
JSON.build do |json|
|
|
|
|
json.object do
|
|
|
|
json.field "query", query
|
|
|
|
json.field "variables", {} of String => String
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|