samples/twitter_timeline.rb in args_parser-0.1.4 vs samples/twitter_timeline.rb in args_parser-0.1.5

- old
+ new

@@ -6,11 +6,11 @@ require 'rubygems' require 'args_parser' gem 'twitter', '< 4.0.0', '>= 3.7.0' require 'twitter' -parser = ArgsParser.parse ARGV, :style => :equal do +args = ArgsParser.parse ARGV, :style => :equal do arg :user, 'user', :alias => :u arg :favorite, 'show favorites', :alias => :fav arg :retweet, 'show retweets', :alias => :rt arg :help, 'show help', :alias => :h @@ -21,42 +21,42 @@ validate :user, "invalid twitter screen_name" do |v| v =~ /^[a-zA-Z0-9_]+$/ end end -if parser.has_option? :help or !parser.has_param? :user +if args.has_option? :help or !args.has_param? :user STDERR.puts "Twitter Timeline\n==" - STDERR.puts parser.help + STDERR.puts args.help STDERR.puts "e.g. ruby #{$0} --user=ymrl" STDERR.puts "e.g. ruby #{$0} --user=ymrl --fav" STDERR.puts "e.g. ruby #{$0} --user=ymrl --fav --rt" exit 1 end -p parser +p args Twitter::configure do end data = [] -Twitter::user_timeline(parser[:user]).each do |i| +Twitter::user_timeline(args[:user]).each do |i| data.push(:id => i.id, :name => i.user.screen_name, :text => i.text, :date => i.created_at) end -if parser.has_option? :favorite - Twitter::favorites(parser[:user]).each do |i| +if args.has_option? :favorite + Twitter::favorites(args[:user]).each do |i| data.push(:id => i.id, :name => i.user.screen_name, :text => i.text, :date => i.created_at) end end -if parser.has_option? :retweet - Twitter::retweeted_by_user(parser[:user]).each do |i| +if args.has_option? :retweet + Twitter::retweeted_by_user(args[:user]).each do |i| data.push(:id => i.id, :name => i.user.screen_name, :text => i.text, :date => i.created_at) end