1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Hborras\TwitterAdsSDK\TwitterAds\Campaign; |
4
|
|
|
|
5
|
|
|
use InvalidArgumentException; |
6
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds; |
7
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Cursor; |
8
|
|
|
use Hborras\TwitterAdsSDK\TwitterAdsException; |
9
|
|
|
|
10
|
|
|
|
11
|
|
View Code Duplication |
class AdvertiserBusinessCategories |
|
|
|
|
12
|
|
|
{ |
13
|
|
|
const RESOURCE_COLLECTION = 'advertiser_business_categories'; |
14
|
|
|
const RESOURCE_REPLACE = '{account_id}'; |
15
|
|
|
|
16
|
|
|
protected $id; |
17
|
|
|
protected $name; |
18
|
|
|
protected $iab_categories; |
19
|
|
|
|
20
|
|
|
/** @var TwitterAds $twitterAds */ |
21
|
|
|
private $twitterAds; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Feature constructor. |
25
|
|
|
* @param TwitterAds $twitterAds |
26
|
|
|
*/ |
27
|
|
|
public function __construct(TwitterAds $twitterAds) |
28
|
|
|
{ |
29
|
|
|
$this->twitterAds = static::assureApi($twitterAds); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param TwitterAds|null $instance |
34
|
|
|
* @return TwitterAds|null |
35
|
|
|
*/ |
36
|
|
|
protected static function assureApi(TwitterAds $instance = null) |
37
|
|
|
{ |
38
|
|
|
$instance = $instance ?: TwitterAds::instance(); |
39
|
|
|
if (!$instance) { |
40
|
|
|
throw new InvalidArgumentException( |
41
|
|
|
'An Api instance must be provided as argument or ' . |
42
|
|
|
'set as instance in the \TwitterAds\Api' |
43
|
|
|
); |
44
|
|
|
} |
45
|
|
|
return $instance; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Returns a Cursor instance for a given resource. |
50
|
|
|
* |
51
|
|
|
* @param array $params |
52
|
|
|
* |
53
|
|
|
* @return Cursor |
54
|
|
|
* @throws TwitterAds\Errors\BadRequest |
55
|
|
|
* @throws TwitterAds\Errors\Forbidden |
56
|
|
|
* @throws TwitterAds\Errors\NotAuthorized |
57
|
|
|
* @throws TwitterAds\Errors\NotFound |
58
|
|
|
* @throws TwitterAds\Errors\RateLimit |
59
|
|
|
* @throws TwitterAds\Errors\ServerError |
60
|
|
|
* @throws TwitterAds\Errors\ServiceUnavailable |
61
|
|
|
* @throws TwitterAdsException |
62
|
|
|
*/ |
63
|
|
|
public function all($params = []) |
64
|
|
|
{ |
65
|
|
|
$resource = str_replace(static::RESOURCE_REPLACE, $this->getTwitterAds()->getAccountId(), static::RESOURCE_COLLECTION); |
66
|
|
|
$response = $this->getTwitterAds()->get($resource, $params); |
67
|
|
|
|
68
|
|
|
return new Cursor($response->getBody()->data, $this->getTwitterAds(), $response->getBody(), $params); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return TwitterAds |
73
|
|
|
*/ |
74
|
|
|
public function getTwitterAds() |
75
|
|
|
{ |
76
|
|
|
return $this->twitterAds; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.