routo 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/routo.rb +6 -0
- data/lib/routo/exception.rb +2 -1
- data/lib/routo/exception/no_credits_left.rb +2 -2
- data/lib/routo/message.rb +21 -20
- metadata +2 -2
data/lib/routo.rb
CHANGED
@@ -42,5 +42,11 @@ module Routo
|
|
42
42
|
def self.send_sms msg, *numbers
|
43
43
|
Message.new(msg).send_sms(*numbers)
|
44
44
|
end
|
45
|
+
|
46
|
+
# not tested
|
47
|
+
def self.balance
|
48
|
+
balance = open("http://smsc5.routotelecom.com/balance.php?username=#{URI.encode(Routo.username)}=&password=#{URI.encode(Routo.password)}")
|
49
|
+
balance.to_i
|
50
|
+
end
|
45
51
|
|
46
52
|
end
|
data/lib/routo/exception.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module Routo
|
2
2
|
module Exception
|
3
3
|
class NoCreditsLeft < Base
|
4
|
-
def initialize
|
5
|
-
super(
|
4
|
+
def initialize message, text
|
5
|
+
super(message, text)
|
6
6
|
Pony.mail(:to => Routo.email, :subject => Routo.no_credits_left[:subject], :body => Routo.no_credits_left[:body]) if Routo.email && Routo.no_credits_left.present? && Routo.no_credits_left_sent_at.to_i<(Time.now.to_i-Routo.seconds_between_mails)
|
7
7
|
Routo.no_credits_left_sent_at = Time.now
|
8
8
|
end
|
data/lib/routo/message.rb
CHANGED
@@ -3,6 +3,7 @@ module Routo
|
|
3
3
|
class Message
|
4
4
|
|
5
5
|
attr_accessor :text
|
6
|
+
attr_accessor :recipients
|
6
7
|
|
7
8
|
def initialize text
|
8
9
|
@text = text
|
@@ -11,25 +12,25 @@ module Routo
|
|
11
12
|
|
12
13
|
def send_sms *numbers
|
13
14
|
options = numbers.last.is_a?(Hash) ? numbers.last : {}
|
14
|
-
recipients = numbers.map{|n| Number.new(n)}
|
15
|
+
@recipients = numbers.map{|n| Number.new(n)}
|
15
16
|
begin
|
16
|
-
parse_response(Net::HTTP.post_form(URI.parse(Routo.http_api_url), params(
|
17
|
+
parse_response(Net::HTTP.post_form(URI.parse(Routo.http_api_url), params(options)))
|
17
18
|
rescue Routo::Exception::SystemError, Routo::Exception::Failed # trying with backup url if Routo returns an internal error
|
18
19
|
begin # here a mail error should not prevent the sms to be send
|
19
20
|
Pony.mail(:to => Routo.email, :subject => Routo.using_backup_url[:subject], :body => Routo.using_backup_url[:body]) if Routo.email && Routo.using_backup_url.present? && Routo.using_backup_url_sent_at.to_i<(Time.now.to_i-Routo.seconds_between_mails)
|
20
21
|
Routo.using_backup_url_sent_at = Time.now
|
21
22
|
ensure
|
22
|
-
parse_response(Net::HTTP.post_form(URI.parse(Routo.http_api_url_backup), params(
|
23
|
+
parse_response(Net::HTTP.post_form(URI.parse(Routo.http_api_url_backup), params(options)))
|
23
24
|
end
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
27
28
|
private
|
28
29
|
|
29
|
-
def params
|
30
|
+
def params options
|
30
31
|
{:user => Routo.username,
|
31
32
|
:pass => URI.encode(Routo.password),
|
32
|
-
:number =>
|
33
|
+
:number => @recipients.map(&:number).join(','),
|
33
34
|
:ownnum => Routo.ownnum,
|
34
35
|
:message => URI.encode(@text),
|
35
36
|
:type => Routo.type,
|
@@ -47,21 +48,21 @@ module Routo
|
|
47
48
|
Rails.logger.debug "msg: "+rep.message.inspect
|
48
49
|
case rep.body
|
49
50
|
when /success/i then return true
|
50
|
-
when /error/i then raise Routo::Exception::Error.new(rep.body)
|
51
|
-
when /auth_failed/i then raise Routo::Exception::AuthFailed.new(rep.body)
|
52
|
-
when /wrong_number/i then raise Routo::Exception::WrongNumber.new(rep.body)
|
53
|
-
when /not_allowed/i then raise Routo::Exception::NotAllowed.new(rep.body)
|
54
|
-
when /too_many_numbers/i then raise Routo::Exception::TooManyNumbers.new(rep.body)
|
55
|
-
when /no_message/i then raise Routo::Exception::NoMessage.new(rep.body)
|
56
|
-
when /too_long/i then raise Routo::Exception::TooLong.new(rep.body)
|
57
|
-
when /wrong_type/i then raise Routo::Exception::WrongType.new(rep.body)
|
58
|
-
when /wrong_message/i then raise Routo::Exception::WrongMessage.new(rep.body)
|
59
|
-
when /wrong_format/i then raise Routo::Exception::WrongFormat.new(rep.body)
|
60
|
-
when /bad_operator/i then raise Routo::Exception::BadOperator.new(rep.body)
|
61
|
-
when /failed/i then raise Routo::Exception::Failed.new(rep.body)
|
62
|
-
when /sys_error/i then raise Routo::Exception::SystemError.new(rep.body)
|
63
|
-
when /no credits left/i then raise Routo::Exception::NoCreditsLeft.new(rep.body)
|
64
|
-
else raise Routo::Exception::Base.new(rep.body)
|
51
|
+
when /error/i then raise Routo::Exception::Error.new(self, rep.body)
|
52
|
+
when /auth_failed/i then raise Routo::Exception::AuthFailed.new(self, rep.body)
|
53
|
+
when /wrong_number/i then raise Routo::Exception::WrongNumber.new(self, rep.body)
|
54
|
+
when /not_allowed/i then raise Routo::Exception::NotAllowed.new(self, rep.body)
|
55
|
+
when /too_many_numbers/i then raise Routo::Exception::TooManyNumbers.new(self, rep.body)
|
56
|
+
when /no_message/i then raise Routo::Exception::NoMessage.new(self, rep.body)
|
57
|
+
when /too_long/i then raise Routo::Exception::TooLong.new(self, rep.body)
|
58
|
+
when /wrong_type/i then raise Routo::Exception::WrongType.new(self, rep.body)
|
59
|
+
when /wrong_message/i then raise Routo::Exception::WrongMessage.new(self, rep.body)
|
60
|
+
when /wrong_format/i then raise Routo::Exception::WrongFormat.new(self, rep.body)
|
61
|
+
when /bad_operator/i then raise Routo::Exception::BadOperator.new(self, rep.body)
|
62
|
+
when /failed/i then raise Routo::Exception::Failed.new(self, rep.body)
|
63
|
+
when /sys_error/i then raise Routo::Exception::SystemError.new(self, rep.body)
|
64
|
+
when /no credits left/i then raise Routo::Exception::NoCreditsLeft.new(self, rep.body)
|
65
|
+
else raise Routo::Exception::Base.new(self, rep.body)
|
65
66
|
end
|
66
67
|
end
|
67
68
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: routo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Adrien Rambert
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-03-
|
13
|
+
date: 2011-03-23 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|