Class: PSWinCom::API
- Inherits:
-
Object
- Object
- PSWinCom::API
- Defined in:
- lib/pswincom/api.rb
Class Attribute Summary collapse
-
.api_host ⇒ Object
Returns the value of attribute api_host.
-
.debug_mode ⇒ Object
Returns the value of attribute debug_mode.
-
.test_mode ⇒ Object
Returns the value of attribute test_mode.
Instance Method Summary collapse
- #add_sms(to, text, args = {}) ⇒ Object
-
#initialize(user, password) ⇒ API
constructor
A new instance of API.
- #send_sms(to = nil, text = nil, args = {}) ⇒ Object
Constructor Details
#initialize(user, password) ⇒ API
Returns a new instance of API.
19 20 21 22 23 24 25 |
# File 'lib/pswincom/api.rb', line 19 def initialize user, password if user.to_s.empty? or password.to_s.empty? raise ArgumentError, "You must specify username and password" end @user, @password = user, password @request = Request.new :user => @user, :passwd => @password end |
Class Attribute Details
.api_host ⇒ Object
Returns the value of attribute api_host.
13 14 15 |
# File 'lib/pswincom/api.rb', line 13 def api_host @api_host end |
.debug_mode ⇒ Object
Returns the value of attribute debug_mode.
12 13 14 |
# File 'lib/pswincom/api.rb', line 12 def debug_mode @debug_mode end |
.test_mode ⇒ Object
Returns the value of attribute test_mode.
11 12 13 |
# File 'lib/pswincom/api.rb', line 11 def test_mode @test_mode end |
Instance Method Details
#add_sms(to, text, args = {}) ⇒ Object
47 48 49 |
# File 'lib/pswincom/api.rb', line 47 def add_sms to, text, args = {} @request.add({:text => text, :receiver => to }.merge(args)) end |
#send_sms(to = nil, text = nil, args = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/pswincom/api.rb', line 27 def send_sms to = nil, text = nil, args={} add_sms(to, text, args) unless (to.nil? || text.nil?) # Check if there are any messages to send if REXML::Document.new(@request.xml). root.get_elements('MSGLST/MSG').count == 0 raise ArgumentError, 'There are no SMS to send' end sender = HttpSender.new PSWinCom.debug "Request", @request.xml unless self.class.test_mode result = sender.send(@request) PSWinCom.debug "Result", result.body end return result end |