Skip to content

Commit 6c2ba4b

Browse files
authored
Merge pull request #26 from modder2/feature/add-advertiser-campaign-statistics-method
Add advertiser statistics by campaign method. Fixed unit tests.
2 parents cea459a + 5e90fe7 commit 6c2ba4b

9 files changed

Lines changed: 203 additions & 77 deletions

File tree

lib/Exads/Api/Campaign.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,9 @@ public function restore(array $data = [])
147147
return $this->put($path, $data);
148148
}
149149

150-
/*
151-
* Add new targeted/blocked element to a campaign
150+
/**
151+
* Add new targeted/blocked element to a campaign.
152+
*
152153
* @param string $elementType [browsers|carriers|categories|countries|devices|languages|operating_systems|sites|keywords|ip_ranges]
153154
* @param string $id
154155
* @param string $type [targeted|blocked]
@@ -163,14 +164,15 @@ public function addElement($elementType, $id, $type, array $data = array())
163164
return $this->post($path, $data);
164165
}
165166

166-
/*
167-
* Replace targeted/blocked element from a campaign
167+
/**
168+
* Replace targeted/blocked element from a campaign.
169+
*
168170
* @param string $elementType [browsers|carriers|categories|countries|devices|languages|operating_systems|sites|keywords|ip_ranges]
169171
* @param string $id
170172
* @param string $type [targeted|blocked]
171173
* @param array $data
172174
*
173-
* @return array
175+
* @return boolean
174176
*/
175177
public function replaceElement($elementType, $id, $type, array $data = array())
176178
{
@@ -179,8 +181,9 @@ public function replaceElement($elementType, $id, $type, array $data = array())
179181
return $this->put($path, $data);
180182
}
181183

182-
/*
183-
* Remove targeted/blocked element from a campaign
184+
/**
185+
* Remove targeted/blocked element from a campaign.
186+
*
184187
* @param string $elementType [browsers|carriers|categories|countries|devices|languages|operating_systems|sites|keywords|ip_ranges]
185188
* @param string $id
186189
* @param string $type [targeted|blocked]
@@ -195,8 +198,9 @@ public function removeElement($elementType, $id, $type, array $data = array())
195198
return $this->delete($path, $data);
196199
}
197200

198-
/*
199-
* Remove all targeted/blocked elements from a campaign
201+
/**
202+
* Remove all targeted/blocked elements from a campaign.
203+
*
200204
* @param string $elementType [browsers|carriers|categories|countries|devices|languages|operating_systems|sites|keywords|ip_ranges]/all
201205
* @param string $id
202206
* @param string $type [targeted|blocked]

lib/Exads/Api/StatisticsAdvertiser.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class StatisticsAdvertiser extends AbstractStatistics
1010
protected $subGroup = 'advertiser';
1111

1212
/**
13+
* Get advertiser statistics by variation.
14+
*
1315
* @param array $params
1416
*
1517
* @return array
@@ -18,4 +20,16 @@ public function variation(array $params = array())
1820
{
1921
return $this->get($this->getPath('variation'), $params);
2022
}
23+
24+
/**
25+
* Get advertiser statistics by campaign.
26+
*
27+
* @param array $params
28+
*
29+
* @return array
30+
*/
31+
public function campaign(array $params = array())
32+
{
33+
return $this->get($this->getPath('campaign'), $params);
34+
}
2135
}

