Skip to content

Instantly share code, notes, and snippets.

@koshian
Last active April 20, 2017 07:26
Show Gist options
  • Save koshian/96b7da7a0d529ca9c5c4cb6bd98e9178 to your computer and use it in GitHub Desktop.
Save koshian/96b7da7a0d529ca9c5c4cb6bd98e9178 to your computer and use it in GitHub Desktop.
はてなブックマークとマストドンを連携するためのCGIスクリプト
#!/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
@koshian
Copy link
Author

koshian commented Apr 20, 2017

はてなブックマークの Webhook を利用した Mastodon 連携スクリプト。マストドンにもはてブ流したいので作りました。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment