Class: Sms::Method::Bezeq

Inherits:
Object
  • Object
show all
Defined in:
lib/sms/method/bezeq.rb

Constant Summary collapse

URL =
URI.parse('https://vast.bezeq.co.il/imsc/interfaces/largeaccount/la3.sms')

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Bezeq

New instance of Bezeq delivery method

Parameters:

  • config (Hash)

Options Hash (config):

  • :account (String)
  • :user (String)
  • :pass (String)
  • :from (String)
  • :port (String)


16
17
18
# File 'lib/sms/method/bezeq.rb', line 16

def initialize(config)
  @config = config.dup
end

Instance Method Details

#deliver!(sms) ⇒ Object

Send an MT message vast.bezeq.co.il/imsc/interfaces/largeaccount/la3.sms?account=myaccount&

user=smsuser&pass=mypass&from=1234&to=972541234567&port=0&text=Hello+world

Parameters:



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/sms/method/bezeq.rb', line 25

def deliver!(sms)
  req = Net::HTTP::Post.new(URL.path)
  hash = sms.serializable_hash
  if hash[:to].is_a?(Array)
    to = hash.delete(:to)
    hash['to[]'] = to
  end

  req.form_data = @config.merge(hash)

  res = Net::HTTP.start(URL.host, URL.port) do |http|
    http.request(req)
  end

  case res
  when Net::HTTPSuccess
    true
  else
    raise DeliveryError.new(res.body, res.code)
  end

end