Passed
Push — main ( ac09e4...1448e3 )
by Pouya
02:58
created

Blockchain::setContainer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Appino\Blockchain\Classes;
4
5
use Appino\Blockchain\Classes\Create;
6
use Appino\Blockchain\Classes\Receive;
7
use Appino\Blockchain\Classes\Wallet;
8
use GuzzleHttp\Client;
9
use GuzzleHttp\Exception\GuzzleException;
10
use Illuminate\Contracts\Container\Container;
11
12
class Blockchain{
13
14
    protected $client;
15
    protected $params;
16
    public $HD = false;
17
    const GET = 'GET';
18
    const POST = 'POST';
19
20
    public function __construct($config){
21
        $this->client = new Client(['base_uri'=>data_get($config,'base_uri')]);
22
        $this->params['api_code'] = data_get($config,'api_code');
23
    }
24
25
    /**
26
     * @return Create
27
     */
28
    public function Create(){
29
        return new Create($this);
30
    }
31
32
    /**
33
     * @return Wallet
34
     */
35
    public function Wallet(){
36
        return new Wallet($this);
37
    }
38
39
    /**
40
     * @return Receive
41
     */
42
    public function Receive(){
43
        return new Receive();
44
    }
45
46
    /**
47
     * @param $base_uri string Default : http://localhost:3000
48
     */
49
50
    public function newBaseUri($base_uri){
51
        $this->client = new Client(['base_uri'=>$base_uri]);
52
    }
53
54
    /**
55
     * @param $method
56
     * @param $url
57
     * @param $params
58
     * @return array
59
     */
60
61
    public function Request($method, $url, $params){
62
        $params = array_merge($params, $this->params);
63
        $options = array(
64
            'form_params'=>$params,
65
            'headers'=>[
66
                'Content-Type'=>'application/x-www-form-urlencoded',
67
            ]
68
        );
69
        try {
70
            $response = $this->client->request($method, $url, $options);
71
            return json_decode($response->getBody()->getContents(),true);
72
        } catch (GuzzleException $e) {
73
            echo $e->getMessage();
74
        }
75
    }
76
77
}
78