Class: Clockwork::API
- Inherits:
-
Object
- Object
- Clockwork::API
- Defined in:
- lib/clockwork/api.rb
Overview
You must create an instance of Clockwork::API to begin using the API.
Constant Summary collapse
- SMS_URL =
URL of the SMS API send action
"api.clockworksms.com/xml/send"
- CREDIT_URL =
URL of the SMS API check credit action
"api.clockworksms.com/xml/credit"
- BALANCE_URL =
URL of the SMS API check balance action
"api.clockworksms.com/xml/balance"
Instance Attribute Summary collapse
-
#api_key ⇒ string
readonly
API key provided in Clockwork::API#initialize.
-
#concat ⇒ symbol
This is the number of messages to concatenate (join together).
-
#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. -
#messages ⇒ Clockwork::MessageCollection
Returns a Clockwork::MessageCollection containing all built SMS messages.
-
#password ⇒ string
readonly
deprecated
Deprecated.
Use api_key instead.
-
#truncate ⇒ boolean
Set to
true
to trim the message content to the maximum length if it is too long. -
#use_ssl ⇒ boolean
Whether to use SSL when connecting to the API.
-
#username ⇒ string
readonly
deprecated
Deprecated.
Use api_key instead.
Instance Method Summary collapse
-
#balance ⇒ integer
Check the remaining credit for this account.
-
#credit ⇒ integer
Check the remaining credit for this account.
-
#deliver ⇒ array
Deliver multiple messages created using Clockwork::API#messages.build.
-
#get_credit ⇒ Object
deprecated
Deprecated.
Use Clockwork::API#credit. Support for Clockwork::API#get_credit will be removed in a future version of this wrapper.
-
#initialize(*args) ⇒ API
constructor
Clockwork::API is initialized with an API key, available from www.mediaburst.co.uk/api.
Constructor Details
#initalize(api_key) ⇒ API #initalize(username, password) ⇒ API
Clockwork::API is initialized with an API key, available from www.mediaburst.co.uk/api.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/clockwork/api.rb', line 98 def initialize *args if args.size == 1 || ( args.size == 2 && args[1].kind_of?(Hash) ) raise Clockwork::Error::InvalidAPIKey unless args[0][/^[A-Fa-f0-9]{40}$/] @api_key = args[0] elsif args.size == 2 || ( args.size == 3 && args[2].kind_of?(Hash) ) raise ArgumentError, "You must pass both a username and password." if args[0].empty? || args[1].empty? @username = args[0] @password = args[1] else raise ArgumentError, "You must pass either an API key OR a username and password." end args.last.each { |k, v| instance_variable_set "@#{k}", v } if args.last.kind_of?(Hash) @use_ssl = true if @use_ssl.nil? @concat = 3 if @concat.nil? && @long @messages ||= Clockwork::MessageCollection.new( :api => self ) @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_key ⇒ string (readonly)
API key provided in Clockwork::API#initialize.
20 21 22 |
# File 'lib/clockwork/api.rb', line 20 def api_key @api_key end |
#concat ⇒ symbol
Defaults to 3 if not set and Clockwork::API#long is set to true
.
This is the number of messages to concatenate (join together).
26 27 28 |
# File 'lib/clockwork/api.rb', line 26 def concat @concat end |
#from ⇒ string
This can be overriden for specific Clockwork::SMS objects; if it is not 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.
32 33 34 |
# File 'lib/clockwork/api.rb', line 32 def from @from end |
#invalid_char_action ⇒ symbol
This can be overriden for specific Clockwork::SMS objects; if it is not 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.
38 39 40 |
# File 'lib/clockwork/api.rb', line 38 def invalid_char_action @invalid_char_action end |
#long ⇒ boolean
This can be overriden for specific Clockwork::SMS objects; if it is not 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.
44 45 46 |
# File 'lib/clockwork/api.rb', line 44 def long @long end |
#messages ⇒ Clockwork::MessageCollection
Returns a Clockwork::MessageCollection containing all built SMS messages.
49 50 51 |
# File 'lib/clockwork/api.rb', line 49 def @messages end |
#password ⇒ string (readonly)
Use api_key instead.
Password provided in Clockwork::API#initialize.
54 55 56 |
# File 'lib/clockwork/api.rb', line 54 def password @password end |
#truncate ⇒ boolean
This can be overriden for specific Clockwork::SMS objects; if it is not set your account default will be used.
Set to true
to trim the message content to the maximum length if it is too long.
60 61 62 |
# File 'lib/clockwork/api.rb', line 60 def truncate @truncate end |
#use_ssl ⇒ boolean
Whether to use SSL when connecting to the API. Defaults to true
65 66 67 |
# File 'lib/clockwork/api.rb', line 65 def use_ssl @use_ssl end |
#username ⇒ string (readonly)
Use api_key instead.
Username provided in Clockwork::API#initialize.
70 71 72 |
# File 'lib/clockwork/api.rb', line 70 def username @username end |
Instance Method Details
#balance ⇒ integer
Check the remaining credit for this account.
131 132 133 134 135 |
# File 'lib/clockwork/api.rb', line 131 def balance xml = Clockwork::XML::Balance.build( self ) response = Clockwork::HTTP.post( Clockwork::API::BALANCE_URL, xml, @use_ssl ) balance = Clockwork::XML::Balance.parse( response ) end |
#credit ⇒ integer
Check the remaining credit for this account.
122 123 124 125 126 |
# File 'lib/clockwork/api.rb', line 122 def credit xml = Clockwork::XML::Credit.build( self ) response = Clockwork::HTTP.post( Clockwork::API::CREDIT_URL, xml, @use_ssl ) credit = Clockwork::XML::Credit.parse( response ) end |
#deliver ⇒ array
Deliver multiple messages created using Clockwork::API#messages.build.
139 140 141 142 143 |
# File 'lib/clockwork/api.rb', line 139 def deliver xml = Clockwork::XML::SMS.build_multiple( self. ) http_response = Clockwork::HTTP.post( Clockwork::API::SMS_URL, xml, @use_ssl ) responses = Clockwork::XML::SMS.parse_multiple( self., http_response ) end |
#get_credit ⇒ Object
Use Clockwork::API#credit. Support for Clockwork::API#get_credit will be removed in a future version of this wrapper.
Alias for Clockwork::API#credit to preserve backwards compatibility with original Mediaburst API.
74 75 76 |
# File 'lib/clockwork/api.rb', line 74 def get_credit credit end |