Created
June 1, 2009 19:01
-
-
Save ultraspeed/121654 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Method to send a message using Esendex's new RESTful | |
# API. | |
# | |
# Most people would think to use Builder to build | |
# the XML for this request. However, Builder seems to | |
# escape the XML in a way that Esendex doesn't under- | |
# stand. I will be asking them more about this | |
# later! | |
# | |
def send_using_esendex | |
xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" | |
xml += "<message><to>#{MOBILE_NUMBER}</to>" | |
xml += "<body>#{MESSAGE}</body>" | |
xml += "<validity>0</validity></message>" | |
uri = URI.parse(ESENDEX_URL) | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.start do | |
req = Net::HTTP::Post.new(uri.path) | |
req.basic_auth(ESENDEX_USERNAME, ESENDEX_PASSWORD) | |
req.content_type = "text/xml" | |
req.body = xml | |
@response = http.request(req) | |
# Parse the XML response we should receive | |
response_xml = REXML::Document.new(@response.body) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment