Skip to content

Commit dec4d4e

Browse files
added market book price projections
1 parent f822d42 commit dec4d4e

12 files changed

+87
-408
lines changed

src/Betfair/AbstractBetfair.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ public function getAll($method)
8282
return $this->adapter->adaptResponse($response);
8383
}
8484

85-
public function executeCustomQuery(ParamInterface $param, $method)
85+
public function executeCustomQuery(ParamInterface $param, $method = null)
8686
{
87+
$method = $method !== null ? $method : $this::METHOD;
8788
$response = $this->doSportApiNgRequest($method, json_encode($param));
8889
return $this->adapter->adaptResponse($response);
8990
}

src/Betfair/Client/BetfairClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ class BetfairClient implements BetfairClientInterface
2121
/** @var BetfairJsonRpcClientInterface */
2222
protected $httpClient;
2323

24-
public function __construct(CredentialInterface $credential, BetfairJsonRpcClientInterface $httpClientInterface)
24+
public function __construct(CredentialInterface $credential, BetfairJsonRpcClientInterface $httpClientInterface = null)
2525
{
2626
$this->credential = $credential;
27-
$this->httpClient = $httpClientInterface;
27+
$this->httpClient = $httpClientInterface !== null ? $httpClientInterface : new JsonRpcClient();
2828

2929
}
3030

src/Betfair/Model/Param.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ public function getMarketProjection()
5757

5858

5959
/**
60-
* @param MarketFilter $filter
60+
* @param MarketFilterInterface $filter
6161
*/
62-
public function setFilter(MarketFilter $filter)
62+
public function setFilter(MarketFilterInterface $filter)
6363
{
6464
$this->filter = $filter;
6565
}

src/Betfair/Model/ParamInterface.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@
1212

1313
interface ParamInterface
1414
{
15-
public function getFilter();
16-
public function getMaxResults();
15+
public function jsonSerialize();
1716
}

src/Betfair/Model/ParamMarketBook.php

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
<?php
2-
/**
3-
* Created by PhpStorm.
4-
* User: danieledangeli
5-
* Date: 5/5/14
6-
* Time: 5:04 AM
7-
*/
82

93
namespace Betfair\Model;
104

11-
12-
class ParamMarketBook extends BetfairSerializable
5+
class ParamMarketBook extends BetfairSerializable implements ParamInterface
136
{
147
/** @var array */
158
protected $marketIds;
169

10+
protected $priceProjection;
11+
1712
/**
1813
* @param array $marketIds
1914
*/
@@ -30,4 +25,51 @@ public function getMarketIds()
3025
return $this->marketIds;
3126
}
3227

28+
public function addPriceProjection($priceProjection)
29+
{
30+
$this->priceProjection[] = $priceProjection;
31+
}
32+
33+
/**
34+
* @param mixed $priceProjection
35+
*/
36+
public function setPriceProjection($priceProjection)
37+
{
38+
$this->priceProjection = $priceProjection;
39+
}
40+
41+
/**
42+
* @return mixed
43+
*/
44+
public function getPriceProjection()
45+
{
46+
return $this->priceProjection;
47+
}
48+
49+
/**
50+
* (PHP 5 &gt;= 5.4.0)<br/>
51+
* Specify data which should be serialized to JSON
52+
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
53+
* @return mixed data which can be serialized by <b>json_encode</b>,
54+
* which is a value of any type other than a resource.
55+
*/
56+
public function jsonSerialize()
57+
{
58+
$array = array();
59+
$properties = get_object_vars($this);
60+
foreach($properties as $key => $value) {
61+
if(null !== $value) {
62+
if($key == 'priceProjection') {
63+
$priceProjections = new \stdClass;
64+
$priceProjections->priceData = $value;
65+
$array[$key] = $priceProjections;
66+
} else {
67+
$array[$key] = $value;
68+
}
69+
}
70+
71+
}
72+
73+
return $array;
74+
}
3375
}

src/Betfair/Model/PriceProjection.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* This file is part of the Betfair library.
4+
*
5+
* (c) Daniele D'Angeli <dangeli88.daniele@gmail.com>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace Betfair\Model;
11+
12+
abstract class PriceProjection
13+
{
14+
const SP_AVAILABLE = "SP_AVAILABLE";
15+
const SP_TRADED = "SP_TRADED";
16+
const EX_BEST_OFFERS = "EX_BEST_OFFERS";
17+
const EX_ALL_OFFERS = "EX_ALL_OFFERS";
18+
const EX_TRADED = "EX_TRADED";
19+
20+
public static function getAll()
21+
{
22+
return array(
23+
self::SP_AVAILABLE,
24+
self::SP_TRADED,
25+
self::EX_BEST_OFFERS,
26+
self::EX_ALL_OFFERS,
27+
self::EX_TRADED,
28+
);
29+
}
30+
}

src/examples/Adapter/CustomAdapter.php

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)