LoginSignup
0
2

More than 5 years have passed since last update.

RubyでTwitterAPIを使いプロフィールを更新しよう

Last updated at Posted at 2017-11-29

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
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2