Class: Smsforall::Sms

Inherits:
Object
  • Object
show all
Defined in:
lib/smsforall.rb

Overview

Class for interaction with smsforall.ru API

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#apiObject (readonly)

Returns the value of attribute api.



11
12
13
# File 'lib/smsforall.rb', line 11

def api
  @api
end

#passwordObject (readonly)

Returns the value of attribute password.



11
12
13
# File 'lib/smsforall.rb', line 11

def password
  @password
end

#usernameObject (readonly)

Returns the value of attribute username.



11
12
13
# File 'lib/smsforall.rb', line 11

def username
  @username
end

Instance Method Details

#get_balanceObject

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 send_message(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