Skip to content

Commit

Permalink
Merge pull request #26 from modder2/feature/add-advertiser-campaign-s…
Browse files Browse the repository at this point in the history
…tatistics-method

Add advertiser statistics by campaign method. Fixed unit tests.
  • Loading branch information
golikov authored Apr 15, 2019
2 parents cea459a + 5e90fe7 commit 6c2ba4b
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 77 deletions.
22 changes: 13 additions & 9 deletions lib/Exads/Api/Campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,9 @@ public function restore(array $data = [])
return $this->put($path, $data);
}

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

/*
* Replace targeted/blocked element from a campaign
/**
* Replace targeted/blocked element from a campaign.
*
* @param string $elementType [browsers|carriers|categories|countries|devices|languages|operating_systems|sites|keywords|ip_ranges]
* @param string $id
* @param string $type [targeted|blocked]
* @param array $data
*
* @return array
* @return boolean
*/
public function replaceElement($elementType, $id, $type, array $data = array())
{
Expand All @@ -179,8 +181,9 @@ public function replaceElement($elementType, $id, $type, array $data = array())
return $this->put($path, $data);
}

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

/*
* Remove all targeted/blocked elements from a campaign
/**
* Remove all targeted/blocked elements from a campaign.
*
* @param string $elementType [browsers|carriers|categories|countries|devices|languages|operating_systems|sites|keywords|ip_ranges]/all
* @param string $id
* @param string $type [targeted|blocked]
Expand Down
14 changes: 14 additions & 0 deletions lib/Exads/Api/StatisticsAdvertiser.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class StatisticsAdvertiser extends AbstractStatistics
protected $subGroup = 'advertiser';

/**
* Get advertiser statistics by variation.
*
* @param array $params
*
* @return array
Expand All @@ -18,4 +20,16 @@ public function variation(array $params = array())
{
return $this->get($this->getPath('variation'), $params);
}

/**
* Get advertiser statistics by campaign.
*
* @param array $params
*
* @return array
*/
public function campaign(array $params = array())
{
return $this->get($this->getPath('campaign'), $params);
}
}
23 changes: 17 additions & 6 deletions lib/Exads/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@
* Simple PHP Exads client.
*
* @link http://github.com/exads/php-exads-api
*
* @property-read Api\Campaign $campaigns
* @property-read Api\Login $login
* @property-read Api\Collection $collections
* @property-read Api\PaymentAdvertiser $payments_advertiser
* @property-read Api\PaymentPublisher $payments_publisher
* @property-read Api\Site $sites
* @property-read Api\StatisticsAdvertiser $statistics_advertiser
* @property-read Api\StatisticsPublisher $statistics_publisher
* @property-read Api\User $user
* @property-read Api\Zone $zones
*/
class Client implements ClientInterface
{
Expand Down Expand Up @@ -161,7 +172,7 @@ public function setUrl($url)
* @param array $params
* @param bool $decode
*
* @return array
* @return array|string
*/
public function get($path, array $params = array(), $decode = true)
{
Expand Down Expand Up @@ -212,7 +223,7 @@ public function decode($json)
* @param mixed $data
* @param array $headers
*
* @return mixed
* @return bool|string
*/
public function post($path, $data = null, $headers = [])
{
Expand All @@ -229,7 +240,7 @@ public function post($path, $data = null, $headers = [])
* @param string $path
* @param mixed $data
*
* @return array
* @return bool|string
*/
public function put($path, $data = null)
{
Expand All @@ -244,7 +255,7 @@ public function put($path, $data = null)
* @param string $path
* @param mixed $data
*
* @return array
* @return bool|string
*/
public function delete($path, $data = null)
{
Expand Down Expand Up @@ -359,12 +370,12 @@ public function getApiToken()
/**
* @param string $path
* @param string $method
* @param string $data
* @param string|array $data
* @param array $headers
*
* @throws \Exception If anything goes wrong on curl request
*
* @return bool|SimpleXMLElement|string
* @return bool|string
*/
protected function runRequest($path, $method = 'GET', $data = '', $headers = [])
{
Expand Down
5 changes: 3 additions & 2 deletions lib/Exads/TestClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ class TestClient extends Client
/**
* @param string $path
* @param string $method
* @param string $data
* @param string|array $data
* @param array $headers
*
* @throws \Exception always!
*
* @return string
*/
protected function runRequest($path, $method = 'GET', $data = '')
protected function runRequest($path, $method = 'GET', $data = '', $headers = [])
{
throw new \Exception('not available');
}
Expand Down
24 changes: 20 additions & 4 deletions lib/Exads/TestUrlClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class TestUrlClient extends Client
{
/**
* @param string $path
* @param array $params
* @param bool $decode
*
* @return array
Expand All @@ -22,17 +23,32 @@ public function get($path, array $params = array(), $decode = true)
/**
* @param string $path
* @param string $method
* @param string $data
* @param string|array $data
* @param array $headers
*
* @throws \Exception If anything goes wrong on curl request
*
* @return string
* @return array
*/
protected function runRequest($path, $method = 'GET', $data = '')
protected function runRequest($path, $method = 'GET', $data = '', $headers = [])
{
return array(
$result = array(
'method' => $method,
'path' => $path,
);

// Try decode data
if (is_string($data)) {
$decoded = json_decode($data, true);
if (JSON_ERROR_NONE === json_last_error()) {
$data = $decoded;
}
}
// Add data element only if it present
if ($data) {
$result['data'] = $data;
}

return $result;
}
}
22 changes: 11 additions & 11 deletions test/Exads/Tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

use Exads\Client;
use Exads\ClientInterface;
use Exads\Exception\InvalidArgumentException;
use InvalidArgumentException;

class ClientTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers Exads\Client
* @covers \Exads\Client
* @test
*/
public function should_instanciate_client_class()
Expand All @@ -19,7 +19,7 @@ public function should_instanciate_client_class()
}

/**
* @covers Exads\Client
* @covers \Exads\Client
* @test
* @expectedException InvalidArgumentException
*/
Expand All @@ -30,7 +30,7 @@ public function should_not_get_api_instance()
}

/**
* @covers Exads\Client
* @covers \Exads\Client
* @test
*/
public function should_return_api_url()
Expand All @@ -40,7 +40,7 @@ public function should_return_api_url()
}

/**
* @covers Exads\Client
* @covers \Exads\Client
* @test
*/
public function should_find_correct_port()
Expand All @@ -53,7 +53,7 @@ public function should_find_correct_port()
}

/**
* @covers Exads\Client
* @covers \Exads\Client
* @test
*/
public function should_update_port()
Expand All @@ -64,7 +64,7 @@ public function should_update_port()
}

/**
* @covers Exads\Client
* @covers \Exads\Client
* @test
*/
public function response_should_be_0_by_default()
Expand All @@ -74,7 +74,7 @@ public function response_should_be_0_by_default()
}

/**
* @covers Exads\Client
* @covers \Exads\Client
* @test
*/
public function should_decode_valid_json()
Expand All @@ -91,7 +91,7 @@ public function should_decode_valid_json()
}

