Skip to content

Instantly share code, notes, and snippets.

@zhiachong
Created January 8, 2016 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhiachong/14d528188fed0cd8cc10 to your computer and use it in GitHub Desktop.
Save zhiachong/14d528188fed0cd8cc10 to your computer and use it in GitHub Desktop.
How to decouple GeoTargetWrapper from this function?
public function getGeotargetingPopulationData($requestBody)
{
return parent::processMessage(
function () use ($requestBody)
{
$this->myPlaceLocal->authorization->validateLoggedInUser();
if (empty($requestBody['geotargeting']) || empty($requestBody['impressions']))
{
throw new InvalidApiParameterException("Expecting geo-targeting and impressions.");
}
$impressions = $requestBody['impressions'];
$impressionName = 'impressions';
$params = [$impressionName => $impressions];
$this->apiValidator->setParams($params);
$this->apiValidator->addRequiredParam($impressionName, 'positive');
$this->apiValidator->validate();
$this->campaignGeotargeting->fromAssociativeArray($requestBody['geotargeting']);
$geoTargetWrapper = new GeoTargetWrapper();
$geoTargetWrapper->transformFrom($this->campaignGeotargeting);
$result = $this->geoTargetingServiceClient->getGeoTargetPopulation($geoTargetWrapper);
$reachRatio = 0;
if (!empty($result))
{
$population = isset($result['total']) ? $result['total'] : 0;
$reachRatio = $population / $impressions;
}
$data = ["reachRatio" => $reachRatio];
$this->apiResponse
->setResult(true)
->setStatusCode(ApiResponse::API_STATUS_SUCCESS)
->setData($data)
->setMessage('Reach ratio retrieved successfully.');
return $this->apiResponse;
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment