Class: MobilySMS

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

Direct Known Subclasses

MobilyFormattedSMS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(auth, numbers = [], sender = '', msg = '', delete_key = nil, msg_id = nil, domain_name = nil, application_type = '70') ⇒ MobilySMS

Returns a new instance of MobilySMS.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/mobily/mobily_sms.rb', line 11

def initialize(auth, numbers=[], sender='', msg='', delete_key=nil, msg_id=nil,
               domain_name=nil, application_type='70')
  @auth = auth
  @numbers = numbers
  @sender = sender
  @msg = msg
  @date_send = 0
  @time_send = 0
  @delete_key = delete_key
  @msg_id = msg_id
  @domain_name = domain_name
  @application_type = application_type
  @api_method_name = 'msgSend'
  @request_handler = MobilyApiJsonRequestHandler.new(@auth)
end

Instance Attribute Details

#authObject

Returns the value of attribute auth.



8
9
10
# File 'lib/mobily/mobily_sms.rb', line 8

def auth
  @auth
end

#date_sendObject (readonly)

Returns the value of attribute date_send.



7
8
9
# File 'lib/mobily/mobily_sms.rb', line 7

def date_send
  @date_send
end

#delete_keyObject

Returns the value of attribute delete_key.



8
9
10
# File 'lib/mobily/mobily_sms.rb', line 8

def delete_key
  @delete_key
end

#domain_nameObject

Returns the value of attribute domain_name.



8
9
10
# File 'lib/mobily/mobily_sms.rb', line 8

def domain_name
  @domain_name
end

#msgObject

Returns the value of attribute msg.



8
9
10
# File 'lib/mobily/mobily_sms.rb', line 8

def msg
  @msg
end

#msg_idObject

Returns the value of attribute msg_id.



8
9
10
# File 'lib/mobily/mobily_sms.rb', line 8

def msg_id
  @msg_id
end

#request_handlerObject

Returns the value of attribute request_handler.



8
9
10
# File 'lib/mobily/mobily_sms.rb', line 8

def request_handler
  @request_handler
end

#senderObject

Returns the value of attribute sender.



8
9
10
# File 'lib/mobily/mobily_sms.rb', line 8

def sender
  @sender
end

#time_sendObject (readonly)

Returns the value of attribute time_send.



7
8
9
# File 'lib/mobily/mobily_sms.rb', line 7

def time_send
  @time_send
end

Class Method Details

.can_send?Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/mobily/mobily_sms.rb', line 35

def self.can_send?

  # send status api method wrapper, doesn't need authentication
  request_handler = MobilyApiJsonRequestHandler.new
  request_handler.set_api_method('sendStatus')
  begin
    response = request_handler.handle
  rescue MobilyApiError
    false
  else
    response.get('result') == '1'
  end
end

Instance Method Details

#add_number(number) ⇒ Object



27
28
29
# File 'lib/mobily/mobily_sms.rb', line 27

def add_number(number)
  @numbers << number
end

#deleteObject



55
56
57
58
59
60
61
62
# File 'lib/mobily/mobily_sms.rb', line 55

def delete
  # send sms api method wrapper
  return if @delete_key.nil?
  request_handler = MobilyApiJsonRequestHandler.new(@auth)
  request_handler.set_api_method('deleteMsg')
  request_handler.add_parameter('deleteKey', @delete_key)
  request_handler.handle
end

#get_numbers_as_csvObject



31
32
33
# File 'lib/mobily/mobily_sms.rb', line 31

def get_numbers_as_csv
  @numbers.join(',')
end

#schedule_to_send_on(day, month, year, hour = 0, min = 0, sec = 0) ⇒ Object



64
65
66
67
# File 'lib/mobily/mobily_sms.rb', line 64

def schedule_to_send_on(day, month, year, hour=0, min=0, sec=0)
  @time_send = '%02d:%02d:%02d' % [hour, min, sec]
  @date_send = '%02d/%02d/%04d' % [month, day, year]
end

#sendObject



49
50
51
52
53
# File 'lib/mobily/mobily_sms.rb', line 49

def send
  # send sms api method wrapper
  prepare_to_send
  @request_handler.handle
end