class Africastalking::Message

Public Class Methods

deliver(recipients, message) click to toggle source
# File lib/africastalking/message.rb, line 9
def deliver(recipients, message)
  post('/version1/messaging', build_message(recipients, message))
end
enqueue_message(data) click to toggle source
# File lib/africastalking/message.rb, line 17
def enqueue_message(data)
  post('/version1/messaging', build_enqueued_messages(data))
end
fetch(last_received_id=0) click to toggle source
# File lib/africastalking/message.rb, line 5
def fetch(last_received_id=0)
  get("/version1/messaging?username=#{Africastalking.config.username}&lastReceivedId=#{last_received_id}")
end
send_premium(data) click to toggle source
# File lib/africastalking/message.rb, line 13
def send_premium(data)
  post('/version1/messaging', build_premium_messages(data))
end

Private Class Methods

build_enqueued_messages(data) click to toggle source
# File lib/africastalking/message.rb, line 46
def build_enqueued_messages(data)
  build_message(
    prepare_recipients(data.fetch(:recipients, [])), data.fetch(:message, '')
  ).merge(enqueue_params(data))
end
build_message(recipients, message) click to toggle source
# File lib/africastalking/message.rb, line 23
def build_message(recipients, message)
  {username: Africastalking.config.username, message: message, to: prepare_recipients(recipients)}
end
build_premium_messages(data) click to toggle source
# File lib/africastalking/message.rb, line 52
def build_premium_messages(data)
  build_message(
    prepare_recipients(data.fetch(:recipients, [])), data.fetch(:message, '')
  ).merge(premium_params(data))
end
enqueue_params(data) click to toggle source
# File lib/africastalking/message.rb, line 34
def enqueue_params(data)
  {
    bulkSMSMode: data.fetch(:bulkSMSMode, 1), sender: data.fetch(:sender, nil), enqueue: data.fetch(:enqueue, 1)
  }
end
premium_params(data) click to toggle source
# File lib/africastalking/message.rb, line 27
def premium_params(data)
  {
    retryDurationInHours: data.fetch(:retryDurationInHours, 1),
    enqueue: data.fetch(:enqueue, 0), linkId: data.fetch(:linkId, nil), keyword: data.fetch(:keyword, nil)
  }
end
prepare_recipients(recipients) click to toggle source
# File lib/africastalking/message.rb, line 40
def prepare_recipients(recipients)
  msg_recipients = Array.new
  recipients.split(',').each {|recipient| msg_recipients << recipient.strip}
  msg_recipients.join(', ')
end