You are here

public function LingotekSession::request in Lingotek Translation 6

Same name and namespace in other branches
  1. 7.7 lingotek.session.inc \LingotekSession::request()
  2. 7.2 lingotek.session.inc \LingotekSession::request()
  3. 7.3 lingotek.session.inc \LingotekSession::request()
  4. 7.4 lingotek.session.inc \LingotekSession::request()
  5. 7.5 lingotek.session.inc \LingotekSession::request()
  6. 7.6 lingotek.session.inc \LingotekSession::request()
3 calls to LingotekSession::request()
LingotekSession::download in ./lingotek.session.inc
LingotekSession::login in ./lingotek.session.inc
LingotekSession::logout in ./lingotek.session.inc

File

./lingotek.session.inc, line 82
Handles api calls, logging in and logging out of LingoTek

Class

LingotekSession

Code

public function request($api, $params = NULL, $data = NULL, $returnJson = TRUE) {
  if (!$this
    ->isLoggedIn() && !in_array($api, $this->sessionless)) {
    $this
      ->login();
  }
  $query = "";
  if (isset($params)) {
    $query = http_build_query($params, '', '&');
  }
  $this->headers["Content-Type"] = "application/x-www-form-urlencoded;";
  $response = drupal_http_request($this->url . "/" . $api, $this->headers, 'POST', $query);
  if ($returnJson) {
    $json = json_decode($response->data);
    if ($json->results != "success") {
      lingotek_error('API ' . $api . ' FAILED', array(
        'params' => $params,
        'response' => $json,
      ), 1);
    }
    return $json;
  }
  else {
    return $response;
  }
}