Class: Clockwork::SMS
- Inherits:
-
Object
- Object
- Clockwork::SMS
- Defined in:
- lib/clockwork/sms.rb,
lib/clockwork/sms/response.rb
Overview
Create an instance of Clockwork::SMS for each SMS message you want to send.
Defined Under Namespace
Classes: Response
Instance Attribute Summary collapse
-
#api ⇒ Clockwork::API
An instance of Clockwork::API.
-
#client_id ⇒ string
An unique message ID specified by the connecting application, for example your database record ID.
-
#content ⇒ string
REQUIRED: The message content to send.
-
#from ⇒ string
The from address displayed on a phone when the SMS is received.
-
#invalid_char_action ⇒ symbol
What to do with any invalid characters in the message content.
-
#long ⇒ boolean
Set to
true
to enable long SMS. -
#to ⇒ string
REQUIRED: The phone number to send the SMS to in international number format (without a leading + or international dialling prefix such as 00, e.g. 441234567890).
-
#truncate ⇒ boolean
Set to
true
to trim the message content to the maximum length if it is too long. -
#wrapper_id ⇒ Object
writeonly
Sets the attribute wrapper_id.
Instance Method Summary collapse
-
#deliver ⇒ Clockwork::SMS::Response
Deliver the SMS message.
-
#initialize(options = {}) ⇒ SMS
constructor
Create a new SMS message.
-
#translated_attributes ⇒ hash
Translate standard variable names to those needed to make an XML request.
Constructor Details
#initialize(options = {}) ⇒ SMS
Create a new SMS message.
59 60 61 62 63 |
# File 'lib/clockwork/sms.rb', line 59 def initialize = {} .each { |k, v| instance_variable_set "@#{k}", v } if .kind_of?(Hash) @invalid_char_action = [nil, :error, :remove, :replace].index(@invalid_char_action) if @invalid_char_action @truncate = @truncate ? true : false unless @truncate.nil? end |
Instance Attribute Details
#api ⇒ Clockwork::API
An instance of Clockwork::API.
10 11 12 |
# File 'lib/clockwork/sms.rb', line 10 def api @api end |
#client_id ⇒ string
An unique message ID specified by the connecting application, for example your database record ID. Maximum length: 50 characters.
20 21 22 |
# File 'lib/clockwork/sms.rb', line 20 def client_id @client_id end |
#content ⇒ string
REQUIRED: The message content to send.
15 16 17 |
# File 'lib/clockwork/sms.rb', line 15 def content @content end |
#from ⇒ string
If this option is set it overrides the global option specified in Clockwork::API for this SMS, if neither option is set your account default will be used.
The from address displayed on a phone when the SMS is received. This can be either a 12 digit number or 11 characters long.
26 27 28 |
# File 'lib/clockwork/sms.rb', line 26 def from @from end |
#invalid_char_action ⇒ symbol
If this option is set it overrides the global option specified in Clockwork::API for this SMS, if neither option is set your account default will be used.
What to do with any invalid characters in the message content. :error
will raise a Clockwork::InvalidCharacterException, :replace
will replace a small number of common invalid characters, such as the smart quotes used by Microsoft Office with a similar match, :remove
will remove invalid characters.
44 45 46 |
# File 'lib/clockwork/sms.rb', line 44 def invalid_char_action @invalid_char_action end |
#long ⇒ boolean
If this option is set it overrides the global option specified in Clockwork::API for this SMS, if neither option is set your account default will be used.
Set to true
to enable long SMS. A standard text can contain 160 characters, a long SMS supports up to 459. Each recipient will cost up to 3 message credits.
32 33 34 |
# File 'lib/clockwork/sms.rb', line 32 def long @long end |
#to ⇒ string
REQUIRED: The phone number to send the SMS to in international number format (without a leading + or international dialling prefix such as 00, e.g. 441234567890).
49 50 51 |
# File 'lib/clockwork/sms.rb', line 49 def to @to end |
#truncate ⇒ boolean
If this option is set it overrides the global option specified in Clockwork::API for this SMS, if neither option is set your account default will be used.
Set to true
to trim the message content to the maximum length if it is too long.
38 39 40 |
# File 'lib/clockwork/sms.rb', line 38 def truncate @truncate end |
#wrapper_id=(value) ⇒ Object (writeonly)
Sets the attribute wrapper_id
51 52 53 |
# File 'lib/clockwork/sms.rb', line 51 def wrapper_id=(value) @wrapper_id = value end |
Instance Method Details
#deliver ⇒ Clockwork::SMS::Response
Deliver the SMS message.
67 68 69 70 71 |
# File 'lib/clockwork/sms.rb', line 67 def deliver xml = Clockwork::XML::SMS.build_single( self ) http_response = Clockwork::HTTP.post( Clockwork::API::SMS_URL, xml, @api.use_ssl ) response = Clockwork::XML::SMS.parse_single( self, http_response ) end |
#translated_attributes ⇒ hash
Translate standard variable names to those needed to make an XML request. First, checks if global variables are set in Clockwork::API then overwrites with variables set in Clockwork::SMS instance.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/clockwork/sms.rb', line 75 def translated_attributes attributes = {} translations = [] translations << { :var => 'client_id', :xml_var => 'ClientID' } translations << { :var => 'concat', :xml_var => 'Concat' } translations << { :var => 'from', :xml_var => 'From' } translations << { :var => 'invalid_char_action', :xml_var => 'InvalidCharAction' } translations << { :var => 'content', :xml_var => 'Content' } translations << { :var => 'to', :xml_var => 'To' } translations << { :var => 'truncate', :xml_var => 'Truncate' } translations << { :var => 'wrapper_id', :xml_var => 'WrapperID' } translations.each do |t| self.instance_variable_set( "@#{t[:var]}", @api.instance_variable_get( "@#{t[:var]}" ) ) if self.instance_variable_get( "@#{t[:var]}" ).nil? attributes[ t[:xml_var] ] = self.instance_variable_get( "@#{t[:var]}" ) unless self.instance_variable_get( "@#{t[:var]}" ).nil? end attributes end |