Last active
April 20, 2017 07:26
-
-
Save koshian/96b7da7a0d529ca9c5c4cb6bd98e9178 to your computer and use it in GitHub Desktop.
はてなブックマークとマストドンを連携するためのCGIスクリプト
This file contains 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
#!/usr/bin/ruby | |
# coding: utf-8 | |
# | |
require 'cgi' | |
require 'net/https' | |
API_POINT = 'https://mstdn.jp/api/v1/statuses' | |
HBKEY='XXXXXXXXXXX' | |
ACCESS_TOKEN = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' | |
cgi = CGI.new | |
exit unless cgi['key'] == HBKEY | |
uri = URI.parse(API_POINT) | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true | |
req = Net::HTTP::Post.new(uri.path) | |
req.set_form_data({ | |
'access_token' => ACCESS_TOKEN, | |
'status' => "%s\n--- \n\"%s\" %s" % [cgi['comment'], cgi['title'], cgi['url']], | |
'visibility' => 'public', | |
}) | |
res = http.request(req) | |
print "Content-Type: text/plain\n\n" | |
if res | |
print "OK\n" | |
else | |
print "NG\n" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
はてなブックマークの Webhook を利用した Mastodon 連携スクリプト。マストドンにもはてブ流したいので作りました。