Exemplo n.º 1
0
 public function testRequest()
 {
     require __DIR__ . '/cfgs/ads_config.php';
     if (isset($proxyHost) && isset($proxyPort)) {
         RestfulEnvironment::setProxy($proxyHost, $proxyPort);
     }
     if (isset($allowAllCerts)) {
         RestfulEnvironment::setAcceptAllCerts($allowAllCerts);
     }
     $tokenSrvc = new OAuthTokenService($FQDN, $api_key, $secret_key);
     $token = $tokenSrvc->getToken('ADS');
     $this->assertTrue($token->getAccessToken() != '');
     $token = $tokenSrvc->refreshToken($token);
     $this->assertTrue($token->getAccessToken() != '');
 }
Exemplo n.º 2
0
 public function testRequest()
 {
     require __DIR__ . '/cfgs/ads_config.php';
     if (isset($proxyHost) && isset($proxyPort)) {
         RestfulEnvironment::setProxy($proxyHost, $proxyPort);
     }
     if (isset($allowAllCerts)) {
         RestfulEnvironment::setAcceptAllCerts($allowAllCerts);
     }
     $osrvc = new OAuthTokenService($FQDN, $api_key, $secret_key);
     $token = $osrvc->getToken('ADS');
     $adsService = new ADSService($FQDN, $token);
     $category = Category::AUTO;
     $ua = 'Mozilla/5.0 (Android; Mobile; rv:13.0) Gecko/13.0 Firefox/13.0';
     $udid = '938382893239492349234923493249';
     $response = $adsService->getAdvertisement($category, $ua, $udid);
     $this->assertTrue($response->getContent() != null);
 }
Exemplo n.º 3
0
 public function testRequest()
 {
     require __DIR__ . '/cfgs/sms_config.php';
     if (isset($proxyHost) && isset($proxyPort)) {
         RestfulEnvironment::setProxy($proxyHost, $proxyPort);
     }
     if (isset($allowAllCerts)) {
         RestfulEnvironment::setAcceptAllCerts($allowAllCerts);
     }
     $osrvc = new OAuthTokenService($FQDN, $api_key, $secret_key);
     $token = $osrvc->getToken('SMS');
     $srvc = new SMSService($FQDN, $token);
     $response = $srvc->getMessages($getMsgsShortCode);
     $this->assertTrue($response->getResourceUrl() != null);
     $response = $srvc->sendSMS($phoneNumber, 'test msg ok', false);
     $this->assertTrue($response->getMessageId() != null);
     $msgId = $response->getMessageId();
     $response = $srvc->getSMSDeliveryStatus($msgId);
     $this->assertTrue($response->getResourceUrl() != null);
 }
Exemplo n.º 4
0
 public function testRequest()
 {
     require __DIR__ . '/cfgs/speech_config.php';
     if (isset($proxyHost) && isset($proxyPort)) {
         RestfulEnvironment::setProxy($proxyHost, $proxyPort);
     }
     if (isset($allowAllCerts)) {
         RestfulEnvironment::setAcceptAllCerts($allowAllCerts);
     }
     $osrvc = new OAuthTokenService($FQDN, $api_key, $secret_key);
     $token = $osrvc->getToken('Speech,TTS,STTC');
     $srvc = new SpeechService($FQDN, $token);
     $fname = __DIR__ . '/files/BostonCeltics.wav';
     $response = $srvc->speechToText($fname, 'Generic');
     $this->assertTrue($response != null);
     $response = $srvc->textToSpeech('text/plain', 'testing ok');
     $this->assertTrue($response != null);
     $response = $srvc->speechToTextCustom('GenericHints', $fname);
     $this->assertTrue($response != null);
 }
/** 
 * Gets an access token that will be cached using a file. 
 *
 * This method works first trying to load the file specified in config, 
 * and, if a saved OAuth token isn't found, this method will send an API 
 * request. The OAuth token will then be saved for future use.
 *
 * @return OAuthToken OAuth token that can be used for authorization
 * @throws OAuthException if API request was not successful or if 
 *                        there was a file IO issue
 */
