You are here

function _evercurrent_send_updates in Evercurrent 7

Same name and namespace in other branches
  1. 7.2 evercurrent.send.inc \_evercurrent_send_updates()
1 call to _evercurrent_send_updates()
evercurrent_run_update_check in ./evercurrent.send.inc

File

./evercurrent.send.inc, line 93

Code

function _evercurrent_send_updates($sender_data) {
  $path = $sender_data['send_url'] . RMH_URL;
  $headers = array(
    'Content-Type' => 'application/x-www-form-urlencoded',
  );
  $data = drupal_json_encode($sender_data);
  $options = array(
    'headers' => $headers,
    'method' => 'POST',
    'data' => http_build_query(array(
      'data' => $data,
    )),
  );
  $response = drupal_http_request($path, $options);
  if ($response->code != 200) {
    _evercurrent_write_status(RMH_STATUS_ERROR, 'Error code ' . $response->code . ' when trying to post to ' . $path);
  }
  else {

    // Check the response data, was it successful?
    $response_data = json_decode($response->data);
    if ($response_data) {
      $saved = $response_data->saved;
      if (!$saved) {
        _evercurrent_write_status(RMH_STATUS_ERROR, check_plain($response_data->message));
        return FALSE;
      }
      else {
        _evercurrent_write_status(RMH_STATUS_OK, $response_data->message);
        return TRUE;
      }
    }
  }
}