/**
* @covers Exads\Client
* @covers \Exads\Client
* @test
*/
public function test_empty_json_decode()
Expand All @@ -104,7 +104,7 @@ public function test_empty_json_decode()
}

/**
* @covers Exads\Client
* @covers \Exads\Client
* @test
*/
public function test_malformed_json_should_return_error()
Expand All @@ -121,7 +121,7 @@ public function test_malformed_json_should_return_error()
}

/**
* @covers Exads\Client
* @covers \Exads\Client
* @test
* @dataProvider getApiClassesProvider
*/
Expand Down
11 changes: 6 additions & 5 deletions test/Exads/Tests/TestClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
namespace Exads\Tests;

use Exads\TestClient;
use Exception;

class TestClientTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers Exads\TestClient
* @covers \Exads\TestClient
* @test
* @expectedException Exception
*/
Expand All @@ -18,7 +19,7 @@ public function test_get_method_not_available()
}

/**
* @covers Exads\TestClient
* @covers \Exads\TestClient
* @test
* @expectedException Exception
*/
Expand All @@ -29,18 +30,18 @@ public function test_delete_method_not_available()
}

/**
* @covers Exads\TestClient
* @covers \Exads\TestClient
* @test
* @expectedException Exception
*/
public function test_post_method_not_available()
{
$client = new TestClient('http://localhost');
$res = $client->post('does_not_exist', 'POST method not available');
$client->post('does_not_exist', 'POST method not available');
}

/**
* @covers Exads\TestClient
* @covers \Exads\TestClient
* @test
* @expectedException Exception
*/
Expand Down
8 changes: 4 additions & 4 deletions test/Exads/Tests/TestUrlClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class TestUrlClientTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers Exads\TestUrlClient
* @covers \Exads\TestUrlClient
* @test
*/
public function test_get_returns_path_and_method()
Expand All @@ -18,7 +18,7 @@ public function test_get_returns_path_and_method()
}

/**
* @covers Exads\TestUrlClient
* @covers \Exads\TestUrlClient
* @test
*/
public function test_delete_returns_path_and_method()
Expand All @@ -29,7 +29,7 @@ public function test_delete_returns_path_and_method()
}

/**
* @covers Exads\TestUrlClient
* @covers \Exads\TestUrlClient
* @test
*/
public function test_post_returns_path_and_method()
Expand All @@ -43,7 +43,7 @@ public function test_post_returns_path_and_method()
}

/**
* @covers Exads\TestUrlClient
* @covers \Exads\TestUrlClient
* @test
*/
public function test_put_returns_path_and_method()
Expand Down
Loading

0 comments on commit 6c2ba4b

Please sign in to comment.