@@ -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 |
@@ -90,6 +90,12 @@ |
||
90 | 90 | return $response; |
91 | 91 | } |
92 | 92 | |
93 | + /** |
|
94 | + * @param integer $chunkSize |
|
95 | + * @param string $bytes |
|
96 | + * @param integer $bytesStart |
|
97 | + * @param integer $bytesRead |
|
98 | + */ |
|
93 | 99 | public function uploadChunk($resource, $chunkSize, $bytes, $bytesStart, $bytesRead) |
94 | 100 | { |
95 | 101 | $headers = [ |
@@ -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 | } |
@@ -18,7 +18,6 @@ |
||
18 | 18 | use Hborras\TwitterAdsSDK\TwitterAds\Errors\ServerError; |
19 | 19 | use Hborras\TwitterAdsSDK\TwitterAds\Errors\ServiceUnavailable; |
20 | 20 | use Hborras\TwitterAdsSDK\Util\JsonDecoder; |
21 | -use GuzzleHttp; |
|
22 | 21 | |
23 | 22 | /** |
24 | 23 | * TwitterAds class for interacting with the Twitter API. |
@@ -225,7 +225,7 @@ |
||
225 | 225 | * @param string $path |
226 | 226 | * @param array $parameters |
227 | 227 | * |
228 | - * @param array $headers |
|
228 | + * @param string[] $headers |
|
229 | 229 | * @return Response |
230 | 230 | */ |
231 | 231 | public function post($path, array $parameters = [], array $headers = []) |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | { |
308 | 308 | if ($parameters['media_type'] == 'video/mp4') { |
309 | 309 | $parameters['media_category'] = "amplify_video"; |
310 | - } elseif($parameters['media_type'] == 'image/gif'){ |
|
310 | + } elseif ($parameters['media_type'] == 'image/gif') { |
|
311 | 311 | $parameters['media_category'] = 'tweet_gif'; |
312 | 312 | } |
313 | 313 | |
@@ -390,10 +390,10 @@ discard block |
||
390 | 390 | $this->method = $method; |
391 | 391 | $this->resource = $path; |
392 | 392 | $this->resetLastResponse(); |
393 | - if(strpos($path, TONUpload::DEFAULT_DOMAIN) === 0) { |
|
393 | + if (strpos($path, TONUpload::DEFAULT_DOMAIN) === 0) { |
|
394 | 394 | $url = $path; |
395 | 395 | } else { |
396 | - if($host == self::UPLOAD_HOST){ |
|
396 | + if ($host == self::UPLOAD_HOST) { |
|
397 | 397 | $url = sprintf('%s/%s/%s', $host, self::API_REST_VERSION, $path); |
398 | 398 | } else { |
399 | 399 | $url = sprintf('%s/%s/%s', $host, self::API_VERSION, $path); |
@@ -420,7 +420,7 @@ discard block |
||
420 | 420 | * @throws ServerError |
421 | 421 | * @throws ServiceUnavailable |
422 | 422 | */ |
423 | - public function manageErrors($response){ |
|
423 | + public function manageErrors($response) { |
|
424 | 424 | switch ($this->getLastHttpCode()) { |
425 | 425 | case 400: |
426 | 426 | throw new BadRequest(TwitterAdsException::BAD_REQUEST, 400, null, $response->errors); |
@@ -466,7 +466,7 @@ discard block |
||
466 | 466 | } else { |
467 | 467 | $authorization = 'Authorization: Bearer '.$this->bearer; |
468 | 468 | } |
469 | - if(strpos($url, TONUpload::DEFAULT_DOMAIN) === 0) { |
|
469 | + if (strpos($url, TONUpload::DEFAULT_DOMAIN) === 0) { |
|
470 | 470 | return $this->request($url, $method, $authorization, $parameters, $headers); |
471 | 471 | } else { |
472 | 472 | return $this->request($request->getNormalizedHttpUrl(), $method, $authorization, $parameters, $headers); |
@@ -494,7 +494,7 @@ discard block |
||
494 | 494 | CURLOPT_CAINFO => __DIR__.DIRECTORY_SEPARATOR.'cacert.pem', |
495 | 495 | CURLOPT_CONNECTTIMEOUT => $this->connectionTimeout, |
496 | 496 | CURLOPT_HEADER => true, |
497 | - CURLOPT_HTTPHEADER => array_merge(['Accept: */*', $authorization, 'Expect:'],$headers,['Connection: close']), |
|
497 | + CURLOPT_HTTPHEADER => array_merge(['Accept: */*', $authorization, 'Expect:'], $headers, ['Connection: close']), |
|
498 | 498 | CURLOPT_RETURNTRANSFER => true, |
499 | 499 | CURLOPT_SSL_VERIFYHOST => 2, |
500 | 500 | CURLOPT_SSL_VERIFYPEER => true, |
@@ -517,7 +517,7 @@ discard block |
||
517 | 517 | break; |
518 | 518 | case 'POST': |
519 | 519 | $options[CURLOPT_POST] = true; |
520 | - if(isset($postfields['raw'])){ |
|
520 | + if (isset($postfields['raw'])) { |
|
521 | 521 | $options[CURLOPT_POSTFIELDS] = $postfields['raw']; |
522 | 522 | } else { |
523 | 523 | $options[CURLOPT_POSTFIELDS] = Util::buildHttpQuery($postfields); |
@@ -529,7 +529,7 @@ discard block |
||
529 | 529 | break; |
530 | 530 | case 'PUT': |
531 | 531 | $options[CURLOPT_CUSTOMREQUEST] = 'PUT'; |
532 | - if(isset($postfields['raw'])){ |
|
532 | + if (isset($postfields['raw'])) { |
|
533 | 533 | $options[CURLOPT_POSTFIELDS] = $postfields['raw']; |
534 | 534 | } |
535 | 535 | break; |
@@ -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, []); |