commonthread-clickatell 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +37 -0
- data/License.txt +20 -0
- data/Manifest.txt +36 -0
- data/RDOC_README.txt +33 -0
- data/README.textile +33 -0
- data/Rakefile +160 -0
- data/clickatell.gemspec +33 -0
- data/lib/clickatell/api/command.rb +30 -0
- data/lib/clickatell/api/command_executor.rb +41 -0
- data/lib/clickatell/api/error.rb +25 -0
- data/lib/clickatell/api/message_status.rb +26 -0
- data/lib/clickatell/api.rb +129 -0
- data/lib/clickatell/response.rb +22 -0
- data/lib/clickatell/utility/options.rb +107 -0
- data/lib/clickatell/utility.rb +6 -0
- data/lib/clickatell/version.rb +13 -0
- data/lib/clickatell.rb +11 -0
- data/setup.rb +1585 -0
- metadata +75 -0
@@ -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
|