Class: Providers::Clickatell

Inherits:
SmsProvider show all
Defined in:
lib/multi_sms/providers/clickatell.rb

Constant Summary collapse

API_VERSION =
""
BASE_DOMAIN =
"api.clickatell.com"

Instance Method Summary collapse

Methods inherited from SmsProvider

#config

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Providers::SmsProvider

Instance Method Details

#send(parameters) ⇒ Object

Send SMS Required parameters

  • :from - Either the one of the allocated numbers or arbitrary alphanumeric string of at most 11 characters

  • :to - Any phone number capable of receiving SMS

  • :message - Any UTF-8 text Splitting and joining multi-part SMS messages are automatically handled by the API



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/multi_sms/providers/clickatell.rb', line 19

def send(parameters)
  base_url = "http://#{BASE_DOMAIN}"
  path = "/http/sendmsg"
  url = base_url + path
  response = RestClient.post url, api_id: config.clickatell.apikey, user: config.clickatell.username, password: config.clickatell.password,  to: parameters[:to], text: parameters[:message]
rescue RestClient::Unauthorized
  raise AuthError, "Authentication failed"
rescue RestClient::InternalServerError
  raise ServerError, "Server error"
rescue RestClient::Forbidden => e
  raise BadRequest, e.http_body
end

#usable?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/multi_sms/providers/clickatell.rb', line 8

def usable?
  config.clickatell.apikey.present? and config.clickatell.username.present? and config.clickatell.password.present?
end