Last active
April 23, 2016 00:04
-
-
Save FromAtom/6445620 to your computer and use it in GitHub Desktop.
はてなブログのAPIを使って、記事を投稿するRubyサンプル
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/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