Module: SmsOnRails::ModelSupport::Draft::InstanceMethods
- Defined in:
- lib/sms_on_rails/model_support/draft.rb
Instance Method Summary collapse
-
#actual_message ⇒ Object
if there is only one outbound message, return the actual (substituted) message.
-
#complete_message ⇒ Object
The complete message with header and footer.
-
#create_outbounds_for_phone_numbers(phone_numbers, options = {}) ⇒ Object
Create Outbound Instances based on
phone_numbers
andoptions
Refer to SmsOnRails::ModelSupport::Outbound.create_outbounds_from_phone. -
#default_headers_and_footers ⇒ Object
default the headers and footers.
-
#deliver(options = {}) ⇒ Object
Deliver all the unsent outbound messages
error
- set this option to add an error message to the draft object. -
#deliver!(options = {}) ⇒ Object
Deliver all outbound messages safely using optimisitic locking Progates any exception thrown.
-
#initialize(args = {}) ⇒ Object
:nodoc:.
- #max_message_length ⇒ Object
-
#message_length ⇒ Object
The length of the message This does not take into consideration substituted params TODO: adjust max length for substituted params.
- #save_and_deliver(options = {}) ⇒ Object
- #save_and_deliver!(options = {}) ⇒ Object
Instance Method Details
#actual_message ⇒ Object
if there is only one outbound message, return the actual (substituted) message. Otherwise, returns the draft message with substituted strings if any
164 165 166 |
# File 'lib/sms_on_rails/model_support/draft.rb', line 164 def self.outbounds.length == 1 ? outbounds.first. : end |
#complete_message ⇒ Object
The complete message with header and footer
118 119 120 121 122 123 124 |
# File 'lib/sms_on_rails/model_support/draft.rb', line 118 def = "" << "#{header}\n" unless header.blank? << << "\n#{}" unless .blank? end |
#create_outbounds_for_phone_numbers(phone_numbers, options = {}) ⇒ Object
Create Outbound Instances based on phone_numbers
and options
Refer to SmsOnRails::ModelSupport::Outbound.create_outbounds_from_phone
158 159 160 |
# File 'lib/sms_on_rails/model_support/draft.rb', line 158 def create_outbounds_for_phone_numbers(phone_numbers, ={}) self.outbounds = self.class.reflections[:outbounds].klass.create_outbounds_for_phone_numbers(phone_numbers, ) end |
#default_headers_and_footers ⇒ Object
default the headers and footers
112 113 114 115 |
# File 'lib/sms_on_rails/model_support/draft.rb', line 112 def self.header ||= self.class.default_header self. ||= self.class. end |
#deliver(options = {}) ⇒ Object
Deliver all the unsent outbound messages error
- set this option to add an error message to the draft object
This is locked and safe for individual messages but the draft object itself is not locked down, so it can be processed by multiple threads
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/sms_on_rails/model_support/draft.rb', line 133 def deliver(={}) ||={} deliver_method = .delete(:bang) ? :deliver! : :deliver = outbounds.inject([]) do |, o| next() if o.delivered? unless o.send(deliver_method, ) << "Message could not be delivered to: #{o.phone_number.human_display}" end end self.update_attribute(:status, .blank? ? 'PROCESSED' : 'FAILED') .each { |msg| errors.add_to_base(msg) } .blank? end |
#deliver!(options = {}) ⇒ Object
Deliver all outbound messages safely using optimisitic locking Progates any exception thrown
152 153 154 |
# File 'lib/sms_on_rails/model_support/draft.rb', line 152 def deliver!(={}) deliver((||{}).merge(:bang => true)) end |
#initialize(args = {}) ⇒ Object
:nodoc:
92 93 94 95 |
# File 'lib/sms_on_rails/model_support/draft.rb', line 92 def initialize(args={})#:nodoc: super args end |
#max_message_length ⇒ Object
109 |
# File 'lib/sms_on_rails/model_support/draft.rb', line 109 def ; self.class.; end |
#message_length ⇒ Object
The length of the message This does not take into consideration substituted params TODO: adjust max length for substituted params
108 |
# File 'lib/sms_on_rails/model_support/draft.rb', line 108 def ; .length; end |
#save_and_deliver(options = {}) ⇒ Object
97 98 99 |
# File 'lib/sms_on_rails/model_support/draft.rb', line 97 def save_and_deliver(={}) save and deliver() end |
#save_and_deliver!(options = {}) ⇒ Object
101 102 103 |
# File 'lib/sms_on_rails/model_support/draft.rb', line 101 def save_and_deliver!(={}) save! and deliver!() end |