| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Incapsula\Api; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | class AccountsApi extends AbstractApi | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |     private $apiUri = 'https://my.incapsula.com/api/prov/v1'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |      *   sub_account_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |      *	Numeric identifier of the sub account to operate on. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |      * @param mixed $subAccountId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     public function delete($subAccountId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |         return $this->client->send(sprintf('%s/subaccounts/delete', $this->apiUri), [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |             'sub_account_id' => $subAccountId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      * Parameters: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      *api_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      *   API authentication identifier. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      *api_key | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      *	API authentication identifier. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      *sub_account_name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      *	The name of the sub account. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      *parent_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      *	The newly created account's parent id. If not specified, the invoking account will be assigned as the parent account. 	Optional:Yes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      *ref_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      *   Customer specific identifier for this operation. 	Optional:Yes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * @param mixed $subAccountName | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 37 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |     public function add($subAccountName) | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |         return $this->client->send(sprintf('%s/subaccounts/add', $this->apiUri), [ | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |             'sub_account_name' => $subAccountName, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |      * @param int $pageSize | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      * @param int $pageNum | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     public function list($pageSize = 50, $pageNum = 0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         return $this->client->send(sprintf('%s/accounts/listSubAccounts', $this->apiUri), [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |             'page_size' => $pageSize, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             'page_num' => $pageNum, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      * Get account login token. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      *Tokens are used instead of user/password based authentication to log in to the Incapsula management console. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      *Use this operation to generate a token for an account. The token is valid for 15 minutes. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      * /api/prov/v1/accounts/gettoken | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |      *In order to use the token, the user must use the following link: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      *https://my.incapsula.com/?token={generated_token} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      * @param mixed $accountId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     public function getLoginToken($accountId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         return $this->client->send(sprintf('%s/accounts/gettoken', $this->apiUri), [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |             'account_id' => $accountId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 80 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 81 |  |  |  |