Module: NetelipSms
- Defined in:
- lib/netelip_sms.rb
Constant Summary collapse
- PhoneFormat =
"00%c%a%n"
- APIUri =
URI.parse("http://sms.netelip.com/api.php")
- @@login =
""
- @@password =
""
- @@from =
""
Class Method Summary collapse
-
.send_sms(options = {}) ⇒ Object
Send a petition to Netelip SMS gateway.
Instance Method Summary collapse
Class Method Details
.send_sms(options = {}) ⇒ Object
Send a petition to Netelip SMS gateway
Example:
>> NetelipSms.send_sms(:login => "netelip\_login",
:password => "netelip\_password",
:from => "Max 11chars",
:destination => "0034999999999",
:message => "Message with 140 chars maximum")
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/netelip_sms.rb', line 35 def send_sms( = {}) # Check for login login = [:login] || @@login raise ArgumentError, "Login must be present" unless login and not login.blank? # Check for password password = [:password] || @@password raise ArgumentError, "Password must be present" unless password and not password.blank? from = [:from].to_s || @@from raise ArgumentError, "Sender must be present (from)" if from.blank? raise ArgumentError, "Sender length 11 characters maximum" if (from.size > 11) raise ArgumentError, "Recipient must be a telephone number with international format" unless Phoner::Phone.valid?([:destination].to_s) destination = Phoner::Phone.parse([:destination].to_s).format(PhoneFormat) = [:message].to_s raise ArgumentError, "Message must be present" if .blank? raise ArgumentError, "Message is 140 chars maximum" if .size > 140 res = Net::HTTP.post_form(APIUri, 'login' => login, 'password' => password, 'from' => from, 'destination' => destination, 'message' => ) if res.code == "200" return true else return res.code end end |
Instance Method Details
#from=(sender) ⇒ Object
21 22 23 |
# File 'lib/netelip_sms.rb', line 21 def from=(sender) @@from = sender end |
#login=(username) ⇒ Object
13 14 15 |
# File 'lib/netelip_sms.rb', line 13 def login=(username) @@login = username end |
#password=(secret) ⇒ Object
17 18 19 |
# File 'lib/netelip_sms.rb', line 17 def password=(secret) @@password = secret end |