Skip to content

Commit

Permalink
Merge pull request #651 from hjmsw/try-617
Browse files Browse the repository at this point in the history
Add try / catch to examples. Fixes #617
  • Loading branch information
thinkingserious authored Aug 7, 2018
2 parents d4c5686 + cb703f6 commit 5bf88ef
Show file tree
Hide file tree
Showing 27 changed files with 2,071 additions and 938 deletions.
81 changes: 55 additions & 26 deletions examples/accesssettings/accesssettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@
// GET /access_settings/activity #

$query_params = json_decode('{"limit": 1}');
$response = $sg->client->access_settings()->activity()->get(null, $query_params);
echo $response->statusCode();
echo $response->body();
print_r($response->headers());

try {
$response = $sg->client->access_settings()->activity()->get(null, $query_params);
print $response->statusCode() . "\n";
print_r($response->headers());
print $response->body() . "\n";
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}

////////////////////////////////////////////////////
// Add one or more IPs to the whitelist #
Expand All @@ -35,52 +40,76 @@
}
]
}');
$response = $sg->client->access_settings()->whitelist()->post($request_body);
echo $response->statusCode();
echo $response->body();
print_r($response->headers());

try {
$response = $sg->client->access_settings()->whitelist()->post($request_body);
print $response->statusCode() . "\n";
print_r($response->headers());
print $response->body() . "\n";
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}

////////////////////////////////////////////////////
// Retrieve a list of currently whitelisted IPs #
// GET /access_settings/whitelist #

$response = $sg->client->access_settings()->whitelist()->get();
echo $response->statusCode();
echo $response->body();
print_r($response->headers());
try {
$response = $sg->client->access_settings()->whitelist()->get();
print $response->statusCode() . "\n";
print_r($response->headers());
print $response->body() . "\n";
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}

////////////////////////////////////////////////////
// Remove one or more IPs from the whitelist #
// DELETE /access_settings/whitelist #

$request_body = json_decode('{
"ids": [
1,
2,
1,
2,
3
]
}');
$response = $sg->client->access_settings()->whitelist()->delete($request_body);
echo $response->statusCode();
echo $response->body();
print_r($response->headers());

try {
$response = $sg->client->access_settings()->whitelist()->delete($request_body);
print $response->statusCode() . "\n";
print_r($response->headers());
print $response->body() . "\n";
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}

////////////////////////////////////////////////////
// Retrieve a specific whitelisted IP #
// GET /access_settings/whitelist/{rule_id} #

$rule_id = "test_url_param";
$response = $sg->client->access_settings()->whitelist()->_($rule_id)->get();
echo $response->statusCode();
echo $response->body();
print_r($response->headers());

try {
$response = $sg->client->access_settings()->whitelist()->_($rule_id)->get();
print $response->statusCode() . "\n";
print_r($response->headers());
print $response->body() . "\n";
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}

////////////////////////////////////////////////////
// Remove a specific IP from the whitelist #
// DELETE /access_settings/whitelist/{rule_id} #

$rule_id = "test_url_param";
$response = $sg->client->access_settings()->whitelist()->_($rule_id)->delete();
echo $response->statusCode();
echo $response->body();
print_r($response->headers());

try {
$response = $sg->client->access_settings()->whitelist()->_($rule_id)->delete();
print $response->statusCode() . "\n";
print_r($response->headers());
print $response->body() . "\n";
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
64 changes: 44 additions & 20 deletions examples/alerts/alerts.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,28 @@
"frequency": "daily",
"type": "stats_notification"
}');
$response = $sg->client->alerts()->post($request_body);
echo $response->statusCode();
echo $response->body();
print_r($response->headers());

try {
$response = $sg->client->alerts()->post($request_body);
print $response->statusCode() . "\n";
print_r($response->headers());
print $response->body() . "\n";
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}

////////////////////////////////////////////////////
// Retrieve all alerts #
// GET /alerts #

$response = $sg->client->alerts()->get();
echo $response->statusCode();
echo $response->body();
print_r($response->headers());
try {
$response = $sg->client->alerts()->get();
print $response->statusCode() . "\n";
print_r($response->headers());
print $response->body() . "\n";
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}

