Completed
Push — master ( 488c2b...222ab4 )
by
unknown
13s
created

Medium   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 71
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 11 2
A getUserProfile() 0 23 2
1
<?php
2
/*!
3
* Hybridauth
4
* https://hybridauth.github.io | https://github.com/hybridauth/hybridauth
5
*  (c) 2017 Hybridauth authors | https://hybridauth.github.io/license.html
6
*/
7
8
namespace Hybridauth\Provider;
9
10
use Hybridauth\Adapter\OAuth2;
11
use Hybridauth\Exception\UnexpectedApiResponseException;
12
use Hybridauth\Data;
13
use Hybridauth\User;
14
15
/**
16
 * Medium OAuth2 provider adapter.
17
 */
18
class Medium extends OAuth2
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    protected $scope = 'basicProfile';
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    protected $apiBaseUrl = 'https://api.medium.com/v1/';
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    protected $authorizeUrl = 'https://medium.com/m/oauth/authorize';
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    protected $accessTokenUrl = 'https://api.medium.com/v1/tokens';
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    protected $apiDocumentation = 'https://github.com/Medium/medium-api-docs';
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    protected function initialize()
49
    {
50
        parent::initialize();
51
52
        if ($this->isRefreshTokenAvailable()) {
53
            $this->tokenRefreshParameters += [
54
                'client_id' => $this->clientId,
55
                'client_secret' => $this->clientSecret,
56
            ];
57
        }
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     *
63
     * See: https://github.com/Medium/medium-api-docs#getting-the-authenticated-users-details
64
     */
65
    public function getUserProfile()
66
    {
67
        $response = $this->apiRequest('me');
68
69
        $data = new Data\Collection($response);
70
71
        $userProfile = new User\Profile();
72
        $data = $data->filter('data');
73
74
        $full_name = explode(' ', $data->get('name'));
75
        if (count($full_name) < 2) {
76
            $full_name[1] = '';
77
        }
78
79
        $userProfile->identifier = $data->get('id');
80
        $userProfile->displayName = $data->get('username');
81
        $userProfile->profileURL = $data->get('imageUrl');
82
        $userProfile->firstName = $full_name[0];
83
        $userProfile->lastName = $full_name[1];
84
        $userProfile->profileURL = $data->get('url');
85
86
        return $userProfile;
87
    }
88
}
89