@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | private $batchSize; |
| 14 | 14 | private $account; |
| 15 | 15 | |
| 16 | - public function __construct(Account $account=null, $batchSize=10, $batch=[]) |
|
| 16 | + public function __construct(Account $account = null, $batchSize = 10, $batch = []) |
|
| 17 | 17 | { |
| 18 | 18 | parent::__construct($account); |
| 19 | 19 | $this->account = $account; |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * @throws BatchLimitExceeded when the batch is full |
| 70 | 70 | * @return $batch|$this->batch |
| 71 | 71 | */ |
| 72 | - public function assureBatchSize($batch=null) |
|
| 72 | + public function assureBatchSize($batch = null) |
|
| 73 | 73 | { |
| 74 | 74 | if (count($batch ?: $this->batch) < $this->batchSize) { |
| 75 | 75 | return $batch ?: $this->batch; |
@@ -18,7 +18,7 @@ |
||
| 18 | 18 | const RESOURCE = 'tailored_audience_memberships'; |
| 19 | 19 | const OPERATION = 'Update'; |
| 20 | 20 | |
| 21 | - public function __construct(Account $account=null, $members=[]) |
|
| 21 | + public function __construct(Account $account = null, $members = []) |
|
| 22 | 22 | { |
| 23 | 23 | parent::__construct($account, self::MAX_BATCH_SIZE, $members); |
| 24 | 24 | } |
@@ -87,7 +87,7 @@ |
||
| 87 | 87 | |
| 88 | 88 | public function setAudienceNames(array $names) |
| 89 | 89 | { |
| 90 | - $this->audience_names = explode(', ', $names); |
|
| 90 | + $this->audience_names = explode(', ', $names); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | public function getEffectiveAt() |
@@ -2,7 +2,7 @@ |
||
| 2 | 2 | |
| 3 | 3 | use Hborras\TwitterAdsSDK\TwitterAds; |
| 4 | 4 | use Hborras\TwitterAdsSDK\TwitterAds\TailoredAudience\TailoredAudienceMemberships; |
| 5 | -use Hborras\TwitterAdsSDK\TwitterAds\TailoredAudience\TailoredAudienceMember;; |
|
| 5 | +use Hborras\TwitterAdsSDK\TwitterAds\TailoredAudience\TailoredAudienceMember; ; |
|
| 6 | 6 | |
| 7 | 7 | require '../autoload.php'; |
| 8 | 8 | |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | $twitterAds = new TwitterAds(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET); |
| 17 | 17 | |
| 18 | 18 | /** If the file is too large, I highly recommend increase the timeout */ |
| 19 | -$twitterAds->setTimeouts(5,45); |
|
| 19 | +$twitterAds->setTimeouts(5, 45); |
|
| 20 | 20 | |
| 21 | 21 | // Retrieve account information |
| 22 | 22 | $account = $twitterAds->getAccounts(ACCOUNT_ID); |
@@ -24,18 +24,18 @@ discard block |
||
| 24 | 24 | /** If the file is not hashed line by line, you need to hash it, for example for emails is this code*/ |
| 25 | 25 | |
| 26 | 26 | $file = fopen("path/to/list.txt", "r"); |
| 27 | -$newFile = fopen('path/to/new_list.txt','w'); |
|
| 28 | -while(!feof($file)){ |
|
| 27 | +$newFile = fopen('path/to/new_list.txt', 'w'); |
|
| 28 | +while (!feof($file)) { |
|
| 29 | 29 | $line = fgets($file); |
| 30 | 30 | $normalized_email = strtolower(trim($line, " \t\r\n\0\x0B.")); |
| 31 | 31 | $normalized_email = hash('sha256', $normalized_email); |
| 32 | - fwrite($newFile,$normalized_email."\n"); |
|
| 32 | + fwrite($newFile, $normalized_email."\n"); |
|
| 33 | 33 | # do same stuff with the $line |
| 34 | 34 | } |
| 35 | 35 | fclose($newFile); |
| 36 | 36 | fclose($file); |
| 37 | 37 | $audience = new TailoredAudience($account); |
| 38 | -$audience->create('path/to/new_list.txt','Test List', TailoredAudience::LIST_TYPE_EMAIL); |
|
| 38 | +$audience->create('path/to/new_list.txt', 'Test List', TailoredAudience::LIST_TYPE_EMAIL); |
|
| 39 | 39 | |
| 40 | 40 | /** @var TwitterAds\TailoredAudience\TailoredAudienceChanges $status */ |
| 41 | 41 | $status = $audience->status(); |
@@ -55,9 +55,9 @@ |
||
| 55 | 55 | $defaults['oauth_token'] = $token->key; |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - if(isset($parameters['raw'])){ |
|
| 58 | + if (isset($parameters['raw'])) { |
|
| 59 | 59 | $parameters = array_merge($defaults, ['oauth_body_hash' => base64_encode(sha1($parameters['raw'], TRUE))]); |
| 60 | - } else if(empty($parameters)){ |
|
| 60 | + } else if (empty($parameters)) { |
|
| 61 | 61 | $parameters = array_merge($defaults, ['oauth_body_hash' => base64_encode(sha1('', TRUE))]); |
| 62 | 62 | } else { |
| 63 | 63 | $parameters = array_merge($defaults, $parameters); |
@@ -57,7 +57,7 @@ |
||
| 57 | 57 | */ |
| 58 | 58 | public function save() |
| 59 | 59 | { |
| 60 | - if(!$this->getId()){ |
|
| 60 | + if (!$this->getId()) { |
|
| 61 | 61 | $resource = str_replace(static::RESOURCE_REPLACE, $this->getAccount()->getId(), static::RESOURCE); |
| 62 | 62 | $resource = str_replace(self::RESOURCE_TAILORED_AUDIENCE_ID_REPLACE, $this->getTailoredAudienceId(), $resource); |
| 63 | 63 | $response = $this->getAccount()->getTwitterAds()->post($resource, []); |
@@ -68,7 +68,7 @@ |
||
| 68 | 68 | $this->createAudience($name, $listType); |
| 69 | 69 | $location = $upload->perform(); |
| 70 | 70 | $tailoredAudienceChange = new TailoredAudienceChanges($this->getAccount()); |
| 71 | - $tailoredAudienceChange->updateAudience($this->getId(),$location, $listType, TailoredAudienceChanges::ADD); |
|
| 71 | + $tailoredAudienceChange->updateAudience($this->getId(), $location, $listType, TailoredAudienceChanges::ADD); |
|
| 72 | 72 | |
| 73 | 73 | return $this->reload(); |
| 74 | 74 | } |
@@ -81,9 +81,9 @@ discard block |
||
| 81 | 81 | { |
| 82 | 82 | /** Here you can add any header you want to the request*/ |
| 83 | 83 | $headers = [ |
| 84 | - 'x-ton-expires: ' . gmdate('D, d M Y H:i:s T', strtotime("+10 day")), |
|
| 85 | - 'content-type: ' . $this->getContentType(), |
|
| 86 | - 'Content-Length: ' . $this->fileSize |
|
| 84 | + 'x-ton-expires: '.gmdate('D, d M Y H:i:s T', strtotime("+10 day")), |
|
| 85 | + 'content-type: '.$this->getContentType(), |
|
| 86 | + 'Content-Length: '.$this->fileSize |
|
| 87 | 87 | ]; |
| 88 | 88 | |
| 89 | 89 | $response = $this->getTwitterAds()->post(self::DEFAULT_DOMAIN.self::DEFAULT_RESOURCE.self::DEFAULT_BUCKET, ['raw' => file_get_contents($this->filePath)], $headers); |
@@ -93,8 +93,8 @@ discard block |
||
| 93 | 93 | public function uploadChunk($resource, $chunkSize, $bytes, $bytesStart, $bytesRead) |
| 94 | 94 | { |
| 95 | 95 | $headers = [ |
| 96 | - 'Content-Type: ' . $this->getContentType(), |
|
| 97 | - 'Content-Range: bytes ' . $bytesStart . '-' . ($bytesRead - 1) . '/' . $this->fileSize |
|
| 96 | + 'Content-Type: '.$this->getContentType(), |
|
| 97 | + 'Content-Range: bytes '.$bytesStart.'-'.($bytesRead - 1).'/'.$this->fileSize |
|
| 98 | 98 | ]; |
| 99 | 99 | $response = $this->getTwitterAds()->put(self::DEFAULT_DOMAIN.$resource, ['raw' => $bytes], $headers); |
| 100 | 100 | |
@@ -104,14 +104,14 @@ discard block |
||
| 104 | 104 | public function initChunkedUpload() |
| 105 | 105 | { |
| 106 | 106 | $headers = [ |
| 107 | - 'X-Ton-Content-Type: ' . $this->getContentType(), |
|
| 108 | - 'X-Ton-Content-Length: ' . $this->fileSize, |
|
| 109 | - 'X-Ton-Expires: ' . gmdate('D, d M Y H:i:s T', strtotime("+6 day")), |
|
| 110 | - 'Content-Type: ' . $this->getContentType(), |
|
| 111 | - 'Content-Length: ' . strval(0) |
|
| 107 | + 'X-Ton-Content-Type: '.$this->getContentType(), |
|
| 108 | + 'X-Ton-Content-Length: '.$this->fileSize, |
|
| 109 | + 'X-Ton-Expires: '.gmdate('D, d M Y H:i:s T', strtotime("+6 day")), |
|
| 110 | + 'Content-Type: '.$this->getContentType(), |
|
| 111 | + 'Content-Length: '.strval(0) |
|
| 112 | 112 | ]; |
| 113 | 113 | |
| 114 | - $resource = self::DEFAULT_DOMAIN.self::DEFAULT_RESOURCE.self::DEFAULT_BUCKET. '?resumable=true'; |
|
| 114 | + $resource = self::DEFAULT_DOMAIN.self::DEFAULT_RESOURCE.self::DEFAULT_BUCKET.'?resumable=true'; |
|
| 115 | 115 | $response = $this->getTwitterAds()->post($resource, [], $headers); |
| 116 | 116 | return $response; |
| 117 | 117 | } |