Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
はてなブログのAPIを使って、記事を投稿するRubyサンプル
#!/usr/bin/env ruby
# -*- encoding: utf-8 -*-
require 'atomutil'
USERNAME = ARGV[0]
BLOG_DOMAIN = ARGV[1]
PASSWORD = ARGV[2]
POST_URI = "http://blog.hatena.ne.jp/#{USERNAME}/#{BLOG_DOMAIN}/atom/entry"
auth = Atompub::Auth::Wsse.new(
username: USERNAME,
password: PASSWORD
)
client = Atompub::Client.new(auth: auth)
entry = Atom::Entry.new(
title: "テストエントリ".encode('BINARY', 'BINARY'),
content: <<'ENDOFCONENT'.encode('BINARY', 'BINARY'))
*もちろん
- はてな記法も
- 書けます
ENDOFCONENT
p client.create_entry(POST_URI, entry);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.