function getFileToken()
{
    require __DIR__ . '/../config.php';
    // maintain backwards compability with older configs
    if (isset($api_key)) {
        $clientId = $api_key;
    }
    if (isset($secret_key)) {
        $clientSecret = $secret_key;
    }
    if (isset($oauth_file)) {
        $oauthFile = $oauth_file;
    }
    $token = OAuthToken::loadToken($oauthFile);
    if ($token == null || $token->isAccessTokenExpired()) {
        $tokenSrvc = new OAuthTokenService($FQDN, $clientId, $clientSecret);
        $token = $tokenSrvc->getTokenUsingScope($scope);
        // save token for future use
        $token->saveToken($oauthFile);
    }
    return $token;
}
 */
session_start();
require __DIR__ . '/../config.php';
require_once __DIR__ . '/../lib/OAuth/OAuthToken.php';
require_once __DIR__ . '/../lib/OAuth/OAuthTokenService.php';
require_once __DIR__ . '/../lib/Util/Util.php';
require_once __DIR__ . '/../lib/Speech/SpeechService.php';
use Att\Api\OAuth\OAuthToken;
use Att\Api\OAuth\OAuthTokenService;
use Att\Api\Util\Util;
use Att\Api\Speech\SpeechService;
$arr = null;
try {
    $token = OAuthToken::loadToken($oauth_file);
    if ($token == null || $token->isAccessTokenExpired()) {
        $tokenSrvc = new OAuthTokenService($FQDN, $api_key, $secret_key);
        $token = $tokenSrvc->getTokenUsingScope($scope);
        $token->saveToken($oauth_file);
    }
    $speechSrvc = new SpeechService($FQDN, $token);
    $speechContext = $_POST['speechContext'];
    $speechFile = $_POST['speechFile'];
    $xArg = $_POST['x_arg'];
    $subContext = $_POST['x_subcontext'];
    $chunked = isset($_POST['chunked']) ? true : null;
    $allowedFiles = array('boston_celtics.wav', 'california.amr', 'coffee.amr', 'doctors.wav', 'nospeech.wav', 'samplerate_conflict_error.wav', 'this_is_a_test.spx', 'too_many_channels_error.wav', 'boston_celtics.wav');
    if (!in_array($speechFile, $allowedFiles, true)) {
        throw new Exception('Invalid speech file specified');
    }
    $flocation = $audioFolder . '/' . $speechFile;
    if ($speechContext !== 'Gaming') {
Exemplo n.º 7
0
// Use any namespaced classes.
use Att\Api\ADS\ADSService;
use Att\Api\ADS\Category;
use Att\Api\OAuth\OAuthTokenService;
use Att\Api\Srvc\ServiceException;
// Use the app account settings from developer.att.com for the following values.
// Make sure that the API scope is set to ADS for the Advertising API before
// retrieving the App Key and App Secret.
// Enter the value from the 'App Key' field obtained at developer.att.com
// in your app account.
$clientId = 'ENTER VALUE!';
// Enter the value from the 'App Secret' field obtained at developer.att.com
// in your app account.
$clientSecret = 'ENTER VALUE!';
// Create the service for requesting an OAuth access token.
$osrvc = new OAuthTokenService('https://api.att.com', $clientId, $clientSecret);
// Get the OAuth access token using the ADS API scope.
$token = $osrvc->getToken('ADS');
// Create the service for interacting with the Advertising API.
$adsSrvc = new ADSService('https://api.att.com', $token);
try {
    // Specify the user agent (must be mobile).
    $ua = 'Mozilla/5.0 (Android; Mobile; rv:13.0) Gecko/13.0 Firefox/13.0';
    // Specify a unique id.
    $udid = '938382893239492349234923493249';
    // Send the request to the API Gateway for getting an advertisement
    // using 'auto' as the category.
    $cat = Category::AUTO;
    $response = $adsSrvc->getAdvertisement($cat, $ua, $udid);
    echo 'clickUrl: ' . $response->getClickUrl() . "\n";
    echo 'adType: ' . $response->getAdsType() . "\n";
 /** 
  * Gets an access token that will be cached using a file. 
  *
  * This method works first trying to load the file specified in config, 
  * and, if a saved OAuth token isn't found, this method will send an API 
  * request. The OAuth token will then be saved for future use.
  *
  * @return OAuthToken OAuth token that can be used for authorization
  * @throws OAuthException if API request was not successful or if 
  *                        there was a file IO issue
  */
 protected function getFileToken()
 {
     // load location where to save token
     include __DIR__ . '/../../config.php';
     if (!isset($oauth_file)) {
         // set default if can't load
         $oauth_file = 'token.php';
     }
     $token = OAuthToken::loadToken($oauth_file);
     if ($token == null || $token->isAccessTokenExpired()) {
         $tokenSrvc = new OAuthTokenService($this->oauthFQDN, $this->clientId, $this->clientSecret);
         $token = $tokenSrvc->getTokenUsingScope($this->scope);
         // save token for future use
         $token->saveToken($oauth_file);
     }
     return $token;
 }
 /**
  * Retrieves a client token from AT&T
  *
  * @method getClientCredentials
  *
  * @return {Response} Returns Response object
  */
 public function getClientCredentials()
 {
     // Create service for requesting an OAuth token
     $osrvc = new OAuthTokenService($this->base_url, $this->client_id, $this->client_secret);
     // Get OAuth token
     $token = $osrvc->getToken($this->clientModelScope);
     $_SESSION['client_token'] = $token->getAccessToken();
     $_SESSION['client_expires_at'] = (int) $token->getTokenExpiry();
     $_SESSION['client_refresh_token'] = $token->getRefreshToken();
     return $token;
 }
Exemplo n.º 10
0
require_once __DIR__ . '/lib/OAuth/OAuthTokenService.php';
require_once __DIR__ . '/lib/Speech/SpeechService.php';
// Use any namespaced classes.
use Att\Api\OAuth\OAuthTokenService;
use Att\Api\Speech\SpeechService;
// Use the app account settings from developer.att.com for the following values.
// Make sure that the API scope is set to SPEECH for the Speech API before
// retrieving the App Key and App Secret.
// Enter the value from the 'App Key' field obtained at developer.att.com
// in your app account.
$clientId = 'ENTER VALUE!';
// Enter the value from the 'App Secret' field obtained at developer.att.com
// in your app account.
$clientSecret = 'ENTER VALUE!';
// Create the service for requesting an OAuth access token.
$osrvc = new OAuthTokenService('https://api.att.com', $clientId, $clientSecret);
// Get the OAuth access token.
$token = $osrvc->getToken('SPEECH,STTC,TTS');
// Create the service for interacting with the Speech API.
$speechSrvc = new SpeechService('https://api.att.com', $token);
// The Speech API requires the audio files to be certain formats. In order to
// convert speech files to the proper format, the ffmpeg program may be used.
// The ffmpeg program can be downloaded from https://ffmpeg.org/
// The following try/catch blocks can be used to test the methods of the
// Speech API. To test a specific method, comment out the other try/catch blocks.
/* This try/catch block tests the speechToText method. */
try {
    // Enter the path of the file to translate. For example: $fname = '/tmp/file.wav';
    $fname = 'ENTER VALUE!';
    $speechContext = 'Generic';
    // Send the request to convert the speech file to text.
Exemplo n.º 11
0
require_once __DIR__ . '/lib/OAuth/OAuthTokenService.php';
require_once __DIR__ . '/lib/SMS/SMSService.php';
// Use any namespaced classes.
use Att\Api\OAuth\OAuthTokenService;
use Att\Api\SMS\SMSService;
// Use the app account settings from developer.att.com for the following values.
// Make sure that the API scope is set to SMS for the SMS API before
// retrieving the App Key and App Secret.
// Enter the value from the 'App Key' field obtained at developer.att.com
// in your app account.
$clientId = 'ENTER VALUE!';
// Enter the value from the 'App Secret' field obtained at developer.att.com
// in your app account.
$clientSecret = 'ENTER VALUE!';
// Create the service for requesting an OAuth access token.
$osrvc = new OAuthTokenService('https://api.att.com', $clientId, $clientSecret);
// Get the OAuth access token using the SMS scope.
$token = $osrvc->getToken('SMS');
// Create the service for interacting with the SMS API.
$smsSrvc = new SMSService('https://api.att.com', $token);
/* This try/catch block tests the sendSMS method. */
try {
    // Specify the phone number where the SMS message is sent.
    // For example: $number = '5555555555';
    $number = 'ENTER VALUE!';
    // Send the SMS message to the specified phone number and
    // do not receive status notification.
    $response = $smsSrvc->sendSMS($number, 'Test Message', false);
    echo 'msgId: ' . $response->getMessageId() . "\n";
} catch (ServiceException $se) {
    echo $se->getErrorResponse();
/** 
 * Gets an access token that will be cached using the user's session. 
 *
 * This method works by first trying to load the token from the user's 
 * session, and, if a saved OAuth token isn't found, this method will send 
 * an API request.
 *
 * @return OAuthToken OAuth token that can be used for authorization
 * @throws OAuthException if API request was not successful or if 
 *                        there was a session issue  
 */
function getSessionToken()
{
    // Try loading token from session
    $token = isset($_SESSION['token']) ? unserialize($_SESSION['token']) : null;
    // No token or token is expired... send token request
    if (!$token || $token->isAccessTokenExpired()) {
        // check for error/error description in request params
        if (isset($_REQUEST['error'])) {
            $error = $_REQUEST['error'];
            $errorDesc = '';
            if (isset($_REQUEST['error_description'])) {
                $errorDesc = $_REQUEST['error_description'];
            }
            throw new OAuthException($error, $errorDesc);
        }
        $code = null;
        // check for code in request params
        if (isset($_REQUEST['code'])) {
            $code = new OAuthCode($_REQUEST['code']);
        } else {
            $error = 'Invalid state';
            $errrorDesc = 'No code found in parameter';
            throw new OAuthException($error, $errrorDesc);
        }
        $fqdn = getFqdn();
        $tokenSrvc = new OAuthTokenService($fqdn, CLIENT_ID, CLIENT_SECRET);
        $token = $tokenSrvc->getTokenUsingCode($code);
        $_SESSION['token'] = serialize($token);
    }
    return $token;
}
Exemplo n.º 13
0
// Make sure that the API scope is set to IMMN for the In-App Messaging API before
// retrieving the App Key and App Secret.
// Enter the value from the 'App Key' field obtained at developer.att.com
// in your app account.
$clientId = 'ENTER VALUE!';
// Enter the value from the 'App Secret' field obtained at developer.att.com
// in your app account.
$clientSecret = 'ENTER VALUE!';
// Get the OAuth code by opening a browser to the following URL:
// https://api.att.com/oauth/v4/authorize?client_id=CLIENT_ID&scope=SCOPE&redirect_uri=REDIRECT_URI
// replacing CLIENT_ID, SCOPE, and REDIRECT_URI with the values configured at
// developer.att.com.
// After authenticating, copy the OAuth code from the browser URL.
$oauthCode = "ENTER VALUE!";
// Create the service for requesting an OAuth access token
$osrvc = new OAuthTokenService('https://api.att.com', $clientId, $clientSecret);
// Get the OAuth token using the OAuth code.
$token = $osrvc->getTokenUsingCode(new OAuthCode($oauthCode));
// Create the service for interacting with the In-App Messaging API.
$immnSrvc = new IMMNService('https://api.att.com', $token);
// The following lines of code can be used to test the method calls for
// the IMMNService class. To test a specific method, comment out
// the other method.
/* This try/catch block tests the sendMessage method. */
try {
    // Specify the address to where the message is sent.
    $addr = array('ENTER VALUE!');
    // Send a test message.
    $response = $immnSrvc->sendMessage($addr, 'Text', 'Subject');
    echo "msgId: " . $response . "\n";
} catch (ServiceException $se) {
Exemplo n.º 14
0
// Enter the API scopes for the resources that you want the token to access.
// All the scopes specified below must be enabled for the App Key and
// App Secret as mentioned above. Note: it is not required to specify all the
// scopes of all the enabled APIs, only those that the token should have access to.
$scopes = 'ENTER_SCOPE_ONE,ENTER_SCOPE_TWO';
// Enter the value from the 'App Key' field obtained at developer.att.com
// in your app account.
$clientId = 'ENTER VALUE!';
// Enter the value from the 'App Secret' field obtained at developer.att.com
// in your app account.
$clientSecret = 'ENTER VALUE!';
// The OAuth access token can be obtained in the following ways.
// Client Credentials - Does not require user authentication to use the API.
// Authorization Code - Requires user authentication to use the API.
// Create the service for requesting an OAuth access token.
$osrvc = new OAuthTokenService('https://api.att.com', $clientId, $clientSecret);
/* This try/catrch block shows the Client Credentials flow. */
try {
    // Get the OAuth access token using the previously specified scopes.
    $token = $osrvc->getToken($scopes);
    echo 'Client Credentials access token: ' . $token->getAccessToken() . "\n";
} catch (OAuthException $se) {
    echo $se->getErrorDescription();
}
/* This try/catch block shows the Authorization Code flow. */
try {
    // Get the OAuth code by opening a browser to the following URL:
    // https://api.att.com/oauth/v4/authorize?client_id=CLIENT_ID&scope=SCOPE&redirect_uri=REDIRECT_URI
    // replacing CLIENT_ID, SCOPE, and REDIRECT_URI with the values configured at
    // developer.att.com.
    // After authenticating, copy the OAuth code from the browser URL.
Exemplo n.º 15
0
require_once __DIR__ . '/../lib/OAuth/OAuthCode.php';
require_once __DIR__ . '/../lib/OAuth/OAuthTokenService.php';
require_once __DIR__ . '/../lib/Restful/RestfulEnvironment.php';
use Att\Api\OAuth\OAuthToken;
use Att\Api\OAuth\OAuthTokenService;
use Att\Api\OAuth\OAuthCode;
use Att\Api\Restful\RestfulEnvironment;
use Exception;
if (isset($proxy_host) && isset($proxy_port)) {
    RestfulEnvironment::setProxy($proxy_host, $proxy_port);
}
if (isset($accept_all_certs)) {
    RestfulEnvironment::setAcceptAllCerts($accept_all_certs);
}
try {
    $tokenSrvc = new OAuthTokenService($FQDN, $api_key, $secret_key);
    $token = null;
    if (isset($_POST['code'])) {
        $code = new OAuthCode($_POST['code']);
        $token = $tokenSrvc->getTokenUsingCode($code);
    } else {
        $token = $tokenSrvc->getTokenUsingScope('WEBRTC');
    }
    $_SESSION['token'] = serialize($token);
    $arr = array('access_token' => $token->getAccessToken(), 'refresh_token' => $token->getRefreshToken(), 'expires_in' => $token->getExpiresIn());
    echo json_encode($arr);
} catch (Exception $e) {
    if (function_exists('http_response_code')) {
        http_response_code(500);
    } else {
        header("HTTP/1.1 500 Internal Server Error");
Exemplo n.º 16
0
require_once __DIR__ . '/lib/Payment/PaymentService.php';
// Use any namespaced classes.
use Att\Api\Notary\NotaryService;
use Att\Api\OAuth\OAuthTokenService;
use Att\Api\Payment\PaymentService;
// Use the app account settings from developer.att.com for the following values.
// Make sure that the API scope is set to Payment for the Payment API before
// retrieving the App Key and App Secret.
// Enter the value from the 'App Key' field obtained at developer.att.com
// in your app account.
$clientId = 'ENTER VALUE!';
// Enter the value from the 'App Secret' field obtained at developer.att.com
// in your app account.
$clientSecret = 'ENTER VALUE!';
// Create the service for requesting an OAuth access token.
$osrvc = new OAuthTokenService('https://api.att.com', $clientId, $clientSecret);
// Get the OAuth access token using the Payment scope.
$token = $osrvc->getToken('Payment');
// Create the service for interacting with the Notary API
$notarySrvc = new NotaryService('https://api.att.com', $clientId, $clientSecret);
// Create the service for interacting with the Payment API
$paymentSrvc = new PaymentService('https://api.att.com', $token);
// The following try/catch blocks can be used to test the methods of the
// Payment API. To test a specific method, comment out the other try/catch blocks.
/* This try/catch block tests the getNotary method. */
try {
    // Specify the payload.
    $payload = 'ENTER VALUE!';
    // Send the request for getting the notary.
    $response = $notarySrvc->getNotary($payload);
    echo 'signature: ' . $response->getSignature() . "\n";