Class: VoodooSMS

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/voodoo_sms.rb

Overview

TODO: RDoc

Defined Under Namespace

Modules: Error

Instance Method Summary collapse

Constructor Details

#initialize(username, password) ⇒ VoodooSMS

Returns a new instance of VoodooSMS.



22
23
24
# File 'lib/voodoo_sms.rb', line 22

def initialize(username, password)
  @params = { query: { uid: username, pass: password } }
end

Instance Method Details

#get_creditObject



26
27
28
# File 'lib/voodoo_sms.rb', line 26

def get_credit
  make_request('getCredit')['credit']
end

#get_sms(from, to, keyword = '') ⇒ Object



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

def get_sms(from, to, keyword = '')
  merge_params(from: format_date(from), to: format_date(to), keyword: keyword)
  response = make_request('getSMS')['messages']
  if response.is_a?(Array)
    response.map { |r| OpenStruct.new(from: r['Originator'],
      timestamp: DateTime.parse(r['TimeStamp']),
      message: r['Message']) }
  else
    []
  end
end

#send_sms(originator, destination, message) ⇒ Object



30
31
32
33
# File 'lib/voodoo_sms.rb', line 30

def send_sms(originator, destination, message)
  merge_params(orig: originator, dest: destination, msg: message, validity: 1)
  make_request('sendSMS')['resultText'].to_s.include? 'OK'
end