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:

Defined Under Namespace

Classes: Response

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (SMS) initialize(options = {})

Create a new SMS message.

Parameters:

  • options (hash) (defaults to: {})

    Optional hash of attributes on Clockwork::SMS



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

- (Clockwork::API) api

An instance of Clockwork::API.

Returns:



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.

Returns:

  • (string)


20
21
22
# File 'lib/clockwork/sms.rb', line 20

def client_id
  @client_id
end

- (string) content

REQUIRED: The message content to send.

Returns:

  • (string)


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

def content
  @content
end

- (string) from

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.

Returns:

  • (string)


26
27
28
# File 'lib/clockwork/sms.rb', line 26

def from
  @from
end

- (symbol) invalid_char_action

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.

Returns:

  • (symbol)

    One of error, :replace, :remove

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

- (boolean) long

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.

Returns:

  • (boolean)


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).

Returns:

  • (string)


49
50
51
# File 'lib/clockwork/sms.rb', line 49

def to
  @to
end

- (boolean) truncate

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.

Returns:

  • (boolean)


38
39
40
# File 'lib/clockwork/sms.rb', line 38

def truncate
  @truncate
end

- (Object) wrapper_id=(value) (writeonly)

Sets the attribute wrapper_id

Parameters:

  • value

    the value to set the attribute wrapper_id to.



51
52
53
# File 'lib/clockwork/sms.rb', line 51

def wrapper_id=(value)
  @wrapper_id = value
end

Instance Method Details

- (Clockwork::SMS::Response) deliver

Deliver the SMS message.

Returns:



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

- (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.

Returns:

  • (hash)

    Hash of XML keys and values



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