forked from sferik/twitter-ruby
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds bin/twitter-cli and interactive console
- Loading branch information
Christopher Burnett
committed
Nov 1, 2012
1 parent
00a8d52
commit 2a93166
Showing
3 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters