-
Notifications
You must be signed in to change notification settings - Fork 4
/twitter
Copy pathexecutable file
·34 lines (28 loc) · 1.18 KB
/twitter
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env ruby
# This lets us to run this from the command line as ./twitter instead of `ruby
# twitter`
require_relative 'lib/twitter_creds'
require_relative 'lib/twitter'
if API_KEY.nil? || API_SECRET.nil?
puts "Make sure you configure your Twitter application first. See README.md."
puts "Your Twitter API key and API secret need to go in .env"
end
# ARGV is where ruby stores command line arguments:
# http://ruby.about.com/od/rubyfeatures/a/argv.htm
#
command = ARGV.shift
# The first value in the ARGV array is the command the user typed (i.e. ./twitter timeline)
#
# Array#shift returns the first value from an array and removes it from the
# array: http://www.ruby-doc.org/core-2.1.2/Array.html#method-i-shift
arguments = ARGV
# After calling ARGV.shfit, ARGV contains the rest of the arguments we passed
# in via the command line. Unfortunately, on the command line, arguments are
# separated by spaces. So, e.g.,
#
# ./twitter tweet Hello everybody
#
# will result in the arguments array being ["Hello", "everybody"] after we
# use Array#shift to remove the first argument, i.e., "tweet".
results = run_app(command, arguments)
# It's up to you to present the results of each command.