Class: Splat::Base

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

Constant Summary collapse

@@gateways =
{}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vendor_name) ⇒ Base

Returns a new instance of Base.



18
19
20
21
22
23
24
25
26
27
# File 'lib/splat.rb', line 18

def initialize(vendor_name)
  self.vendor = vendor_name

  if number_format = Gateway.default_configuration['number_format']
    @number_format_regx =  Regexp.new(number_format)
  else
    raise SplatError.new("default:  number_format not define in splat.yml") unless number_format
  end

end

Instance Attribute Details

#number_format_regxObject (readonly)

Returns the value of attribute number_format_regx.



16
17
18
# File 'lib/splat.rb', line 16

def number_format_regx
  @number_format_regx
end

Instance Method Details

#send_bulk_sms(message, numbers = [], options = {}) ⇒ Object



37
38
39
40
# File 'lib/splat.rb', line 37

def send_bulk_sms(message, numbers = [], options = {})
   options[:response] = validate_phones(numbers)    
   get_vender_object(vendor).send_bulk_sms(message, numbers - options[:response].invalid_phone_numbers, options)
end

#send_bulk_sms_with_insertion(message, insertions = {}, options = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/splat.rb', line 42

def send_bulk_sms_with_insertion(message, insertions ={}, options = {})
   options[:response] = validate_phones(insertions.keys)    

   insertions.delete_if do |key, value|
     !options[:response].phone_numbers[key].nil?
   end

   get_vender_object(vendor).send_bulk_sms_with_insertion(message, insertions, options)
end

#send_sms(message, number, options = {}) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/splat.rb', line 29

def send_sms(message, number, options = {})
  options[:response] = Response.new
  unless validate_phone?(number)
    return options[:response].invalid_phone_format(number)
  end
  get_vender_object(vendor).send_sms(message, number, options) 
end

#vendorObject

Raises:



52
53
54
55
# File 'lib/splat.rb', line 52

def vendor
  raise SplatError.new('Vendor is nil.Set vendor name.') unless @vendor
  @vendor
end