Class: Smartcall::Utility::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/smartcall/utility/options.rb

Overview

:nodoc:

Class Method Summary collapse

Class Method Details

.default_optionsObject



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/smartcall/utility/options.rb', line 71

def default_options
  options = OpenStruct.new
  config_file = File.open(File.join(ENV['HOME'], '.smartcall'))
  config = ::YAML.load(config_file)
  options.username = config['username']
  options.password = config['password']
  options.campaign_id  = config['campaign_id']
  options.reference = config['reference']
  return options
rescue Errno::ENOENT
  return options
end

.parse(args) ⇒ Object



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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/smartcall/utility/options.rb', line 10

def parse(args)
  @options = self.default_options
  parser = OptionParser.new do |opts|
    opts.banner = "Usage: smartcall [options] recipient message"
    opts.separator ""
    opts.separator "Specific options:"
    
    opts.on('-u', '--username USERNAME',
      "Specify the smartcall username (overrides ~/.smartcall setting)") do |username|
       @options.username = username 
    end
  
    opts.on('-p', '--password PASSWORD',
      "Specify the smartcall password (overrides ~/.smartcall setting)") do |password|
       @options.password = password
    end
  
    opts.on('-c', '--campaign CAMPAIGN_ID',
      "Specify the campaign key (overrides ~/.smartcall setting)") do |key|
       @options.campaign_id = key
    end
    
    opts.on('-r', '--reference REFERENCE',
      "Specify the reference (overrides ~/.smartcall setting)") do |reference|
       @options.reference = reference
    end
              
    opts.on('-d', '--debug') do
       Smartcall::Soap::SmsWSClient.debug_mode = true
    end
  
    opts.on_tail('-h', '--help', "Show this message") do
      puts opts
      exit
    end
  
    opts.on_tail('-v', '--version') do
      puts "Ruby Smartcall SMS Utility #{Smartcall::VERSION}"
      exit
    end
  end

  parser.parse!(args)
  @options.recipient = ARGV[-2]
  @options.message   = ARGV[-1]

  if (@options.message.nil? || @options.recipient.nil?) && send_message?
    puts "You must specify a recipient and message!"
    puts parser
    exit
  end

  return @options

rescue OptionParser::MissingArgument => e
  switch_given = e.message.split(':').last.strip
  puts "The #{switch_given} option requires an argument."
  puts parser
  exit
end

.send_message?Boolean

Returns:

  • (Boolean)


84
85
86
87
# File 'lib/smartcall/utility/options.rb', line 84

def send_message?
  (@options.show_status.nil? &&
   @options.show_balance.nil?)
end