44 lines
1.2 KiB
Ruby
44 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Requests
|
|
class Pastebin
|
|
include HTTParty
|
|
base_uri "https://pastebin.com/api"
|
|
attr_reader :dev_key, :user_key, :folder
|
|
|
|
def initialize(dev_key:, user_key:, folder: nil)
|
|
@dev_key = dev_key
|
|
@user_key = user_key
|
|
@folder = folder
|
|
end
|
|
|
|
def create(title:, content:)
|
|
data = self.class.post("/api_post.php", {
|
|
body: URI.encode_www_form({
|
|
api_option: "paste",
|
|
api_dev_key: dev_key,
|
|
api_user_key: user_key,
|
|
api_paste_code: content,
|
|
api_paste_name: title,
|
|
api_paste_expire_date: "1W",
|
|
api_paste_private: 2,
|
|
api_folder_key: folder,
|
|
}),
|
|
headers: {
|
|
"Content-Type" => "application/x-www-form-urlencoded",
|
|
},
|
|
})
|
|
if data.code != 200
|
|
Rails.logger.error("Failed to paste to pastebin:")
|
|
Rails.logger.error(data)
|
|
return nil
|
|
end
|
|
data.gsub("https://pastebin.com/", "")
|
|
end
|
|
|
|
def self.default
|
|
new(dev_key: Websites.config.pastebin_dev_key, user_key: Websites.config.pastebin_user_key, folder: Websites.config.pastebin_folder)
|
|
end
|
|
end
|
|
end
|