You are here

function shurly_service_get_key in ShURLy 6

1 string reference to 'shurly_service_get_key'
shurly_service_menu in shurly_service/shurly_service.module
Implements hook_menu().

File

shurly_service/shurly_service.inc, line 79
Link general search functionalities to services module.

Code

function shurly_service_get_key() {
  $defaults = array(
    'format' => 'json',
    'callback' => 'getData',
    // function name for padded JSON
    'primary' => 'key',
  );
  $input = $_GET + $defaults;
  module_load_include('inc', 'shurly_service', 'shurly_api_keys');
  global $user;
  $key = FALSE;
  $success = FALSE;
  $error = '';
  if ($user->uid) {
    $key = shurly_get_api_key($user->uid);
    if (!$key) {

      // user doesn't have a key yet, let's get one
      $key = shurly_generate_new_api_key($user->uid);
    }
    if ($key) {
      $success = TRUE;
    }
    else {

      // honestly, we should never really end up here
      $error = t('User has no API key');
    }
  }
  else {

    // user isn't logged in
    $error = t('User is not logged in');
  }
  $data = array(
    'success' => $success,
    'error' => $error,
    'key' => $key,
    'user' => (int) $user->uid,
  );
  shurly_service_output($data, $input);
}