|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Github; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
|
6
|
|
|
use App\Http\Requests; |
|
7
|
|
|
use App\Http\Controllers\Controller; |
|
8
|
|
|
use App\Model\Github\Github; |
|
9
|
|
|
|
|
10
|
|
|
class GithubApiController extends Controller { |
|
11
|
|
|
|
|
12
|
|
|
private $username; |
|
13
|
|
|
private $password; |
|
14
|
|
|
private $github; |
|
15
|
|
|
|
|
16
|
|
|
public function __construct() { |
|
17
|
|
|
$model = new Github(); |
|
18
|
|
|
$this->github = $model->firstOrFail(); |
|
19
|
|
|
|
|
20
|
|
|
$this->username = $this->github->username; |
|
21
|
|
|
$this->password = $this->github->password; |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function postCurl($url,$data='',$method="POST") { |
|
25
|
|
|
$ch = curl_init(); |
|
26
|
|
|
curl_setopt($ch, CURLOPT_URL, $url); |
|
27
|
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); |
|
28
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
29
|
|
|
curl_setopt($ch, CURLOPT_POST, true); |
|
30
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); |
|
31
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array("User-Agent:$this->username")); |
|
32
|
|
|
curl_setopt($ch, CURLOPT_USERPWD, "$this->username:$this->password"); |
|
33
|
|
|
$content = curl_exec($ch); |
|
34
|
|
|
curl_close($ch); |
|
35
|
|
|
return json_decode($content, true); |
|
36
|
|
|
|
|
37
|
|
|
} |
|
38
|
|
|
public function getCurl($url) { |
|
39
|
|
|
$ch = curl_init(); |
|
40
|
|
|
curl_setopt($ch, CURLOPT_URL, $url); |
|
41
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
42
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array("User-Agent:$this->username")); |
|
43
|
|
|
curl_setopt($ch, CURLOPT_USERPWD, "$this->username:$this->password"); |
|
44
|
|
|
$content = curl_exec($ch); |
|
45
|
|
|
curl_close($ch); |
|
46
|
|
|
return json_decode($content, true); |
|
47
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
} |
|
52
|
|
|
|