Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option to change the service URL #15

Closed
wants to merge 2 commits into from
Closed
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
32 changes: 31 additions & 1 deletion src/Widop/GoogleAnalytics/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class Query

/** @var integer */
protected $maxResults;

/** @var string */
protected $serviceURL;

/** @var boolean */
protected $prettyPrint;
Expand All @@ -72,6 +75,7 @@ public function __construct($ids)
$this->filters = array();
$this->startIndex = 1;
$this->maxResults = 10000;
$this->serviceURL = self::URL;
$this->prettyPrint = false;
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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));
}
}
9 changes: 9 additions & 0 deletions tests/Widop/Tests/GoogleAnalytics/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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');

Expand Down