Skip to content

Commit 57738f8

Browse files
ycecubeboobaa
authored andcommitted
Add Gallery In-Page Experience API
1 parent 4da1149 commit 57738f8

File tree

12 files changed

+616
-2
lines changed

12 files changed

+616
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
config.json
22
vendor
3+
.idea

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
"phpunit/phpunit": "7.2.*"
2323
},
2424
"require": {
25+
"ext-curl": "*",
26+
"ext-json": "*",
2527
"php": ">=7.1"
2628
},
2729
"autoload": {

lib/Brightcove/API/API.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
* @internal
99
*/
1010
abstract class API {
11+
12+
protected const API_VERSION = '1';
13+
1114
protected $account;
15+
1216
protected $client;
1317

1418
/**

lib/Brightcove/API/Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ function ($ch) use ($client_id, $client_secret) {
311311
* This class must implement ObjectInterface.
312312
* @param bool $is_array
313313
* TRUE if the result is an array of objects. Not used when $result is NULL.
314-
* @param ObjectInterface $post
315-
* A ObjectInterface to post.
314+
* @param ObjectInterface|null $post
315+
* An ObjectInterface to post.
316316
* @return ObjectInterface|ObjectInterface[]|null
317317
* The endpoint result.
318318
* @throws APIException
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Brightcove\API;
6+
7+
use Brightcove\Item\InPageExperience\InPageExperience as InPageExperienceItem;
8+
use Brightcove\Item\InPageExperience\InPageExperienceInterface as InPageExperienceItemInterface;
9+
use Brightcove\Item\InPageExperience\InPageExperienceList;
10+
use Brightcove\Item\InPageExperience\InPageExperienceListInterface;
11+
use Brightcove\Item\ObjectInterface;
12+
use Brightcove\Type\SortInterface;
13+
14+
/**
15+
* In-Page Experience API.
16+
*/
17+
final class InPageExperience extends API implements InPageExperienceInterface
18+
{
19+
private const API_TYPE = 'experiences';
20+
private const API_BASE_PATH = '/experiences';
21+
22+
/**
23+
* API request callback.
24+
*
25+
* @param string $method
26+
* HTTP method.
27+
* @param string $endpoint
28+
* API endpoint
29+
* @param string|null $result
30+
* NULL to return the unmarshalled JSON, or a class name to deserialize
31+
* into.
32+
* This class must implement ObjectInterface.
33+
* @param ObjectInterface|null $post
34+
* An ObjectInterface to post.
35+
*
36+
* @return ObjectInterface|ObjectInterface[]|null
37+
* The given result based on $result.
38+
*
39+
* @throws \Brightcove\API\Exception\APIException
40+
*/
41+
private function request(string $method, string $endpoint, ?string $result, $post = null)
42+
{
43+
return $this->client->request(
44+
$method,
45+
static::API_VERSION,
46+
static::API_TYPE,
47+
$this->account,
48+
$endpoint,
49+
$result,
50+
false,
51+
$post
52+
);
53+
}
54+
55+
/**
56+
* {@inheritdoc}
57+
*/
58+
public function delete(string $id): void
59+
{
60+
$this->request('DELETE', static::API_BASE_PATH . '/' . $id, null);
61+
}
62+
63+
/**
64+
* {@inheritdoc}
65+
*/
66+
public function get(string $id): InPageExperienceItemInterface
67+
{
68+
return $this->request('GET', static::API_BASE_PATH . '/' . $id, InPageExperienceItem::class);
69+
}
70+
71+
/**
72+
* {@inheritdoc}
73+
*/
74+
public function getAll(string $search = null, SortInterface $sort = null): InPageExperienceListInterface
75+
{
76+
$http_query = [];
77+
if ($search !== null) {
78+
$http_query['q'] = $search;
79+
}
80+
if ($sort !== null) {
81+
$http_query['sort'] = (string) $sort;
82+
}
83+
$http_query = http_build_query($http_query);
84+
85+
return $this->request(
86+
'GET',
87+
static::API_BASE_PATH . (!empty($http_query) ? "?{$http_query}" : ''),
88+
InPageExperienceList::class
89+
);
90+
}
91+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Brightcove\API;
6+
7+
use Brightcove\API\Exception\APIException;
8+
use Brightcove\Item\InPageExperience\InPageExperienceInterface as InPageExperienceItemInterface;
9+
use Brightcove\Item\InPageExperience\InPageExperienceListInterface;
10+
use Brightcove\Type\SortInterface;
11+
12+
/**
13+
* In-Page Experience API interface.
14+
*/
15+
interface InPageExperienceInterface
16+
{
17+
/**
18+
* Deletes an entity with the given ID.
19+
*
20+
* @throws APIException
21+
*/
22+
public function delete(string $id): void;
23+
24+
/**
25+
* Gets an entity with the given ID.
26+
*
27+
* @throws APIException
28+
*/
29+
public function get(string $id): InPageExperienceItemInterface;
30+
31+
/**
32+
* Gets all entities.
33+
*
34+
* @param string|null $search
35+
* A string to search for in name or description.
36+
* @param SortInterface|null $sort
37+
* To sort the results by a specific field.
38+
*
39+
* @throws APIException
40+
*/
41+
public function getAll(string $search = null, SortInterface $sort = null): InPageExperienceListInterface;
42+
}
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Brightcove\Item\InPageExperience;
6+
7+
use Brightcove\Item\ObjectBase;
8+
9+
/**
10+
* In-Page Experience entity.
11+
*/
12+
final class InPageExperience extends ObjectBase implements InPageExperienceInterface
13+
{
14+
/**
15+
* Video Cloud Account ID.
16+
*
17+
* @var int
18+
*/
19+
protected $accountId;
20+
21+
/**
22+
* Create date in ISO-8601 format.
23+
*
24+
* @var string
25+
*/
26+
protected $createdAt;
27+
28+
/**
29+
* Description
30+
*
31+
* @var string
32+
*/
33+
protected $description;
34+
35+
/**
36+
* Entity ID.
37+
*
38+
* @var string
39+
*/
40+
protected $id;
41+
42+
/**
43+
* Name of the entity.
44+
*
45+
* @var string
46+
*/
47+
protected $name;
48+
49+
/**
50+
* The current published status.
51+
*
52+
* Enum:
53+
* - unpublished
54+
* - success
55+
* - publishing
56+
* - unpublishing
57+
* - inactive
58+
* - failed
59+
*
60+
* @var string
61+
*/
62+
protected $publishedStatus;
63+
64+
/**
65+
* Update date in ISO-8601 format.
66+
*
67+
* @var string
68+
*/
69+
protected $updatedAt;
70+
71+
/**
72+
* {@inheritdoc}
73+
*/
74+
public function applyJSON(array $json): void
75+
{
76+
parent::applyJSON($json);
77+
78+
$this->applyProperty($json, 'accountId');
79+
$this->applyProperty($json, 'createdAt');
80+
$this->applyProperty($json, 'description');
81+
$this->applyProperty($json, 'id');
82+
$this->applyProperty($json, 'name');
83+
$this->applyProperty($json, 'publishedStatus');
84+
$this->applyProperty($json, 'updatedAt');
85+
}
86+
87+
/**
88+
* {@inheritdoc}
89+
*/
90+
public function getAccountId(): int
91+
{
92+
return $this->accountId;
93+
}
94+
95+
/**
96+
* {@inheritdoc}
97+
*/
98+
public function getCreatedAt(): string
99+
{
100+
return $this->createdAt;
101+
}
102+
103+
/**
104+
* {@inheritdoc}
105+
*/
106+
public function getDescription(): string
107+
{
108+
return $this->description;
109+
}
110+
111+
/**
112+
* {@inheritdoc}
113+
*/
114+
public function getId(): string
115+
{
116+
return $this->id;
117+
}
118+
119+
/**
120+
* {@inheritdoc}
121+
*/
122+
public function getName(): string
123+
{
124+
return $this->name;
125+
}
126+
127+
/**
128+
* {@inheritdoc}
129+
*/
130+
public function getPublishedStatus(): string
131+
{
132+
return $this->publishedStatus;
133+
}
134+
135+
/**
136+
* {@inheritdoc}
137+
*/
138+
public function getUpdatedAt(): string
139+
{
140+
return $this->updatedAt;
141+
}
142+
143+
/**
144+
* {@inheritdoc}
145+
*/
146+
public function setAccountId(int $account_id): void
147+
{
148+
$this->accountId = $account_id;
149+
$this->fieldChanged('accountId');
150+
}
151+
152+
/**
153+
* {@inheritdoc}
154+
*/
155+
public function setCreatedAt(string $createdAt): void
156+
{
157+
$this->createdAt = $createdAt;
158+
$this->fieldChanged('createdAt');
159+
}
160+
161+
/**
162+
* {@inheritdoc}
163+
*/
164+
public function setDescription(string $description): void
165+
{
166+
$this->description = $description;
167+
$this->fieldChanged('description');
168+
}
169+
170+
/**
171+
* {@inheritdoc}
172+
*/
173+
public function setId(string $id): void
174+
{
175+
$this->id = $id;
176+
$this->fieldChanged('id');
177+
}
178+
179+
/**
180+
* {@inheritdoc}
181+
*/
182+
public function setName(string $name): void
183+
{
184+
$this->name = $name;
185+
$this->fieldChanged('name');
186+
}
187+
188+
/**
189+
* {@inheritdoc}
190+
*/
191+
public function setPublishedStatus(string $publishedStatus): void
192+
{
193+
$this->publishedStatus = $publishedStatus;
194+
$this->fieldChanged('publishedStatus');
195+
}
196+
197+
/**
198+
* {@inheritdoc}
199+
*/
200+
public function setUpdatedAt(string $updatedAt): void
201+
{
202+
$this->updatedAt = $updatedAt;
203+
$this->fieldChanged('updatedAt');
204+
}
205+
}

0 commit comments

Comments
 (0)