Skip to content

Instantly share code, notes, and snippets.

@FromAtom
Last active April 23, 2016 00:04
Show Gist options
  • Save FromAtom/6445620 to your computer and use it in GitHub Desktop.
Save FromAtom/6445620 to your computer and use it in GitHub Desktop.
はてなブログの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