commonthread-clickatell 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,107 @@
1
+ require 'optparse'
2
+ require 'ostruct'
3
+
4
+ module Clickatell
5
+ module Utility
6
+ class Options #:nodoc:
7
+ class << self
8
+
9
+ def parse(args)
10
+ @options = self.default_options
11
+ parser = OptionParser.new do |opts|
12
+ opts.banner = "Usage: sms [options] recipient message"
13
+ opts.separator ""
14
+ opts.separator "Specific options:"
15
+
16
+ opts.on('-u', '--username USERNAME',
17
+ "Specify the clickatell username (overrides ~/.clickatell setting)") do |username|
18
+ @options.username = username
19
+ end
20
+
21
+ opts.on('-p', '--password PASSWORD',
22
+ "Specify the clickatell password (overrides ~/.clickatell setting)") do |password|
23
+ @options.password = password
24
+ end
25
+
26
+ opts.on('-k', '--apikey API_KEY',
27
+ "Specify the clickatell API key (overrides ~/.clickatell setting)") do |key|
28
+ @options.api_key = key
29
+ end
30
+
31
+ opts.on('-f', '--from NAME_OR_NUMBER',
32
+ "Specify the name or number that the SMS will appear from") do |from|
33
+ @options.from = from
34
+ end
35
+
36
+ opts.on('-b', '--show-balance',
37
+ "Shows the total number of credits remaining on your account") do
38
+ @options.show_balance = true
39
+ end
40
+
41
+ opts.on('-s', '--status MESSAGE_ID',
42
+ "Displays the status of the specified message.") do |message_id|
43
+ @options.message_id = message_id
44
+ @options.show_status = true
45
+ end
46
+
47
+ opts.on('-S', '--secure',
48
+ "Sends request using HTTPS") do
49
+ Clickatell::API.secure_mode = true
50
+ end
51
+
52
+ opts.on('-d', '--debug') do
53
+ Clickatell::API.debug_mode = true
54
+ end
55
+
56
+ opts.on_tail('-h', '--help', "Show this message") do
57
+ puts opts
58
+ exit
59
+ end
60
+
61
+ opts.on_tail('-v', '--version') do
62
+ puts "Ruby Clickatell SMS Utility #{Clickatell::VERSION}"
63
+ exit
64
+ end
65
+ end
66
+
67
+ parser.parse!(args)
68
+ @options.recipient = ARGV[-2]
69
+ @options.message = ARGV[-1]
70
+
71
+ if (@options.message.nil? || @options.recipient.nil?) && send_message?
72
+ puts "You must specify a recipient and message!"
73
+ puts parser
74
+ exit
75
+ end
76
+
77
+ return @options
78
+
79
+ rescue OptionParser::MissingArgument => e
80
+ switch_given = e.message.split(':').last.strip
81
+ puts "The #{switch_given} option requires an argument."
82
+ puts parser
83
+ exit
84
+ end
85
+
86
+ def default_options
87
+ options = OpenStruct.new
88
+ config_file = File.open(File.join(ENV['HOME'], '.clickatell'))
89
+ config = YAML.load(config_file)
90
+ options.username = config['username']
91
+ options.password = config['password']
92
+ options.api_key = config['api_key']
93
+ options.from = config['from']
94
+ return options
95
+ rescue Errno::ENOENT
96
+ return options
97
+ end
98
+
99
+ def send_message?
100
+ (@options.show_status.nil? &&
101
+ @options.show_balance.nil?)
102
+ end
103
+
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,6 @@
1
+ module Clickatell
2
+ module Utility
3
+ end
4
+ end
5
+
6
+ require File.join(File.dirname(__FILE__), *%w[utility/options])
@@ -0,0 +1,13 @@
1
+ module Clickatell #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 5
5
+ TINY = 0
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+
9
+ def self.to_s
10
+ STRING
11
+ end
12
+ end
13
+ end
data/lib/clickatell.rb ADDED
@@ -0,0 +1,11 @@
1
+ module Clickatelll end
2
+
3
+ %w( core-ext/hash
4
+ core-ext/object
5
+ clickatell/version
6
+ clickatell/api
7
+ clickatell/response
8
+
9
+ ).each do |lib|
10
+ require File.join(File.dirname(__FILE__), lib)
11
+ end