Meetup   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 8
dl 0
loc 91
ccs 28
cts 35
cp 0.8
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getBaseUri() 0 4 1
A getAuthorizeUri() 0 4 1
A getRequestTokenUri() 0 4 1
A getName() 0 4 1
A parseToken() 0 9 2
A getIdentity() 0 38 3
1
<?php
2
/**
3
 * SocialConnect project
4
 *
5
 * @author: Andreas Heigl https://github.com/heiglandreas <[email protected]>
6
 */
7
8
namespace SocialConnect\OAuth2\Provider;
9
10
use SocialConnect\Common\Http\Client\Client;
11
use SocialConnect\Provider\AccessTokenInterface;
12
use SocialConnect\Provider\Exception\InvalidAccessToken;
13
use SocialConnect\Provider\Exception\InvalidResponse;
14
use SocialConnect\Common\Entity\User;
15
use SocialConnect\Common\Hydrator\ObjectMap;
16
use SocialConnect\OAuth2\AccessToken;
17
18
class Meetup extends \SocialConnect\OAuth2\AbstractProvider
19
{
20
    const NAME = 'meetup';
21
22
    /**
23
     * {@inheritdoc}
24
     */
25 3
    public function getBaseUri()
26
    {
27 3
        return 'https://api.meetup.com/';
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 2
    public function getAuthorizeUri()
34
    {
35 2
        return 'https://secure.meetup.com/oauth2/authorize';
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 2
    public function getRequestTokenUri()
42
    {
43 2
        return 'https://secure.meetup.com/oauth2/access';
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49 3
    public function getName()
50
    {
51 3
        return self::NAME;
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57 3
    public function parseToken($body)
58
    {
59 3
        $result = json_decode($body, true);
60 3
        if ($result) {
61 1
            return new AccessToken($result);
62
        }
63
64 2
        throw new InvalidAccessToken('AccessToken is not a valid JSON');
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70 2
    public function getIdentity(AccessTokenInterface $accessToken)
71
    {
72 2
        $response = $this->httpClient->request(
73 2
            $this->getBaseUri() . '2/member/self?sign=true&photo-host=public&fields=gender',
74
            [
75 2
                'format' => 'json'
76
            ],
77 2
            Client::GET,
78
            [
79 2
                'Authorization' => 'Bearer ' . $accessToken->getToken(),
80
            ]
81
        );
82
83 2
        if (!$response->isSuccess()) {
84 1
            throw new InvalidResponse(
85 1
                'API response with error code',
86 1
                $response
87
            );
88
        }
89
90 1
        $result = $response->json();
91 1
        if (!$result) {
92 1
            throw new InvalidResponse(
93 1
                'API response is not a valid JSON object',
94 1
                $response
95
            );
96
        }
97
98
        $user = new User();
99
100
        $user->id         = $result->id;
101
        $user->username   = $result->name;
102
        $user->fullname   = $result->name;
103
        $user->sex        = $result->gender;
104
        $user->pictureURL = $result->photo->photo_link;
105
106
        return $user;
107
    }
108
}
109