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.



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

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

Instance Method Details

#get_creditObject



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

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

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



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

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



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

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