Skip to content

Instantly share code, notes, and snippets.

# 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
require 'active_resource'
class TextMessage < ActiveResource::Base
self.site = "http://api.esendex.com/"
self.user = "XXX@ultraspeed.com"
self.password = "XXX"
ESENDEX_API_REFERENCE = "XXX"
class << self
if registration?
if supports_automatic_registrations?
if contact_information_valid?
if registration_complete?
toggle!(:processed)
else
return false
end
else
...
raise ArgumentError, "Registration type is not 'registration'" unless registration?
raise ArgumentError, "TLD does not support automatic registrations" unless supports_automatic_registrations?
raise ArgumentError, "Contact information is invalid" unless contact_information_valid?
if registration_complete?
toggle!(:processed)
else
return false
end
raise ArgumentError, "Registration type is not 'registration'" unless registration?
raise ArgumentError, "TLD does not support automatic registrations" unless supports_automatic_registrations?
raise ArgumentError, "Contact information is invalid" unless contact_information_valid?
if registration_complete?
toggle!(:processed)
else
return false
end
# Changes the default date and time string formatters in Rails. See http://j.mp/2nZ022 and http://j.mp/1BRFSf for more info
#
# >> Time.now.to_s
# => "3rd Nov, 2009 10:54 PM GMT"
# >> Date.today.to_s
# => "3rd Nov, 2009"
Time::DATE_FORMATS[:default] = lambda { |time| time.strftime("#{time.day.ordinalize} %b, %Y %I:%M %p %Z") }
Date::DATE_FORMATS[:default] = lambda { |date| date.strftime("#{date.day.ordinalize} %b, %Y") }
@driver = SOAP::WSDLDriverFactory.new("http://www.webservice.com/services/order.wsdl").create_rpc_driver
@driver.GSDVOrder(:RequestID => 1)
@driver.return_response_as_xml = true
response = @driver.GSDVOrder(:RequestID => 1)
parsed_response = Hpricot::XML(response)
ActionController::Base.asset_host = Proc.new do |source|
# This will give you asset1-asset8.example.com
"http://assets#{rand(8) + 1}.example.com"
end