Class: Smshelper::Api::Mycoolsms

Inherits:
Base
  • Object
show all
Defined in:
lib/smshelper/api/mycoolsms.rb

Instance Attribute Summary

Attributes inherited from Base

#extra_options, #sent_message_ids, #sent_message_statuses

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Mycoolsms

Returns a new instance of Mycoolsms.



6
7
8
9
10
# File 'lib/smshelper/api/mycoolsms.rb', line 6

def initialize(*args)
  config = args.shift
  add_query_options! :username => config.mycoolsms[:uname], :password => config.mycoolsms[:passwd]
  super
end

Instance Method Details

#get_balanceObject



23
24
25
# File 'lib/smshelper/api/mycoolsms.rb', line 23

def get_balance
  {'EUR' => JSON.parse(post 'api-socket.php', :extra_query => {:function => 'getBalance'})['balance']}
end

#get_callback_response(args = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/smshelper/api/mycoolsms.rb', line 35

def get_callback_response(args = {})
  data = JSON.parse args[:request_body]
  DeliveryReport.new(
                     :message_id => data['smsid'],
                     :timestamp => Time.now,
                     :delivered => ((data['status'] == 'SMS_STATUS_DELIVERED') ? true : false),
                     :original_params => args
                     )
end

#get_statusObject



27
28
29
# File 'lib/smshelper/api/mycoolsms.rb', line 27

def get_status
  raise NotImplementedError, "Sms status checks unsupported by #{self.class.name}"
end

#hlr_lookup(number) ⇒ Object



31
32
33
# File 'lib/smshelper/api/mycoolsms.rb', line 31

def hlr_lookup(number)
  JSON.parse(post 'api-socket.php', :extra_query => {:function => 'doHlrLookup', :number => number})
end

#send_message(message) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/smshelper/api/mycoolsms.rb', line 12

def send_message(message)
  options = {
    :number => message.recipient,
    :message => message.text,
    :senderid => message.sender,
    :function => 'sendSms'}
  options = options.merge(@extra_options) unless @extra_options.nil?
  resp = JSON.parse(post 'api-socket.php', :extra_query => options)
  process_response_code(resp) ? (@sent_message_ids << resp['smsid']; resp['smsid']) : (raise ErrorDuringSend, resp)
end