Skip to content

Instantly share code, notes, and snippets.

@mikker
Created April 15, 2009 13:00
Show Gist options
  • Save mikker/95752 to your computer and use it in GitHub Desktop.
Save mikker/95752 to your computer and use it in GitHub Desktop.
Ruby example for mobilemarketing.dk
class MessagesController < ApplicationController
# Send sms's
def send_sms
sms = {
:userid => 1516,
:username => "mikkelm",
:password => "kodeord123",
:keyword => "mmtest ruby", # your keyword (not subkeyword)
:mobile => "4520202020", # mobile number with country prefix
:message => "Text message from johnco.",
:from => "John Doe", # name or number of sender (up to 11 chars)
:tsp => "TDC", # only required if price is not 0.
:price => 0, # price in øre (1kr = 100øre)
:id => 14 # ID number for identifing the message when the status report returns.
}
# make the POST request
result = Net::HTTP.post_form URI.parse("http://mmgw2.mobilemarketing.dk/modules/api.cmod.php"), sms
# printing out the answer from the MMGW
render :text => "#{result.body}"
end
# Receive status messages on sent messages and log them
def status
unless request.remote_ip == "194.150.115.118" # Only allowing the MMGW to access.
redirect_to "/"
else
status = params[:status] # Status message: SENT/WAITING/FAILED
id = params[:id] # Message identifier (prevously sent with the message)
keyword = params[:keyword]
# Format the log message
log = "Status: #{status} - Msg id: #{id} - Keyword: #{keyword}\n\r";
# Write to the log file in log/sms.log
File.open(File.join(RAILS_ROOT, "log", "sms.log"), "a") {|f| f.write(log) }
render :text => "#{log}"
end
end
# Basic receive action
def receive
unless request.remote_ip == "194.150.115.118" # Only allowing the MMGW to access.
redirect_to "/"
else
mobile = params[:mobile] # Mobile number of sender
tsp = params[:tsp] # Telephone company of sender
keyword = params[:keyword] #Keyword
message = params[:message] # Message (including keyword)
# Format the log message
log = "From: #{mobile} - Tsp: #{tsp} - Keyword: #{keyword} - Message: #{message}\n\r";
# Write to the log file in log/sms.log or do whatever with it
File.open(File.join(RAILS_ROOT, "log", "inbox.log"), "a") {|f| f.write(log) }
render :text => "#{log}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment