Class: Clockwork::SMS

Inherits:
Object
  • Object
show all
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.

Author:

  • James Inman <james@mediaburst.co.uk>

Defined Under Namespace

Classes: Response

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ SMS

Create a new SMS message.



59
60
61
# File 'lib/clockwork/sms.rb', line 59

def initialize options = {}      
  options.each { |k, v| instance_variable_set "@#{k}", v } if options.kind_of?(Hash)
end

Instance Attribute Details

#apiClockwork::API

An instance of Clockwork::API.



10
11
12
# File 'lib/clockwork/sms.rb', line 10

def api
  @api
end

#client_idstring

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

#contentstring

REQUIRED: The message content to send.



15
16
17
# File 'lib/clockwork/sms.rb', line 15

def content
  @content
end

#fromstring

Note:

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_actionsymbol

Note:

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.

Raises:

  • ArgumentError - if value is not one of :error, :replace, :remove



44
45
46
# File 'lib/clockwork/sms.rb', line 44

def invalid_char_action
  @invalid_char_action
end

#longboolean

Note:

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

#tostring

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

#truncateboolean

Note:

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

#deliverClockwork::SMS::Response

Deliver the SMS message.



65
66
67
68
69
# File 'lib/clockwork/sms.rb', line 65

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_attributeshash

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.



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/clockwork/sms.rb', line 73

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