Created
January 8, 2016 02:42
-
-
Save zhiachong/14d528188fed0cd8cc10 to your computer and use it in GitHub Desktop.
How to decouple GeoTargetWrapper from this function?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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