smsforall 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -0
- data/bin/smsforall +114 -76
- data/lib/smsforall/version.rb +1 -1
- data/smsforall.gemspec +1 -0
- metadata +15 -4
data/Gemfile
CHANGED
data/bin/smsforall
CHANGED
@@ -2,90 +2,128 @@
|
|
2
2
|
|
3
3
|
require 'smsforall'
|
4
4
|
require 'optparse'
|
5
|
+
require 'logger/colors'
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
opts.separator " send SENDER NUMBER TEXT : send SMS with TEXT to NUMBER"
|
16
|
-
opts.separator " status TRANSACTION : get status of transaction"
|
17
|
-
opts.separator ""
|
18
|
-
opts.separator "Options"
|
19
|
-
|
20
|
-
# Define the options, and what they do
|
21
|
-
options[:login] = nil
|
22
|
-
opts.on( '-l', '--login LOGIN', 'Login' ) do|login|
|
23
|
-
options[:login] = login
|
24
|
-
end
|
25
|
-
|
26
|
-
options[:password] = nil
|
27
|
-
opts.on( '-p', '--password PASSWORD', 'Password' ) do|password|
|
28
|
-
options[:password] = password
|
29
|
-
end
|
30
|
-
|
31
|
-
options[:test] = :production
|
32
|
-
opts.on( '-t', '--test', 'Enable test mode' ) do
|
33
|
-
options[:test] = :test
|
34
|
-
end
|
35
|
-
|
36
|
-
opts.on( '-h', '--help', 'Display this screen' ) do
|
37
|
-
puts opts
|
38
|
-
exit
|
7
|
+
class SmsforallScript
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@log = Logger.new(STDOUT)
|
11
|
+
@log.formatter = proc{ |level, datetime, progname, msg| "[#{level}]: #{msg}\n" }
|
12
|
+
@log.level = Logger::ERROR
|
13
|
+
parse_parameters
|
14
|
+
@sms = Smsforall::Sms.new(@options[:login],@options[:password], @options[:test])
|
15
|
+
route
|
39
16
|
end
|
40
|
-
end
|
41
|
-
|
42
|
-
optparse.parse!
|
43
17
|
|
44
|
-
|
45
|
-
puts "[WARNING]: test mode enabled!"
|
46
|
-
options[:login] = "test"
|
47
|
-
options[:password] = "test"
|
48
|
-
end
|
18
|
+
private
|
49
19
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
20
|
+
def parse_parameters
|
21
|
+
# Parameters parsing
|
22
|
+
@options = {}
|
23
|
+
|
24
|
+
optparse = OptionParser.new do|opts|
|
25
|
+
opts.banner = "Usage: smsforall (-l login -p password|--test) [-v|V] [-q] COMMAND [options] ..."
|
54
26
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
27
|
+
opts.separator ""
|
28
|
+
opts.separator "Commands"
|
29
|
+
opts.separator " balance : get balance"
|
30
|
+
opts.separator " send SENDER NUMBER TEXT : send SMS with TEXT to NUMBER"
|
31
|
+
opts.separator " status TRANSACTION : get status of transaction"
|
32
|
+
opts.separator ""
|
33
|
+
opts.separator "Options"
|
34
|
+
|
35
|
+
# Define the options, and what they do
|
36
|
+
@options[:login] = nil
|
37
|
+
opts.on( '-l', '--login LOGIN', 'Login' ) do|login|
|
38
|
+
@options[:login] = login
|
39
|
+
end
|
40
|
+
|
41
|
+
@options[:password] = nil
|
42
|
+
opts.on( '-p', '--password PASSWORD', 'Password' ) do|password|
|
43
|
+
@options[:password] = password
|
44
|
+
end
|
45
|
+
|
46
|
+
@options[:test] = :production
|
47
|
+
opts.on( '-t', '--test', 'Enable test mode' ) do
|
48
|
+
@options[:test] = :test
|
49
|
+
end
|
59
50
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
51
|
+
@options[:verbose] = false
|
52
|
+
opts.on( '-v', '--verbose', 'Verbose output' ) do
|
53
|
+
@options[:verbose] = true
|
54
|
+
end
|
55
|
+
|
56
|
+
@options[:more_verbose] = false
|
57
|
+
opts.on( '-V', '--more_verbose', 'More verbose output' ) do
|
58
|
+
@options[:more_verbose] = true
|
59
|
+
end
|
60
|
+
|
61
|
+
@options[:quiet] = false
|
62
|
+
opts.on( '-q', '--quiet', 'Quiet mode' ) do
|
63
|
+
@options[:quiet] = true
|
64
|
+
end
|
65
|
+
|
66
|
+
opts.on( '-h', '--help', 'Display this screen' ) do
|
67
|
+
puts opts
|
68
|
+
exit
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
optparse.parse!
|
73
|
+
|
74
|
+
if @options[:verbose] then @log.level = Logger::WARN end
|
75
|
+
if @options[:more_verbose] then @log.level = Logger::DEBUG end
|
76
|
+
if @options[:quiet] then @log.level = Logger::FATAL end
|
67
77
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
78
|
+
if @options[:test] == :test
|
79
|
+
@log.warn "test mode enabled!"
|
80
|
+
@options[:login] = "test"
|
81
|
+
@options[:password] = "test"
|
82
|
+
end
|
83
|
+
|
84
|
+
if not (@options[:login] && @options[:password])
|
85
|
+
@log.error "you must provide login and password!"
|
86
|
+
exit
|
87
|
+
end
|
88
|
+
|
89
|
+
if not %w[balance send status].include?(ARGV[0])
|
90
|
+
@log.error "command not defined!"
|
91
|
+
exit
|
92
|
+
end
|
72
93
|
end
|
73
|
-
puts "[INFO]: sending SMS to #{number}"
|
74
|
-
sms = Smsforall::Sms.new(login,password, test)
|
75
|
-
transaction = sms.send_message(sender, text, number)
|
76
|
-
puts "#{transaction}"
|
77
|
-
end
|
78
94
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
95
|
+
# route command
|
96
|
+
def route
|
97
|
+
case ARGV[0]
|
98
|
+
when "balance" then get_balance
|
99
|
+
when "send" then send_sms(ARGV[1], ARGV[2], ARGV[3])
|
100
|
+
when "status" then get_status(ARGV[1])
|
101
|
+
end
|
102
|
+
end
|
85
103
|
|
86
|
-
#
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
104
|
+
# actions
|
105
|
+
def get_balance()
|
106
|
+
@log.info "getting balance for #{@options[:login]}"
|
107
|
+
balance = @sms.get_balance()
|
108
|
+
puts "#{balance}"
|
109
|
+
end
|
110
|
+
|
111
|
+
def send_sms(sender, number, text)
|
112
|
+
if not (sender && number && text)
|
113
|
+
@log.error "wrong number of parameters!"
|
114
|
+
exit
|
115
|
+
end
|
116
|
+
@log.info "sending SMS to #{number}"
|
117
|
+
transaction = @sms.send_message(sender, text, number)
|
118
|
+
puts "#{transaction}"
|
119
|
+
end
|
120
|
+
|
121
|
+
def get_status(transaction)
|
122
|
+
@log.info "getting status"
|
123
|
+
status = @sms.get_status(transaction)["status"]
|
124
|
+
puts "#{status}"
|
125
|
+
end
|
126
|
+
|
91
127
|
end
|
128
|
+
|
129
|
+
sms = SmsforallScript.new
|
data/lib/smsforall/version.rb
CHANGED
data/smsforall.gemspec
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: smsforall
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0
|
5
|
+
version: 0.1.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- drakmail
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-09-
|
13
|
+
date: 2012-09-03 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json_pure
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
type: :runtime
|
25
25
|
version_requirements: *id001
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
|
-
name:
|
27
|
+
name: logger-colors
|
28
28
|
prerelease: false
|
29
29
|
requirement: &id002 !ruby/object:Gem::Requirement
|
30
30
|
none: false
|
@@ -32,8 +32,19 @@ dependencies:
|
|
32
32
|
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: "0"
|
35
|
-
type: :
|
35
|
+
type: :runtime
|
36
36
|
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rspec
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id003
|
37
48
|
description: Interaction with smsforall.ru API
|
38
49
|
email:
|
39
50
|
- drakmail@delta.pm
|