Blame view

common/components/nodge/eauth/src/services/extended/OdnoklassnikiOAuth2Service.php 1.26 KB
b0f143c3   Yarik   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
  <?php
  /**
   * An example of extending the provider class.
   *
   * @author Maxim Zemskov <nodge@yandex.ru>
   * @link http://github.com/Nodge/yii2-eauth/
   * @license http://www.opensource.org/licenses/bsd-license.php
   */
  
  namespace nodge\eauth\services\extended;
  
  class OdnoklassnikiOAuth2Service extends \nodge\eauth\services\OdnoklassnikiOAuth2Service
  {
  
  	protected $scopes = [self::SCOPE_VALUABLE_ACCESS];
  
  	protected function fetchAttributes()
  	{
  		parent::fetchAttributes();
  
  		$info = $this->makeSignedRequest('', [
  			'query' => [
  				'method' => 'users.getInfo',
  				'uids' => $this->attributes['id'],
  				'fields' => 'url_profile',
  				'format' => 'JSON',
  				'application_key' => $this->clientPublic,
  				'client_id' => $this->clientId,
  			],
  		]);
  
  		preg_match('/\d+\/{0,1}$/', $info[0]->url_profile, $matches);
  		$this->attributes['id'] = (int)$matches[0];
  		$this->attributes['url'] = $info[0]->url_profile;
  
  		return true;
  	}
  
  
  	/**
  	 * @param string $link
  	 * @param string $message
  	 * @return array
  	 */
  	public function wallPost($link, $message)
  	{
  		return $this->makeSignedRequest('', [
  			'query' => [
  				'application_key' => $this->clientPublic,
  				'method' => 'share.addLink',
  				'format' => 'JSON',
  				'linkUrl' => $link,
  				'comment' => $message,
  			],
  		]);
  	}
  
  }