Passed
Push — master ( 96cf51...30fd96 )
by Antônio
01:42
created

ApiCliente::getRespostaArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * To change this license header, choose License Headers in Project Properties.
5
 * To change this template file, choose Tools | Templates
6
 * and open the template in the editor.
7
 */
8
9
namespace OBRSDK\HttpClient\Nucleo;
10
11
/**
12
 * Description of ApiCliente
13
 *
14
 * @author Antonio
15
 */
16
class ApiCliente implements \OBRSDK\HttpClient\Interfaces\ICoreCliente {
17
18
    private $instancia;
19
20
    public function __construct(\OBRSDK\ObjetoBoletosRegistrados $instancia) {
21
        $this->instancia = $instancia;
22
    }
23
24
    /**
25
     * Adiciona o cabeçalho de autorizacao com o token da instancia
26
     * @return \OBRSDK\HttpClient\Nucleo\ApiCliente
27
     */
28
    public function addAuthorization() {
29
        $this->instancia->verificarAccessToken();
30
        $this->addHeader('Authorization', 'Bearer ' . $this->instancia->getObjAccessToken()->getAccessToken());
31
        return $this;
32
    }
33
34
    /**
35
     * Adiciona um cabeçalho opcional
36
     * 
37
     * @param string $nome
38
     * @param string $valor
39
     * @return \OBRSDK\HttpClient\Nucleo\ApiCliente
40
     */
41
    public function addHeader($nome, $valor) {
42
        HttpCliente::getInstance()->addHeader($nome, $valor);
43
        return $this;
44
    }
45
46
    /**
47
     * Faz requisição get no endpoint com os parametros via querystring
48
     * 
49
     * @param string $endpoint
50
     * @param array $queryString
51
     * @return \OBRSDK\HttpClient\Nucleo\ApiCliente
52
     */
53
    public function get($endpoint, array $queryString = null) {
54
        HttpCliente::getInstance()->get($endpoint, $queryString);
55
        return $this;
56
    }
57
58
    /**
59
     * Faz requisição post no endpoint com corpo json opcional
60
     * 
61
     * @param string $endpoint
62
     * @param array $body
63
     * @return \OBRSDK\HttpClient\Nucleo\ApiCliente
64
     */
65
    public function postJson($endpoint, array $body = null) {
66
        HttpCliente::getInstance()->postJson($endpoint, $body);
0 ignored issues
show
Bug introduced by
$endpoint of type string is incompatible with the type OBRSDK\HttpClient\Nucleo\type expected by parameter $endpoint of OBRSDK\HttpClient\Nucleo\HttpCliente::postJson(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

66
        HttpCliente::getInstance()->postJson(/** @scrutinizer ignore-type */ $endpoint, $body);
Loading history...
67
        return $this;
68
    }
69
70
    /**
71
     * Faz requisição post no endpoint com parametros application/x-www-form-urlencoded
72
     * opcional
73
     * 
74
     * @param string $endpoint
75
     * @param array $param
76
     * @return \OBRSDK\HttpClient\Nucleo\ApiCliente
77
     */
78
    public function postParam($endpoint, array $param = null) {
79
        HttpCliente::getInstance()->postParam($endpoint, $param);
80
        return $this;
81
    }
82
83
    /**
84
     * Pega a resposta da requisição feita
85
     * @return array
86
     */
87
    public function getRespostaArray() {
88
        return HttpCliente::getInstance()->getResposta(true);
89
    }
90
91
    /**
92
     * Pega a resposta da requisição feita
93
     * @return object
94
     */
95
    public function getRespostaObject() {
96
        return HttpCliente::getInstance()->getResposta(false);
97
    }
98
99
    /**
100
     * Envia requisição delete no endpoint especificado
101
     * 
102
     * @param string $endpoint
103
     * @return \OBRSDK\HttpClient\Nucleo\ApiCliente
104
     */
105
    public function delete($endpoint) {
106
        HttpCliente::getInstance()->delete($endpoint);
107
        return $this;
108
    }
109
110
    /**
111
     * Envia a requisição patch no endpoint especificado podendo passar 
112
     * um corpo json
113
     * 
114
     * @param string $endpoint
115
     * @param array $body
116
     * @return \OBRSDK\HttpClient\Nucleo\ApiCliente
117
     */
118
    public function patchJson($endpoint, array $body = null) {
119
        HttpCliente::getInstance()->patchJson($endpoint, $body);
120
        return $this;
121
    }
122
123
    /**
124
     * Envia a requisição put no endpoint especificado podendo passar 
125
     * um corpo json
126
     * 
127
     * @param string $endpoint
128
     * @param array $body
129
     * @return \OBRSDK\HttpClient\Nucleo\ApiCliente
130
     */
131
    public function putJson($endpoint, array $body = null) {
132
        HttpCliente::getInstance()->putJson($endpoint, $body);
133
        return $this;
134
    }
135
136
    /**
137
     * Faz upload de um arquivo para a API
138
     * 
139
     * @param string $endpoint
140
     * @param string $arquivo
141
     * @return \OBRSDK\HttpClient\Nucleo\ApiCliente
142
     */
143
    public function enviarArquivo($endpoint, $arquivo) {
144
        HttpCliente::getInstance()->enviarArquivo($endpoint, $arquivo);
145
        return $this;
146
    }
147
148
}
149