Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions bin/googlevoice
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env ruby
# encoding: UTF-8

# resolve bin path, ignoring symlinks
require 'pathname'
bin_file = Pathname.new(__FILE__).realpath

# add self to libpath
$:.unshift File.expand_path('../../lib', bin_file)

# start up the CLI
require 'googlevoiceapi/cli'
GoogleVoice::CLI.new(ARGV).run
89 changes: 89 additions & 0 deletions lib/googlevoiceapi/cli.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
require 'googlevoiceapi'
require 'optparse'

module GoogleVoice
class CLI

def initialize(args)
@args = args
end

def run
options = {}

optparse = OptionParser.new do |opts|

opts.on('-u U', '--username U', 'Account username (optional)') do |username|
options[:username] = username
end

opts.on('--call', 'Connect a call: [number from] [number to]') do
options[:call] = true
end

opts.on('--sms', 'Send SMS message: [number to]') do
options[:sms] = true
end

opts.on('--smstext T', 'SMS message text (Optional)') do |smstext|
options[:smstext] = smstext
end

opts.on('-h', '--help', 'Print help') do
STDERR.puts optparse
exit 1
end

end

optparse.parse!(@args)

if options[:help]
STDERR.puts optparse
exit 1
end

unless options[:call] || options[:get_number] || options[:sms]
STDERR.puts "Missing command: [call, sms]"
STDERR.puts optparse
exit 1
end

unless options[:username]
print "Username: "
options[:username] = STDIN.gets.chomp;
end

print "Password: "
begin
system "stty -echo"
options[:password] = STDIN.gets.chomp; puts "\n"
ensure
system "stty echo"
end

gv = GoogleVoice::Api.new(options[:username], options[:password])
if options[:call]
if @args.length != 2
STDERR.puts "Invalid call parameters: [number from] [number to]"
STDERR.puts optparse
exit 1
end
gv.call(@args[0], @args[1])
elsif options[:sms]
unless options[:smstext]
print "SMS Text: "
options[:smstext] = STDIN.gets.chomp!
end
if @args.length != 1
STDERR.puts "Invalid sms parameter: [number to]"
STDERR.puts optparse
exit 1
end
gv.sms(@args[0], options[:smstext])
end

end

end
end
2 changes: 1 addition & 1 deletion lib/googlevoiceapi/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module GoogleVoice
VERSION = "0.1.7"
VERSION = "0.2.0"
end