| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Darkgoldblade01\Wordpress; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Darkgoldblade01\Wordpress\Api\Core; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Darkgoldblade01\Wordpress\Api\Plugin; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Darkgoldblade01\Wordpress\Api\Secret; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Darkgoldblade01\Wordpress\Api\Stats; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Darkgoldblade01\Wordpress\Api\Theme; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Darkgoldblade01\Wordpress\Api\Translation; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use GuzzleHttp\Client; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use GuzzleHttp\Exception\GuzzleException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | class WordpressApi | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      * Base URI. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |      * The base URI for the API. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     protected $base_uri = 'https://api.wordpress.org/'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      * @var Client | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     private $client; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 | 7 |  |     public function __construct() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 | 7 |  |         $this->client = new Client([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 | 7 |  |             'base_uri' => $this->base_uri, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 | 7 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * @return Core | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 | 3 |  |     public static function core(): Core | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 | 3 |  |         return new Core(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |      * @return Plugin | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 | 1 |  |     public static function plugin(): Plugin | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 | 1 |  |         return new Plugin(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      * @return Secret | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     public static function secret(): Secret | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         return new Secret(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * @return Stats | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     public static function stats(): Stats | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         return new Stats(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * @return Theme | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     public static function theme(): Theme | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         return new Theme(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      * @return Translation | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     public static function translation(): Translation | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         return new Translation(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |      * @param null $endpoint | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |      * @param bool $json_decode | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      * @throws GuzzleException | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 90 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 91 | 5 |  |     protected function get($endpoint = null, $json_decode = true) | 
            
                                                        
            
                                    
            
            
                | 92 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 93 | 5 |  |         $response = $this->client->get($endpoint); | 
            
                                                        
            
                                    
            
            
                | 94 | 5 |  |         if ($json_decode) { | 
            
                                                        
            
                                    
            
            
                | 95 | 5 |  |             return json_decode($response->getBody()->getContents(), true); | 
            
                                                        
            
                                    
            
            
                | 96 |  |  |         } else { | 
            
                                                        
            
                                    
            
            
                | 97 |  |  |             return $response->getBody()->getContents(); | 
            
                                                        
            
                                    
            
            
                | 98 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 99 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 100 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 101 |  |  |  |