Vonage / vonage-php-sdk-core

Vonage REST API client for PHP. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.
https://developer.vonage.com/
Apache License 2.0
916 stars 180 forks source link

Get whole response #412

Closed tonyjesus closed 1 year ago

tonyjesus commented 1 year ago

Hey guys,

This is not an issue, it's more a feature request.

I'm using the code below to send messages and everything works perfectly. I was just wondering if there is a way to get the whole response? After inspecting the response object I can see it is an instance of Vonage\SMS\Collection and the whole response is stored inside a protected property $data. However, I cannot access it directly (for example, to keep a responses log). Would it be possible to add a method getData() that exposes the $data property?

<?php

require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../vendor/autoload.php';

$basic  = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client($basic);

$response = $client->sms()->send(
    new \Vonage\SMS\Message\SMS(TO_NUMBER, BRAND_NAME, 'A text message sent using the Nexmo SMS API')
);

$message = $response->current();

if ($message->getStatus() == 0) {
    echo "The message was sent successfully\n";
} else {
    echo "The message failed with status: " . $message->getStatus() . "\n";
}
SecondeJK commented 1 year ago

Functionality added in #425, thank you for your input!