OAuth   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 8
c 3
b 0
f 0
dl 0
loc 28
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getOAuthApp() 0 3 1
A getOAuthToken() 0 4 1
1
<?php
2
3
// OAuth.php
4
#################################################
5
##
6
## PHPLicengine
7
##
8
#################################################
9
## Copyright 2009-{current_year} PHPLicengine
10
## 
11
## Licensed under the Apache License, Version 2.0 (the "License");
12
## you may not use this file except in compliance with the License.
13
## You may obtain a copy of the License at
14
##
15
##    http://www.apache.org/licenses/LICENSE-2.0
16
##
17
## Unless required by applicable law or agreed to in writing, software
18
## distributed under the License is distributed on an "AS IS" BASIS,
19
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
## See the License for the specific language governing permissions and
21
## limitations under the License.
22
#################################################
23
24
namespace PHPLicengine\Service;
25
use PHPLicengine\Exception\ResponseException;
26
use PHPLicengine\Exception\CurlException;
27
use PHPLicengine\Api\ApiInterface;
28
29
class OAuth {
30
 
31
       private $url;
32
       private $api;
33
 
34
       public function __construct(ApiInterface $api)
35
       {
36
              $this->api = $api;
37
              $this->url = 'https://api-ssl.bitly.com';       
38
       }
39
 
40
       /*
41
       Retrieve OAuth App
42
       https://dev.bitly.com/v4/#operation/getOAuthApp
43
       */
44
       public function getOAuthApp(string $client_id) 
45
       {
46
              return $this->api->get($this->url.'/v4/apps/'.$client_id);
47
       }
48
49
       /*
50
       OAuth web flow
51
       https://dev.bitly.com/docs/getting-started/authentication
52
       */
53
       public function getOAuthToken(array $params) 
54
       {
55
              $this->api->setOAuth();
56
              return $this->api->post($this->url.'/oauth/access_token', $params);
57
       }
58
      
59
}
60