diff --git a/src/Widop/GoogleAnalytics/Query.php b/src/Widop/GoogleAnalytics/Query.php index 028a18e..4ee6440 100644 --- a/src/Widop/GoogleAnalytics/Query.php +++ b/src/Widop/GoogleAnalytics/Query.php @@ -50,6 +50,9 @@ class Query /** @var integer */ protected $maxResults; + + /** @var string */ + protected $serviceURL; /** @var boolean */ protected $prettyPrint; @@ -72,6 +75,7 @@ public function __construct($ids) $this->filters = array(); $this->startIndex = 1; $this->maxResults = 10000; + $this->serviceURL = self::URL; $this->prettyPrint = false; } @@ -456,6 +460,32 @@ public function setMaxResults($maxResults) return $this; } + + /** + * Gets the google analytics service URL. + * + * @return string The google analytics service url. + */ + public function getServiceURL() + { + return $this->serviceURL; + } + + /** + * Sets the google analytics service URL + * + * @param string $serviceURL The google analytics service url. + * + * @return \Widop\GoogleAnalytics\Query The query. + */ + public function setServiceURL($serviceURL) + { + $this->serviceURL = $serviceURL; + return $this; + } + + + /** * Gets the google analytics query prettyPrint option. @@ -558,6 +588,6 @@ public function build($accessToken) $query['callback'] = $this->getCallback(); } - return sprintf('%s?%s', self::URL, http_build_query($query)); + return sprintf('%s?%s', $this->serviceURL, http_build_query($query)); } } diff --git a/tests/Widop/Tests/GoogleAnalytics/QueryTest.php b/tests/Widop/Tests/GoogleAnalytics/QueryTest.php index e7d4750..1e6c9bc 100644 --- a/tests/Widop/Tests/GoogleAnalytics/QueryTest.php +++ b/tests/Widop/Tests/GoogleAnalytics/QueryTest.php @@ -144,6 +144,14 @@ public function testMaxResults() $this->assertSame($maxResults, $this->query->getMaxResults()); } + public function testServiceURL() + { + $serviceURL = 'http://google.com'; + $this->query->setServiceURL($serviceURL); + + $this->assertSame($serviceURL, $this->query->getServiceURL()); + } + public function testPrettyPrint() { $this->query->setPrettyPrint(true); @@ -172,6 +180,7 @@ public function testBuild() $this->query->setSegment('seg'); $this->query->setStartIndex(10); $this->query->setMaxResults(100); + $this->query->setServiceURL($serviceURL = 'https://www.googleapis.com/analytics/v3/data/ga'); $this->query->setPrettyPrint(true); $this->query->setCallback('call');