You are here

public static function DrupalOAuthToken::fromResult in OAuth 1.0 6.3

Same name and namespace in other branches
  1. 7.4 includes/DrupalOAuthToken.inc \DrupalOAuthToken::fromResult()
  2. 7.3 includes/DrupalOAuthToken.inc \DrupalOAuthToken::fromResult()

Constructs a token from a db-result resource

Parameters

resource $res: A database result resource

Return value

DrupalOAuthToken The constructed token object or NULL if no rows could be read or construction failed

4 calls to DrupalOAuthToken::fromResult()
DrupalOAuthToken::loadById in includes/DrupalOAuthToken.inc
Gets the token with the specified id
DrupalOAuthToken::loadByKey in includes/DrupalOAuthToken.inc
Gets the token with the specified key
oauth_common_get_user_provider_tokens in ./oauth_common.module
Gets the tokens for a user.
oauth_common_user_access_tokens in ./oauth_common.inc
Return information about access tokens related to a user.

File

includes/DrupalOAuthToken.inc, line 223

Class

DrupalOAuthToken

Code

public static function fromResult($res, $consumer = FALSE) {

  //TODO: Ensure this works with old inputs?
  if ($data = db_fetch_array($res)) {
    if (isset($data['services'])) {
      $data['services'] = json_decode($data['services']);
    }
    $data['in_database'] = TRUE;
    if (is_object($consumer) && $consumer->csid == $data['csid']) {
      $token_consumer = $consumer;
    }
    else {
      $token_consumer = DrupalOAuthConsumer::loadById($data['csid'], isset($data['services']));
    }
    return new DrupalOAuthToken($data['token_key'], $data['secret'], $token_consumer, $data);
  }
  return NULL;
}