Syndicate code posts to Github Gists

This commit is contained in:
2024-03-05 20:34:34 +11:00
parent 56edde6ab5
commit 97c05d3f86
11 changed files with 84 additions and 2 deletions

View File

@@ -0,0 +1,31 @@
require "httparty"
module Adamantium
module Client
class Gist
include Dry::Monads[:result]
def initialize(token:)
@token = token
end
def create_gist(description:, public:, files: {})
request_body = {
description: description,
public: public,
files: files
}
res = HTTParty.post("https://api.github.com/gists",
body: JSON.generate(request_body),
headers: {Authorization: "Bearer #{@token}"})
if res.code >= 200 && res.code < 400
Success(res["html_url"])
else
Failure(:could_not_save_gist)
end
end
end
end
end

View File

@@ -0,0 +1,23 @@
require "dry/monads"
require "sanitize"
module Adamantium
module Syndication
class Gist
include Dry::Monads[:result]
include Deps[gist_client: "clients.gist"]
def call(post:)
description = ""
public = true
files = {
post[:name] => {content: Sanitize.fragment(post[:content])}
}
gist_client.create_gist(description: description,
public: public,
files: files)
end
end
end
end