lib/Exads/Client.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@
88
* Simple PHP Exads client.
99
*
1010
* @link http://github.com/exads/php-exads-api
11+
*
12+
* @property-read Api\Campaign $campaigns
13+
* @property-read Api\Login $login
14+
* @property-read Api\Collection $collections
15+
* @property-read Api\PaymentAdvertiser $payments_advertiser
16+
* @property-read Api\PaymentPublisher $payments_publisher
17+
* @property-read Api\Site $sites
18+
* @property-read Api\StatisticsAdvertiser $statistics_advertiser
19+
* @property-read Api\StatisticsPublisher $statistics_publisher
20+
* @property-read Api\User $user
21+
* @property-read Api\Zone $zones
1122
*/
1223
class Client implements ClientInterface
1324
{
@@ -161,7 +172,7 @@ public function setUrl($url)
161172
* @param array $params
162173
* @param bool $decode
163174
*
164-
* @return array
175+
* @return array|string
165176
*/
166177
public function get($path, array $params = array(), $decode = true)
167178
{
@@ -212,7 +223,7 @@ public function decode($json)
212223
* @param mixed $data
213224
* @param array $headers
214225
*
215-
* @return mixed
226+
* @return bool|string
216227
*/
217228
public function post($path, $data = null, $headers = [])
218229
{
@@ -229,7 +240,7 @@ public function post($path, $data = null, $headers = [])
229240
* @param string $path
230241
* @param mixed $data
231242
*
232-
* @return array
243+
* @return bool|string
233244
*/
234245
public function put($path, $data = null)
235246
{
@@ -244,7 +255,7 @@ public function put($path, $data = null)
244255
* @param string $path
245256
* @param mixed $data
246257
*
247-
* @return array
258+
* @return bool|string
248259
*/
249260
public function delete($path, $data = null)
250261
{
@@ -359,12 +370,12 @@ public function getApiToken()
359370
/**
360371
* @param string $path
361372
* @param string $method
362-
* @param string $data
373+
* @param string|array $data
363374
* @param array $headers
364375
*
365376
* @throws \Exception If anything goes wrong on curl request
366377
*
367-
* @return bool|SimpleXMLElement|string
378+
* @return bool|string
368379
*/
369380
protected function runRequest($path, $method = 'GET', $data = '', $headers = [])
370381
{

lib/Exads/TestClient.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ class TestClient extends Client
77
/**
88
* @param string $path
99
* @param string $method
10-
* @param string $data
10+
* @param string|array $data
11+
* @param array $headers
1112
*
1213
* @throws \Exception always!
1314
*
1415
* @return string
1516
*/
16-
protected function runRequest($path, $method = 'GET', $data = '')
17+
protected function runRequest($path, $method = 'GET', $data = '', $headers = [])
1718
{
1819
throw new \Exception('not available');
1920
}

lib/Exads/TestUrlClient.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class TestUrlClient extends Client
66
{
77
/**
88
* @param string $path
9+
* @param array $params
910
* @param bool $decode
1011
*
1112
* @return array
@@ -22,17 +23,32 @@ public function get($path, array $params = array(), $decode = true)
2223
/**
2324
* @param string $path
2425
* @param string $method
25-
* @param string $data
26+
* @param string|array $data
27+
* @param array $headers
2628
*
2729
* @throws \Exception If anything goes wrong on curl request
2830
*
29-
* @return string
31+
* @return array
3032
*/
31-
protected function runRequest($path, $method = 'GET', $data = '')
33+
protected function runRequest($path, $method = 'GET', $data = '', $headers = [])
3234
{
33-
return array(
35+
$result = array(
3436
'method' => $method,
3537
'path' => $path,
3638
);
39+
40+
// Try decode data
41+
if (is_string($data)) {
42+
$decoded = json_decode($data, true);
43+
if (JSON_ERROR_NONE === json_last_error()) {
44+
$data = $decoded;
45+
}
46+
}
47+
// Add data element only if it present
48+
if ($data) {
49+
$result['data'] = $data;
50+
}
51+
52+
return $result;
3753
}
3854
}

test/Exads/Tests/ClientTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
use Exads\Client;
66
use Exads\ClientInterface;
7-
use Exads\Exception\InvalidArgumentException;
7+
use InvalidArgumentException;
88

99
class ClientTest extends \PHPUnit_Framework_TestCase
1010
{
1111
/**
12-
* @covers Exads\Client
12+
* @covers \Exads\Client
1313
* @test
1414
*/
1515
public function should_instanciate_client_class()
@@ -19,7 +19,7 @@ public function should_instanciate_client_class()
1919
}
2020

2121
/**
22-
* @covers Exads\Client
22+
* @covers \Exads\Client
2323
* @test
2424
* @expectedException InvalidArgumentException
2525
*/
@@ -30,7 +30,7 @@ public function should_not_get_api_instance()
3030
}
3131

3232
/**
33-
* @covers Exads\Client
33+
* @covers \Exads\Client
3434
* @test
3535
*/
3636
public function should_return_api_url()
@@ -40,7 +40,7 @@ public function should_return_api_url()
4040
}
4141

4242
/**
43-
* @covers Exads\Client
43+
* @covers \Exads\Client
4444
* @test
4545
*/
4646
public function should_find_correct_port()
@@ -53,7 +53,7 @@ public function should_find_correct_port()
5353
}
5454

5555
/**
56-
* @covers Exads\Client
56+
* @covers \Exads\Client
5757
* @test
5858
*/
5959
public function should_update_port()
@@ -64,7 +64,7 @@ public function should_update_port()
6464
}
6565

6666
/**
67-
* @covers Exads\Client
67+
* @covers \Exads\Client
6868
* @test
6969
*/
7070
public function response_should_be_0_by_default()
@@ -74,7 +74,7 @@ public function response_should_be_0_by_default()
7474
}
7575

7676
/**
77-
* @covers Exads\Client
77+
* @covers \Exads\Client
7878
* @test
7979
*/
8080
public function should_decode_valid_json()
@@ -91,7 +91,7 @@ public function should_decode_valid_json()
9191
}
9292

9393
/**
94-
* @covers Exads\Client
94+
* @covers \Exads\Client
9595
* @test
9696
*/
9797
public function test_empty_json_decode()
@@ -104,7 +104,7 @@ public function test_empty_json_decode()
104104
}
105105

