Completed
Branch master (bb48cc)
by vijay
148:50 queued 92:39
created

GithubApiController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
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