ReviewOS

also looking at this

meemalabs/meema-client-php

Media model

#6
Merged glennmichael123 wants to merge media-model into main
7 files +1700 -76

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.

composer.jsonmodified+2-1
Changes to composer.json
@@ -18,7 +18,8 @@
1818 }
1919 ],
2020 "require": {
21 "guzzlehttp/guzzle": "^7.2"
21 "guzzlehttp/guzzle": "^7.2",
22 "vlucas/phpdotenv": "^5.3"
2223 },
2324 "autoload": {
2425 "psr-4": {
composer.lockmodified+438-2
Changes to composer.lock
@@ -4,8 +4,70 @@
44 "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
55 "This file is @generated automatically"
66 ],
7 "content-hash": "8bb6064c215286e90527567ef11ef40b",
7 "content-hash": "81f9442b4c68ef1ee0152dda21744b84",
88 "packages": [
9 {
10 "name": "graham-campbell/result-type",
11 "version": "v1.0.1",
12 "source": {
13 "type": "git",
14 "url": "https://github.com/GrahamCampbell/Result-Type.git",
15 "reference": "7e279d2cd5d7fbb156ce46daada972355cea27bb"
16 },
17 "dist": {
18 "type": "zip",
19 "url": "https://api.github.com/repos/GrahamCampbell/Result-Type/zipball/7e279d2cd5d7fbb156ce46daada972355cea27bb",
20 "reference": "7e279d2cd5d7fbb156ce46daada972355cea27bb",
21 "shasum": ""
22 },
23 "require": {
24 "php": "^7.0|^8.0",
25 "phpoption/phpoption": "^1.7.3"
26 },
27 "require-dev": {
28 "phpunit/phpunit": "^6.5|^7.5|^8.5|^9.0"
29 },
30 "type": "library",
31 "extra": {
32 "branch-alias": {
33 "dev-master": "1.0-dev"
34 }
35 },
36 "autoload": {
37 "psr-4": {
38 "GrahamCampbell\\ResultType\\": "src/"
39 }
40 },
41 "notification-url": "https://packagist.org/downloads/",
42 "license": [
43 "MIT"
44 ],
45 "authors": [
46 {
47 "name": "Graham Campbell",
48 "email": "graham@alt-three.com"
49 }
50 ],
51 "description": "An Implementation Of The Result Type",
52 "keywords": [
53 "Graham Campbell",
54 "GrahamCampbell",
55 "Result Type",
56 "Result-Type",
57 "result"
58 ],
59 "funding": [
60 {
61 "url": "https://github.com/GrahamCampbell",
62 "type": "github"
63 },
64 {
65 "url": "https://tidelift.com/funding/github/packagist/graham-campbell/result-type",
66 "type": "tidelift"
67 }
68 ],
69 "time": "2020-04-13T13:17:36+00:00"
70 },
971 {
1072 "name": "guzzlehttp/guzzle",
1173 "version": "7.2.0",
@@ -238,6 +300,71 @@
238300 },
239301 "time": "2020-09-30T07:37:11+00:00"
240302 },
303 {
304 "name": "phpoption/phpoption",
305 "version": "1.7.5",
306 "source": {
307 "type": "git",
308 "url": "https://github.com/schmittjoh/php-option.git",
309 "reference": "994ecccd8f3283ecf5ac33254543eb0ac946d525"
310 },
311 "dist": {
312 "type": "zip",
313 "url": "https://api.github.com/repos/schmittjoh/php-option/zipball/994ecccd8f3283ecf5ac33254543eb0ac946d525",
314 "reference": "994ecccd8f3283ecf5ac33254543eb0ac946d525",
315 "shasum": ""
316 },
317 "require": {
318 "php": "^5.5.9 || ^7.0 || ^8.0"
319 },
320 "require-dev": {
321 "bamarni/composer-bin-plugin": "^1.4.1",
322 "phpunit/phpunit": "^4.8.35 || ^5.7.27 || ^6.5.6 || ^7.0 || ^8.0 || ^9.0"
323 },
324 "type": "library",
325 "extra": {
326 "branch-alias": {
327 "dev-master": "1.7-dev"
328 }
329 },
330 "autoload": {
331 "psr-4": {
332 "PhpOption\\": "src/PhpOption/"
333 }
334 },
335 "notification-url": "https://packagist.org/downloads/",
336 "license": [
337 "Apache-2.0"
338 ],
339 "authors": [
340 {
341 "name": "Johannes M. Schmitt",
342 "email": "schmittjoh@gmail.com"
343 },
344 {
345 "name": "Graham Campbell",
346 "email": "graham@alt-three.com"
347 }
348 ],
349 "description": "Option Type for PHP",
350 "keywords": [
351 "language",
352 "option",
353 "php",
354 "type"
355 ],
356 "funding": [
357 {
358 "url": "https://github.com/GrahamCampbell",
359 "type": "github"
360 },
361 {
362 "url": "https://tidelift.com/funding/github/packagist/phpoption/phpoption",
363 "type": "tidelift"
364 }
365 ],
366 "time": "2020-07-20T17:29:33+00:00"
367 },
241368 {
242369 "name": "psr/http-client",
243370 "version": "1.0.1",
@@ -386,6 +513,315 @@
386513 "source": "https://github.com/ralouphie/getallheaders/tree/develop"
387514 },
388515 "time": "2019-03-08T08:55:37+00:00"
516 },
517 {
518 "name": "symfony/polyfill-ctype",
519 "version": "v1.22.1",
520 "source": {
521 "type": "git",
522 "url": "https://github.com/symfony/polyfill-ctype.git",
523 "reference": "c6c942b1ac76c82448322025e084cadc56048b4e"
524 },
525 "dist": {
526 "type": "zip",
527 "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/c6c942b1ac76c82448322025e084cadc56048b4e",
528 "reference": "c6c942b1ac76c82448322025e084cadc56048b4e",
529 "shasum": ""
530 },
531 "require": {
532 "php": ">=7.1"
533 },
534 "suggest": {
535 "ext-ctype": "For best performance"
536 },
537 "type": "library",
538 "extra": {
539 "branch-alias": {
540 "dev-main": "1.22-dev"
541 },
542 "thanks": {
543 "name": "symfony/polyfill",
544 "url": "https://github.com/symfony/polyfill"
545 }
546 },
547 "autoload": {
548 "psr-4": {
549 "Symfony\\Polyfill\\Ctype\\": ""
550 },
551 "files": [
552 "bootstrap.php"
553 ]
554 },
555 "notification-url": "https://packagist.org/downloads/",
556 "license": [
557 "MIT"
558 ],
559 "authors": [
560 {
561 "name": "Gert de Pagter",
562 "email": "BackEndTea@gmail.com"
563 },
564 {
565 "name": "Symfony Community",
566 "homepage": "https://symfony.com/contributors"
567 }
568 ],
569 "description": "Symfony polyfill for ctype functions",
570 "homepage": "https://symfony.com",
571 "keywords": [
572 "compatibility",
573 "ctype",
574 "polyfill",
575 "portable"
576 ],
577 "funding": [
578 {
579 "url": "https://symfony.com/sponsor",
580 "type": "custom"
581 },
582 {
583 "url": "https://github.com/fabpot",
584 "type": "github"
585 },
586 {
587 "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
588 "type": "tidelift"
589 }
590 ],
591 "time": "2021-01-07T16:49:33+00:00"
592 },
593 {
594 "name": "symfony/polyfill-mbstring",
595 "version": "v1.22.1",
596 "source": {
597 "type": "git",
598 "url": "https://github.com/symfony/polyfill-mbstring.git",
599 "reference": "5232de97ee3b75b0360528dae24e73db49566ab1"
600 },
601 "dist": {
602 "type": "zip",
603 "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/5232de97ee3b75b0360528dae24e73db49566ab1",
604 "reference": "5232de97ee3b75b0360528dae24e73db49566ab1",
605 "shasum": ""
606 },
607 "require": {
608 "php": ">=7.1"
609 },
610 "suggest": {
611 "ext-mbstring": "For best performance"
612 },
613 "type": "library",
614 "extra": {
615 "branch-alias": {
616 "dev-main": "1.22-dev"
617 },
618 "thanks": {
619 "name": "symfony/polyfill",
620 "url": "https://github.com/symfony/polyfill"
621 }
622 },
623 "autoload": {
624 "psr-4": {
625 "Symfony\\Polyfill\\Mbstring\\": ""
626 },
627 "files": [
628 "bootstrap.php"
629 ]
630 },
631 "notification-url": "https://packagist.org/downloads/",
632 "license": [
633 "MIT"
634 ],
635 "authors": [
636 {
637 "name": "Nicolas Grekas",
638 "email": "p@tchwork.com"
639 },
640 {
641 "name": "Symfony Community",
642 "homepage": "https://symfony.com/contributors"
643 }
644 ],
645 "description": "Symfony polyfill for the Mbstring extension",
646 "homepage": "https://symfony.com",
647 "keywords": [
648 "compatibility",
649 "mbstring",
650 "polyfill",
651 "portable",
652 "shim"
653 ],
654 "funding": [
655 {
656 "url": "https://symfony.com/sponsor",
657 "type": "custom"
658 },
659 {
660 "url": "https://github.com/fabpot",
661 "type": "github"
662 },
663 {
664 "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
665 "type": "tidelift"
666 }
667 ],
668 "time": "2021-01-22T09:19:47+00:00"
669 },
670 {
671 "name": "symfony/polyfill-php80",
672 "version": "v1.22.1",
673 "source": {
674 "type": "git",
675 "url": "https://github.com/symfony/polyfill-php80.git",
676 "reference": "dc3063ba22c2a1fd2f45ed856374d79114998f91"
677 },
678 "dist": {
679 "type": "zip",
680 "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/dc3063ba22c2a1fd2f45ed856374d79114998f91",
681 "reference": "dc3063ba22c2a1fd2f45ed856374d79114998f91",
682 "shasum": ""
683 },
684 "require": {
685 "php": ">=7.1"
686 },
687 "type": "library",
688 "extra": {
689 "branch-alias": {
690 "dev-main": "1.22-dev"
691 },
692 "thanks": {
693 "name": "symfony/polyfill",
694 "url": "https://github.com/symfony/polyfill"
695 }
696 },
697 "autoload": {
698 "psr-4": {
699 "Symfony\\Polyfill\\Php80\\": ""
700 },
701 "files": [
702 "bootstrap.php"
703 ],
704 "classmap": [
705 "Resources/stubs"
706 ]
707 },
708 "notification-url": "https://packagist.org/downloads/",
709 "license": [
710 "MIT"
711 ],
712 "authors": [
713 {
714 "name": "Ion Bazan",
715 "email": "ion.bazan@gmail.com"
716 },
717 {
718 "name": "Nicolas Grekas",
719 "email": "p@tchwork.com"
720 },
721 {
722 "name": "Symfony Community",
723 "homepage": "https://symfony.com/contributors"
724 }
725 ],
726 "description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions",
727 "homepage": "https://symfony.com",
728 "keywords": [
729 "compatibility",
730 "polyfill",
731 "portable",
732 "shim"
733 ],
734 "funding": [
735 {
736 "url": "https://symfony.com/sponsor",
737 "type": "custom"
738 },
739 {
740 "url": "https://github.com/fabpot",
741 "type": "github"
742 },
743 {
744 "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
745 "type": "tidelift"
746 }
747 ],
748 "time": "2021-01-07T16:49:33+00:00"
749 },
750 {
751 "name": "vlucas/phpdotenv",
752 "version": "v5.3.0",
753 "source": {
754 "type": "git",
755 "url": "https://github.com/vlucas/phpdotenv.git",
756 "reference": "b3eac5c7ac896e52deab4a99068e3f4ab12d9e56"
757 },
758 "dist": {
759 "type": "zip",
760 "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/b3eac5c7ac896e52deab4a99068e3f4ab12d9e56",
761 "reference": "b3eac5c7ac896e52deab4a99068e3f4ab12d9e56",
762 "shasum": ""
763 },
764 "require": {
765 "ext-pcre": "*",
766 "graham-campbell/result-type": "^1.0.1",
767 "php": "^7.1.3 || ^8.0",
768 "phpoption/phpoption": "^1.7.4",
769 "symfony/polyfill-ctype": "^1.17",
770 "symfony/polyfill-mbstring": "^1.17",
771 "symfony/polyfill-php80": "^1.17"
772 },
773 "require-dev": {
774 "bamarni/composer-bin-plugin": "^1.4.1",
775 "ext-filter": "*",
776 "phpunit/phpunit": "^7.5.20 || ^8.5.14 || ^9.5.1"
777 },
778 "suggest": {
779 "ext-filter": "Required to use the boolean validator."
780 },
781 "type": "library",
782 "extra": {
783 "branch-alias": {
784 "dev-master": "5.3-dev"
785 }
786 },
787 "autoload": {
788 "psr-4": {
789 "Dotenv\\": "src/"
790 }
791 },
792 "notification-url": "https://packagist.org/downloads/",
793 "license": [
794 "BSD-3-Clause"
795 ],
796 "authors": [
797 {
798 "name": "Graham Campbell",
799 "email": "graham@alt-three.com",
800 "homepage": "https://gjcampbell.co.uk/"
801 },
802 {
803 "name": "Vance Lucas",
804 "email": "vance@vancelucas.com",
805 "homepage": "https://vancelucas.com/"
806 }
807 ],
808 "description": "Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.",
809 "keywords": [
810 "dotenv",
811 "env",
812 "environment"
813 ],
814 "funding": [
815 {
816 "url": "https://github.com/GrahamCampbell",
817 "type": "github"
818 },
819 {
820 "url": "https://tidelift.com/funding/github/packagist/vlucas/phpdotenv",
821 "type": "tidelift"
822 }
823 ],
824 "time": "2021-01-20T15:23:13+00:00"
389825 }
390826 ],
391827 "packages-dev": [],
@@ -396,5 +832,5 @@
396832 "prefer-lowest": false,
397833 "platform": [],
398834 "platform-dev": [],
399 "plugin-api-version": "2.0.0"
835 "plugin-api-version": "1.1.0"
400836}
src/Client.phpmodified+11-0
Changes to src/Client.php
@@ -5,6 +5,7 @@ namespace Meema\MeemaApi;
55use Dotenv\Dotenv;
66use GuzzleHttp\Client as GuzzleClient;
77use Meema\MeemaApi\Models\Folder;
8use Meema\MeemaApi\Models\Media;
89
910class Client
1011{
@@ -94,4 +95,14 @@ class Client
9495 {
9596 return new Folder($this);
9697 }
98
99 /**
100 * Initialize the media model.
101 *
102 * @return Meema\MeemaApi\Models\Media
103 */
104 public function media(): Media
105 {
106 return new Media($this);
107 }
97108}
src/Models/Media.phpadded+145-0
Changes to src/Models/Media.php
@@ -0,0 +1,145 @@
1<?php
2
3namespace Meema\MeemaApi\Models;
4
5use Meema\MeemaApi\Client;
6
7class Media
8{
9 /**
10 * @var Meema\MeemaApi\Client
11 */
12 public $client;
13
14 /**
15 * @var int
16 */
17 public $id;
18
19 /**
20 * Construct media model.
21 *
22 * @param Meema\MeemaApi\Client $client
23 */
24 public function __construct(Client $client)
25 {
26 $this->client = $client;
27 }
28
29 /**
30 * List all media.
31 *
32 * @return array
33 */
34 public function all(): array
35 {
36 return $this->client->request('GET', 'media');
37 }
38
39 /**
40 * Get specific media.
41 *
42 * @return array
43 */
44 public function get($id = null)
45 {
46 if (! $id) {
47 return $this->all();
48 }
49
50 $ids = is_array($id) ? $id : func_get_args();
51
52 return $this->client->request('GET', 'media/show', ['media_ids' => $ids]);
53 }
54
55 /**
56 * Create media.
57 *
58 * @param string $name
59 *
60 * @return array
61 */
62 public function create($name): array
63 {
64 $name = is_array($name) ? $name : compact('name');
65
66 return $this->client->request('POST', "media/{$this->client->getAccessKey()}", $name);
67 }
68
69 /**
70 * Update media.
71 *
72 * @param int $id
73 * @param string $name
74 *
75 * @return array
76 */
77 public function update($id, $name): array
78 {
79 $name = is_array($name) ? $name : compact('name');
80
81 return $this->client->request('PATCH', "media/{$id}/file-name", $name);
82 }
83
84 /**
85 * Delete a media.
86 *
87 * @param int|array $id
88 *
89 * @return null
90 */
91 public function delete($id)
92 {
93 return $this->client->request('DELETE', "media/{$id}", ['media_id' => $id]);
94 }
95
96 /**
97 * Archive a media.
98 *
99 * @return array
100 */
101 public function archive($id): array
102 {
103 return $this->client->request('POST', "media/{$id}/archive");
104 }
105
106 /**
107 * Unarchive a media.
108 *
109 * @return array
110 */
111 public function unarchive($id): array
112 {
113 return $this->client->request('POST', "media/{$id}/unarchive");
114 }
115
116 /**
117 * Make a media private.
118 *
119 * @return array
120 */
121 public function makePrivate($id): array
122 {
123 return $this->client->request('PATCH', "media/{$id}/make-private");
124 }
125
126 /**
127 * Make a media public.
128 *
129 * @return array
130 */
131 public function makePublic($id): array
132 {
133 return $this->client->request('PATCH', "media/{$id}/make-public");
134 }
135
136 /**
137 * Duplicate a media.
138 *
139 * @return array
140 */
141 public function duplicate($id): array
142 {
143 return $this->client->request('POST', "media/{$id}/duplicate");
144 }
145}