RubyでTwitterAPIを使いプロフィールを更新しよう
今回はの「RubyでTwitterAPIを使う準備をしよう。」ができていることを前提に話を進めて行きます。
"この中を変えて自分の変えたいプロフィールにしよう"
T_ZONE = "Tokyo"
NAME = "テストアカウント"
URL = "http://xxx.yyy.zzz/"
LOCATION = "Ruby City MATSUE"
DESC = "これはテストアカウントです。"
LN_COLOR = "FA743E"
RubyでTwitterAPIを使う準備をしよう。に以下のコードを書き加えていきます。
twitter.rb
class TwitterSet
T_ZONE = "Tokyo"
NAME = "テストアカウント"
URL = "http://xxx.yyy.zzz/"
LOCATION = "Ruby City MATSUE"
DESC = "これはテストアカウントです。"
LN_COLOR = "FA743E"
def control
settings
update_profile
rescue => e
$stderr.puts "[EXCEPTION][#{self.class.name}.#{__method__}] #{e}"
exit 1
end
private
def settings
begin
@rest.settings({time_zone: T_ZONE})
rescue => e
raise
end
end
def update_profile
begin
@rest.update_profile(
{
name: NAME,
url: URL,
location: LOCATION,
description: DESC,
profile_link_color: LN_COLOR
}
)
rescue => e
raise
end
end
end
app = Twitter.new(CONFIG)
app.control