Skip to content

Instantly share code, notes, and snippets.

@eraserewind
Created January 12, 2012 14:43
Show Gist options
  • Save eraserewind/1600910 to your computer and use it in GitHub Desktop.
Save eraserewind/1600910 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
# Send an SMS using OVH SOAPI. Requires an OVH account.
#
# Best used when installed somewhere in your PATH.
#
# TODO: Read from STDIN. Send multiple SMS if the input > 160 chars.
#
# README: Create ~/.sms.yml like this:
# credentials:
# user: "xxx-OVH"
# pass: "xxx"
# domain: "sms-xxxx-1"
# from: "+xxxxxx"
# addresses:
# alias1: "+xxxx"
# alias2: "+xxxx"
require 'rubygems'
require 'soap/wsdlDriver'
require 'yaml'
@config = YAML.load_file(File.expand_path('~/.sms.yml'))
raise "Not Configured!" unless @config['credentials']
def halp
puts "Usage: sms [to (number or alias)] [text]"
exit 1
end
to_id = ARGV.shift
to = @config['addresses'][to_id] || to_id
text = ARGV.join(' ')
halp() if !to
halp() if !text && text.empty?
puts "Sending SMS to: #{to}, Text: #{text}"
raise "TL;DR (Text is longer than 160 chars)" if text.length > 160
wsdl = 'https://www.ovh.com/soapi/soapi-re-1.29.wsdl'
soapi = SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
session = soapi.login(@config['credentials']['user'], @config['credentials']['pass'], 'fr', false)
result = soapi.telephonySmsSend(session, @config['credentials']['domain'], @config['credentials']['from'], to, text, 2880, 0, 0, 3, 2, '')
soapi.logout(session)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment