Completed
Push — master ( 1b0622...b59bdb )
by François
01:52
created

WordpressClient   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 36
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 13 2
A post() 0 15 2
1
<?php
2
3
/*
4
 * This file is part of the Bouncer package.
5
 *
6
 * (c) François Hodierne <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Bouncer\Http;
13
14
class WordpressClient
15
{
16
17
    protected $timeout = 2;
18
19
    public function get($url)
20
    {
21
        $response = wp_remote_get($url, array(
22
            'headers' => array(
23
                'Accept: application/json',
24
            ),
25
            'timeout' => $this->timeout,
26
        ));
27
        if (is_array($response)) {
28
            $response = json_decode($response['body'], true);
29
            return $response;
30
        }
31
    }
32
33
    public function post($url, $data = null)
34
    {
35
        $response = wp_remote_post($url, array(
36
            'headers' => array(
37
                'Accept: application/json',
38
                'Content-Type: application/json'
39
            ),
40
            'body' => json_encode($data),
41
            'timeout' => $this->timeout,
42
        ));
43
        if (is_array($response)) {
44
            $response = json_decode($response['body'], true);
45
            return $response;
46
        }
47
    }
48
49
}
50