106106
/**
107-
* @covers Exads\Client
107+
* @covers \Exads\Client
108108
* @test
109109
*/
110110
public function test_malformed_json_should_return_error()
@@ -121,7 +121,7 @@ public function test_malformed_json_should_return_error()
121121
}
122122

123123
/**
124-
* @covers Exads\Client
124+
* @covers \Exads\Client
125125
* @test
126126
* @dataProvider getApiClassesProvider
127127
*/

test/Exads/Tests/TestClientTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
namespace Exads\Tests;
44

55
use Exads\TestClient;
6+
use Exception;
67

78
class TestClientTest extends \PHPUnit_Framework_TestCase
89
{
910
/**
10-
* @covers Exads\TestClient
11+
* @covers \Exads\TestClient
1112
* @test
1213
* @expectedException Exception
1314
*/
@@ -18,7 +19,7 @@ public function test_get_method_not_available()
1819
}
1920

2021
/**
21-
* @covers Exads\TestClient
22+
* @covers \Exads\TestClient
2223
* @test
2324
* @expectedException Exception
2425
*/
@@ -29,18 +30,18 @@ public function test_delete_method_not_available()
2930
}
3031

3132
/**
32-
* @covers Exads\TestClient
33+
* @covers \Exads\TestClient
3334
* @test
3435
* @expectedException Exception
3536
*/
3637
public function test_post_method_not_available()
3738
{
3839
$client = new TestClient('http://localhost');
39-
$res = $client->post('does_not_exist', 'POST method not available');
40+
$client->post('does_not_exist', 'POST method not available');
4041
}
4142

4243
/**
43-
* @covers Exads\TestClient
44+
* @covers \Exads\TestClient
4445
* @test
4546
* @expectedException Exception
4647
*/

test/Exads/Tests/TestUrlClientTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class TestUrlClientTest extends \PHPUnit_Framework_TestCase
88
{
99
/**
10-
* @covers Exads\TestUrlClient
10+
* @covers \Exads\TestUrlClient
1111
* @test
1212
*/
1313
public function test_get_returns_path_and_method()
@@ -18,7 +18,7 @@ public function test_get_returns_path_and_method()
1818
}
1919

2020
/**
21-
* @covers Exads\TestUrlClient
21+
* @covers \Exads\TestUrlClient
2222
* @test
2323
*/
2424
public function test_delete_returns_path_and_method()
@@ -29,7 +29,7 @@ public function test_delete_returns_path_and_method()
2929
}
3030

3131
/**
32-
* @covers Exads\TestUrlClient
32+
* @covers \Exads\TestUrlClient
3333
* @test
3434
*/
3535
public function test_post_returns_path_and_method()
@@ -43,7 +43,7 @@ public function test_post_returns_path_and_method()
4343
}
4444

4545
/**
46-
* @covers Exads\TestUrlClient
46+
* @covers \Exads\TestUrlClient
4747
* @test
4848
*/
4949
public function test_put_returns_path_and_method()

0 commit comments

Comments
 (0)