Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adds bin/twitter-cli and interactive console

  • Loading branch information...
commit 2a93166e17625d60405629744233bc484309b759 1 parent 00a8d52
@twoism authored
Showing with 67 additions and 0 deletions.
  1. +11 −0 bin/twitter-cli
  2. +55 −0 lib/twitter/cli.rb
  3. +1 −0  twitter.gemspec
View
11 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
View
55 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
View
1  twitter.gemspec
@@ -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/**/*")
Please sign in to comment.
Something went wrong with that request. Please try again.