You are here

function nexmo_send in Nexmo SMS Gateway 7

Implements hook_send().

1 string reference to 'nexmo_send'
nexmo_gateway_info in ./nexmo.module
Implements hook_gateway_info().

File

./nexmo.module, line 87
Provides NEXMO implementation methods.

Code

function nexmo_send($number, $message, $options = array()) {
  $config = array();
  $config['nexmo_api_key'] = variable_get('nexmo_api_key', '');
  $config['nexmo_api_secret'] = variable_get('nexmo_api_secret', '');
  $config['nexmo_api_sender'] = variable_get('nexmo_api_sender', '');
  if ($unicode_message = nexmo_unicode($message)) {
    $message = $unicode_message;
  }
  else {
    $message = rawurlencode($message);
  }
  $number = isset($options['country']) ? $options['country'] . $number : $number;
  $api_key = !empty($config['nexmo_api_key']) ? $config['nexmo_api_key'] : '';
  $api_secret = !empty($config['nexmo_api_secret']) ? $config['nexmo_api_secret'] : '';
  $from = !empty($config['nexmo_api_sender']) ? $config['nexmo_api_sender'] : 'NEXMO';
  $query = 'api_key=' . $api_key . '&api_secret=' . $api_secret . '&from=' . $from . '&to=' . $number . '&text=' . $message . '&status-report-req=1';
  $api_send_url = 'https://rest.nexmo.com/sms/json';
  $http_result = drupal_http_request($api_send_url . '?' . $query);
  if (isset($http_result->error)) {
    return array(
      'status' => FALSE,
      'message' => 'An error occurred during the HTTP request: @error',
      array(
        '@error' => $http_result->error,
      ),
    );
  }
  if (isset($http_result->data)) {
    if (strpos($http_result->data, 'ERR') !== FALSE) {
      $result = array(
        'status' => FALSE,
        'message' => $http_result->data,
      );
    }
    else {
      $result = array(
        'status' => TRUE,
        'data' => $http_result->data,
      );
    }
  }
  return $result;
}