Module: SmsOnRails::ModelSupport::Outbound::ClassMethods
- Defined in:
- lib/sms_on_rails/model_support/outbound.rb
Instance Method Summary collapse
- #create_outbounds_for_phone_numbers(phone_numbers, options = {}) ⇒ Object
- #create_sms(message, number, options = {}) ⇒ Object
- #create_sms!(message, number, options = {}) ⇒ Object
-
#create_with_phone(attributes, draft = nil) ⇒ Object
Create the object find the existing phone if already stored.
- #send_immediately(message, phone_number, options = {}) ⇒ Object
- #send_immediately!(message, phone_number, options = {}) ⇒ Object
Instance Method Details
#create_outbounds_for_phone_numbers(phone_numbers, options = {}) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/sms_on_rails/model_support/outbound.rb', line 52 def create_outbounds_for_phone_numbers(phone_numbers, ={}) smses = reflections[:phone_number].klass.find_and_create_all_by_numbers(phone_numbers, ([:find]||{}).reverse_merge(:create => :new)).inject([]) do |smses, phone| phone.attributes = [:phone_number] if [:phone_number] phone.carrier = [:carrier] if [:carrier] sms = self.new([:sms]||{}) sms.phone_number = phone sms.service_provider = [:service_provider] if [:service_provider] smses << sms smses end smses end |
#create_sms(message, number, options = {}) ⇒ Object
42 43 44 45 |
# File 'lib/sms_on_rails/model_support/outbound.rb', line 42 def create_sms(, number, ={}) draft = reflections[:draft].klass.create_sms(, number, .reverse_merge(:keep_failed_outbounds => true)) number.is_a?(Array) ? draft.outbounds : draft.outbounds.first end |
#create_sms!(message, number, options = {}) ⇒ Object
47 48 49 50 |
# File 'lib/sms_on_rails/model_support/outbound.rb', line 47 def create_sms!(, number, ={}) draft = reflections[:draft].klass.create_sms!(, number, ) number.is_a?(Array) ? draft.outbounds : draft.outbounds.first end |
#create_with_phone(attributes, draft = nil) ⇒ Object
Create the object find the existing phone if already stored
66 67 68 69 70 71 72 73 74 |
# File 'lib/sms_on_rails/model_support/outbound.rb', line 66 def create_with_phone(attributes, draft=nil) outbound = new(attributes) transaction { outbound.assign_existing_phone outbound.draft = draft outbound.save } outbound end |
#send_immediately(message, phone_number, options = {}) ⇒ Object
34 35 36 |
# File 'lib/sms_on_rails/model_support/outbound.rb', line 34 def send_immediately(, phone_number, ={}) create_sms(, phone_number, .merge(:send_immediately => true)) end |
#send_immediately!(message, phone_number, options = {}) ⇒ Object
38 39 40 |
# File 'lib/sms_on_rails/model_support/outbound.rb', line 38 def send_immediately!(, phone_number, ={}) create_sms!(, phone_number, .merge(:send_immediately => true)) end |