Class: ASPSMS::Gateway

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

Overview

Handles network communication with the ASPSMS gateways.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cfg, gw) ⇒ Gateway

Returns a new instance of Gateway.



345
346
347
348
349
350
351
# File 'lib/aspsms.rb', line 345

def initialize(cfg, gw)
  @cfg = cfg
  if gw.match(/^(.*):([0-9]{1,5})$/)
    @host, @port = $1, $2
  end
  @http = @cfg.http_class.new(host, port)
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



331
332
333
# File 'lib/aspsms.rb', line 331

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



331
332
333
# File 'lib/aspsms.rb', line 331

def port
  @port
end

Class Method Details

.send(cfg, req) ⇒ Object



332
333
334
335
336
337
338
339
340
341
342
343
# File 'lib/aspsms.rb', line 332

def self.send(cfg, req)
  cfg.gateways.each do |spec|
    begin
      resp = Gateway.new(cfg, spec).send(req)
      return resp
    rescue
      # continue with next gateway in list
      # XXX collect exception objects and add to raise below
    end
  end
  raise 'Failed to send request to gateways!'
end

Instance Method Details

#send(req) ⇒ Object



353
354
355
356
357
358
# File 'lib/aspsms.rb', line 353

def send(req)
  headers = { 'User-Agent' => @cfg.useragent,
              'Content-Type' => 'text/xml' }
  resp = @http.post('/xmlsvr.asp', req.to_s, headers)
  ASPSMS::Response.parse(@cfg, resp.body)
end