Class: PSWinCom::API

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

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, password) ⇒ API

Returns a new instance of API.



19
20
21
22
# File 'lib/pswincom/api.rb', line 19

def initialize user, password
  @user, @password = user, password
  @request = Request.new :user => @user, :passwd => @password      
end

Class Attribute Details

.api_hostObject

Returns the value of attribute api_host.



13
14
15
# File 'lib/pswincom/api.rb', line 13

def api_host
  @api_host
end

.debug_modeObject

Returns the value of attribute debug_mode.



12
13
14
# File 'lib/pswincom/api.rb', line 12

def debug_mode
  @debug_mode
end

.test_modeObject

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



44
45
46
# File 'lib/pswincom/api.rb', line 44

def add_sms to, text, args = {}
  @request.add({:text => text, :receiver => to }.merge(args))
end

#send_sms(to = nil, text = nil, args = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pswincom/api.rb', line 24

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