Skip to content

Commit

Permalink
facebook insights
Browse files Browse the repository at this point in the history
  • Loading branch information
edbizarro committed Sep 14, 2018
1 parent c424786 commit 6854843
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
2 changes: 2 additions & 0 deletions src/FacebookAds.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class FacebookAds extends AbstractFacebookAds
* @param array $params
*
* @see https://developers.facebook.com/docs/marketing-api/insights
*
* @return \Illuminate\Support\Collection
*/
public function insights(
Period $period,
Expand Down
12 changes: 6 additions & 6 deletions src/FormatResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ trait FormatResponse
{
protected function format(Cursor $response)
{
$data = null;
$data = new Collection;

try {
switch (true) {
case $response instanceof Cursor:
$data = new Collection;

foreach ($response->getLastResponse()->getContent() as $item) {
$data->push($item);
foreach ($response->getLastResponse()->getContent() as $items) {
foreach ($items as $item) {
$data->push($item);
}
}
break;
case $response instanceof AbstractObject:
$data = $response->getLastResponse()->getContent();
$data->push($response->getLastResponse()->getContent());
break;
}

Expand Down
21 changes: 12 additions & 9 deletions src/Insights.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use FacebookAds\Object\AdSet;
use FacebookAds\Object\Campaign;
use FacebookAds\Object\AdAccount;
use FacebookAds\Object\Values\AdsInsightsLevelValues;

class Insights
{
Expand All @@ -20,8 +21,10 @@ public function get(
$levelClass = $this->selectClassByLevel($level, $accountId);

$fields = $params['fields'];
unset($params['fields']);
// unset($params['fields']);

$params['time_increment'] = '1';
$params['level'] = $level;
$params['time_range'] = [
'since' => $period->startDate->format('Y-m-d'),
'until' => $period->endDate->format('Y-m-d'),
Expand All @@ -39,17 +42,17 @@ public function get(
protected function selectClassByLevel(string $level, string $accountId)
{
switch ($level) {
case 'ad':
return new Ad($accountId);
case AdsInsightsLevelValues::AD:
return (new Ad)->setId($accountId);
break;
case 'campaign':
return new Campaign($accountId);
case AdsInsightsLevelValues::CAMPAIGN:
return (new Campaign)->setId($accountId);
break;
case 'adset':
return new AdSet($accountId);
case AdsInsightsLevelValues::ADSET:
return (new AdSet)->setId($accountId);
break;
case 'account':
return new AdAccount($accountId);
case AdsInsightsLevelValues::ACCOUNT:
return (new AdAccount)->setId($accountId);
break;
}
}
Expand Down

0 comments on commit 6854843

Please sign in to comment.