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)
-
- (Clockwork::API) api
An instance of Clockwork::API.
-
- (string) client_id
An unique message ID specified by the connecting application, for example your database record ID.
-
- (string) content
REQUIRED: The message content to send.
-
- (string) from
The from address displayed on a phone when the SMS is received.
-
- (symbol) invalid_char_action
What to do with any invalid characters in the message content.
-
- (boolean) long
Set to true to enable long SMS.
-
- (string) to
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).
-
- (boolean) truncate
Set to true to trim the message content to the maximum length if it is too long.
Instance Method Summary (collapse)
-
- (Clockwork::SMS::Response) deliver
Deliver the SMS message.
-
- (SMS) initialize(options = {})
constructor
Create a new SMS message.
-
- (hash) translated_attributes
Translate standard variable names to those needed to make an XML request.
Constructor Details
- (SMS) initialize(options = {})
Create a new SMS message.
57 58 59 |
# File 'lib/clockwork/sms.rb', line 57 def initialize = {} .each { |k, v| instance_variable_set "@#{k}", v } if .kind_of?(Hash) end |
Instance Attribute Details
- (Clockwork::API) api
An instance of Clockwork::API.
10 11 12 |
# File 'lib/clockwork/sms.rb', line 10 def api @api end |
- (string) client_id
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 |
- (string) content
REQUIRED: The message content to send.
15 16 17 |
# File 'lib/clockwork/sms.rb', line 15 def content @content end |
- (string) from
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 |
- (symbol) invalid_char_action
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 |
- (boolean) long
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 |
- (string) to
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 |
- (boolean) truncate
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 |
Instance Method Details
- (Clockwork::SMS::Response) deliver
Deliver the SMS message.
63 64 65 66 67 |
# File 'lib/clockwork/sms.rb', line 63 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 |
- (hash) translated_attributes
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.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/clockwork/sms.rb', line 71 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.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 |