////////////////////////////////////////////////////
// Update an alert #
Expand All @@ -39,27 +48,42 @@
"email_to": "[email protected]"
}');
$alert_id = "test_url_param";
$response = $sg->client->alerts()->_($alert_id)->patch($request_body);
echo $response->statusCode();
echo $response->body();
print_r($response->headers());

try {
$response = $sg->client->alerts()->_($alert_id)->patch($request_body);
print $response->statusCode() . "\n";
print_r($response->headers());
print $response->body() . "\n";
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}

////////////////////////////////////////////////////
// Retrieve a specific alert #
// GET /alerts/{alert_id} #

$alert_id = "test_url_param";
$response = $sg->client->alerts()->_($alert_id)->get();
echo $response->statusCode();
echo $response->body();
print_r($response->headers());

try {
$response = $sg->client->alerts()->_($alert_id)->get();
print $response->statusCode() . "\n";
print_r($response->headers());
print $response->body() . "\n";
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}

////////////////////////////////////////////////////
// Delete an alert #
// DELETE /alerts/{alert_id} #

$alert_id = "test_url_param";
$response = $sg->client->alerts()->_($alert_id)->delete();
echo $response->statusCode();
echo $response->body();
print_r($response->headers());

try {
$response = $sg->client->alerts()->_($alert_id)->delete();
print $response->statusCode() . "\n";
print_r($response->headers());
print $response->body() . "\n";
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
78 changes: 54 additions & 24 deletions examples/apikeys/apikeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,30 @@
"alerts.read"
]
}');
$response = $sg->client->api_keys()->post($request_body);
echo $response->statusCode();
echo $response->body();
print_r($response->headers());

try {
$response = $sg->client->api_keys()->post($request_body);
print $response->statusCode() . "\n";
print_r($response->headers());
print $response->body() . "\n";
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}

////////////////////////////////////////////////////
// Retrieve all API Keys belonging to the authenticated user #
// GET /api_keys #

$query_params = json_decode('{"limit": 1}');
$response = $sg->client->api_keys()->get(null, $query_params);
echo $response->statusCode();
echo $response->body();
print_r($response->headers());

try {
$response = $sg->client->api_keys()->get(null, $query_params);
print $response->statusCode() . "\n";
print_r($response->headers());
print $response->body() . "\n";
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}

////////////////////////////////////////////////////
// Update the name & scopes of an API Key #
Expand All @@ -48,10 +58,15 @@
]
}');
$api_key_id = "test_url_param";
$response = $sg->client->api_keys()->_($api_key_id)->put($request_body);
echo $response->statusCode();
echo $response->body();
print_r($response->headers());

try {
$response = $sg->client->api_keys()->_($api_key_id)->put($request_body);
print $response->statusCode() . "\n";
print_r($response->headers());
print $response->body() . "\n";
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}

////////////////////////////////////////////////////
// Update API keys #
Expand All @@ -61,27 +76,42 @@
"name": "A New Hope"
}');
$api_key_id = "test_url_param";
$response = $sg->client->api_keys()->_($api_key_id)->patch($request_body);
echo $response->statusCode();
echo $response->body();
print_r($response->headers());

try {
$response = $sg->client->api_keys()->_($api_key_id)->patch($request_body);
print $response->statusCode() . "\n";
print_r($response->headers());
print $response->body() . "\n";
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}

////////////////////////////////////////////////////
// Retrieve an existing API Key #
// GET /api_keys/{api_key_id} #

$api_key_id = "test_url_param";
$response = $sg->client->api_keys()->_($api_key_id)->get();
echo $response->statusCode();
echo $response->body();
print_r($response->headers());

try {
$response = $sg->client->api_keys()->_($api_key_id)->get();
print $response->statusCode() . "\n";
print_r($response->headers());
print $response->body() . "\n";
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}

////////////////////////////////////////////////////
// Delete API keys #
// DELETE /api_keys/{api_key_id} #

$api_key_id = "test_url_param";
$response = $sg->client->api_keys()->_($api_key_id)->delete();
echo $response->statusCode();
echo $response->body();
print_r($response->headers());

try {
$response = $sg->client->api_keys()->_($api_key_id)->delete();
print $response->statusCode() . "\n";
print_r($response->headers());
print $response->body() . "\n";
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
Loading

0 comments on commit 5bf88ef

Please sign in to comment.