| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Acquia\LiftClient\Manager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Acquia\LiftClient\Entity\Slot; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use GuzzleHttp\Psr7\Request; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | class SlotManager extends ManagerBase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     protected $queryParameters = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |         'visible_on_page' => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |         'status' => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |      * Get a list of slots. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      * Example of how to structure the $options parameter: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      * <code> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      * $options = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      *     'visible_on_page'  => 'http://localhost/blog/*', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      *     'status' => 'enabled', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      * ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * </code> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * @see http://docs.decision-api.acquia.com/#slots_get | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      * @param array $options | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * @throws \GuzzleHttp\Exception\RequestException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * @return \Acquia\LiftClient\Entity\Slot[] | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 36 |  |  |      */ | 
            
                                                                        
                            
            
                                                                    
                                                                                                        
            
            
                | 37 | 10 | View Code Duplication |     public function query($options = []) | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 39 | 6 |  |         $url = '/slots'; | 
            
                                                                        
                            
            
                                    
            
            
                | 40 | 6 |  |         $url .= $this->getQueryString($options); | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |         // Now make the request. | 
            
                                                                        
                            
            
                                    
            
            
                | 43 | 10 |  |         $request = new Request('GET', $url); | 
            
                                                                        
                            
            
                                    
            
            
                | 44 | 6 |  |         $data = $this->getResponseJson($request); | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |         // Get them as Slot objects | 
            
                                                                        
                            
            
                                    
            
            
                | 47 | 3 |  |         $slots = []; | 
            
                                                                        
                            
            
                                    
            
            
                | 48 | 3 |  |         foreach ($data as $dataItem) { | 
            
                                                                        
                            
            
                                    
            
            
                | 49 | 3 |  |             $slots[] = new Slot($dataItem); | 
            
                                                                        
                            
            
                                    
            
            
                | 50 | 2 |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 52 | 3 |  |         return $slots; | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      * Get a specific slot. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      * Example of how to structure the $options parameter: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      * @see http://docs.decision-api.acquia.com/#slots__slotId__get | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * @param array $id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * @throws \GuzzleHttp\Exception\RequestException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      * @return \Acquia\LiftClient\Entity\Slot | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 68 | 6 | View Code Duplication |     public function get($id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 | 6 |  |         $url = "/slots/{$id}"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         // Now make the request. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 | 6 |  |         $request = new Request('GET', $url); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 | 6 |  |         $data = $this->getResponseJson($request); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 | 3 |  |         return new Slot($data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      * Add a slot. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      * @param \Acquia\LiftClient\Entity\Slot $slot | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      * @throws \GuzzleHttp\Exception\RequestException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |      * @return \Acquia\LiftClient\Entity\Slot | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 88 | 6 | View Code Duplication |     public function add(Slot $slot) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 | 6 |  |         $body = $slot->json(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 | 6 |  |         $url = '/slots'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 | 6 |  |         $request = new Request('POST', $url, [], $body); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 | 6 |  |         $data = $this->getResponseJson($request); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 | 3 |  |         return new Slot($data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      * Deletes a slot by ID. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |      * @param string $id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |      * @throws \GuzzleHttp\Exception\RequestException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 | 6 |  |     public function delete($id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 | 6 |  |         $url = "/slots/{$id}"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 | 6 |  |         $this->client->delete($url); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 | 3 |  |         return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 114 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 115 |  |  |  |