Esempio n. 1
0
 public function testGetSignature()
 {
     $Class = new ReflectionClass(Client::class);
     $Method = $Class->getMethod('getSignature');
     $Method->setAccessible(true);
     $Token = new Token();
     $Token->setAccessToken('accesssss_tokkken');
     $Client = new Client();
     $Client->setToken($Token)->setClientSecret('ClienTSECRET');
     $this->assertEquals('01a36a2aa93eb052cbabc18febbaa992', $Method->invoke($Client, ['bbb' => 'opka', 'aaa' => 7]));
 }
Esempio n. 2
0
 public function testMerge()
 {
     $Token1 = Token::initializeByObject(new stdClass());
     $Token2 = new Token();
     $Token2->setAccessToken('accesssss_tokkken');
     $Token2->setRefreshToken('someREFREshTOken');
     $Token2->setTokenType(Token::TYPE_SESSION);
     $this->assertEmpty($Token1->getAccessToken());
     $this->assertEmpty($Token1->getRefreshToken());
     $this->assertFalse($Token1->hasRefreshToken());
     $this->assertEquals(Token::TYPE_NONE, $Token1->getTokenType());
     $Token1->merge($Token2);
     $this->assertEquals('accesssss_tokkken', $Token1->getAccessToken());
     $this->assertEmpty($Token1->getRefreshToken());
     $this->assertFalse($Token1->hasRefreshToken());
     $this->assertEquals(Token::TYPE_SESSION, $Token1->getTokenType());
 }
 /**
  * Create response instance by JSON object
  * @param stdClass $Value response object
  * @return Token|Error response instance: error or token data
  */
 private static function createResponseFromJson($Value)
 {
     switch (true) {
         case isset($Value->error):
             return Error::initializeByObject($Value);
         default:
             return Token::initializeByObject($Value);
     }
 }
Esempio n. 4
0
$Command = new CommandPosix();
$Command->appendHelpParameter('show help');
$Command->appendParameter(new Option('client', 'c', 'client id', Option::TYPE_STRING, true), function ($name, $value) use(&$clientId) {
    $clientId = $value;
});
$Command->appendParameter(new Option('data', 'd', 'API method parameters (JSON)', Option::TYPE_STRING, true), function ($name, $value) use(&$methodData) {
    $methodData = json_decode($value, true);
});
$Command->appendParameter(new Option('key', 'k', 'application key', Option::TYPE_STRING, true), function ($name, $value) use(&$applicationKey) {
    $applicationKey = $value;
});
$Command->appendParameter(new Option('method', 'm', 'API method name', Option::TYPE_STRING, true), function ($name, $value) use(&$methodName) {
    $methodName = $value;
});
$Command->appendParameter(new Option('secret', 's', 'client secret', Option::TYPE_STRING, true), function ($name, $value) use(&$clientSecret) {
    $clientSecret = $value;
});
$Command->appendParameter(new Option('token', 't', 'access token', Option::TYPE_STRING, true), function ($name, $value) use(&$accessToken) {
    $accessToken = $value;
});
try {
    $Command->parse(true);
    $Token = new Token();
    $Token->setAccessToken($accessToken)->setTokenType(Token::TYPE_SESSION);
    $Client = new Client();
    $Client->setApplicationKey($applicationKey)->setToken($Token)->setClientId($clientId)->setClientSecret($clientSecret);
    $Result = $Client->call($methodName, $methodData);
    print_r($Result);
} catch (RequiredOptionException $Ex) {
    $Command->displayHelp();
}
/**
 * Copyright 2015 Alexey Maslov <*****@*****.**>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Odnoklassniki API method users.getCurrentUser example
 * @author alxmsl
 * @date 8/13/13
 */
include '../vendor/autoload.php';
use alxmsl\Odnoklassniki\OAuth2\Response\Token;
use alxmsl\Odnoklassniki\API\Client;
// Create authorization token instance
$Token = new Token();
$Token->setAccessToken('4cCE5s_T0KEn')->setRefreshToken('ReFRE5H_t0Ken')->setTokenType(Token::TYPE_SESSION);
// Create and initialize OK API client instance
$Client = new Client();
$Client->setApplicationKey('4Pp1IC4t10n_KEy')->setToken($Token)->setClientId(1234567890)->setClientSecret('C11eNt_SEcREt');
// Get current user info
$Result = $Client->call('users.getCurrentUser');
print_r($Result);
Esempio n. 6
0
 /**
  * Merge token instances.
  * Apply access token and token type values for current token
  * Save refresh token value
  * @param Token $Token token instance
  * @return Token self
  */
 public function merge(Token $Token)
 {
     $this->setAccessToken($Token->getAccessToken())->setTokenType($Token->getTokenType());
     return $this;
 }