Sha256: 964da50fd11619c2af2beabd3d16861646d5de92b7a4d2ea9ea4e3ace2ff1579

Contents?: true

Size: 1.61 KB

Versions: 3

Compression:

Stored size: 1.61 KB

Contents

#!/usr/bin/env ruby

# Trap interrupts to quit cleanly. See
# https://twitter.com/mitchellh/status/283014103189053442
Signal.trap("INT") { exit 1 }

require 'oauth'
require 't'
require 'twitter'

# Output message to $stderr, prefixed with the program name
def pute(*args)
  first = args.shift.dup
  first.insert(0, "#{$0}: ")
  args.unshift(first)
  $stderr.puts(*args)
end

begin
  T::CLI.start(ARGV)
rescue Interrupt
  pute "Quitting..."
  exit 1
rescue OAuth::Unauthorized
  pute "Authorization failed"
  exit 1
rescue Twitter::Error::TooManyRequests => error
  pute error.message,
    "The rate limit for this request will reset in #{error.rate_limit.reset_in} seconds.",
    "While you wait, consider making a polite request for Twitter to increase the API rate limit at https://dev.twitter.com/discussions/10644"
  exit 1
rescue Twitter::Error::BadRequest => error
  pute error.message,
    "Run `t authorize` to authorize."
  exit 1
rescue Twitter::Error::Forbidden, Twitter::Error::Unauthorized => error
  pute error.message
  if error.message == "Error processing your OAuth request: Read-only application cannot POST" ||
    error.message == "This application is not allowed to access or delete your direct messages"
    $stderr.puts(%q(Make sure to set your Twitter application's Access Level to "Read, Write and Access direct messages".))
    require 'thor'
    Thor::Shell::Basic.new.ask "Press [Enter] to open the Twitter Developer site."
    require 'launchy'
    Launchy.open("https://dev.twitter.com/apps") { |u,o,e| $stderr.puts "Manually open #{u}" }
  end
  exit 1
rescue Twitter::Error => error
  pute error.message
  exit 1
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
t-2.0.1 bin/t
t-2.0.0 bin/t
t-1.7.2 bin/t