| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace GalantomApi; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use GalantomApi\Description\PhpLoader; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use GuzzleHttp\Client; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use GuzzleHttp\Command\Guzzle\Description; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use GuzzleHttp\Command\Guzzle\GuzzleClient; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use GuzzleHttp\Command\Result as GuzzleResult; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Symfony\Component\Config\FileLocator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * Class GalantomClient | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @package GalantomApi | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * @method GuzzleResult getPageDonations(array $args = []) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | @command GalantomClient getPageDonations | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * @method GuzzleResult getDonation(array $args = []) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | @command GalantomClient getPageDonations | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 22 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  | class GalantomClient extends GuzzleClient | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |      * Version for this library | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |      * @const string | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |     const VERSION = '1.0.1'; | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |      * GalantomClient constructor. | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |      * @param Client $client | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |      * @param array $config | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 | 2 |  |     public function __construct(Client $client, $config = []) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 | 2 |  |         $description = $this->generateDescription(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $config = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |             'defaults' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 2 |  |                 'api_token' => (isset($config['api_token']) ? $config['api_token'] : '') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |             ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 | 2 |  |         parent::__construct($client, $description, null, null, null, $config); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 47 | 2 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |      * @param array $config | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |      * @return GalantomClient | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 2 |  |     public static function factory($config = []) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 2 |  |         $client = new Client($config); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 | 2 |  |         return new self($client, $config); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 57 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |      * Load configuration file(s) and parse resources. | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |      * @return Description | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 | 2 |  |     protected function generateDescription() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 | 2 |  |         $locator = new FileLocator(realpath(__DIR__ . '/Resources/v1.0')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 | 2 |  |         $phpLoader = new PhpLoader($locator); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 2 |  |         $description = $phpLoader->load($locator->locate('service-description.php')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 2 |  |         return new Description($description); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 72 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 73 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 74 |  |  |  |