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
29
# File 'lib/voodoo_sms.rb', line 26

def get_credit
  response = make_request('getCredit')
  fetch_from_response(response, 'credit')
end

#get_delivery_status(reference_id) ⇒ Object



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

def get_delivery_status(reference_id)
  merge_params(reference_id: reference_id)
  response = make_request('getDlrStatus')
  fetch_from_response(response, 'delivery_status')
end

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



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

def get_sms(from, to, keyword = '')
  merge_params(from: format_date(from), to: format_date(to), keyword: keyword)
  response = make_request('getSMS')['messages'] # unfortunately we can't use fetch_from_response here
  if response.is_a?(Array)                      # response doesn't have messages key if no new messages
    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



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

def send_sms(originator, destination, message)
  merge_params(orig: originator, dest: destination, msg: message, validity: 1)
  response = make_request('sendSMS').parsed_response
  fetch_from_response(response, 'reference_id')
end