From 4c1b777458b90de5d7c01cf7d14ef0be2fdcc4e6 Mon Sep 17 00:00:00 2001 From: Brendan G. Lim Date: Wed, 18 Feb 2009 20:12:33 -0500 Subject: Adding in some view helpers for mobile carrier select boxes and updating README --- README.rdoc | 20 +++++++++++++++++--- init.rb | 4 +++- lib/sms_fu.rb | 2 +- lib/sms_fu_helper.rb | 15 +++++++++++++++ lib/sms_notifier.rb | 1 - templates/sms_fu.yml | 1 + 6 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 lib/sms_fu_helper.rb diff --git a/README.rdoc b/README.rdoc index 08680cd..5355cbc 100644 --- a/README.rdoc +++ b/README.rdoc @@ -7,9 +7,10 @@ of the supported carriers. == Supported Carriers (US & International): Alltel, Ameritech, AT&T, BellSouth Mobility, BlueSkyFrog, Boost Mobile, Cellular South, -E-Plus, Fido, kajeet, Metro PCS, Powertel, PSC Wireless, Qwest, Southern Link, Sprint, -Suncom, T-Mobile (US/UK/Germany), Telefonica, Virgin Mobile, Verizon Wireless, -Vodafone (UK,Italy,Japan, Spain) +Du, E-Plus, Etisalat, Fido, kajeet, Mobinil, Mobitel, Movistar, Metro PCS, Powertel, +PSC Wireless, Qwest, Rogers, Southern Link, Sprint, Suncom, T-Mobile (US/UK/Germany), +Telefonica, Virgin Mobile, Verizon Wireless, Vodafone (UK, Egypt, Italy, Japan, Spain), +and many more ... == Setup Instructions @@ -60,5 +61,18 @@ That's it! Now you're good to go. get_sms_address("5558675309","at&t") # => "5558675309@txt.att.net" +== View Helpers + +* Retrieve a collection of all carriers + + <%= carrier_collection %> + +* Display a select box with mobile carriers + + <%= carrier_select %> + +* Display a custom select box with mobile carriers + + <%= carrier_select('user[carrier_name]', "Please choose a carrier") %> Copyright (c) 2008 Brendan G. Lim, Intridea, Inc., released under the MIT license diff --git a/init.rb b/init.rb index c6df249..b6cf0d9 100644 --- a/init.rb +++ b/init.rb @@ -1,3 +1,5 @@ require "action_mailer" require File.dirname(__FILE__) + '/lib/sms_fu' -ActionView::Base.send(:include, SMSFu) \ No newline at end of file +require File.dirname(__FILE__) + '/lib/sms_fu_helper.rb' +ActionView::Base.send(:include, SMSFu) +ActionView::Base.send(:include, SMSFuHelper) \ No newline at end of file diff --git a/lib/sms_fu.rb b/lib/sms_fu.rb index 2aa2dea..6e22079 100644 --- a/lib/sms_fu.rb +++ b/lib/sms_fu.rb @@ -58,7 +58,7 @@ module SMSFu end def is_valid?(number) - return (number.length >= 10 && number[/^.\d+$/]) ? true : false + number.length >= 10 && number[/^.\d+$/] end def determine_sms_email(phone_number, carrier) diff --git a/lib/sms_fu_helper.rb b/lib/sms_fu_helper.rb new file mode 100644 index 0000000..fdc67c1 --- /dev/null +++ b/lib/sms_fu_helper.rb @@ -0,0 +1,15 @@ +module SMSFuHelper + # Returns a collection of carriers to be used in your own select tag + # e.g., <%= f.select :mobile_carrier, carrier_collection %> + def carrier_collection + SMSFu.carriers.sort.collect{ |carrier| [carrier[0].titleize, carrier[0]] } + end + + # Returns a formatted select box filled with carriers + # e.g., <%= carrier_select %> + # - name => name of the method in which you want to store the carrier name + # - phrase => default selected blank option in select box + def carrier_select(name = :mobile_carrier, phrase = "Select a Carrier") + select_tag name, options_for_select([phrase,nil]+carrier_collection, phrase) + end +end \ No newline at end of file diff --git a/lib/sms_notifier.rb b/lib/sms_notifier.rb index 5d960c6..644408a 100644 --- a/lib/sms_notifier.rb +++ b/lib/sms_notifier.rb @@ -27,7 +27,6 @@ class SmsNotifier < ActionMailer::Base content_type "text/plain" recipients recipient from sender_email - body['message'] = message end diff --git a/templates/sms_fu.yml b/templates/sms_fu.yml index bb8ab42..9a3b1d1 100644 --- a/templates/sms_fu.yml +++ b/templates/sms_fu.yml @@ -28,6 +28,7 @@ carriers: etisalat-arab-emirates: @email2sms.ae fido-canada: @fido.ca mobinil-egypt: @mobinil.net + mobitel: @sms.mobitel.lk movistar-spain: @correo.movistar.net o2-germany: @o2online.de o2-uk: @mmail.co.uk -- cgit v1.2.3