"Fossies" - the Fresh Open Source Software Archive

Member "seopanel/libs/sendgrid-php/examples/accesssettings/accesssettings.php" (22 Dec 2019, 2266 Bytes) of package /linux/www/seopanel.v.4.3.0.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 <?php
    2 // If you are using Composer
    3 require 'vendor/autoload.php';
    4 
    5 
    6 $apiKey = getenv('SENDGRID_API_KEY');
    7 $sg = new \SendGrid($apiKey);
    8 
    9 ////////////////////////////////////////////////////
   10 // Retrieve all recent access attempts #
   11 // GET /access_settings/activity #
   12 
   13 $query_params = json_decode('{"limit": 1}');
   14 $response = $sg->client->access_settings()->activity()->get(null, $query_params);
   15 echo $response->statusCode();
   16 echo $response->body();
   17 echo $response->headers();
   18 
   19 ////////////////////////////////////////////////////
   20 // Add one or more IPs to the whitelist #
   21 // POST /access_settings/whitelist #
   22 
   23 $request_body = json_decode('{
   24   "ips": [
   25     {
   26       "ip": "192.168.1.1"
   27     }, 
   28     {
   29       "ip": "192.*.*.*"
   30     }, 
   31     {
   32       "ip": "192.168.1.3/32"
   33     }
   34   ]
   35 }');
   36 $response = $sg->client->access_settings()->whitelist()->post($request_body);
   37 echo $response->statusCode();
   38 echo $response->body();
   39 echo $response->headers();
   40 
   41 ////////////////////////////////////////////////////
   42 // Retrieve a list of currently whitelisted IPs #
   43 // GET /access_settings/whitelist #
   44 
   45 $response = $sg->client->access_settings()->whitelist()->get();
   46 echo $response->statusCode();
   47 echo $response->body();
   48 echo $response->headers();
   49 
   50 ////////////////////////////////////////////////////
   51 // Remove one or more IPs from the whitelist #
   52 // DELETE /access_settings/whitelist #
   53 
   54 $request_body = json_decode('{
   55   "ids": [
   56     1, 
   57     2, 
   58     3
   59   ]
   60 }');
   61 $response = $sg->client->access_settings()->whitelist()->delete($request_body);
   62 echo $response->statusCode();
   63 echo $response->body();
   64 echo $response->headers();
   65 
   66 ////////////////////////////////////////////////////
   67 // Retrieve a specific whitelisted IP #
   68 // GET /access_settings/whitelist/{rule_id} #
   69 
   70 $rule_id = "test_url_param";
   71 $response = $sg->client->access_settings()->whitelist()->_($rule_id)->get();
   72 echo $response->statusCode();
   73 echo $response->body();
   74 echo $response->headers();
   75 
   76 ////////////////////////////////////////////////////
   77 // Remove a specific IP from the whitelist #
   78 // DELETE /access_settings/whitelist/{rule_id} #
   79 
   80 $rule_id = "test_url_param";
   81 $response = $sg->client->access_settings()->whitelist()->_($rule_id)->delete();
   82 echo $response->statusCode();
   83 echo $response->body();
   84 echo $response->headers();