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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Guzzle\Common\Collection;
use Guzzle\Http\Message\Request;
use Guzzle\Service\Client;
use Guzzle\Plugin\Async\AsyncPlugin;
use Guzzle\Service\Description\ServiceDescription;

class MeasurementProtocolClient extends Client
Expand All @@ -22,6 +23,7 @@ public static function factory($config = array())
{
$default = array(
'ssl' => false,
'async' => false,
'tid' => null
);
$required = array('ssl');
Expand All @@ -32,6 +34,10 @@ public static function factory($config = array())

$client = new self($baseUrl, $config);

if($config->get('async') === true) {
$client->addSubscriber(new AsyncPlugin());
}

$description = ServiceDescription::factory(__DIR__ . '/Resources/service.php');
$client->setDescription($description);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Krizon\Google\Analytics\MeasurementProtocol\Test;

use Guzzle\Http\Message\Response;
use Guzzle\Plugin\Async\AsyncPlugin;
use Guzzle\Plugin\History\HistoryPlugin;
use Guzzle\Plugin\Mock\MockPlugin;
use Guzzle\Service\Exception\ValidationException;
Expand Down Expand Up @@ -42,6 +43,18 @@ public function testFactoryInitializesClientWithSsl()
$this->assertTrue($client->getConfig('ssl'));
}

public function testFactoryInitializesClientWithAsync()
{
$client = MeasurementProtocolClient::factory(array(
'async' => true
));
$this->assertEquals('http://www.google-analytics.com', $client->getBaseUrl());
// We try to check if the is asynch plugin is correctly registered in the listeners list
$ed = $client-> getEventDispatcher()->getListeners();
$classList = array_map(function($elt){return get_class($elt[0]);}, $ed['request.sent']);
$this->assertContains(get_class(new AsyncPlugin()), $classList);
}

public function testAbstractCollect()
{
$response = $this->getResponse('abstract.collect', array(
Expand Down Expand Up @@ -223,6 +236,25 @@ public function testTrackingIdAsParamWins()
$this->assertEquals('X3', $this->history->getLastRequest()->getQuery()->get('tid'));
}

/**
* @group internet
*/
public function testAsyncRequestLive()
{
$client = MeasurementProtocolClient::factory(array(
'async' => true
));
$response = $this->getResponse('pageview', array(
'tid' => $this->getTrackingId(),
'cid' => $this->getCustomerId(),
't' => 'pageview',
'dh' => 'domain.do',
'dp' => '/php-ga-measurement-protocol/phpunit-test/async',
'dt' => 'PHP GA Measurement Protocol Async'
), false, $client);
$this->assertEquals(200, $response->getStatusCode());
}

/**
* @param $operation
* @param array $parameters
Expand Down