Class: Smsforall::Sms
- Inherits:
-
Object
- Object
- Smsforall::Sms
- Defined in:
- lib/smsforall.rb
Overview
Class for interaction with smsforall.ru API
Instance Attribute Summary collapse
-
#api ⇒ Object
readonly
Returns the value of attribute api.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
-
#get_balance ⇒ Object
Return user balance.
-
#get_status(transactionid) ⇒ Object
Get status of transaction.
-
#initialize(username, password, mode = :production) ⇒ Sms
constructor
Initialize Sms-API class.
-
#send_message(sender, text, msisdn) ⇒ Object
Send message.
Constructor Details
#initialize(username, password, mode = :production) ⇒ Sms
Initialize Sms-API class. For testing purporoses set mode to :test
14 15 16 17 18 19 |
# File 'lib/smsforall.rb', line 14 def initialize(username, password, mode=:production) @username = username @password = Digest::MD5.hexdigest(password) modes = {:production => "/api/", :test => "/testapi/"} @api = modes[mode] end |
Instance Attribute Details
#api ⇒ Object (readonly)
Returns the value of attribute api.
11 12 13 |
# File 'lib/smsforall.rb', line 11 def api @api end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
11 12 13 |
# File 'lib/smsforall.rb', line 11 def password @password end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
11 12 13 |
# File 'lib/smsforall.rb', line 11 def username @username end |
Instance Method Details
#get_balance ⇒ Object
Return user balance
22 23 24 |
# File 'lib/smsforall.rb', line 22 def get_balance() do_request("balance", {})["balance"] end |
#get_status(transactionid) ⇒ Object
Get status of transaction
33 34 35 |
# File 'lib/smsforall.rb', line 33 def get_status(transactionid) do_request("status", { :transactionid => transactionid }) end |
#send_message(sender, text, msisdn) ⇒ Object
Send message
27 28 29 30 |
# File 'lib/smsforall.rb', line 27 def (sender,text,msisdn) if sender.size > 11 then raise 'Sender name to long!' end do_request("send", { :msisdn => msisdn, :sender => sender, :text => text })["transactionid"] end |