Completed
Push — master ( 6ad9e3...7a68b3 )
by Dmitry
01:36
created

Campaign::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
c 0
b 0
f 0
dl 0
loc 19
rs 9.9666
cc 1
nc 1
nop 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Promopult\TikTokMarketingApi\Service;
6
7
final class Campaign extends \Promopult\TikTokMarketingApi\AbstractService
8
{
9
    /**
10
     * Getting Campaigns
11
     *
12
     * @param string $advertiserId      Advertiser ID
13
     * @param ?array $fields            Return field, optional values "campaign_id", "campaign_name", "advertiser_id",
14
     *                                  "budget", "budget_mode", "status", "opt_status", "objective", "objective_type",
15
     *                                  "create_time", "modify_time", "is_new_structure", "split_test_variable".
16
     *                                  When not specified, all fields are returned by default.
17
     * @param ?array $filtering         Filters on the data. This parameter is an array of filter objects.
18
     * @param ?int $page                Current page number. Default value: 1,value range: ≥ 1
19
     * @param ?int $pageSize            Page size,Default value: 10,Range of values: 1-1000
20
     *
21
     * @return array
22
     *
23
     * @throws \Throwable
24
     *
25
     * @see https://ads.tiktok.com/marketing_api/docs?id=100528
26
     */
27
    public function get(
28
        string $advertiserId,
29
        ?array $fields = null,
30
        ?array $filtering = null,
0 ignored issues
show
Unused Code introduced by
The parameter $filtering is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

30
        /** @scrutinizer ignore-unused */ ?array $filtering = null,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
31
        ?int $page = null,
0 ignored issues
show
Unused Code introduced by
The parameter $page is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

31
        /** @scrutinizer ignore-unused */ ?int $page = null,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
32
        ?int $pageSize = null
0 ignored issues
show
Unused Code introduced by
The parameter $pageSize is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

32
        /** @scrutinizer ignore-unused */ ?int $pageSize = null

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
33
    ): array
34
    {
35
        return $this->requestApi(
36
            'GET',
37
            '/open_api/v1.2/campaign/get/',
38
            [
39
                'advertiser_id' => $advertiserId,
40
                'fields' => $fields
41
            ]
42
        );
43
    }
44
45
    /**
46
     * Creating a Campaign
47
     *
48
     * @param string $advertiserId          Advertiser ID
49
     * @param string $campaignName          Campaign name. It can contain up to 512 characters. Emoji is not supported.
50
     * @param string $objectiveType         Advertising objective.
51
     * @param string $budgetMode            Budget type.
52
     * @param ?float $budget                Campaign budget, required when is 'BUDGET_MODE_DAY' or 'BUDGET_MODE_TOTAL'.
53
     * @param ?string $splitTestVariable    Split Test variables. Values: TARGETING, BIDDING_OPTIMIZATION, CREATIVE.
54
     *
55
     * @return array
56
     *
57
     * @throws \Throwable
58
     *
59
     * @see https://ads.tiktok.com/marketing_api/docs?id=100528
60
     */
61
    public function create(
62
        string $advertiserId,
63
        string $campaignName,
64
        string $objectiveType,
65
        string $budgetMode,
66
        ?float $budget = null,
67
        ?string $splitTestVariable = null
68
    ): array
69
    {
70
        return $this->requestApi(
71
            'POST',
72
            '/open_api/v1.2/campaign/create/',
73
            [
74
                'advertiser_id' => $advertiserId,
75
                'budget' => $budget,
76
                'budget_mode' => $budgetMode,
77
                'campaign_name' => $campaignName,
78
                'objective_type' => $objectiveType,
79
                'split_test_variable' => $splitTestVariable
80
            ]
81
        );
82
    }
83
84
    /**
85
     * Creating a Campaign
86
     *
87
     * @param string $advertiserId          Advertiser ID
88
     * @param string $campaignName          Campaign name. It can contain up to 512 characters. Emoji is not supported.
89
     * @param string $objectiveType         Advertising objective.
90
     * @param string $budgetMode            Budget type.
91
     * @param ?float $budget                Campaign budget, required when is 'BUDGET_MODE_DAY' or 'BUDGET_MODE_TOTAL'.
92
     *                                      note:
93
     *                                          1. Unlimited budget can be changed to limited
94
     *                                          2. Daily budget and total budget cannot be switched with each other.
95
     *
96
     * @return array
97
     *
98
     * @throws \Throwable
99
     *
100
     * @see https://ads.tiktok.com/marketing_api/docs?id=100528
101
     */
102
    public function update(
103
        string $advertiserId,
104
        string $campaignName,
105
        string $objectiveType,
106
        string $budgetMode,
107
        ?float $budget = null
108
    ): array
109
    {
110
        return $this->requestApi(
111
            'POST',
112
            '/open_api/v1.2/campaign/update/',
113
            [
114
                'advertiser_id' => $advertiserId,
115
                'budget' => $budget,
116
                'budget_mode' => $budgetMode,
117
                'campaign_name' => $campaignName,
118
                'objective_type' => $objectiveType
119
            ]
120
        );
121
    }
122
123
    /**
124
     * Modifying the Status of a Campaign
125
     *
126
     * @param int $advertiserId     Advertiser ID
127
     * @param array $campaignIds    A list of campaign IDs, with an allowed quantity range from 1-100
128
     * @param string $optStatus     The operation being made , optional values include: DELETE,DISABLE,ENABLE
129
     *                              Note: The status of deleted ads cannot be modified.
130
     * @return array
131
     * @throws \Throwable
132
     */
133
    public function updateStatus(
134
        int $advertiserId,
135
        array $campaignIds,
136
        string $optStatus
137
    ): array {
138
        return $this->requestApi(
139
            'POST',
140
            '/open_api/v1.2/campaign/update/status/',
141
            [
142
                'advertiser_id' => $advertiserId,
143
                'campaign_ids' => $campaignIds,
144
                'opt_status' => $optStatus
145
            ]
146
        );
147
    }
148
}
149