Completed
Push — master ( bed516...da6d05 )
by Jared
02:19
created

JCRequest::patch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 1
nc 1
nop 4
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: jaredchu
5
 * Date: 31/05/2017
6
 * Time: 09:40
7
 */
8
9
namespace JC;
10
11
12
use GuzzleHttp\Client;
13
use Purl\Url;
14
use JC\Enums\Method;
15
16
class JCRequest implements iJCRequest
17
{
18
    public static function request($method, $url, $options)
19
    {
20
        return new JCResponse((new Client())->request($method, $url, $options));
21
    }
22
23
    /**
24
     * @param $url
25
     * @param array $headers
26
     * @param array $params
27
     * @param array $options
28
     * @return JCResponse
29
     */
30
    public static function get($url, $params = [], $headers = [], $options = [])
31
    {
32
        return static::request(Method::GET, static::manipulateUrl($url, $params), [
33
            'headers' => $headers
34
        ]);
35
    }
36
37
    public static function post($url, $params = [], $headers = [], $options = [])
38
    {
39
        return static::request(Method::POST, $url, [
40
            'headers' => $headers,
41
            'form_params' => $params
42
        ]);
43
    }
44
45
    public static function put($url, $params, $headers, $options)
46
    {
47
        // TODO: Implement put() method.
48
    }
49
50
    public static function patch($url, $params, $headers, $options)
51
    {
52
        // TODO: Implement patch() method.
53
    }
54
55
    public static function head($url, $params, $headers, $options)
56
    {
57
        // TODO: Implement head() method.
58
    }
59
60
    public static function delete($url, $params, $headers, $options)
61
    {
62
        // TODO: Implement delete() method.
63
    }
64
65
66
    /**
67
     * @param string $url
68
     * @param array $params
69
     * @return string
70
     */
71
    protected static function manipulateUrl($url, $params = [])
72
    {
73
        $urlObject = Url::parse($url);
74
        $queryData = array_merge($urlObject->query->getData(), $params);
75
        $urlObject->query->setData($queryData);
76
77
        return $urlObject->getUrl();
78
    }
79
}