Completed
Push — master ( dfec85...be4840 )
by Peter
02:18
created

BaseApi::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 2
eloc 2
nc 2
nop 1
1
<?php
2
3
namespace PeterColes\Betfair\Api;
4
5
use PeterColes\Betfair\Http\Client as HttpClient;
6
7
abstract class BaseApi
8
{
9
    protected $httpClient;
10
11
    protected $method;
12
13
    public function __construct(HttpClient $httpClient = null)
14
    {
15
        $this->httpClient = $httpClient ?: new HttpClient;
16
    }
17
18
    public function execute($params)
19
    {
20
        $this->method = array_shift($params);
21
22
        return $this->httpClient
23
            ->setMethod('post')
24
            ->setEndPoint(static::ENDPOINT.$this->method.'/')
25
            ->authHeaders()
26
            ->addHeader([ 'Content-Type' => 'application/json' ])
27
            ->setParams($this->prepare($params))
28
            ->send();
29
    }
30
31
    protected function prepare($params)
32
    {
33
        return !empty($params) ? $params[ 0 ] : null;
34
    }
35
}
36