@@ -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 | } |
@@ -225,7 +225,7 @@ discard block |
||
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 = []) |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | * @param array $parameters |
267 | 267 | * @param bool $chunked |
268 | 268 | * |
269 | - * @return array|object |
|
269 | + * @return Response |
|
270 | 270 | */ |
271 | 271 | public function upload($path, array $parameters = [], $chunked = false) |
272 | 272 | { |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | * @param string $path |
284 | 284 | * @param array $parameters |
285 | 285 | * |
286 | - * @return array|object |
|
286 | + * @return Response |
|
287 | 287 | */ |
288 | 288 | private function uploadMediaNotChunked($path, $parameters) |
289 | 289 | { |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | * @param string $path |
301 | 301 | * @param array $parameters |
302 | 302 | * |
303 | - * @return array|object |
|
303 | + * @return Response |
|
304 | 304 | */ |
305 | 305 | private function uploadMediaChunked($path, $parameters) |
306 | 306 | { |
@@ -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. |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | $this->method = $method; |
367 | 367 | $this->resource = $path; |
368 | 368 | $this->resetLastResponse(); |
369 | - if(strpos($path, TONUpload::DEFAULT_DOMAIN) === 0) { |
|
369 | + if (strpos($path, TONUpload::DEFAULT_DOMAIN) === 0) { |
|
370 | 370 | $url = $path; |
371 | 371 | } else { |
372 | 372 | $url = sprintf('%s/%s/%s', $host, self::API_VERSION, $path); |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | * @throws ServerError |
393 | 393 | * @throws ServiceUnavailable |
394 | 394 | */ |
395 | - public function manageErrors($response){ |
|
395 | + public function manageErrors($response) { |
|
396 | 396 | switch ($this->getLastHttpCode()) { |
397 | 397 | case 400: |
398 | 398 | throw new BadRequest(TwitterAdsException::BAD_REQUEST, 400, null, $response->errors); |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | } else { |
439 | 439 | $authorization = 'Authorization: Bearer '.$this->bearer; |
440 | 440 | } |
441 | - if(strpos($url, TONUpload::DEFAULT_DOMAIN) === 0) { |
|
441 | + if (strpos($url, TONUpload::DEFAULT_DOMAIN) === 0) { |
|
442 | 442 | return $this->request($url, $method, $authorization, $parameters, $headers); |
443 | 443 | } else { |
444 | 444 | return $this->request($request->getNormalizedHttpUrl(), $method, $authorization, $parameters, $headers); |
@@ -466,7 +466,7 @@ discard block |
||
466 | 466 | CURLOPT_CAINFO => __DIR__.DIRECTORY_SEPARATOR.'cacert.pem', |
467 | 467 | CURLOPT_CONNECTTIMEOUT => $this->connectionTimeout, |
468 | 468 | CURLOPT_HEADER => true, |
469 | - CURLOPT_HTTPHEADER => array_merge(['Accept: */*', $authorization, 'Expect:'],$headers,['Connection: close']), |
|
469 | + CURLOPT_HTTPHEADER => array_merge(['Accept: */*', $authorization, 'Expect:'], $headers, ['Connection: close']), |
|
470 | 470 | CURLOPT_RETURNTRANSFER => true, |
471 | 471 | CURLOPT_SSL_VERIFYHOST => 2, |
472 | 472 | CURLOPT_SSL_VERIFYPEER => true, |
@@ -489,7 +489,7 @@ discard block |
||
489 | 489 | break; |
490 | 490 | case 'POST': |
491 | 491 | $options[CURLOPT_POST] = true; |
492 | - if(isset($postfields['raw'])){ |
|
492 | + if (isset($postfields['raw'])) { |
|
493 | 493 | $options[CURLOPT_POSTFIELDS] = $postfields['raw']; |
494 | 494 | } else { |
495 | 495 | $options[CURLOPT_POSTFIELDS] = Util::buildHttpQuery($postfields); |
@@ -501,7 +501,7 @@ discard block |
||
501 | 501 | break; |
502 | 502 | case 'PUT': |
503 | 503 | $options[CURLOPT_CUSTOMREQUEST] = 'PUT'; |
504 | - if(isset($postfields['raw'])){ |
|
504 | + if (isset($postfields['raw'])) { |
|
505 | 505 | $options[CURLOPT_POSTFIELDS] = $postfields['raw']; |
506 | 506 | } |
507 | 507 | 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); |
@@ -60,7 +60,7 @@ |
||
60 | 60 | $resource = str_replace(Resource::RESOURCE_REPLACE, $account->getId(), self::TWEET_CREATE); |
61 | 61 | try { |
62 | 62 | $response = $account->getTwitterAds()->post($resource, $params); |
63 | - } catch( \Exception $e) { |
|
63 | + } catch (\Exception $e) { |
|
64 | 64 | print_r($e->getErrors()); |
65 | 65 | } |
66 | 66 | die(); |