Skip to content

Instantly share code, notes, and snippets.

@komasaru komasaru/tumblr_text.rb
Last active Apr 19, 2018

Embed
What would you like to do?
Ruby script to post texts to Tumblr.
#! /usr/local/bin/ruby
# coding: utf-8
#=タイトル、内容を引数で与えて Tumblr にテキスト投稿する
#
# date name version
# 2017.01.03 mk-mode 1.00 新規作成
#
# Copyright(C) 2017 mk-mode.com All Rights Reserved.
#---------------------------------------------------------------------------------
# 引数 : 第1 - タイトル
# 第2 - 内容
# ( 半角スペースが存在する場合は "" で括る。内容の改行は \n を使用する )
#---------------------------------------------------------------------------------
#
require 'tumblr_client'
class TumblrText
# Tumblr API Keys
CONS_KEY = "<Consumer Key>"
CONS_SEC = "<Consumer Secret>"
ACCS_KEY = "<Access Token>"
ACCS_SEC = "<Access Token Secret>"
SITE = "<your_site>.tumblr.com"
def initialize(args)
@title, @body = args[0], args[1].gsub(/\\n/, "\n")
Tumblr.configure do |config|
config.consumer_key = CONS_KEY
config.consumer_secret = CONS_SEC
config.oauth_token = ACCS_KEY
config.oauth_token_secret = ACCS_SEC
end
@client = Tumblr::Client.new
end
def exec
@client.text(SITE, {title: @title, body: @body})
rescue => e
$stderr.puts "[#{e.class}] #{e.message}"
e.backtrace.each { |tr| $stderr.puts "\t#{tr}" }
exit 1
end
end
if __FILE__ == $0
exit if ARGV.size < 2
TumblrText.new(ARGV).exec
end
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.