Skip to content

Instantly share code, notes, and snippets.

@t2-support-gists
Last active October 10, 2015 17:08
Show Gist options
  • Select an option

  • Save t2-support-gists/3723816 to your computer and use it in GitHub Desktop.

Select an option

Save t2-support-gists/3723816 to your computer and use it in GitHub Desktop.
DC Php RESTFul App 1
AT&T API Platform Samples - DC App 1
-------------------------------------
This application demonstrates the usage of Device Capabilities API of AT&T platform.
The application allows an AT&T subscriber to retrieve the device specific information
about the mobile device.
This file describes how to set up, configure and run the PHP Application of the
AT&T API Platform sample applications. It covers all steps required to register the
application and, based on the generated API keys and secrets,
create and run one's own full-fledged sample applications.
1. Configuration
2. Installation
3. Parameters
4. Running the application
1. Configuration
Configuration consists of a few steps necessary to get an application registered
with the proper services and endpoints, depending on the type of client-side
application (autonomous/non-autonomous).
To register an application, go to
https://developer.att.com/developer/mvc/auth/login and login with
your valid username and password. Next, choose "My Apps" from the bar at the top
of the page and click the "Setup a New Application" button.
Fill in the form, in particular all fields marked as "required".
Be careful while filling in the "OAuth Redirect URL" field. It should contain the
URL that the oAuth provider will redirect users to when he/she successfully
authenticates and authorizes your application.
NOTE: You MUST select Device Capability in the list of services under field
'Services' in order to use this sample application code.
Having your application registered, you will get back an important pair of data:
an API key and Secret key. They are necessary to get your applications working with
the AT&T Platform APIs.
Initially your newly registered application is restricted to the "Sandbox"
environment only. To move it to production, you may promote it by clicking the
"Promote to production" button. Notice that you will get a different API key and
secret, so these values in your application should be adjusted accordingly.
Depending on the kind of authentication used, an application may be based on either
the Autonomous Client or the Web-Server Client OAuth flow (see
https://developer.att.com/apis/oauth-2/docs respectively).
2. Installation
Requirements:
Apache web server
PHP 5.4+
PHP CURL extension
Apache and PHP configured. The package manager on most GNU/Linux systems should automatically
configure Apache/PHP upon installation.
Installation:
Install Apache, PHP, and PHP CURL extension according to their respective documentation.
Copy the sample application folder to Apache web root folder, for example /var/www/html.
3. Parameters
Each application contains a config.php file. This file holds configurable parameters described in an
easy-to-read format. Please modify the config.php file using the comments specified within the file.
Note: If your application is promoted from Sandbox environment to Production environment and you decide to use
production application settings, you must update parameters as per production application details.
4. Running the application
After the sample application folder has been copied to the Apache web root folder, you need to start Apache.
Once Apache has been started, use a web browser and open the the web page to where you copied the sample application folder.
For example, http://localhost/app1/index.php
<?php
$api_key = "82f873f065eb1f0d909b95a99af79241";
$secret_key = "be0f17906e0f0fdc";
$FQDN = "https://api.att.com";
$authorize_redirect_uri = "https://lprod.code-api-att.com/APIPlatform/2/2/0/PROD/PHP-RESTful/DC/app1/index.php";
$scope = "DC";
$linkSource = "https://gist.github.com/3723816";
$linkDownload = "https://github.com/attdevsupport/ATT_APIPlatform_SampleApps/tree/master/RESTFul/DC/PHP/app1";
$linkHelp = "https://raw.github.com/attdevsupport/ATT_APIPlatform_SampleApps/master/RESTFul/DC/PHP/app1/README.txt";
/* List global configuration constants
define('API_KEY', '82f873f065eb1f0d909b95a99af79241');
define('SECRET_KEY', 'be0f17906e0f0fdc');
//FDQN = Fully qualified domain name
define('FQDN', 'https://api.att.com');
//DC = Device Capabilities
define('SCOPE', 'DC');
define('REDIRECT_URL', 'https://lprod.code-api-att.com/R2-2-0/PROD/PHP-RESTful/DC/PHP/app1/oauth/callback/callback.php');
define('AUTH_CODE_URL', FQDN . '/oauth/authorize?scope='. SCOPE .'&client_id=' . API_KEY . '&redirect_uri=' . REDIRECT_URL);
define('ACCESSTOK_URL', FQDN . '/oauth/token');
define('GETDCURL', FQDN . '/rest/2/Devices/Info');
define('POSTAUTH_URL', 'https://lprod.code-api-att.com/R2-2-0/PROD/PHP-RESTful/DC/PHP/app1/index.php');
//Index in session array for storing access token
define("SESSION_TOKEN_INDEX", "devicecapabilities_access_token");
*/
?>
<?php
/*
Licensed by AT&T under 'Software Development Kit Tools Agreement.' September 2011
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION: http://developer.att.com/sdk_agreement/
Copyright 2011 AT&T Intellectual Property. All rights reserved. http://developer.att.com
For more information contact [email protected]
*/
?>
<!-- open HEADER -->
<div id="header">
<div>
<div class="hcRight">
<?php echo date("D M j G:i:s T Y"); ?>
</div>
<div class="hcLeft">Server Time:</div>
</div>
<div>
<div class="hcRight">
<script language="JavaScript" type="text/javascript">
var myDate = new Date();
document.write(myDate);
</script>
</div>
<div class="hcLeft">Client Time:</div>
</div>
<div>
<div class="hcRight">
<script language="JavaScript" type="text/javascript">
document.write("" + navigator.userAgent);
</script>
</div>
<div class="hcLeft">User Agent:</div>
</div>
<br clear="all" />
</div>
<!-- close HEADER -->
<?php
session_start();
require __DIR__ . '/config.php';
require_once __DIR__ . '/src/Controller/DCController.php';
require_once __DIR__ . '/lib/Util/Util.php';
use Att\Api\Util\Util;
$controller = new DCController();
$controller->handleRequest();
$results = $controller->getResults();
$errors = $controller->getErrors();
?>
<!DOCTYPE html>
<!--
Copyright 2014 AT&T
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html lang="en">
<head>
<title>AT&amp;T Sample DC Application - Get Device Capabilities Application</title>
<meta id="viewport" name="viewport" content="width=device-width,minimum-scale=1,maximum-scale=1">
<link rel="stylesheet" type="text/css" href="style/common.css">
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-33466541-1']);
_gaq.push(['_trackPageview']);
(function () {
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl'
: 'http://www')
+ '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<div id="pageContainer">
<div id="header">
<div class="logo">
</div>
<div id="menuButton" class="hide">
<a id="jump" href="#nav">Main Navigation</a>
</div>
<ul class="links" id="nav">
<li>
<a href="<?php echo $linkSource; ?>" target="_blank">Source<img src="images/opensource.png" /></a>
<span class="divider"> |&nbsp;</span>
</li>
<li>
<a href="<?php echo $linkDownload; ?>" target="_blank">Download<img src="images/download.png"></a>
<span class="divider"> |&nbsp;</span>
</li>
<li>
<a href="<?php echo $linkHelp; ?>" target="_blank">Help</a>
</li>
<li id="back"><a href="#top">Back to top</a>
</li>
</ul> <!-- end of links -->
</div> <!-- end of header -->
<div id="content">
<div id="contentHeading">
<h1>AT&amp;T Sample DC Application - Get Device Capabilities Application</h1>
<div class="border"></div>
<div id="introtext">
<div><b>Server Time:&nbsp;</b><?php echo Util::getServerTime(); ?></div>
<div><b>Client Time:&nbsp;</b><script>document.write("" + new Date());</script></div>
<div><b>User Agent:&nbsp;</b><script>document.write("" + navigator.userAgent);</script></div>
</div> <!-- end of introtext -->
</div> <!-- end of contentHeading -->
<!-- SAMPLE APP CONTENT STARTS HERE! -->
<div class="formBox" id="formBox">
<div class="formContainer" id="formContainer">
<h2>Feature 1: Get Device Capabilities</h2>
<div class="lightBorder"></div>
<div class="note">
<strong>OnNet Flow:</strong>
Request Device Capabilities details from the AT&amp;T network
for the mobile device of an AT&amp;T subscriber who is using an AT&amp;T direct Mobile data
connection to access this application.
<br />
<strong>OffNet Flow:</strong> Where the end-user is not on an AT&amp;T Mobile data connection
or using a Wi-Fi or tethering connection while accessing this application. This
will result in an HTTP 400 error.
</div> <!-- end note -->
<?php
if (isset($results[DCController::RESULT_DEVICE_INFO])) {
$dInfo = $results[DCController::RESULT_DEVICE_INFO];
$dcaps = $dInfo->getCapabilities();
?>
<div class="successWide">
<strong>SUCCESS:</strong>
<br />
Device parameters listed below.
</div>
<table class="kvp" id="kvp">
<thead>
<tr>
<th>Parameter</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tr>
<td data-value="Parameter">TypeAllocationCode</td>
<td data-value="Value"> <?php echo htmlspecialchars($dInfo->getTypeAllocationCode()); ?></td>
</tr>
<tr>
<td data-value="Parameter">Name</td>
<td data-value="Value"> <?php echo htmlspecialchars($dcaps->getName()); ?></td>
</tr>
<tr>
<td data-value="Parameter">Vendor</td>
<td data-value="Value"> <?php echo htmlspecialchars($dcaps->getVendor()); ?></td>
</tr>
<tr>
<td data-value="Parameter">Model</td>
<td data-value="Value"> <?php echo htmlspecialchars($dcaps->getModel()); ?></td>
</tr>
<tr>
<td data-value="Parameter">FirmwareVersion</td>
<td data-value="Value"> <?php echo htmlspecialchars($dcaps->getFirmwareVersion()); ?></td>
</tr>
<tr>
<td data-value="Parameter">UaProf</td>
<td data-value="Value"> <?php echo htmlspecialchars($dcaps->getUaProf()); ?></td>
</tr>
<tr>
<td data-value="Parameter">MmsCapable</td>
<td data-value="Value"> <?php echo $dcaps->isMmsCapable() ? 'Y' : 'N'; ?></td>
</tr>
<tr>
<td data-value="Parameter">AssistedGps</td>
<td data-value="Value"> <?php echo $dcaps->isAssistedGps() ? 'Y' : 'N'; ?></td>
</tr>
<tr>
<td data-value="Parameter">LocationTechnology</td>
<td data-value="Value"> <?php echo htmlspecialchars($dcaps->getLocationTechnology()); ?></td>
</tr>
<tr>
<td data-value="Parameter">DeviceBrowser</td>
<td data-value="Value"> <?php echo htmlspecialchars($dcaps->getDeviceBrowser()); ?></td>
</tr>
<tr>
<td data-value="Parameter">WapPushCapable</td>
<td data-value="Value"> <?php echo $dcaps->getDeviceBrowser() ? 'Y' : 'N'; ?></td>
</tr>
</tbody>
</table>
<?php } ?>
<?php
if (isset($errors[DCController::ERROR_DEVICE_INFO])) {
$err = $errors[DCController::ERROR_DEVICE_INFO];
?>
<div class="errorWide">
<b>ERROR:</b><br>
<?php echo htmlspecialchars($err); ?>
</div>
<?php } ?>
</div> <!-- end of formContainer -->
</div> <!-- end of formBox -->
<!-- SAMPLE APP CONTENT ENDS HERE! -->
</div> <!-- end of content -->
<div class="border"></div>
<div id="footer">
<div id="powered_by">
Powered by AT&amp;T Cloud Architecture
</div>
<p>
The Application hosted on this site are working examples
intended to be used for reference in creating products to consume
AT&amp;T Services and not meant to be used as part of your
product. The data in these pages is for test purposes only and
intended only for use as a reference in how the services perform.
<br /><br />
To access your apps, please go to
<a href="https://developer.att.com/developer/mvc/auth/login"
target="_blank">https://developer.att.com/developer/mvc/auth/login</a>
<br> For support refer to
<a href="https://developer.att.com/support">https://developer.att.com/support</a>
<br /><br />
&#169; 2014 AT&amp;T Intellectual Property. All rights reserved.
<a href="http://developer.att.com/" target="_blank">http://developer.att.com</a>
</p>
</div> <!-- end of footer -->
</div> <!-- end of page_container -->
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment