Completed
Push — master ( 152a1e...ef5096 )
by Peter
02:22
created

Betting   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 10
Bugs 0 Features 3
Metric Value
wmc 11
c 10
b 0
f 3
lcom 1
cbo 1
dl 0
loc 108
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A listMarketcatalogue() 0 14 1
A listMarketBook() 0 15 1
A listTimeRanges() 0 11 1
A listMarketProfitAndLoss() 0 13 1
A listCurrentOrders() 0 16 1
A __call() 0 17 4
1
<?php
2
3
namespace PeterColes\Betfair\Api;
4
5
use PeterColes\Betfair\Http\Client as HttpClient;
6
7
class Betting
8
{
9
    const ENDPOINT = 'https://api.betfair.com/exchange/betting/rest/v1.0/';
10
11
    protected $httpClient;
12
13
    public function __construct(HttpClient $httpClient = null)
14
    {
15
        $this->httpClient = $httpClient ?: new HttpClient;
16
    }
17
18
    public function listMarketcatalogue($filter = [ ], $marketProjection = [ ], $sort = null, $maxResults = 100, $locale = null)
19
    {
20
        return $this->httpClient
21
            ->setMethod('post')
22
            ->setEndPoint(self::ENDPOINT.'listMarketCatalogue/')
23
            ->authHeaders()
24
            ->addHeader([ 'Content-Type' => 'application/json' ])
25
            ->setFilter($filter)
26
            ->setProjection('marketProjection', $marketProjection)
27
            ->setSort($sort)
28
            ->setMaxResults($maxResults)
29
            ->setLocale($locale)
30
            ->send();
31
    }
32
33
    public function listMarketBook($marketIds = [ ], $priceProjection = null, $orderProjection = null, $matchProjection = null, $currencyCode = null, $locale = null)
34
    {
35
        return $this->httpClient
36
            ->setMethod('post')
37
            ->setEndPoint(self::ENDPOINT.'listMarketBook/')
38
            ->authHeaders()
39
            ->addHeader([ 'Content-Type' => 'application/json' ])
40
            ->setMarketIds($marketIds, true)
41
            ->setProjection('priceProjection', $priceProjection)
42
            ->setProjection('orderProjection', $orderProjection)
43
            ->setProjection('matchProjection', $matchProjection)
44
            ->setCurrencyCode($currencyCode)
45
            ->setLocale($locale)
46
            ->send();
47
    }
48
49
    public function listMarketProfitAndLoss($marketIds = [ ], $includeSettledBets = false, $includeBspBets = false, $netOfCommission = false)
50
    {
51
        return $this->httpClient
52
            ->setMethod('post')
53
            ->setEndPoint(self::ENDPOINT.'listMarketProfitAndLoss/')
54
            ->authHeaders()
55
            ->addHeader([ 'Content-Type' => 'application/json' ])
56
            ->setMarketIds($marketIds, true)
57
            ->setFlag('includeSettledBets', $includeSettledBets)
58
            ->setFlag('includeBspBets', $includeBspBets)
59
            ->setFlag('netOfCommission', $netOfCommission)
60
            ->send();
61
    }
62
63
    public function listTimeRanges($marketFilter, $timeGranularity)
64
    {
65
        return $this->httpClient
66
            ->setMethod('post')
67
            ->setEndPoint(self::ENDPOINT.'listTimeRanges/')
68
            ->authHeaders()
69
            ->addHeader([ 'Content-Type' => 'application/json' ])
70
            ->setFilter($marketFilter)
71
            ->setTimeGranularity($timeGranularity)
72
            ->send();
73
    }
74
75
    public function listCurrentOrders($betIds = null, $marketIds = null, $orderProjection = null, $placedDateRange = null, $dateRange = null, $orderBy = null, $sortDir = null, $fromRecord = null, $recordCount = null)
76
    {
77
        return $this->httpClient
78
            ->setMethod('post')
79
            ->setEndPoint(self::ENDPOINT.'listCurrentOrders/')
80
            ->authHeaders()
81
            ->addHeader([ 'Content-Type' => 'application/json' ])
82
            ->setBetIds($betIds)
83
            ->setMarketIds($marketIds)
84
            ->setProjection('orderProjection' , $orderProjection)
85
            ->setDateRange('placedDateRange', $placedDateRange)
86
            ->setDateRange('dateRange', $dateRange)
87
            ->setOrder($orderBy, $sortDir)
88
            ->setRecordRange($fromRecord, $recordCount)
89
            ->send();
90
    }
91
92
    /**
93
     * Six Exchange methods have an identical API, so we bundle them into a single magic call e.g.
94
     * @method listCompetitions(array $filters, string $locale)
95
     * @return array
96
     */
97
    public function __call($method, $params)
98
    {
99
        if (in_array($method, [ 'listCompetitions', 'listCountries', 'listEvents', 'listEventTypes', 'listMarketTypes', 'listVenues' ])) {
100
101
            $filter = isset($params[ 0 ]) ? $params[ 0 ] : [ ];
102
            $locale = isset($params[ 1 ]) ? $params[ 1 ] : [ ];
103
104
            return $this->httpClient
105
                ->setMethod('post')
106
                ->setEndPoint(self::ENDPOINT.$method.'/')
107
                ->authHeaders()
108
                ->addHeader([ 'Content-Type' => 'application/json' ])
109
                ->setFilter($filter)
110
                ->setLocale($locale)
111
                ->send();
112
        }
113
    }
114
}
115