Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ See Exads API's documentation.

## Features

* Follows PSR-0 conventions and coding standard: autoload friendly
* Follows PSR-2 conventions and coding standard: autoload friendly
* API entry points implementation state :
* Campaign
* Collection
Expand Down
2 changes: 1 addition & 1 deletion lib/Exads/Api/AbstractPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Exads\Api;

/**
* @link https://api.exads.com/v2/docs/index.html#!/payments
* @link https://api.exoclick.com/v2/docs/index.html#!/47payments
*/
class AbstractPayment extends AbstractApi
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Exads/Api/AbstractStatistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Exads\Api;

/**
* @link https://api.exads.com/v2/docs/index.html#!/statistics
* @link https://api.exoclick.com/v2/docs/index.html#!/47statistics
*/
abstract class AbstractStatistics extends AbstractApi
{
Expand Down
37 changes: 18 additions & 19 deletions lib/Exads/Api/Campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Exads\Api;

/**
* @link https://api.exads.com/v2/docs/index.html#!/campaigns
* @link https://api.exoclick.com/v2/docs/index.html#!/47campaigns
*/
class Campaign extends AbstractApi
{
Expand Down Expand Up @@ -249,16 +249,21 @@ protected function getPath($endPoint = null, $id = null, $type = null)
);

if (null !== $type) {
// add targeted/blocked elements routes
$elementTypes = $this->getElementTypes($endPoint);
foreach ($elementTypes as $elementType) {
$pathMapping[$elementType] = '%s/%s/%s/'.$elementType;
if ('countries' === $elementType) {
continue;
}
$pathMapping[$elementType.'_all'] = '%s/%s/%s/'.$elementType.'/all';

$realEndPoint = preg_replace('/_(all)$/', '/$1', $endPoint);

if (in_array($realEndPoint, array('countries/all', 'categories/all'))) {
throw new \InvalidArgumentException("$realEndPoint does not exist");
} elseif (in_array($realEndPoint, array('countries', 'categories')) && $type == 'blocked') {
throw new \InvalidArgumentException("$realEndPoint does not support type $type");
} elseif (!in_array($type, array('blocked', 'targeted'))) {
throw new \InvalidArgumentException("Unsupported type $type");
} else {
return sprintf('%s/%s/%s/'.$realEndPoint, $this->apiGroup, urlencode($id), urlencode($type));
}
}

if (!isset($pathMapping[$endPoint])) {
throw new \InvalidArgumentException('Non existing path');
}
Expand All @@ -267,11 +272,7 @@ protected function getPath($endPoint = null, $id = null, $type = null)
if (null === $id) {
return sprintf($path, $this->apiGroup);
}
if (null === $type) {
return sprintf($path, $this->apiGroup, urlencode($id));
}

return sprintf($path, $this->apiGroup, urlencode($id), urlencode($type));
return sprintf($path, $this->apiGroup, urlencode($id));
}

/**
Expand All @@ -283,6 +284,8 @@ protected function getPath($endPoint = null, $id = null, $type = null)
*/
private function getElementTypes($type)
{
$type = preg_replace('/_all$/', '', $type);

$elementTypes = array(
'browsers',
'carriers',
Expand All @@ -297,14 +300,10 @@ private function getElementTypes($type)
);

// validate elementType
$tmp = $elementTypes;
foreach ($tmp as $type) {
$tmp[] = $type.'_all';
}
if (!in_array($type, $tmp, true)) {
if (!in_array($type, $elementTypes, true)) {
throw new \InvalidArgumentException(
sprintf(
'Unknown element type "%s". Availabe types : %s',
'Unknown element type "%s". Available types : %s',
$type,
implode(', ', $elementTypes)
)
Expand Down
2 changes: 1 addition & 1 deletion lib/Exads/Api/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Exads\Api;

/**
* @link https://api.exads.com/v2/docs/index.html#!/collections
* @link https://api.exoclick.com/v2/docs/index.html#!/47collections
*/
class Collection extends AbstractApi
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Exads/Api/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Exads\Api;

/**
* @link https://api.exads.com/v2/docs/index.html#!/login
* @link https://api.exoclick.com/v2/docs/index.html#!/47login
*/
class Login extends AbstractApi
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Exads/Api/Offer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Exads\Api;

/**
* @link https://api.exads.com/v2/docs/index.html#!/offers
* @link https://api.exoclick.com/v2/docs/index.html#!/47offers
*/
class Offer extends AbstractApi
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Exads/Api/PaymentAdvertiser.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Exads\Api;

/**
* @link https://api.exads.com/v2/docs/index.html#!/payments
* @link https://api.exoclick.com/v2/docs/index.html#!/47payments
*/
class PaymentAdvertiser extends AbstractPayment
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Exads/Api/PaymentPublisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Exads\Api;

/**
* @link https://api.exads.com/v2/docs/index.html#!/payments
* @link https://api.exoclick.com/v2/docs/index.html#!/47payments
*/
class PaymentPublisher extends AbstractPayment
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Exads/Api/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Exads\Api;

/**
* @link https://api.exads.com/v2/docs/index.html#!/sites
* @link https://api.exoclick.com/v2/docs/index.html#!/47sites
*/
class Site extends AbstractApi
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Exads/Api/StatisticsAdvertiser.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Exads\Api;

/**
* @link https://api.exads.com/v2/docs/index.html#!/statistics
* @link https://api.exoclick.com/v2/docs/index.html#!/47statistics
*/
class StatisticsAdvertiser extends AbstractStatistics
{
Expand Down
12 changes: 1 addition & 11 deletions lib/Exads/Api/StatisticsPublisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Exads\Api;

/**
* @link https://api.exads.com/v2/docs/index.html#!/statistics
* @link https://api.exoclick.com/v2/docs/index.html#!/47statistics
*/
class StatisticsPublisher extends AbstractStatistics
{
Expand All @@ -18,14 +18,4 @@ public function sub(array $params = array())
{
return $this->get($this->getPath('sub'), $params);
}

/**
* @param array $params
*
* @return array
*/
public function zone(array $params = array())
{
return $this->get($this->getPath('zone'), $params);
}
}
2 changes: 1 addition & 1 deletion lib/Exads/Api/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Exads\Api;

/**
* @link https://api.exads.com/v2/docs/index.html#!/user
* @link https://api.exoclick.com/v2/docs/index.html#!/47user
*/
class User extends AbstractApi
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Exads/Api/Zone.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Exads\Api;

/**
* @link https://api.exads.com/v2/docs/index.html#!/zones
* @link https://api.exoclick.com/v2/docs/index.html#!/47zones
*/
class Zone extends AbstractApi
{
Expand Down
17 changes: 9 additions & 8 deletions lib/Exads/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* @property-read Api\StatisticsPublisher $statistics_publisher
* @property-read Api\User $user
* @property-read Api\Zone $zones
* @property-read Api\Offer $offers
*/
class Client implements ClientInterface
{
Expand Down Expand Up @@ -101,6 +102,7 @@ class Client implements ClientInterface
'statistics_publisher' => 'StatisticsPublisher',
'user' => 'User',
'zones' => 'Zone',
'offers' => 'Offer',
);

/**
Expand Down Expand Up @@ -227,7 +229,7 @@ public function decode($json)
*/
public function post($path, $data = null, $headers = [])
{
if ( empty($headers['Content-Type']) || $headers['Content-Type'] == 'application/json' ) {
if (empty($headers['Content-Type']) || $headers['Content-Type'] == 'application/json') {
$data = $this->encodeData($data);
}

Expand Down Expand Up @@ -397,11 +399,11 @@ protected function runRequest($path, $method = 'GET', $data = '', $headers = [])
'Content-Type: application/json'
);

if ( ! empty($headers) ) {
if (! empty($headers)) {
foreach ($headers as $key => $value) {
$existingKey = $this->array_match(sprintf("%s", $key), $requestHeader);
$existingKey = $this->arrayMatch(sprintf("%s", $key), $requestHeader);
$valueStr = sprintf("%s: %s", $key, $value);
if ( $existingKey !== false ) {
if ($existingKey !== false) {
$requestHeader[$existingKey] = $valueStr;
} else {
$requestHeader[] = $valueStr;
Expand All @@ -427,7 +429,6 @@ protected function runRequest($path, $method = 'GET', $data = '', $headers = [])
}
break;
case 'DELETE':
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
if (isset($data)) {
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
Expand Down Expand Up @@ -519,17 +520,17 @@ private function parseResponse($rawResponse, $headerSize)
* @param $haystack
* @return bool|int
*/
public function array_match($needle, $haystack)
public function arrayMatch($needle, $haystack)
{
$i = 0;
$n = count($haystack);
$key = false;
do {
if ( strpos($haystack[$i], $needle) !== false ) {
if (strpos($haystack[$i], $needle) !== false) {
$key = $i;
}
$i ++;
} while ( $key === false && $i < $n );
} while ($key === false && $i < $n);

return $key;
}
Expand Down
18 changes: 9 additions & 9 deletions test/Exads/Tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
* @covers \Exads\Client
* @test
*/
public function should_instanciate_client_class()
public function shouldInstanciateClientClass()
{
$client = new Client('http://localhost');
$this->assertInstanceOf(ClientInterface::class, $client);
Expand All @@ -23,7 +23,7 @@ public function should_instanciate_client_class()
* @test
* @expectedException InvalidArgumentException
*/
public function should_not_get_api_instance()
public function shouldNotGetApiInstance()
{
$client = new Client('http://localhost');
$client->api('do_not_exist');
Expand All @@ -33,7 +33,7 @@ public function should_not_get_api_instance()
* @covers \Exads\Client
* @test
*/
public function should_return_api_url()
public function shouldReturnAPIUrl()
{
$client = new Client('http://localhost');
$this->assertSame('http://localhost', $client->getUrl());
Expand All @@ -43,7 +43,7 @@ public function should_return_api_url()
* @covers \Exads\Client
* @test
*/
public function should_find_correct_port()
public function shouldFindCorrectPort()
{
$client = new Client('http://localhost');
$this->assertSame(80, $client->getPort());
Expand All @@ -56,7 +56,7 @@ public function should_find_correct_port()
* @covers \Exads\Client
* @test
*/
public function should_update_port()
public function shouldUpdatePort()
{
$client = new Client('http://localhost');
$this->assertSame($client, $client->setPort(28080));
Expand All @@ -67,7 +67,7 @@ public function should_update_port()
* @covers \Exads\Client
* @test
*/
public function response_should_be_0_by_default()
public function responseShouldBe0ByDefault()
{
$client = new Client('http://localhost');
$this->assertEquals(0, $client->getResponseCode());
Expand All @@ -77,7 +77,7 @@ public function response_should_be_0_by_default()
* @covers \Exads\Client
* @test
*/
public function should_decode_valid_json()
public function shouldDecodeValidJson()
{
// Test values
$inputJson = '{"token":"34fb12b579a9e6bc7a28238db3ff79aed04827ab","type":"Bearer","expires_in":3600}';
Expand All @@ -94,7 +94,7 @@ public function should_decode_valid_json()
* @covers \Exads\Client
* @test
*/
public function test_empty_json_decode()
public function testEmptyJsonDecode()
{
$invalidJson = '';
$expectedError = '';
Expand All @@ -107,7 +107,7 @@ public function test_empty_json_decode()
* @covers \Exads\Client
* @test
*/
public function test_malformed_json_should_return_error()
public function testMalformedJsonShouldReturnError()
{
$invalidJson = '{"token":"34fb12b579a9e6bc7a28238db3ff79aed04827ab","type":"Bearer","expires_in":3600';
$expectedError = 'Syntax error';
Expand Down
8 changes: 4 additions & 4 deletions test/Exads/Tests/TestClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class TestClientTest extends \PHPUnit_Framework_TestCase
* @test
* @expectedException Exception
*/
public function test_get_method_not_available()
public function testGetMethodNotAvailable()
{
$client = new TestClient('http://localhost');
$client->get('does_not_exist');
Expand All @@ -23,7 +23,7 @@ public function test_get_method_not_available()
* @test
* @expectedException Exception
*/
public function test_delete_method_not_available()
public function testDeleteMethodNotAvailable()
{
$client = new TestClient('http://localhost');
$client->delete('does_not_exist');
Expand All @@ -34,7 +34,7 @@ public function test_delete_method_not_available()
* @test
* @expectedException Exception
*/
public function test_post_method_not_available()
public function testPostMethodNotAvailable()
{
$client = new TestClient('http://localhost');
$client->post('does_not_exist', 'POST method not available');
Expand All @@ -45,7 +45,7 @@ public function test_post_method_not_available()
* @test
* @expectedException Exception
*/
public function test_put_method_not_available()
public function testPutMethodNotAvailable()
{
$client = new TestClient('http://localhost');
$client->put('does_not_exist', 'PUT method not available');
Expand Down
Loading