ReviewOS

also looking at this

meemalabs/meema-client-php

Video Functionalities

#69
Merged glennmichael123 wants to merge video-functionalities into main
4 files +190 -32

Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.

src/Client.phpmodified+12-1
Changes to src/Client.php
@@ -4,7 +4,8 @@ namespace Meema\MeemaClient;
44
55use Dotenv\Dotenv;
66use GuzzleHttp\Client as GuzzleClient;
7use Meema\MeemaClient\Function\Image;
7use Meema\MeemaClient\Functions\Image;
8use Meema\MeemaClient\Functions\Video;
89use Meema\MeemaClient\Models\Favorite;
910use Meema\MeemaClient\Models\Folder;
1011use Meema\MeemaClient\Models\Media;
@@ -170,6 +171,16 @@ class Client
170171 return new Image($this);
171172 }
172173
174 /**
175 * Initialize the on-the-fly image video operations.
176 *
177 * @return Meema\MeemaClient\Functions\Video
178 */
179 public function videos(): Video
180 {
181 return new Video($this);
182 }
183
173184 /**
174185 * Get the client config.
175186 *
src/Functions/Image.phpmodified+3-31
Changes to src/Functions/Image.php
@@ -3,19 +3,17 @@
33namespace Meema\MeemaClient\Functions;
44
55use Meema\MeemaClient\Client;
6use Meema\MeemaClient\Traits\UrlResponse;
67
78class Image
89{
10 use UrlResponse;
11
912 /**
1013 * @var \Meema\MeemaClient\Client
1114 */
1215 protected $client;
1316
14 /**
15 * @var int
16 */
17 protected $id;
18
1917 /**
2018 * @var array
2119 */
@@ -1346,30 +1344,4 @@ class Image
13461344
13471345 return $this;
13481346 }
1349
1350 /**
1351 * Convert all parameters to string url.
1352 *
1353 * @return string
1354 */
1355 public function toUrl()
1356 {
1357 $queryParams = '';
1358
1359 $index = 0;
1360
1361 foreach ($this->args as $key => $param) {
1362 $separator = '?';
1363
1364 if ($index) {
1365 $separator = '&';
1366 }
1367
1368 $queryParams .= "{$separator}{$key}={$param}";
1369
1370 $index++;
1371 }
1372
1373 return "https://dev-ops.mee.ma/glenn/1/5/people.jpg{$queryParams}";
1374 }
13751347}
src/Functions/Video.phpmodified+129-0
Changes to src/Functions/Video.php
@@ -0,0 +1,129 @@
1<?php
2
3namespace Meema\MeemaClient\Functions;
4
5use Meema\MeemaClient\Client;
6use Meema\MeemaClient\Traits\UrlResponse;
7
8class Video
9{
10 use UrlResponse;
11
12 /**
13 * @var \Meema\MeemaClient\Client
14 */
15 protected $client;
16
17 /**
18 * @var array
19 */
20 protected $args = [];
21
22 /**
23 * Construct media model.
24 *
25 * @param Meema\MeemaClient\Client $client
26 */
27 public function __construct(Client $client)
28 {
29 $this->client = $client;
30 }
31
32 /**
33 * Set the video thumbnail value.
34 *
35 * @param string|bool $value
36 *
37 * @return $this
38 */
39 public function thumbnails($value)
40 {
41 $this->args = array_merge($this->args, ['thumbnails' => $value]);
42
43 return $this;
44 }
45
46 /**
47 * Set the video hls value.
48 *
49 * @param bool $value
50 *
51 * @return $this
52 */
53 public function hls($value)
54 {
55 $this->args = array_merge($this->args, ['hls' => $value]);
56
57 return $this;
58 }
59
60 /**
61 * Set the video dash value.
62 *
63 * @param bool $value
64 *
65 * @return $this
66 */
67 public function dash($value)
68 {
69 $this->args = array_merge($this->args, ['dash' => $value]);
70
71 return $this;
72 }
73
74 /**
75 * Set the video poster value.
76 *
77 * @param int $value
78 *
79 * @return $this
80 */
81 public function poster($value)
82 {
83 $this->args = array_merge($this->args, ['dash' => $value]);
84
85 return $this;
86 }
87
88 /**
89 * Set the video webvtt value.
90 *
91 * @param bool $value
92 *
93 * @return $this
94 */
95 public function webvtt($value)
96 {
97 $this->args = array_merge($this->args, ['webvtt' => $value]);
98
99 return $this;
100 }
101
102 /**
103 * Set the video format value.
104 *
105 * @param string $value
106 *
107 * @return $this
108 */
109 public function format($value)
110 {
111 $this->args = array_merge($this->args, ['format' => $value]);
112
113 return $this;
114 }
115
116 /**
117 * Set the video web optimized value.
118 *
119 * @param bool $value
120 *
121 * @return $this
122 */
123 public function webOptimized($value)
124 {
125 $this->args = array_merge($this->args, ['web-optimized' => $value]);
126
127 return $this;
128 }
129}
src/Traits/UrlResponse.phpadded+46-0
Changes to src/Traits/UrlResponse.php
@@ -0,0 +1,46 @@
1<?php
2
3namespace Meema\MeemaClient\Traits;
4
5use GuzzleHttp\Psr7\Utils;
6
7trait UrlResponse
8{
9 /**
10 * Convert all parameters to string url.
11 *
12 * @return string
13 */
14 public function toUrl()
15 {
16 $queryParams = '';
17
18 $index = 0;
19
20 foreach ($this->args as $key => $param) {
21 $separator = '?';
22
23 if ($index) {
24 $separator = '&';
25 }
26
27 $queryParams .= "{$separator}{$key}={$param}";
28
29 $index++;
30 }
31
32 return "https://dev-ops.mee.ma/glenn/1/5/people.jpg{$queryParams}";
33 }
34
35 /**
36 * Convert all parameters to string url.
37 *
38 * @return string
39 */
40 public function toBuffer()
41 {
42 $path = $this->toUrl();
43
44 return Utils::streamFor($path);
45 }
46}