From cb703f6f9c7a65f78449fdc1542b7550f5e9ac13 Mon Sep 17 00:00:00 2001 From: James Harding Date: Sat, 28 Jul 2018 21:33:55 +0100 Subject: [PATCH] Add try catch to examples --- examples/accesssettings/accesssettings.php | 81 ++-- examples/alerts/alerts.php | 64 ++- examples/apikeys/apikeys.php | 78 ++-- examples/asm/asm.php | 182 +++++--- examples/browsers/browsers.php | 13 +- examples/campaigns/campaigns.php | 143 +++++-- examples/categories/categories.php | 39 +- examples/clients/clients.php | 26 +- examples/contactdb/contactdb.php | 397 ++++++++++++------ examples/devices/devices.php | 13 +- examples/geo/geo.php | 13 +- examples/helpers/contacts/recipients.php | 13 +- examples/helpers/mail/example.php | 26 +- examples/ips/ips.php | 179 +++++--- examples/mail/mail.php | 38 +- .../mailboxproviders/mailboxproviders.php | 13 +- examples/mailsettings/mailsettings.php | 238 +++++++---- examples/partnersettings/partnersettings.php | 39 +- examples/scopes/scopes.php | 12 +- examples/senders/senders.php | 77 ++-- examples/stats/stats.php | 13 +- examples/subusers/subusers.php | 182 +++++--- examples/suppression/suppression.php | 221 +++++++--- examples/templates/templates.php | 131 ++++-- .../trackingsettings/trackingsettings.php | 113 +++-- examples/user/user.php | 317 +++++++++----- examples/whitelabel/whitelabel.php | 348 ++++++++++----- 27 files changed, 2071 insertions(+), 938 deletions(-) diff --git a/examples/accesssettings/accesssettings.php b/examples/accesssettings/accesssettings.php index ca36d296f..b55adc9aa 100644 --- a/examples/accesssettings/accesssettings.php +++ b/examples/accesssettings/accesssettings.php @@ -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 # @@ -35,19 +40,28 @@ } ] }'); -$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 # @@ -55,32 +69,47 @@ $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"; +} diff --git a/examples/alerts/alerts.php b/examples/alerts/alerts.php index 38de8749f..8eafac5cb 100644 --- a/examples/alerts/alerts.php +++ b/examples/alerts/alerts.php @@ -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 # @@ -39,27 +48,42 @@ "email_to": "example@example.com" }'); $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"; +} diff --git a/examples/apikeys/apikeys.php b/examples/apikeys/apikeys.php index 27a05cf87..ddc56cc19 100644 --- a/examples/apikeys/apikeys.php +++ b/examples/apikeys/apikeys.php @@ -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 # @@ -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 # @@ -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"; +} diff --git a/examples/asm/asm.php b/examples/asm/asm.php index 123db57e5..9e3cd4fd8 100644 --- a/examples/asm/asm.php +++ b/examples/asm/asm.php @@ -17,20 +17,30 @@ "is_default": true, "name": "Product Suggestions" }'); -$response = $sg->client->asm()->groups()->post($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->asm()->groups()->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 information about multiple suppression groups # // GET /asm/groups # $query_params = json_decode('{"id": 1}'); -$response = $sg->client->asm()->groups()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->asm()->groups()->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 a suppression group. # @@ -42,30 +52,45 @@ "name": "Item Suggestions" }'); $group_id = "test_url_param"; -$response = $sg->client->asm()->groups()->_($group_id)->patch($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->asm()->groups()->_($group_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"; +} //////////////////////////////////////////////////// // Get information on a single suppression group. # // GET /asm/groups/{group_id} # $group_id = "test_url_param"; -$response = $sg->client->asm()->groups()->_($group_id)->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->asm()->groups()->_($group_id)->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Delete a suppression group. # // DELETE /asm/groups/{group_id} # $group_id = "test_url_param"; -$response = $sg->client->asm()->groups()->_($group_id)->delete(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->asm()->groups()->_($group_id)->delete(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Add suppressions to a suppression group # @@ -78,20 +103,30 @@ ] }'); $group_id = "test_url_param"; -$response = $sg->client->asm()->groups()->_($group_id)->suppressions()->post($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->asm()->groups()->_($group_id)->suppressions()->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 suppressions for a suppression group # // GET /asm/groups/{group_id}/suppressions # $group_id = "test_url_param"; -$response = $sg->client->asm()->groups()->_($group_id)->suppressions()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->asm()->groups()->_($group_id)->suppressions()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Search for suppressions within a group # @@ -105,10 +140,15 @@ ] }'); $group_id = "test_url_param"; -$response = $sg->client->asm()->groups()->_($group_id)->suppressions()->search()->post($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->asm()->groups()->_($group_id)->suppressions()->search()->post($request_body); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Delete a suppression from a suppression group # @@ -116,19 +156,29 @@ $group_id = "test_url_param"; $email = "test_url_param"; -$response = $sg->client->asm()->groups()->_($group_id)->suppressions()->_($email)->delete(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->asm()->groups()->_($group_id)->suppressions()->_($email)->delete(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Retrieve all suppressions # // GET /asm/suppressions # -$response = $sg->client->asm()->suppressions()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->asm()->suppressions()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Add recipient addresses to the global suppression group. # @@ -140,37 +190,57 @@ "test2@example.com" ] }'); -$response = $sg->client->asm()->suppressions()->global()->post($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->asm()->suppressions()->global()->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 Global Suppression # // GET /asm/suppressions/global/{email} # $email = "test_url_param"; -$response = $sg->client->asm()->suppressions()->global()->_($email)->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->asm()->suppressions()->global()->_($email)->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Delete a Global Suppression # // DELETE /asm/suppressions/global/{email} # $email = "test_url_param"; -$response = $sg->client->asm()->suppressions()->global()->_($email)->delete(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->asm()->suppressions()->global()->_($email)->delete(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Retrieve all suppression groups for an email address # // GET /asm/suppressions/{email} # $email = "test_url_param"; -$response = $sg->client->asm()->suppressions()->_($email)->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->asm()->suppressions()->_($email)->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} diff --git a/examples/browsers/browsers.php b/examples/browsers/browsers.php index 06e007b44..c54162155 100644 --- a/examples/browsers/browsers.php +++ b/examples/browsers/browsers.php @@ -13,7 +13,12 @@ // GET /browsers/stats # $query_params = json_decode('{"end_date": "2016-04-01", "aggregated_by": "day", "browsers": "test_string", "limit": "test_string", "offset": "test_string", "start_date": "2016-01-01"}'); -$response = $sg->client->browsers()->stats()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->browsers()->stats()->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"; +} diff --git a/examples/campaigns/campaigns.php b/examples/campaigns/campaigns.php index 9ae395409..2f9ffb337 100644 --- a/examples/campaigns/campaigns.php +++ b/examples/campaigns/campaigns.php @@ -32,20 +32,30 @@ "suppression_group_id": 42, "title": "March Newsletter" }'); -$response = $sg->client->campaigns()->post($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->campaigns()->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 Campaigns # // GET /campaigns # $query_params = json_decode('{"limit": 1, "offset": 1}'); -$response = $sg->client->campaigns()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->campaigns()->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 a Campaign # @@ -61,30 +71,45 @@ "title": "May Newsletter" }'); $campaign_id = "test_url_param"; -$response = $sg->client->campaigns()->_($campaign_id)->patch($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->campaigns()->_($campaign_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 single campaign # // GET /campaigns/{campaign_id} # $campaign_id = "test_url_param"; -$response = $sg->client->campaigns()->_($campaign_id)->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->campaigns()->_($campaign_id)->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Delete a Campaign # // DELETE /campaigns/{campaign_id} # $campaign_id = "test_url_param"; -$response = $sg->client->campaigns()->_($campaign_id)->delete(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->campaigns()->_($campaign_id)->delete(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Update a Scheduled Campaign # @@ -94,10 +119,15 @@ "send_at": 1489451436 }'); $campaign_id = "test_url_param"; -$response = $sg->client->campaigns()->_($campaign_id)->schedules()->patch($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->campaigns()->_($campaign_id)->schedules()->patch($request_body); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Schedule a Campaign # @@ -107,40 +137,60 @@ "send_at": 1489771528 }'); $campaign_id = "test_url_param"; -$response = $sg->client->campaigns()->_($campaign_id)->schedules()->post($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->campaigns()->_($campaign_id)->schedules()->post($request_body); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // View Scheduled Time of a Campaign # // GET /campaigns/{campaign_id}/schedules # $campaign_id = "test_url_param"; -$response = $sg->client->campaigns()->_($campaign_id)->schedules()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->campaigns()->_($campaign_id)->schedules()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Unschedule a Scheduled Campaign # // DELETE /campaigns/{campaign_id}/schedules # $campaign_id = "test_url_param"; -$response = $sg->client->campaigns()->_($campaign_id)->schedules()->delete(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->campaigns()->_($campaign_id)->schedules()->delete(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Send a Campaign # // POST /campaigns/{campaign_id}/schedules/now # $campaign_id = "test_url_param"; -$response = $sg->client->campaigns()->_($campaign_id)->schedules()->now()->post(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->campaigns()->_($campaign_id)->schedules()->now()->post(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Send a Test Campaign # @@ -150,7 +200,12 @@ "to": "your.email@example.com" }'); $campaign_id = "test_url_param"; -$response = $sg->client->campaigns()->_($campaign_id)->schedules()->test()->post($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->campaigns()->_($campaign_id)->schedules()->test()->post($request_body); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} diff --git a/examples/categories/categories.php b/examples/categories/categories.php index a235e83a0..443029629 100644 --- a/examples/categories/categories.php +++ b/examples/categories/categories.php @@ -13,27 +13,42 @@ // GET /categories # $query_params = json_decode('{"category": "test_string", "limit": 1, "offset": 1}'); -$response = $sg->client->categories()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->categories()->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"; +} //////////////////////////////////////////////////// // Retrieve Email Statistics for Categories # // GET /categories/stats # $query_params = json_decode('{"end_date": "2016-04-01", "aggregated_by": "day", "limit": 1, "offset": 1, "start_date": "2016-01-01", "categories": "test_string"}'); -$response = $sg->client->categories()->stats()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->categories()->stats()->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"; +} //////////////////////////////////////////////////// // Retrieve sums of email stats for each category [Needs: Stats object defined, has category ID?] # // GET /categories/stats/sums # $query_params = json_decode('{"end_date": "2016-04-01", "aggregated_by": "day", "limit": 1, "sort_by_metric": "test_string", "offset": 1, "start_date": "2016-01-01", "sort_by_direction": "asc"}'); -$response = $sg->client->categories()->stats()->sums()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->categories()->stats()->sums()->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"; +} diff --git a/examples/clients/clients.php b/examples/clients/clients.php index 22de0f75d..4e31b21eb 100644 --- a/examples/clients/clients.php +++ b/examples/clients/clients.php @@ -13,10 +13,15 @@ // GET /clients/stats # $query_params = json_decode('{"aggregated_by": "day", "start_date": "2016-01-01", "end_date": "2016-04-01"}'); -$response = $sg->client->clients()->stats()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->clients()->stats()->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"; +} //////////////////////////////////////////////////// // Retrieve stats by a specific client type. # @@ -24,7 +29,12 @@ $query_params = json_decode('{"aggregated_by": "day", "start_date": "2016-01-01", "end_date": "2016-04-01"}'); $client_type = "test_url_param"; -$response = $sg->client->clients()->_($client_type)->stats()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->clients()->_($client_type)->stats()->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"; +} diff --git a/examples/contactdb/contactdb.php b/examples/contactdb/contactdb.php index b41661b9e..b2ee7b20d 100644 --- a/examples/contactdb/contactdb.php +++ b/examples/contactdb/contactdb.php @@ -16,39 +16,58 @@ "name": "pet", "type": "text" }'); -$response = $sg->client->contactdb()->custom_fields()->post($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->contactdb()->custom_fields()->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 custom fields # // GET /contactdb/custom_fields # -$response = $sg->client->contactdb()->custom_fields()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->contactdb()->custom_fields()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Retrieve a Custom Field # // GET /contactdb/custom_fields/{custom_field_id} # $custom_field_id = "test_url_param"; -$response = $sg->client->contactdb()->custom_fields()->_($custom_field_id)->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->contactdb()->custom_fields()->_($custom_field_id)->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Delete a Custom Field # // DELETE /contactdb/custom_fields/{custom_field_id} # $custom_field_id = "test_url_param"; -$response = $sg->client->contactdb()->custom_fields()->_($custom_field_id)->delete(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->contactdb()->custom_fields()->_($custom_field_id)->delete(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Create a List # @@ -57,19 +76,28 @@ $request_body = json_decode('{ "name": "your list name" }'); -$response = $sg->client->contactdb()->lists()->post($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->contactdb()->lists()->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 lists # // GET /contactdb/lists # -$response = $sg->client->contactdb()->lists()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->contactdb()->lists()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Delete Multiple lists # @@ -81,10 +109,15 @@ 3, 4 ]'); -$response = $sg->client->contactdb()->lists()->delete($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->contactdb()->lists()->delete($request_body); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Update a List # @@ -95,10 +128,15 @@ }'); $query_params = json_decode('{"list_id": 1}'); $list_id = "test_url_param"; -$response = $sg->client->contactdb()->lists()->_($list_id)->patch($request_body, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->contactdb()->lists()->_($list_id)->patch($request_body, $query_params); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Retrieve a single list # @@ -106,10 +144,15 @@ $query_params = json_decode('{"list_id": 1}'); $list_id = "test_url_param"; -$response = $sg->client->contactdb()->lists()->_($list_id)->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->contactdb()->lists()->_($list_id)->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"; +} //////////////////////////////////////////////////// // Delete a List # @@ -117,10 +160,15 @@ $query_params = json_decode('{"delete_contacts": "true"}'); $list_id = "test_url_param"; -$response = $sg->client->contactdb()->lists()->_($list_id)->delete(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->contactdb()->lists()->_($list_id)->delete(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 Multiple Recipients to a List # @@ -131,10 +179,15 @@ "recipient_id2" ]'); $list_id = "test_url_param"; -$response = $sg->client->contactdb()->lists()->_($list_id)->recipients()->post($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->contactdb()->lists()->_($list_id)->recipients()->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 recipients on a List # @@ -142,10 +195,15 @@ $query_params = json_decode('{"page": 1, "page_size": 1, "list_id": 1}'); $list_id = "test_url_param"; -$response = $sg->client->contactdb()->lists()->_($list_id)->recipients()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->contactdb()->lists()->_($list_id)->recipients()->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 a Single Recipient to a List # @@ -153,10 +211,15 @@ $list_id = "test_url_param"; $recipient_id = "test_url_param"; -$response = $sg->client->contactdb()->lists()->_($list_id)->recipients()->_($recipient_id)->post(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->contactdb()->lists()->_($list_id)->recipients()->_($recipient_id)->post(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Delete a Single Recipient from a Single List # @@ -165,10 +228,15 @@ $query_params = json_decode('{"recipient_id": 1, "list_id": 1}'); $list_id = "test_url_param"; $recipient_id = "test_url_param"; -$response = $sg->client->contactdb()->lists()->_($list_id)->recipients()->_($recipient_id)->delete(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->contactdb()->lists()->_($list_id)->recipients()->_($recipient_id)->delete(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 Recipient # @@ -181,10 +249,15 @@ "last_name": "Jones" } ]'); -$response = $sg->client->contactdb()->recipients()->patch($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->contactdb()->recipients()->patch($request_body); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Add recipients # @@ -204,20 +277,30 @@ "last_name": "User" } ]'); -$response = $sg->client->contactdb()->recipients()->post($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->contactdb()->recipients()->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 recipients # // GET /contactdb/recipients # $query_params = json_decode('{"page": 1, "page_size": 1}'); -$response = $sg->client->contactdb()->recipients()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->contactdb()->recipients()->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"; +} //////////////////////////////////////////////////// // Delete Recipient # @@ -227,77 +310,114 @@ "recipient_id1", "recipient_id2" ]'); -$response = $sg->client->contactdb()->recipients()->delete($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->contactdb()->recipients()->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 the count of billable recipients # // GET /contactdb/recipients/billable_count # -$response = $sg->client->contactdb()->recipients()->billable_count()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->contactdb()->recipients()->billable_count()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Retrieve a Count of Recipients # // GET /contactdb/recipients/count # -$response = $sg->client->contactdb()->recipients()->count()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->contactdb()->recipients()->count()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Retrieve recipients matching search criteria # // GET /contactdb/recipients/search # $query_params = json_decode('{"{field_name}": "test_string"}'); -$response = $sg->client->contactdb()->recipients()->search()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->contactdb()->recipients()->search()->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"; +} //////////////////////////////////////////////////// // Retrieve a single recipient # // GET /contactdb/recipients/{recipient_id} # $recipient_id = "test_url_param"; -$response = $sg->client->contactdb()->recipients()->_($recipient_id)->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->contactdb()->recipients()->_($recipient_id)->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Delete a Recipient # // DELETE /contactdb/recipients/{recipient_id} # $recipient_id = "test_url_param"; -$response = $sg->client->contactdb()->recipients()->_($recipient_id)->delete(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->contactdb()->recipients()->_($recipient_id)->delete(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Retrieve the lists that a recipient is on # // GET /contactdb/recipients/{recipient_id}/lists # $recipient_id = "test_url_param"; -$response = $sg->client->contactdb()->recipients()->_($recipient_id)->lists()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->contactdb()->recipients()->_($recipient_id)->lists()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Retrieve reserved fields # // GET /contactdb/reserved_fields # -$response = $sg->client->contactdb()->reserved_fields()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->contactdb()->reserved_fields()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Create a Segment # @@ -327,19 +447,28 @@ "list_id": 4, "name": "Last Name Miller" }'); -$response = $sg->client->contactdb()->segments()->post($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->contactdb()->segments()->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 segments # // GET /contactdb/segments # -$response = $sg->client->contactdb()->segments()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->contactdb()->segments()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Update a segment # @@ -359,10 +488,15 @@ }'); $query_params = json_decode('{"segment_id": "test_string"}'); $segment_id = "test_url_param"; -$response = $sg->client->contactdb()->segments()->_($segment_id)->patch($request_body, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->contactdb()->segments()->_($segment_id)->patch($request_body, $query_params); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Retrieve a segment # @@ -370,10 +504,15 @@ $query_params = json_decode('{"segment_id": 1}'); $segment_id = "test_url_param"; -$response = $sg->client->contactdb()->segments()->_($segment_id)->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->contactdb()->segments()->_($segment_id)->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"; +} //////////////////////////////////////////////////// // Delete a segment # @@ -381,10 +520,15 @@ $query_params = json_decode('{"delete_contacts": "true"}'); $segment_id = "test_url_param"; -$response = $sg->client->contactdb()->segments()->_($segment_id)->delete(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->contactdb()->segments()->_($segment_id)->delete(null, $query_params); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Retrieve recipients on a segment # @@ -392,7 +536,12 @@ $query_params = json_decode('{"page": 1, "page_size": 1}'); $segment_id = "test_url_param"; -$response = $sg->client->contactdb()->segments()->_($segment_id)->recipients()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->contactdb()->segments()->_($segment_id)->recipients()->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"; +} diff --git a/examples/devices/devices.php b/examples/devices/devices.php index 6f992de17..a6b9d0870 100644 --- a/examples/devices/devices.php +++ b/examples/devices/devices.php @@ -12,7 +12,12 @@ // GET /devices/stats # $query_params = json_decode('{"aggregated_by": "day", "limit": 1, "start_date": "2016-01-01", "end_date": "2016-04-01", "offset": 1}'); -$response = $sg->client->devices()->stats()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->devices()->stats()->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"; +} diff --git a/examples/geo/geo.php b/examples/geo/geo.php index f431a6270..708ca5d18 100644 --- a/examples/geo/geo.php +++ b/examples/geo/geo.php @@ -13,7 +13,12 @@ // GET /geo/stats # $query_params = json_decode('{"end_date": "2016-04-01", "country": "US", "aggregated_by": "day", "limit": 1, "offset": 1, "start_date": "2016-01-01"}'); -$response = $sg->client->geo()->stats()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->geo()->stats()->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"; +} diff --git a/examples/helpers/contacts/recipients.php b/examples/helpers/contacts/recipients.php index 4173e46fb..ace54a3cd 100644 --- a/examples/helpers/contacts/recipients.php +++ b/examples/helpers/contacts/recipients.php @@ -41,10 +41,15 @@ function recipientFormSubmit() } ]' ); - $response = $sg->client->contactdb()->recipients()->post($request_body); - echo $response->statusCode(); - echo $response->body(); - print_r($response->headers()); + + try { + $response = $sg->client->contactdb()->recipients()->post($request_body); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; + } catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; + } } buildRecipientForm(); // This will build and output an HTML form diff --git a/examples/helpers/mail/example.php b/examples/helpers/mail/example.php index 07c838a34..007145584 100644 --- a/examples/helpers/mail/example.php +++ b/examples/helpers/mail/example.php @@ -180,10 +180,15 @@ function sendHelloEmail() $sg = new \SendGrid($apiKey); $request_body = helloEmail(); - $response = $sg->client->mail()->send()->post($request_body); - echo $response->statusCode(); - echo $response->body(); - print_r($response->headers()); + + try { + $response = $sg->client->mail()->send()->post($request_body); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; + } catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; + } } function sendKitchenSink() @@ -192,10 +197,15 @@ function sendKitchenSink() $sg = new \SendGrid($apiKey); $request_body = kitchenSink(); - $response = $sg->client->mail()->send()->post($request_body); - echo $response->statusCode(); - echo $response->body(); - print_r($response->headers()); + + try { + $response = $sg->client->mail()->send()->post($request_body); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; + } catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; + } } sendHelloEmail(); // this will actually send an email diff --git a/examples/ips/ips.php b/examples/ips/ips.php index 30d91d4c6..bf7c45301 100644 --- a/examples/ips/ips.php +++ b/examples/ips/ips.php @@ -13,19 +13,28 @@ // GET /ips # $query_params = json_decode('{"subuser": "test_string", "ip": "test_string", "limit": 1, "exclude_whitelabels": "true", "offset": 1}'); -$response = $sg->client->ips()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->ips()->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"; +} //////////////////////////////////////////////////// // Retrieve all assigned IPs # // GET /ips/assigned # -$response = $sg->client->ips()->assigned()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->ips()->assigned()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Create an IP pool. # @@ -34,19 +43,28 @@ $request_body = json_decode('{ "name": "marketing" }'); -$response = $sg->client->ips()->pools()->post($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->ips()->pools()->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 IP pools. # // GET /ips/pools # -$response = $sg->client->ips()->pools()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->ips()->pools()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Update an IP pools name. # @@ -56,30 +74,45 @@ "name": "new_pool_name" }'); $pool_name = "test_url_param"; -$response = $sg->client->ips()->pools()->_($pool_name)->put($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->ips()->pools()->_($pool_name)->put($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 IPs in a specified pool. # // GET /ips/pools/{pool_name} # $pool_name = "test_url_param"; -$response = $sg->client->ips()->pools()->_($pool_name)->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->ips()->pools()->_($pool_name)->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Delete an IP pool. # // DELETE /ips/pools/{pool_name} # $pool_name = "test_url_param"; -$response = $sg->client->ips()->pools()->_($pool_name)->delete(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->ips()->pools()->_($pool_name)->delete(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Add an IP address to a pool # @@ -89,10 +122,15 @@ "ip": "0.0.0.0" }'); $pool_name = "test_url_param"; -$response = $sg->client->ips()->pools()->_($pool_name)->ips()->post($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->ips()->pools()->_($pool_name)->ips()->post($request_body); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Remove an IP address from a pool. # @@ -100,10 +138,15 @@ $pool_name = "test_url_param"; $ip = "test_url_param"; -$response = $sg->client->ips()->pools()->_($pool_name)->ips()->_($ip)->delete(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->ips()->pools()->_($pool_name)->ips()->_($ip)->delete(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Add an IP to warmup # @@ -112,46 +155,70 @@ $request_body = json_decode('{ "ip": "0.0.0.0" }'); -$response = $sg->client->ips()->warmup()->post($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->ips()->warmup()->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 IPs currently in warmup # // GET /ips/warmup # -$response = $sg->client->ips()->warmup()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->ips()->warmup()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Retrieve warmup status for a specific IP address # // GET /ips/warmup/{ip_address} # $ip_address = "test_url_param"; -$response = $sg->client->ips()->warmup()->_($ip_address)->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->ips()->warmup()->_($ip_address)->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Remove an IP from warmup # // DELETE /ips/warmup/{ip_address} # $ip_address = "test_url_param"; -$response = $sg->client->ips()->warmup()->_($ip_address)->delete(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->ips()->warmup()->_($ip_address)->delete(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Retrieve all IP pools an IP address belongs to # // GET /ips/{ip_address} # $ip_address = "test_url_param"; -$response = $sg->client->ips()->_($ip_address)->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->ips()->_($ip_address)->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} diff --git a/examples/mail/mail.php b/examples/mail/mail.php index a2c7622f0..a8aa5feaa 100644 --- a/examples/mail/mail.php +++ b/examples/mail/mail.php @@ -12,20 +12,29 @@ // Create a batch ID # // POST /mail/batch # -$response = $sg->client->mail()->batch()->post(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->mail()->batch()->post(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Validate batch ID # // GET /mail/batch/{batch_id} # $batch_id = "test_url_param"; -$response = $sg->client->mail()->batch()->_($batch_id)->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->mail()->batch()->_($batch_id)->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // v3 Mail Send # @@ -170,7 +179,12 @@ } } }'); -$response = $sg->client->mail()->send()->post($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->mail()->send()->post($request_body); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} diff --git a/examples/mailboxproviders/mailboxproviders.php b/examples/mailboxproviders/mailboxproviders.php index 6f82475f5..6cf1be3b8 100644 --- a/examples/mailboxproviders/mailboxproviders.php +++ b/examples/mailboxproviders/mailboxproviders.php @@ -13,7 +13,12 @@ // GET /mailbox_providers/stats # $query_params = json_decode('{"end_date": "2016-04-01", "mailbox_providers": "test_string", "aggregated_by": "day", "limit": 1, "offset": 1, "start_date": "2016-01-01"}'); -$response = $sg->client->mailbox_providers()->stats()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->mailbox_providers()->stats()->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"; +} diff --git a/examples/mailsettings/mailsettings.php b/examples/mailsettings/mailsettings.php index b9e5f4bf4..40d3668a7 100644 --- a/examples/mailsettings/mailsettings.php +++ b/examples/mailsettings/mailsettings.php @@ -13,10 +13,15 @@ // GET /mail_settings # $query_params = json_decode('{"limit": 1, "offset": 1}'); -$response = $sg->client->mail_settings()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->mail_settings()->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 address whitelist mail settings # @@ -29,19 +34,28 @@ "example.com" ] }'); -$response = $sg->client->mail_settings()->address_whitelist()->patch($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->mail_settings()->address_whitelist()->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 address whitelist mail settings # // GET /mail_settings/address_whitelist # -$response = $sg->client->mail_settings()->address_whitelist()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->mail_settings()->address_whitelist()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Update BCC mail settings # @@ -51,19 +65,28 @@ "email": "email@example.com", "enabled": false }'); -$response = $sg->client->mail_settings()->bcc()->patch($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->mail_settings()->bcc()->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 all BCC mail settings # // GET /mail_settings/bcc # -$response = $sg->client->mail_settings()->bcc()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->mail_settings()->bcc()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Update bounce purge mail settings # @@ -74,19 +97,28 @@ "hard_bounces": 5, "soft_bounces": 5 }'); -$response = $sg->client->mail_settings()->bounce_purge()->patch($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->mail_settings()->bounce_purge()->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 bounce purge mail settings # // GET /mail_settings/bounce_purge # -$response = $sg->client->mail_settings()->bounce_purge()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->mail_settings()->bounce_purge()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Update footer mail settings # @@ -97,19 +129,28 @@ "html_content": "...", "plain_content": "..." }'); -$response = $sg->client->mail_settings()->footer()->patch($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->mail_settings()->footer()->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 footer mail settings # // GET /mail_settings/footer # -$response = $sg->client->mail_settings()->footer()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->mail_settings()->footer()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Update forward bounce mail settings # @@ -119,19 +160,28 @@ "email": "example@example.com", "enabled": true }'); -$response = $sg->client->mail_settings()->forward_bounce()->patch($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->mail_settings()->forward_bounce()->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 forward bounce mail settings # // GET /mail_settings/forward_bounce # -$response = $sg->client->mail_settings()->forward_bounce()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->mail_settings()->forward_bounce()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Update forward spam mail settings # @@ -141,19 +191,28 @@ "email": "", "enabled": false }'); -$response = $sg->client->mail_settings()->forward_spam()->patch($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->mail_settings()->forward_spam()->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 forward spam mail settings # // GET /mail_settings/forward_spam # -$response = $sg->client->mail_settings()->forward_spam()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->mail_settings()->forward_spam()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Update plain content mail settings # @@ -162,19 +221,28 @@ $request_body = json_decode('{ "enabled": false }'); -$response = $sg->client->mail_settings()->plain_content()->patch($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->mail_settings()->plain_content()->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 plain content mail settings # // GET /mail_settings/plain_content # -$response = $sg->client->mail_settings()->plain_content()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->mail_settings()->plain_content()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Update spam check mail settings # @@ -185,19 +253,28 @@ "max_score": 5, "url": "url" }'); -$response = $sg->client->mail_settings()->spam_check()->patch($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->mail_settings()->spam_check()->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 spam check mail settings # // GET /mail_settings/spam_check # -$response = $sg->client->mail_settings()->spam_check()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->mail_settings()->spam_check()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Update template mail settings # @@ -207,16 +284,25 @@ "enabled": true, "html_content": "<% body %>" }'); -$response = $sg->client->mail_settings()->template()->patch($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->mail_settings()->template()->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 legacy template mail settings # // GET /mail_settings/template # -$response = $sg->client->mail_settings()->template()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->mail_settings()->template()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} diff --git a/examples/partnersettings/partnersettings.php b/examples/partnersettings/partnersettings.php index b75624102..17d528750 100644 --- a/examples/partnersettings/partnersettings.php +++ b/examples/partnersettings/partnersettings.php @@ -13,10 +13,15 @@ // GET /partner_settings # $query_params = json_decode('{"limit": 1, "offset": 1}'); -$response = $sg->client->partner_settings()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->partner_settings()->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"; +} //////////////////////////////////////////////////// // Updates New Relic partner settings. # @@ -27,16 +32,26 @@ "enabled": true, "license_key": "" }'); -$response = $sg->client->partner_settings()->new_relic()->patch($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->partner_settings()->new_relic()->patch($request_body); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Returns all New Relic partner settings. # // GET /partner_settings/new_relic # -$response = $sg->client->partner_settings()->new_relic()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->partner_settings()->new_relic()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} diff --git a/examples/scopes/scopes.php b/examples/scopes/scopes.php index 48ea6e5b7..dd60f63cd 100644 --- a/examples/scopes/scopes.php +++ b/examples/scopes/scopes.php @@ -12,7 +12,11 @@ // Retrieve a list of scopes for which this user has access. # // GET /scopes # -$response = $sg->client->scopes()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->scopes()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} diff --git a/examples/senders/senders.php b/examples/senders/senders.php index 949b91cdc..71f844716 100644 --- a/examples/senders/senders.php +++ b/examples/senders/senders.php @@ -29,19 +29,28 @@ "state": "Colorado", "zip": "80202" }'); -$response = $sg->client->senders()->post($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->senders()->post($request_body); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Get all Sender Identities # // GET /senders # -$response = $sg->client->senders()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->senders()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Update a Sender Identity # @@ -65,37 +74,57 @@ "zip": "80202" }'); $sender_id = "test_url_param"; -$response = $sg->client->senders()->_($sender_id)->patch($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->senders()->_($sender_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"; +} //////////////////////////////////////////////////// // View a Sender Identity # // GET /senders/{sender_id} # $sender_id = "test_url_param"; -$response = $sg->client->senders()->_($sender_id)->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->senders()->_($sender_id)->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Delete a Sender Identity # // DELETE /senders/{sender_id} # $sender_id = "test_url_param"; -$response = $sg->client->senders()->_($sender_id)->delete(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->senders()->_($sender_id)->delete(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Resend Sender Identity Verification # // POST /senders/{sender_id}/resend_verification # $sender_id = "test_url_param"; -$response = $sg->client->senders()->_($sender_id)->resend_verification()->post(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->senders()->_($sender_id)->resend_verification()->post(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} diff --git a/examples/stats/stats.php b/examples/stats/stats.php index 3ce05a850..9021bbef2 100644 --- a/examples/stats/stats.php +++ b/examples/stats/stats.php @@ -13,7 +13,12 @@ // GET /stats # $query_params = json_decode('{"aggregated_by": "day", "limit": 1, "start_date": "2016-01-01", "end_date": "2016-04-01", "offset": 1}'); -$response = $sg->client->stats()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->stats()->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"; +} diff --git a/examples/subusers/subusers.php b/examples/subusers/subusers.php index 206ada9f8..25d44e07c 100644 --- a/examples/subusers/subusers.php +++ b/examples/subusers/subusers.php @@ -21,60 +21,90 @@ "password": "johns_password", "username": "John@example.com" }'); -$response = $sg->client->subusers()->post($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->subusers()->post($request_body); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // List all Subusers # // GET /subusers # $query_params = json_decode('{"username": "test_string", "limit": 1, "offset": 1}'); -$response = $sg->client->subusers()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->subusers()->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"; +} //////////////////////////////////////////////////// // Retrieve Subuser Reputations # // GET /subusers/reputations # $query_params = json_decode('{"usernames": "test_string"}'); -$response = $sg->client->subusers()->reputations()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->subusers()->reputations()->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"; +} //////////////////////////////////////////////////// // Retrieve email statistics for your subusers. # // GET /subusers/stats # $query_params = json_decode('{"end_date": "2016-04-01", "aggregated_by": "day", "limit": 1, "offset": 1, "start_date": "2016-01-01", "subusers": "test_string"}'); -$response = $sg->client->subusers()->stats()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->subusers()->stats()->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"; +} //////////////////////////////////////////////////// // Retrieve monthly stats for all subusers # // GET /subusers/stats/monthly # $query_params = json_decode('{"subuser": "test_string", "limit": 1, "sort_by_metric": "test_string", "offset": 1, "date": "test_string", "sort_by_direction": "asc"}'); -$response = $sg->client->subusers()->stats()->monthly()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->subusers()->stats()->monthly()->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"; +} //////////////////////////////////////////////////// // Retrieve the totals for each email statistic metric for all subusers. # // GET /subusers/stats/sums # $query_params = json_decode('{"end_date": "2016-04-01", "aggregated_by": "day", "limit": 1, "sort_by_metric": "test_string", "offset": 1, "start_date": "2016-01-01", "sort_by_direction": "asc"}'); -$response = $sg->client->subusers()->stats()->sums()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->subusers()->stats()->sums()->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"; +} //////////////////////////////////////////////////// // Enable/disable a subuser # @@ -84,20 +114,30 @@ "disabled": false }'); $subuser_name = "test_url_param"; -$response = $sg->client->subusers()->_($subuser_name)->patch($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->subusers()->_($subuser_name)->patch($request_body); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Delete a subuser # // DELETE /subusers/{subuser_name} # $subuser_name = "test_url_param"; -$response = $sg->client->subusers()->_($subuser_name)->delete(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->subusers()->_($subuser_name)->delete(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Update IPs assigned to a subuser # @@ -107,10 +147,15 @@ "127.0.0.1" ]'); $subuser_name = "test_url_param"; -$response = $sg->client->subusers()->_($subuser_name)->ips()->put($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->subusers()->_($subuser_name)->ips()->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 Monitor Settings for a subuser # @@ -121,10 +166,15 @@ "frequency": 500 }'); $subuser_name = "test_url_param"; -$response = $sg->client->subusers()->_($subuser_name)->monitor()->put($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->subusers()->_($subuser_name)->monitor()->put($request_body); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Create monitor settings # @@ -135,30 +185,45 @@ "frequency": 50000 }'); $subuser_name = "test_url_param"; -$response = $sg->client->subusers()->_($subuser_name)->monitor()->post($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->subusers()->_($subuser_name)->monitor()->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 monitor settings for a subuser # // GET /subusers/{subuser_name}/monitor # $subuser_name = "test_url_param"; -$response = $sg->client->subusers()->_($subuser_name)->monitor()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->subusers()->_($subuser_name)->monitor()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Delete monitor settings # // DELETE /subusers/{subuser_name}/monitor # $subuser_name = "test_url_param"; -$response = $sg->client->subusers()->_($subuser_name)->monitor()->delete(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->subusers()->_($subuser_name)->monitor()->delete(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Retrieve the monthly email statistics for a single subuser # @@ -166,7 +231,12 @@ $query_params = json_decode('{"date": "test_string", "sort_by_direction": "asc", "limit": 1, "sort_by_metric": "test_string", "offset": 1}'); $subuser_name = "test_url_param"; -$response = $sg->client->subusers()->_($subuser_name)->stats()->monthly()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->subusers()->_($subuser_name)->stats()->monthly()->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"; +} diff --git a/examples/suppression/suppression.php b/examples/suppression/suppression.php index 47e2933fb..dd20bebd2 100644 --- a/examples/suppression/suppression.php +++ b/examples/suppression/suppression.php @@ -13,10 +13,15 @@ // GET /suppression/blocks # $query_params = json_decode('{"start_time": 1, "limit": 1, "end_time": 1, "offset": 1}'); -$response = $sg->client->suppression()->blocks()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->suppression()->blocks()->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"; +} //////////////////////////////////////////////////// // Delete blocks # @@ -29,40 +34,60 @@ "example2@example.com" ] }'); -$response = $sg->client->suppression()->blocks()->delete($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->suppression()->blocks()->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 block # // GET /suppression/blocks/{email} # $email = "test_url_param"; -$response = $sg->client->suppression()->blocks()->_($email)->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->suppression()->blocks()->_($email)->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Delete a specific block # // DELETE /suppression/blocks/{email} # $email = "test_url_param"; -$response = $sg->client->suppression()->blocks()->_($email)->delete(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->suppression()->blocks()->_($email)->delete(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Retrieve all bounces # // GET /suppression/bounces # $query_params = json_decode('{"start_time": 1, "end_time": 1}'); -$response = $sg->client->suppression()->bounces()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->suppression()->bounces()->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"; +} //////////////////////////////////////////////////// // Delete bounces # @@ -75,20 +100,30 @@ "example2@example.com" ] }'); -$response = $sg->client->suppression()->bounces()->delete($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->suppression()->bounces()->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 Bounce # // GET /suppression/bounces/{email} # $email = "test_url_param"; -$response = $sg->client->suppression()->bounces()->_($email)->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->suppression()->bounces()->_($email)->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Delete a bounce # @@ -96,20 +131,30 @@ $query_params = json_decode('{"email_address": "example@example.com"}'); $email = "test_url_param"; -$response = $sg->client->suppression()->bounces()->_($email)->delete(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->suppression()->bounces()->_($email)->delete(null, $query_params); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Retrieve all invalid emails # // GET /suppression/invalid_emails # $query_params = json_decode('{"start_time": 1, "limit": 1, "end_time": 1, "offset": 1}'); -$response = $sg->client->suppression()->invalid_emails()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->suppression()->invalid_emails()->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"; +} //////////////////////////////////////////////////// // Delete invalid emails # @@ -122,60 +167,90 @@ "example2@example.com" ] }'); -$response = $sg->client->suppression()->invalid_emails()->delete($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->suppression()->invalid_emails()->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 invalid email # // GET /suppression/invalid_emails/{email} # $email = "test_url_param"; -$response = $sg->client->suppression()->invalid_emails()->_($email)->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->suppression()->invalid_emails()->_($email)->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Delete a specific invalid email # // DELETE /suppression/invalid_emails/{email} # $email = "test_url_param"; -$response = $sg->client->suppression()->invalid_emails()->_($email)->delete(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->suppression()->invalid_emails()->_($email)->delete(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Retrieve a specific spam report # // GET /suppression/spam_report/{email} # $email = "test_url_param"; -$response = $sg->client->suppression()->spam_reports()->_($email)->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->suppression()->spam_reports()->_($email)->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Delete a specific spam report # // DELETE /suppression/spam_report/{email} # $email = "test_url_param"; -$response = $sg->client->suppression()->spam_reports()->_($email)->delete(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->suppression()->spam_reports()->_($email)->delete(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Retrieve all spam reports # // GET /suppression/spam_reports # $query_params = json_decode('{"start_time": 1, "limit": 1, "end_time": 1, "offset": 1}'); -$response = $sg->client->suppression()->spam_reports()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->suppression()->spam_reports()->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"; +} //////////////////////////////////////////////////// // Delete spam reports # @@ -188,17 +263,27 @@ "example2@example.com" ] }'); -$response = $sg->client->suppression()->spam_reports()->delete($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->suppression()->spam_reports()->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 all global suppressions # // GET /suppression/unsubscribes # $query_params = json_decode('{"start_time": 1, "limit": 1, "end_time": 1, "offset": 1}'); -$response = $sg->client->suppression()->unsubscribes()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->suppression()->unsubscribes()->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"; +} diff --git a/examples/templates/templates.php b/examples/templates/templates.php index c4a2fcd7d..3c8678f98 100644 --- a/examples/templates/templates.php +++ b/examples/templates/templates.php @@ -15,19 +15,29 @@ $request_body = json_decode('{ "name": "example_name" }'); -$response = $sg->client->templates()->post($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->templates()->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 transactional templates. # // GET /templates # -$response = $sg->client->templates()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->templates()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Edit a transactional template. # @@ -37,30 +47,46 @@ "name": "new_example_name" }'); $template_id = "test_url_param"; -$response = $sg->client->templates()->_($template_id)->patch($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->templates()->_($template_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 single transactional template. # // GET /templates/{template_id} # $template_id = "test_url_param"; -$response = $sg->client->templates()->_($template_id)->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->templates()->_($template_id)->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Delete a template. # // DELETE /templates/{template_id} # $template_id = "test_url_param"; -$response = $sg->client->templates()->_($template_id)->delete(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->templates()->_($template_id)->delete(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} + //////////////////////////////////////////////////// // Create a new transactional template version. # @@ -75,10 +101,15 @@ "template_id": "ddb96bbc-9b92-425e-8979-99464621b543" }'); $template_id = "test_url_param"; -$response = $sg->client->templates()->_($template_id)->versions()->post($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->templates()->_($template_id)->versions()->post($request_body); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Edit a transactional template version. # @@ -93,10 +124,15 @@ }'); $template_id = "test_url_param"; $version_id = "test_url_param"; -$response = $sg->client->templates()->_($template_id)->versions()->_($version_id)->patch($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->templates()->_($template_id)->versions()->_($version_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 transactional template version. # @@ -104,10 +140,15 @@ $template_id = "test_url_param"; $version_id = "test_url_param"; -$response = $sg->client->templates()->_($template_id)->versions()->_($version_id)->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->templates()->_($template_id)->versions()->_($version_id)->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Delete a transactional template version. # @@ -115,10 +156,15 @@ $template_id = "test_url_param"; $version_id = "test_url_param"; -$response = $sg->client->templates()->_($template_id)->versions()->_($version_id)->delete(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->templates()->_($template_id)->versions()->_($version_id)->delete(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Activate a transactional template version. # @@ -126,7 +172,12 @@ $template_id = "test_url_param"; $version_id = "test_url_param"; -$response = $sg->client->templates()->_($template_id)->versions()->_($version_id)->activate()->post(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->templates()->_($template_id)->versions()->_($version_id)->activate()->post(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} diff --git a/examples/trackingsettings/trackingsettings.php b/examples/trackingsettings/trackingsettings.php index b2f46d66b..8d58b6303 100644 --- a/examples/trackingsettings/trackingsettings.php +++ b/examples/trackingsettings/trackingsettings.php @@ -12,10 +12,15 @@ // GET /tracking_settings # $query_params = json_decode('{"limit": 1, "offset": 1}'); -$response = $sg->client->tracking_settings()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->tracking_settings()->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 Click Tracking Settings # @@ -24,19 +29,28 @@ $request_body = json_decode('{ "enabled": true }'); -$response = $sg->client->tracking_settings()->click()->patch($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->tracking_settings()->click()->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 Click Track Settings # // GET /tracking_settings/click # -$response = $sg->client->tracking_settings()->click()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->tracking_settings()->click()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Update Google Analytics Settings # @@ -50,19 +64,28 @@ "utm_source": "sendgrid.com", "utm_term": "" }'); -$response = $sg->client->tracking_settings()->google_analytics()->patch($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->tracking_settings()->google_analytics()->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 Google Analytics Settings # // GET /tracking_settings/google_analytics # -$response = $sg->client->tracking_settings()->google_analytics()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->tracking_settings()->google_analytics()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Update Open Tracking Settings # @@ -71,19 +94,28 @@ $request_body = json_decode('{ "enabled": true }'); -$response = $sg->client->tracking_settings()->open()->patch($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->tracking_settings()->open()->patch($request_body); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Get Open Tracking Settings # // GET /tracking_settings/open # -$response = $sg->client->tracking_settings()->open()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->tracking_settings()->open()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Update Subscription Tracking Settings # @@ -97,16 +129,25 @@ "replace": "replacement tag", "url": "url" }'); -$response = $sg->client->tracking_settings()->subscription()->patch($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->tracking_settings()->subscription()->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 Subscription Tracking Settings # // GET /tracking_settings/subscription # -$response = $sg->client->tracking_settings()->subscription()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->tracking_settings()->subscription()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} diff --git a/examples/user/user.php b/examples/user/user.php index 4cf6d9831..fd7a20d7a 100644 --- a/examples/user/user.php +++ b/examples/user/user.php @@ -12,19 +12,27 @@ // Get a user's account information. # // GET /user/account # -$response = $sg->client->user()->account()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->user()->account()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Retrieve your credit balance # // GET /user/credits # -$response = $sg->client->user()->credits()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->user()->credits()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Update your account email address # @@ -33,19 +41,28 @@ $request_body = json_decode('{ "email": "example@example.com" }'); -$response = $sg->client->user()->email()->put($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->user()->email()->put($request_body); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Retrieve your account email address # // GET /user/email # -$response = $sg->client->user()->email()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->user()->email()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Update your password # @@ -55,10 +72,15 @@ "new_password": "new_password", "old_password": "old_password" }'); -$response = $sg->client->user()->password()->put($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->user()->password()->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 a user's profile # @@ -69,19 +91,29 @@ "first_name": "Example", "last_name": "User" }'); -$response = $sg->client->user()->profile()->patch($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->user()->profile()->patch($request_body); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Get a user's profile # // GET /user/profile # -$response = $sg->client->user()->profile()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->user()->profile()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Cancel or pause a scheduled send # @@ -91,19 +123,28 @@ "batch_id": "YOUR_BATCH_ID", "status": "pause" }'); -$response = $sg->client->user()->scheduled_sends()->post($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->user()->scheduled_sends()->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 scheduled sends # // GET /user/scheduled_sends # -$response = $sg->client->user()->scheduled_sends()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->user()->scheduled_sends()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Update user scheduled send information # @@ -113,30 +154,45 @@ "status": "pause" }'); $batch_id = "test_url_param"; -$response = $sg->client->user()->scheduled_sends()->_($batch_id)->patch($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->user()->scheduled_sends()->_($batch_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 scheduled send # // GET /user/scheduled_sends/{batch_id} # $batch_id = "test_url_param"; -$response = $sg->client->user()->scheduled_sends()->_($batch_id)->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->user()->scheduled_sends()->_($batch_id)->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Delete a cancellation or pause of a scheduled send # // DELETE /user/scheduled_sends/{batch_id} # $batch_id = "test_url_param"; -$response = $sg->client->user()->scheduled_sends()->_($batch_id)->delete(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->user()->scheduled_sends()->_($batch_id)->delete(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Update Enforced TLS settings # @@ -146,19 +202,28 @@ "require_tls": true, "require_valid_cert": false }'); -$response = $sg->client->user()->settings()->enforced_tls()->patch($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->user()->settings()->enforced_tls()->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 current Enforced TLS settings. # // GET /user/settings/enforced_tls # -$response = $sg->client->user()->settings()->enforced_tls()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->user()->settings()->enforced_tls()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Update your username # @@ -167,19 +232,28 @@ $request_body = json_decode('{ "username": "test_username" }'); -$response = $sg->client->user()->username()->put($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->user()->username()->put($request_body); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Retrieve your username # // GET /user/username # -$response = $sg->client->user()->username()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->user()->username()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Update Event Notification Settings # @@ -200,19 +274,28 @@ "unsubscribe": true, "url": "url" }'); -$response = $sg->client->user()->webhooks()->event()->settings()->patch($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->user()->webhooks()->event()->settings()->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 Event Webhook settings # // GET /user/webhooks/event/settings # -$response = $sg->client->user()->webhooks()->event()->settings()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->user()->webhooks()->event()->settings()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Test Event Notification Settings # @@ -221,10 +304,15 @@ $request_body = json_decode('{ "url": "url" }'); -$response = $sg->client->user()->webhooks()->event()->test()->post($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->user()->webhooks()->event()->test()->post($request_body); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Create a parse setting # @@ -236,19 +324,28 @@ "spam_check": true, "url": "http://email.myhosthame.com" }'); -$response = $sg->client->user()->webhooks()->parse()->settings()->post($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->user()->webhooks()->parse()->settings()->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 parse settings # // GET /user/webhooks/parse/settings # -$response = $sg->client->user()->webhooks()->parse()->settings()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->user()->webhooks()->parse()->settings()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Update a parse setting # @@ -260,37 +357,57 @@ "url": "http://newdomain.com/parse" }'); $hostname = "test_url_param"; -$response = $sg->client->user()->webhooks()->parse()->settings()->_($hostname)->patch($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->user()->webhooks()->parse()->settings()->_($hostname)->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 parse setting # // GET /user/webhooks/parse/settings/{hostname} # $hostname = "test_url_param"; -$response = $sg->client->user()->webhooks()->parse()->settings()->_($hostname)->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->user()->webhooks()->parse()->settings()->_($hostname)->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Delete a parse setting # // DELETE /user/webhooks/parse/settings/{hostname} # $hostname = "test_url_param"; -$response = $sg->client->user()->webhooks()->parse()->settings()->_($hostname)->delete(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->user()->webhooks()->parse()->settings()->_($hostname)->delete(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Retrieves Inbound Parse Webhook statistics. # // GET /user/webhooks/parse/stats # $query_params = json_decode('{"aggregated_by": "day", "limit": "test_string", "start_date": "2016-01-01", "end_date": "2016-04-01", "offset": "test_string"}'); -$response = $sg->client->user()->webhooks()->parse()->stats()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->user()->webhooks()->parse()->stats()->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"; +} diff --git a/examples/whitelabel/whitelabel.php b/examples/whitelabel/whitelabel.php index d572e24d5..7642a38ac 100644 --- a/examples/whitelabel/whitelabel.php +++ b/examples/whitelabel/whitelabel.php @@ -24,47 +24,69 @@ "subdomain": "news", "username": "john@example.com" }'); -$response = $sg->client->whitelabel()->domains()->post($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->whitelabel()->domains()->post($request_body); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // List all domain whitelabels. # // GET /whitelabel/domains # $query_params = json_decode('{"username": "test_string", "domain": "test_string", "exclude_subusers": "true", "limit": 1, "offset": 1}'); -$response = $sg->client->whitelabel()->domains()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->whitelabel()->domains()->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"; +} //////////////////////////////////////////////////// // Get the default domain whitelabel. # // GET /whitelabel/domains/default # -$response = $sg->client->whitelabel()->domains()->default()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->whitelabel()->domains()->default()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // List the domain whitelabel associated with the given user. # // GET /whitelabel/domains/subuser # -$response = $sg->client->whitelabel()->domains()->subuser()->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->whitelabel()->domains()->subuser()->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Disassociate a domain whitelabel from a given user. # // DELETE /whitelabel/domains/subuser # -$response = $sg->client->whitelabel()->domains()->subuser()->delete(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); +try { + $response = $sg->client->whitelabel()->domains()->subuser()->delete(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Update a domain whitelabel. # @@ -75,30 +97,45 @@ "default": false }'); $domain_id = "test_url_param"; -$response = $sg->client->whitelabel()->domains()->_($domain_id)->patch($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->whitelabel()->domains()->_($domain_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 domain whitelabel. # // GET /whitelabel/domains/{domain_id} # $domain_id = "test_url_param"; -$response = $sg->client->whitelabel()->domains()->_($domain_id)->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->whitelabel()->domains()->_($domain_id)->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Delete a domain whitelabel. # // DELETE /whitelabel/domains/{domain_id} # $domain_id = "test_url_param"; -$response = $sg->client->whitelabel()->domains()->_($domain_id)->delete(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->whitelabel()->domains()->_($domain_id)->delete(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Associate a domain whitelabel with a given user. # @@ -108,10 +145,15 @@ "username": "jane@example.com" }'); $domain_id = "test_url_param"; -$response = $sg->client->whitelabel()->domains()->_($domain_id)->subuser()->post($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->whitelabel()->domains()->_($domain_id)->subuser()->post($request_body); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Add an IP to a domain whitelabel. # @@ -121,10 +163,15 @@ "ip": "192.168.0.1" }'); $id = "test_url_param"; -$response = $sg->client->whitelabel()->domains()->_($id)->ips()->post($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->whitelabel()->domains()->_($id)->ips()->post($request_body); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Remove an IP from a domain whitelabel. # @@ -132,20 +179,30 @@ $id = "test_url_param"; $ip = "test_url_param"; -$response = $sg->client->whitelabel()->domains()->_($id)->ips()->_($ip)->delete(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->whitelabel()->domains()->_($id)->ips()->_($ip)->delete(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Validate a domain whitelabel. # // POST /whitelabel/domains/{id}/validate # $id = "test_url_param"; -$response = $sg->client->whitelabel()->domains()->_($id)->validate()->post(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->whitelabel()->domains()->_($id)->validate()->post(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Create an IP whitelabel # @@ -156,50 +213,75 @@ "ip": "192.168.1.1", "subdomain": "email" }'); -$response = $sg->client->whitelabel()->ips()->post($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->whitelabel()->ips()->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 IP whitelabels # // GET /whitelabel/ips # $query_params = json_decode('{"ip": "test_string", "limit": 1, "offset": 1}'); -$response = $sg->client->whitelabel()->ips()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->whitelabel()->ips()->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"; +} //////////////////////////////////////////////////// // Retrieve an IP whitelabel # // GET /whitelabel/ips/{id} # $id = "test_url_param"; -$response = $sg->client->whitelabel()->ips()->_($id)->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->whitelabel()->ips()->_($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 IP whitelabel # // DELETE /whitelabel/ips/{id} # $id = "test_url_param"; -$response = $sg->client->whitelabel()->ips()->_($id)->delete(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->whitelabel()->ips()->_($id)->delete(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Validate an IP whitelabel # // POST /whitelabel/ips/{id}/validate # $id = "test_url_param"; -$response = $sg->client->whitelabel()->ips()->_($id)->validate()->post(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->whitelabel()->ips()->_($id)->validate()->post(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Create a Link Whitelabel # @@ -211,50 +293,75 @@ "subdomain": "mail" }'); $query_params = json_decode('{"limit": 1, "offset": 1}'); -$response = $sg->client->whitelabel()->links()->post($request_body, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->whitelabel()->links()->post($request_body, $query_params); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Retrieve all link whitelabels # // GET /whitelabel/links # $query_params = json_decode('{"limit": 1}'); -$response = $sg->client->whitelabel()->links()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->whitelabel()->links()->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"; +} //////////////////////////////////////////////////// // Retrieve a Default Link Whitelabel # // GET /whitelabel/links/default # $query_params = json_decode('{"domain": "test_string"}'); -$response = $sg->client->whitelabel()->links()->default()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->whitelabel()->links()->default()->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"; +} //////////////////////////////////////////////////// // Retrieve Associated Link Whitelabel # // GET /whitelabel/links/subuser # $query_params = json_decode('{"username": "test_string"}'); -$response = $sg->client->whitelabel()->links()->subuser()->get(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->whitelabel()->links()->subuser()->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"; +} //////////////////////////////////////////////////// // Disassociate a Link Whitelabel # // DELETE /whitelabel/links/subuser # $query_params = json_decode('{"username": "test_string"}'); -$response = $sg->client->whitelabel()->links()->subuser()->delete(null, $query_params); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->whitelabel()->links()->subuser()->delete(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 a Link Whitelabel # @@ -264,40 +371,60 @@ "default": true }'); $id = "test_url_param"; -$response = $sg->client->whitelabel()->links()->_($id)->patch($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->whitelabel()->links()->_($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 Link Whitelabel # // GET /whitelabel/links/{id} # $id = "test_url_param"; -$response = $sg->client->whitelabel()->links()->_($id)->get(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->whitelabel()->links()->_($id)->get(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Delete a Link Whitelabel # // DELETE /whitelabel/links/{id} # $id = "test_url_param"; -$response = $sg->client->whitelabel()->links()->_($id)->delete(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->whitelabel()->links()->_($id)->delete(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Validate a Link Whitelabel # // POST /whitelabel/links/{id}/validate # $id = "test_url_param"; -$response = $sg->client->whitelabel()->links()->_($id)->validate()->post(); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->whitelabel()->links()->_($id)->validate()->post(); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +} //////////////////////////////////////////////////// // Associate a Link Whitelabel # @@ -307,7 +434,12 @@ "username": "jane@example.com" }'); $link_id = "test_url_param"; -$response = $sg->client->whitelabel()->links()->_($link_id)->subuser()->post($request_body); -echo $response->statusCode(); -echo $response->body(); -print_r($response->headers()); + +try { + $response = $sg->client->whitelabel()->links()->_($link_id)->subuser()->post($request_body); + print $response->statusCode() . "\n"; + print_r($response->headers()); + print $response->body() . "\n"; +} catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; +}