Skip to content

Commit

Permalink
Adds bin/twitter-cli and interactive console
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Burnett committed Nov 1, 2012
1 parent 00a8d52 commit 2a93166
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
11 changes: 11 additions & 0 deletions bin/twitter-cli
@@ -0,0 +1,11 @@
#!/usr/bin/env ruby

$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')

require 'twitter'
require 'twitter/cli'
require 'irb'

include Twitter::Cli

start
55 changes: 55 additions & 0 deletions lib/twitter/cli.rb
@@ -0,0 +1,55 @@
module Twitter
module Cli

class ClientProxy < Twitter::Client
[:get, :post, :put, :delete].each do |http_method|
class_eval %Q[
def #{http_method}(*args)
super(*args)[:body]
end]
end
end

BANNER = "Twitter CLI -- Type `usage` for examples."
USAGE = %Q{
Fetch a user
api.get('/1/users/show.json?screen_name=<screen_name>')
Image uploads
image = File.open("/path/to/banner.png")
api.post('/1/account/profile_banner.json', :banner => image)
}.gsub(/^\t{4}/,'')

def usage
print USAGE
end

def endpoint
ENV['TWITTER_API_ENDPOINT'] || Twitter::Default::ENDPOINT
end

def api
@api ||= ClientProxy.new(:endpoint => endpoint)
end

def start
puts BANNER

IRB.setup(nil)
irb = IRB::Irb.new

IRB.conf[:MAIN_CONTEXT] = irb.context

irb.context.evaluate("require 'irb/completion'", 0)

trap("SIGINT") do
irb.signal_handle
end

catch(:IRB_EXIT) do
irb.eval_input
end
end
end
end
1 change: 1 addition & 0 deletions twitter.gemspec
Expand Up @@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
spec.homepage = 'https://github.com/sferik/twitter'
spec.name = 'twitter'
spec.require_paths = ['lib']
spec.executables = ["twitter-cli"]
spec.required_rubygems_version = Gem::Requirement.new('>= 1.3.6')
spec.summary = spec.description
spec.test_files = Dir.glob("spec/**/*")
Expand Down

0 comments on commit 2a93166

Please sign in to comment.