smsc_manager 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/send_sms.rb +8 -4
- data/lib/smsc_manager/smsc_connection.rb +15 -37
- data/lib/smsc_manager/version.rb +1 -1
- metadata +2 -2
data/bin/send_sms.rb
CHANGED
@@ -3,6 +3,7 @@ if ARGV.size !=4
|
|
3
3
|
puts "Usage: send_sms.rb user destination source text"
|
4
4
|
exit
|
5
5
|
end
|
6
|
+
require 'pp'
|
6
7
|
|
7
8
|
require 'rubygems'
|
8
9
|
gem 'smsc_manager'
|
@@ -14,7 +15,7 @@ require 'smsc_manager'
|
|
14
15
|
rescue Exception => e
|
15
16
|
puts "exception found"
|
16
17
|
end
|
17
|
-
puts "Found smsc: #{smsc.hostname}"
|
18
|
+
puts "Found smsc: #{smsc.hostname} port #{smsc.port}"
|
18
19
|
|
19
20
|
user=ARGV[0]
|
20
21
|
destination=ARGV[1]
|
@@ -22,7 +23,10 @@ require 'smsc_manager'
|
|
22
23
|
text=ARGV[3]
|
23
24
|
sms=SmscManager::Sms.new(text,destination,source)
|
24
25
|
puts "Sending user: #{user} destination: #{destination} text: #{text}"
|
25
|
-
res= smsc.
|
26
|
-
# puts "Response code: #{res.response} body: #{res.response_body}"
|
27
|
-
|
26
|
+
res= smsc.send(sms)
|
27
|
+
# puts "Response code: #{res.response} body: #{res.response_body}"
|
28
|
+
puts "Response code: #{res}" if res.kind_of? String
|
29
|
+
puts "pretty print response:"
|
30
|
+
pp res
|
31
|
+
# puts "Response code: #{res.} body: #{res.code}" if res.kind_of? Net::Http
|
28
32
|
|
@@ -10,7 +10,7 @@ class SmscConnection
|
|
10
10
|
|
11
11
|
# def intialize(pass, user, port=13013, host='localhost')
|
12
12
|
# end
|
13
|
-
def send_block(
|
13
|
+
def send_block(text,destination,source)
|
14
14
|
@flag=false
|
15
15
|
s = Time.now #max forty second timeout
|
16
16
|
@res='before'
|
@@ -34,13 +34,13 @@ class SmscConnection
|
|
34
34
|
def dump
|
35
35
|
#change this in database or here
|
36
36
|
test_path=SmscManager::SmscConnection.path_to_config
|
37
|
-
|
37
|
+
# puts "Path to config file is: #{test_path}"
|
38
38
|
config = File.open(test_path,'w') { |f| YAML.dump(self,f) }
|
39
39
|
end
|
40
40
|
def self.load_smsc
|
41
41
|
#change this in database or here
|
42
42
|
test_path=self.path_to_config
|
43
|
-
|
43
|
+
# puts "Path to config file is: #{test_path}"
|
44
44
|
config = File.open(test_path) { |f| YAML.load(f) }
|
45
45
|
#puts "config is: #{config} config.class is: #{config.class}"
|
46
46
|
if config.class==SmscManager::SmscConnection
|
@@ -55,34 +55,12 @@ class SmscConnection
|
|
55
55
|
end
|
56
56
|
smsc
|
57
57
|
end
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
sms_transaction_log.sms_content=sms.text
|
63
|
-
sms_transaction_log.destination=sms.destination
|
64
|
-
sms_transaction_log.source=sms.source
|
65
|
-
sms_transaction_log.username=user
|
66
|
-
|
67
|
-
r= sms_send(sms)
|
68
|
-
|
69
|
-
if r.kind_of? Net::HTTPResponse
|
70
|
-
sms_transaction_log.response=r.code
|
71
|
-
sms_transaction_log.response_body=r.body
|
72
|
-
else
|
73
|
-
sms_transaction_log.response=9000
|
74
|
-
sms_transaction_log.response_body=r.to_s
|
75
|
-
end
|
76
|
-
|
77
|
-
rescue Exception => e
|
78
|
-
sms_transaction_log.response=9999
|
79
|
-
sms_transaction_log.response_body=e
|
80
|
-
end
|
81
|
-
sms_transaction_log.save!
|
82
|
-
sms_transaction_log
|
83
|
-
end
|
58
|
+
|
59
|
+
def send(sms)
|
60
|
+
sms_send(sms)
|
61
|
+
end
|
84
62
|
def test(sms)
|
85
|
-
|
63
|
+
send(sms)
|
86
64
|
end
|
87
65
|
def self.factory
|
88
66
|
SmscManager::SmscConnection.load_smsc
|
@@ -96,16 +74,16 @@ class SmscConnection
|
|
96
74
|
|
97
75
|
txt_encoded=ERB::Util.url_encode(sms.text)
|
98
76
|
# txt_encoded=limit_text(txt_encoded)
|
99
|
-
|
100
|
-
internal_send(
|
77
|
+
# smsc=SmscManager::SmscConnection.factory
|
78
|
+
internal_send(txt_encoded,sms.destination,sms.source)
|
101
79
|
end
|
102
80
|
private
|
103
|
-
def internal_send(
|
81
|
+
def internal_send(text,destination,source)
|
104
82
|
|
105
|
-
return send_block(
|
106
|
-
ht =Net::HTTP.start(
|
107
|
-
puts "hostname: #{
|
108
|
-
url="/cgi-bin/sendsms?username=#{
|
83
|
+
return send_block(text,destination,source) {
|
84
|
+
ht =Net::HTTP.start(self.hostname,self.port)
|
85
|
+
puts "hostname: #{self.hostname} port #{self.port} destination #{destination}"
|
86
|
+
url="/cgi-bin/sendsms?username=#{self.username}&password=#{self.password}&from=#{source}&to=#{destination}&text=#{text}"
|
109
87
|
r=ht.get(url)
|
110
88
|
puts "url was: #{url}"
|
111
89
|
@res = r.code
|
data/lib/smsc_manager/version.rb
CHANGED
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: smsc_manager
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.2.
|
7
|
-
date: 2007-02-
|
6
|
+
version: 0.2.6
|
7
|
+
date: 2007-02-13 00:00:00 +08:00
|
8
8
|
summary: connection to smsc via http using kannel
|
9
9
|
require_paths:
|
10
10
|
- lib
|