Twitter投稿サービスのリファクタ

Twitterのシステムリファクタのコードです。Rubyで書いています。接続情報などは、yamlで記述しています。また、メッセージも合わせてyamlで取るようにしています。

#!/usr/bin/ruby
# encoding: utf-8

require 'twitter'
require 'oauth'
require 'yaml'

  twitterAccuont = ARGV[0]
  messageInfo    = ARGV[1]

  key     = YAML.load_file('../twitterConf/twitter.yml')
  massage = YAML.load_file('../twitterConf/massage.yml')

  begin

    client = Twitter::REST::Client.new do |config|
      config.consumer_key        = key[twitterAccuont]['consumer_key'    ]
      config.consumer_secret     = key[twitterAccuont]['consumer_select' ]
      config.access_token        = key[twitterAccuont]['access_token_key']
      config.access_token_secret = key[twitterAccuont]['access_secret'   ]
    end

    str_out =           massage[messageInfo]['message'] + " "
    str_out = str_out + massage[messageInfo]['tag'] + " " + Time.now.strftime("%Y-%m-%d %H:%M:%S")
    
    client.update(str_out)
    
    p Time.now.strftime("%Y-%m-%d %H:%M:%S") + " " + twitterAccuont + " " + "tweet-msg" + " " + messageInfo
    
    rescue => e
    STDERR.puts "[EXCEPTION] " + e.to_s
    p Time.now.strftime("%Y-%m-%d %H:%M:%S") + " " + twitterAccuont + " " + "tweet-msg" + " " + messageInfo + " Error:" + e.to_s
    exit 1

  end

Twitterの設定ファイルのyamlでは

roku-miai:
    consumer_key     : xxxxxxxxxxxxxxxxxxxxx
    consumer_select  : XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    access_token_key : XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    access_secret    : XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

メッセージはYamlは

say_hello:
  message : "おはようございます。Good morning. Starting to update Today."
  tag     : " #goldfish #金魚 #水温 #RaspberryPi #MiraiWaterTemp #netthing #IoT #M2M"
say_goodby:
  message : "こんばんは。Stopping update because of dark. See you. "
  tag     : " #goldfish #金魚 #水温 #RaspberryPi #MiraiWaterTemp #netthing #IoT #M2M"