Using text magic

Add gem to your Gemfile

[code language=”ruby”]
gem ‘textmagic’
[/code]
[code language=”ruby”]
class MessagesController < ApplicationController
def create
require ‘textmagic’
@phone_number = message_params[:phone_number]
@message = message_params[:message]
@gateway = TextMagic::API.new(‘username’, ‘api_password’)
@gateway.send "hello how are you ?", "9632587412"
end
private
def message_params
params.require(:message).permit(:phone_number, :message)
end
end
[/code]

Using sms-easy

Add gem to your Gemfile

[code language=”ruby”]
gem ‘sms-easy’
[/code]
[code language=”ruby”]
Usage
###Basic Rails Configuration
# Override the default "from" address with config/initializers/sms-easy.rb
SMSEasy::Client.config[‘from_address’] = "[email protected]"
# Or, you can completely copy sms-easy.yml to your app (http://github.com/preston/sms-easy/blob/master/templates/sms-easy.yml), change it to your liking, and override the default configuration with:
SMSEasy::Client.configure(YAML.load(…))
# Your apps existing ActionMailer configuration will be used. 🙂
# Create the client
easy = SMSEasy::Client.new
# Deliver a simple message.
easy.deliver("5551234567", "verizon", "Hey!")
Basic Ruby (non-Rails) Use Case (non-Rails)
# SMSEasy will use actionmailer’s default configuration, which can be overriden if needed:
ActionMailer::Base.smtp_settings = {
:address => ‘smtp.example.com’,
# :port => ‘587’,
:domain => ‘example.com’,
:enable_starttls_auto => false
}
# Configure SMSEasy’s "from" address:
SMSEasy::Client.config[‘from_address’] = "[email protected]"
# Optionally override the carries list using your own data file.
# SMSEasy::Client.configure(YAML.load(…))
# Create the client
easy = SMSEasy::Client.new
# Deliver a simple message.
easy.deliver("5551234567", "verizon", "Hey!")
# To set a custom from e-mail per SMS message:
easy.deliver("5551234567", "verizon", "Sup.", :from => "[email protected]")
# You can set the maximum length of the SMS message, which is not set by default. Most phones can only accept 128 characters. To do this just specify the limit option.
easy.deliver("5551234567", "verizon", "Boo-yaa!", :limit => 128)
# You can retrieve just the formatted address to use in your own mailer.
SMSEasy::Client.sms_address("5558675309","at&t") # => "[email protected]"
[/code]

using sms_fu gem

[code language=”ruby”]
gem ‘sms_fu’
[/code]
[code language=”ruby”]
Numbers and Carriers
You have to send in the phone number, without any non-numeric characters. The phone numbers must be 10 digits in length.
The two required parameters are the phone number and the phone carrier.
Here are some of the default carrier values:
Alltel Wireless => "alltel"
AT&T/Cingular => "at&t"
Boost Mobile => "boost"
Sprint Wireless => "sprint"
T-Mobile US => "t-mobile"
T-Mobile UK => "t-mobile-uk"
Virgin Mobile => "virgin"
Verizon Wireless => "verizon"
Vodafone Tokyo => "vodafone-jp-tokyo"
Check sms_fu.yml for a complete list of supported carriers, including international carriers as well.
Configuration and Usage
SMS Fu relies on either ActionMailer or Pony for delivery. You can now specify which you’d like to use for delivery.
You can use your ActionMailer settings by just specifying the :delivery option as :action_mailer.
If you would like to use Pony, you can configure it to use :sendmail or :smtp via Pony. Set the :delivery option to :pony and then make sure to include :pony_config as well
# ActionMailer delivery
sms_fu = SMSFu::Client.configure(:delivery => :action_mailer)
# Pony delivery via Sendmail
sms_fu = SMSFu::Client.configure(:delivery => :pony, :pony_config => { :via => :sendmail })
# Pony delivery via SMTP
PONY_CONFIG = {
:via => :smtp,
:via_options => {
:address => ‘smtp.gmail.com’,
:port => ‘587’,
:user_name => ‘username’,
:password => ‘password’,
:authentication => :plain,
:enable_starttls_auto => true,
:domain => "localhost.localdomain"
}}
sms_fu = SMSFu::Client.configure(:delivery => :pony, :pony_config => PONY_CONFIG)
You can view more pony ‘via_options’ at github.com/benprew/pony
Basic SMS delivery
sms_fu.deliver("5558675309","at&t","message")
If you want to set a custom from e-mail per SMS message, you can do so by doing the following.
sms_fu.deliver("5558675309","at&t","message", :from => "[email protected]")
You can set the maximum length of the SMS message, which is not set by default. Most phones can only accept 128 characters. To do this just specify the limit option.
sms_fu.deliver("5558675309","at&t","message", :limit => 128)
You can retrieve just the formatted address to use in your own mailer.
SMSFu.sms_address("5558675309","at&t") # => "[email protected]"
[/code]

Using twilio-ruby

Add to gemfile
[code language=”ruby”]
gem ‘twilio-ruby’
[/code]
[code language=”ruby”]
class SendTextController < ApplicationController
def send_text_message
number_to_send_to = params[:number_to_send_to]
twilio_sid = "jkkjkk"
twilio_token = "hgfhgfghfh"
twilio_phone_number = "963258746"
@twilio_client = Twilio::REST::Client.new twilio_sid, twilio_token
@twilio_client.account.sms.messages.create(
:from => "+1#{twilio_phone_number}",
:to => number_to_send_to,
:body => "This is a message"
)
end
end
[/code]